00001
00026 package org.objectweb.jonas_lib.deployment.work;
00027
00028 import java.io.File;
00029 import java.net.MalformedURLException;
00030 import java.net.URL;
00031 import java.util.Vector;
00032
00033 import org.objectweb.jonas.service.ServiceManager;
00034 import org.objectweb.jonas.ear.EarService;
00035
00036 import org.objectweb.util.monolog.api.BasicLevel;
00037
00044 public class EarCleanTask extends AbsCleanTask {
00045
00049 private static DeployerLog earDeployerLog = null;
00050
00054 private static URL earAppsUrl = null;
00055
00061 public EarCleanTask(URL earApps, DeployerLog earDeployerLog) {
00062 super();
00063 EarCleanTask.earAppsUrl = earApps;
00064 EarCleanTask.earDeployerLog = earDeployerLog;
00065 }
00066
00073 protected boolean isValidLogEntry(LogEntry logEntry) throws CleanerException {
00074 String fTimeStamp = null;
00075 File earLogEntryFile = logEntry.getOriginal();
00076 String earLogEntryUnpackedDir = logEntry.getCopy().getName();
00077
00078
00079 getLogger().log(BasicLevel.DEBUG,
00080 "LogEntry <" + earLogEntryFile.getName() + "> exist :" + earLogEntryFile.exists());
00081
00082
00083 if (!earLogEntryFile.exists()) {
00084 return false;
00085 }
00086
00087
00088 try {
00089 fTimeStamp = FileManager.fileToTimeStampDir(earLogEntryFile.toURL());
00090 } catch (FileManagerException efme) {
00091 throw new CleanerException("Can't get the timestamp of the file " + earLogEntryFile + " : "
00092 + efme.getMessage());
00093 } catch (MalformedURLException mue) {
00094 throw new CleanerException("Can't get the timestamp of the file " + earLogEntryFile + " : "
00095 + mue.getMessage());
00096 }
00097
00098 getLogger().log(BasicLevel.DEBUG, "LogEntry fTimeStamp :" + fTimeStamp);
00099 getLogger().log(BasicLevel.DEBUG, "LogEntry isValid :" + fTimeStamp.equalsIgnoreCase(earLogEntryUnpackedDir));
00100
00101
00102 return (fTimeStamp.equalsIgnoreCase(earLogEntryUnpackedDir));
00103
00104 }
00105
00111 protected void removeLogEntry(LogEntry logEntry) throws CleanerException {
00112 String earLogEntryUnpackedDir = logEntry.getCopy().getName();
00113
00114 File dirEar = new File(earAppsUrl.getFile() + File.separator + earLogEntryUnpackedDir);
00115
00116 removeRecursiveDirectory(dirEar);
00117
00118 try {
00119 earDeployerLog.removeEntry(logEntry);
00120 } catch (DeployerLogException edle) {
00121 throw new CleanerException("Can't remove an entry" + edle.getMessage());
00122 }
00123
00124 }
00125
00130 protected Vector getLogEntries() {
00131 return earDeployerLog.getEntries();
00132 }
00133
00140 protected boolean isDeployLogEntry(LogEntry logEntry) throws CleanerException {
00141
00142
00143 ServiceManager sm = null;
00144
00145 try {
00146 sm = ServiceManager.getInstance();
00147 } catch (Exception e) {
00148 throw new CleanerException("Cannot get ServiceManager instance");
00149 }
00150 EarService earService = (EarService) sm.getEarService();
00151
00152
00153 return earService.isEarDeployedByUnpackName(logEntry.getCopy().getName());
00154 }
00155 }