Version Differences for Miscellaneous Scripts

(AHPSCRIPTS-61)
(AHPSCRIPTS-62)
Line 1170:
   
  </pre>    </pre> 
       
    + = Script That Optionally Cleans Working Directory =  
    + * Sometimes we want to clean the workflow directory, other times we don't. The determination is property drive.  
       
    + ==== AHPSCRIPTS-34 ====  
    + <pre>import com.urbancode.anthill3.command.workdir.PathBuilder;  
    + import com.urbancode.anthill3.domain.source.*;  
    + import com.urbancode.anthill3.domain.workdir.*;  
    + import com.urbancode.command.path.Path;  
    + import com.urbancode.devilfish.services.file.*;  
       
    + org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("OptionallyCleanWorkingDirectory");  
       
    + SourceConfig source = SourceConfigLookup.getCurrent();  
    + if (source instanceof WithWorkDirScript) {  
    + WorkDirScript workDirConfig = ((WithWorkDirScript) source).getWorkDirScript();  
    + Path workDirPath = PathBuilder.buildPath(workDirConfig);  
    + WorkDirPath.setPath(workDirPath);  
    + log.warn("Setting working directory to " + workDirPath.getPathStr());  
    + }  
    + else {  
    + log.warn("NOT setting working directory. Source Configuration does not support it.");  
    + }  
       
    + if (Boolean.valueOf(PropertyLookup.getValue("shouldCleanup")).booleanValue()) {  
    + log.warn("Workflow property configured to clean the working directory.");  
    + FileServiceClient service = new FileServiceClient(JobTraceLookup.getCurrent().getAgent().getEndpoint());  
       
    + File workDir = new File(WorkDirPath.get().getPathStr());  
    + FileInfo info = service.getFileInfo(workDir);  
       
    + if (info.exists()) {  
    + log.warn("Directory exists. Deleting directory \'"+info.getPath()+"\'.");  
       
    + results = service.deleteFile(workDir);  
       
    + log.warn("Cleanup of " + info.getPath() + " complete!");  
    + log.warn("Successfully removed " + results.filesDeleted + " files/directories.");  
    + log.warn("Failed to remove " + results.getFailedDeletionCount() + " files/directories.");  
    + if (results.hasFailedDeletions()) {  
    + throw new Exception("Failed to clean the working directory");  
    + }  
    + }  
    + else {  
    + log.warn("Directory does not exist. No action needed.");  
    + }  
    + }  
    + else {  
    + log.warn("Workflow property configured to NOT clean the working directory.");  
    + }</pre>