1 23 24 30 31 package com.sun.enterprise.deployment.autodeploy; 32 33 import java.io.File ; 34 import java.io.FileFilter ; 35 import java.util.Set ; 36 import java.util.HashSet ; 37 import java.util.logging.Logger ; 38 import java.util.logging.Level ; 39 import com.sun.enterprise.util.i18n.StringManager; 40 41 50 public class AutoDeployDirectoryScanner implements DirectoryScanner{ 51 52 53 private static final Logger sLogger=AutoDeployControllerImpl.sLogger; 54 private static StringManager localStrings = 55 StringManager.getManager( AutoDeployDirectoryScanner.class ); 56 57 public AutoDeployDirectoryScanner() { 58 } 59 60 public void deployedEntity(File autodeployDir, File deployedEntity) { 61 try { 62 AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir); 63 adfm.setDeployedFileInfo(deployedEntity); 64 adfm.writeStatus(); 65 } catch (Exception e) { 66 printException(e); 67 } 69 70 } 71 72 public void undeployedEntity(File autodeployDir, File undeployedEntity) { 73 try { 74 AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir); 75 adfm.deleteDeployedFileInfo(undeployedEntity); 76 adfm.writeStatus(); 77 } catch (Exception e) { 78 printException(e); 79 } 81 } 82 83 88 public boolean hasNewDeployableEntity(File autodeployDir) { 89 boolean newFilesExist=false; 90 try { 91 AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir); 92 if(adfm.getFilesForDeployment(getListOfFiles(autodeployDir)).length > 0) { 93 newFilesExist=true; 95 } 96 } catch (Exception e) { 97 printException(e); 98 return false; 99 } 100 101 return newFilesExist; 102 103 } 104 public File [] getAllFilesForUndeployment(File autodeployDir) { 106 107 try { 108 AutoDeployedFilesManager adfm = AutoDeployedFilesManager.loadStatus(autodeployDir); 109 return adfm.getFilesForUndeployment(getListOfFiles(autodeployDir, true)); 110 } catch (Exception e) { 111 printException(e); 112 return new File [0]; 113 } 114 } 115 116 120 public File [] getAllDeployableModules(File autodeployDir, boolean includeSubDir) { 121 122 AutoDeployedFilesManager adfm = null; 123 try { 124 adfm = AutoDeployedFilesManager.loadStatus(autodeployDir); 125 } catch (Exception e) { 126 printException(e); 127 return new File [0]; 128 } 129 130 return adfm.getFilesForDeployment(getListOfFiles(autodeployDir, includeSubDir)); 131 } 132 133 protected void printException(Exception e) { 134 sLogger.log(Level.SEVERE, e.getMessage(), e); 135 e.printStackTrace(); 136 } 137 138 protected File [] getListOfFiles(File dir) { 139 return getListOfFiles(dir, false); 140 } 141 142 protected File [] getListOfFiles(File dir, boolean includeSubDir) { 143 return getListOfFilesAsSet(dir, includeSubDir).toArray(new File [0]); 144 } 145 146 147 static Set <File > getListOfFilesAsSet(File dir, boolean includeSubDir) { 148 Set <File > result = new HashSet <File >(); 149 File [] dirFiles = dir.listFiles(); 150 for (File dirFile : dirFiles) { 151 if (dirFile.isDirectory()) { 152 if (includeSubDir && !(dirFile.getName().equals(".autodeploystatus"))) { 153 result.addAll(getListOfFilesAsSet(dirFile, true)); 154 } 155 } else { 156 String name = dirFile.getName(); 157 String fileType = name.substring(name.lastIndexOf(".") + 1); 158 if(fileType != null && !fileType.equals("") && 159 (fileType.equals(AutoDeployConstants.EAR_EXTENSION) || 160 fileType.equals(AutoDeployConstants.WAR_EXTENSION) || 161 fileType.equals(AutoDeployConstants.JAR_EXTENSION) || 162 fileType.equals(AutoDeployConstants.RAR_EXTENSION) || 163 fileType.equals("class"))) { 164 165 result.add(dirFile); 166 } 167 168 } 169 } 170 return result; 171 } 172 173 } 174 | Popular Tags |