1 2 24 25 31 32 package com.sun.enterprise.deployment.autodeploy; 33 34 import java.io.*; 35 import java.util.*; 36 import java.util.logging.Logger ; 37 import java.util.logging.Level ; 38 import com.sun.enterprise.server.Constants; 39 40 45 46 public class AutoDeployedFilesManager { 47 48 private static final Logger sLogger=AutoDeployControllerImpl.sLogger; 49 protected static final String STATUS_DIR_NAME = ".autodeploystatus"; 50 protected String statDir = null; 51 52 53 public AutoDeployedFilesManager() { 54 } 55 56 protected AutoDeployedFilesManager(String s) { 57 statDir = s; 58 } 59 60 64 public static AutoDeployedFilesManager loadStatus(File statusDir) throws Exception { 65 return loadStatus(statusDir.getAbsolutePath()); 66 } 67 68 public static AutoDeployedFilesManager loadStatus(String autoDeploymentDir) throws Exception { 69 70 String statusDir = autoDeploymentDir + File.separator + STATUS_DIR_NAME; 71 String sysAppDirPath = System.getProperty(Constants.INSTALL_ROOT) + 72 File.separator + Constants.LIB + File.separator + 73 Constants.LIB_INSTALL + File.separator + 74 Constants.LIB_INSTALL_APPLICATIONS; 75 76 File fileObj = new File(statusDir); 77 78 if (!fileObj.exists() && !autoDeploymentDir.equals(sysAppDirPath)) { 82 sLogger.log(Level.INFO, "autoDeployment status dir missing, creating a new one"); 83 fileObj.mkdirs(); 84 } 85 AutoDeployedFilesManager adfm = new AutoDeployedFilesManager(statusDir); 86 return adfm; 87 88 } 89 90 public void writeStatus() throws Exception { 91 } 93 94 98 public void setDeployedFileInfo(File f) throws Exception { 99 try { 100 File statusFile = getStatusFile(f); 101 statusFile.createNewFile(); 102 statusFile.setLastModified(f.lastModified()); 103 } catch (Exception e) { throw e; } 104 } 105 106 109 public void deleteDeployedFileInfo(File f) throws Exception { 110 try { 111 File statusFile = getStatusFile(f); 112 statusFile.delete(); 113 } catch (Exception e) { throw e;} 114 } 115 116 private File getStatusFile(File f) { 118 119 File outDir = new File(this.statDir); 120 File autoDeployDir = outDir.getParentFile(); 121 File dir = f.getParentFile(); 122 while (!dir.getAbsolutePath().equals(autoDeployDir.getAbsolutePath())) { 123 outDir = new File(outDir, dir.getName()); 124 dir = dir.getParentFile(); 125 } 126 outDir.mkdirs(); 127 return new File(outDir, f.getName()); 128 } 129 130 135 public File[] getFilesForDeployment(File[] latestFiles) { 136 137 if (latestFiles == null) return new File[0]; 138 File statusDir = new File(statDir); 139 140 ArrayList<File> arrList = new ArrayList<File>(); 141 for (File deployDirFile : latestFiles) { 142 File statusFile = getStatusFile(deployDirFile); 143 if (!statusFile.exists() || deployDirFile.lastModified() != statusFile.lastModified()) { 144 arrList.add(deployDirFile); 145 } 146 } 147 return arrList.toArray(new File[0]); 148 149 } 150 151 156 public File[] getFilesForUndeployment(File[] latestFiles) { 157 158 File statusDir = new File(statDir); 159 Set<File> statusFiles = 160 AutoDeployDirectoryScanner.getListOfFilesAsSet(statusDir, true); 161 162 if (statusFiles == null || statusFiles.isEmpty()){ 164 return null; 165 } 166 167 for (File deployDirFile : latestFiles) { 171 statusFiles.remove(getStatusFile(deployDirFile)); 172 } 173 ArrayList<File> appNames = new ArrayList<File>(); 174 File autodeployDir = statusDir.getParentFile(); 175 for(File statusDirFile : statusFiles) { 176 177 File filePath = statusDir.getParentFile(); 180 File f = statusDirFile.getParentFile(); 181 while (!f.equals(statusDir)) { 182 filePath = new File(filePath, f.getName()); 183 f = f.getParentFile(); 184 } 185 filePath = new File(filePath, statusDirFile.getName()); 186 appNames.add(filePath); 187 } 188 return appNames.toArray(new File[0]); 189 } 190 } 191 192 193 | Popular Tags |