1 25 26 package org.objectweb.jonas_lib.deployment.work; 27 28 import java.io.File ; 29 import java.net.MalformedURLException ; 30 import java.net.URL ; 31 import java.util.Vector ; 32 33 import org.objectweb.jonas.service.ServiceManager; 34 import org.objectweb.jonas.ear.EarService; 35 36 import org.objectweb.util.monolog.api.BasicLevel; 37 38 44 public class EarCleanTask extends AbsCleanTask { 45 46 49 private static DeployerLog earDeployerLog = null; 50 51 54 private static URL earAppsUrl = null; 55 56 61 public EarCleanTask(URL earApps, DeployerLog earDeployerLog) { 62 super(); 63 EarCleanTask.earAppsUrl = earApps; 64 EarCleanTask.earDeployerLog = earDeployerLog; 65 } 66 67 73 protected boolean isValidLogEntry(LogEntry logEntry) throws CleanerException { 74 String fTimeStamp = null; 75 File earLogEntryFile = logEntry.getOriginal(); 76 String earLogEntryUnpackedDir = logEntry.getCopy().getName(); 77 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 79 getLogger().log(BasicLevel.DEBUG, 80 "LogEntry <" + earLogEntryFile.getName() + "> exist :" + earLogEntryFile.exists()); 81 } 82 83 if (!earLogEntryFile.exists()) { 85 return false; 86 } 87 88 try { 90 fTimeStamp = FileManager.fileToTimeStampDir(earLogEntryFile.toURL()); 91 } catch (FileManagerException efme) { 92 throw new CleanerException("Can't get the timestamp of the file " + earLogEntryFile + " : " 93 + efme.getMessage()); 94 } catch (MalformedURLException mue) { 95 throw new CleanerException("Can't get the timestamp of the file " + earLogEntryFile + " : " 96 + mue.getMessage()); 97 } 98 99 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 100 getLogger().log(BasicLevel.DEBUG, "LogEntry fTimeStamp :" + fTimeStamp); 101 getLogger().log(BasicLevel.DEBUG, "LogEntry isValid :" + fTimeStamp.equalsIgnoreCase(earLogEntryUnpackedDir)); 102 } 103 104 return (fTimeStamp.equalsIgnoreCase(earLogEntryUnpackedDir)); 106 107 } 108 109 114 protected void removeLogEntry(LogEntry logEntry) throws CleanerException { 115 String earLogEntryUnpackedDir = logEntry.getCopy().getName(); 116 117 File dirEar = new File (earAppsUrl.getFile() + File.separator + earLogEntryUnpackedDir); 118 119 removeRecursiveDirectory(dirEar); 120 121 try { 122 earDeployerLog.removeEntry(logEntry); 123 } catch (DeployerLogException edle) { 124 throw new CleanerException("Can't remove an entry" + edle.getMessage()); 125 } 126 127 } 128 129 133 protected Vector getLogEntries() { 134 return earDeployerLog.getEntries(); 135 } 136 137 143 protected boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException { 144 145 ServiceManager sm = null; 147 148 try { 149 sm = ServiceManager.getInstance(); 150 } catch (Exception e) { 151 throw new CleanerException("Cannot get ServiceManager instance"); 152 } 153 EarService earService = (EarService) sm.getEarService(); 154 155 return earService.isEarDeployedByUnpackName(logEntry.getCopy().getName()); 157 } 158 } | Popular Tags |