1 8 package org.codehaus.aspectwerkz.compiler; 9 10 import org.apache.tools.ant.BuildLogger; 11 import org.apache.tools.ant.DefaultLogger; 12 import org.apache.tools.ant.Project; 13 import org.apache.tools.ant.taskdefs.Copy; 14 import org.apache.tools.ant.taskdefs.Delete; 15 import org.apache.tools.ant.types.FileSet; 16 import org.apache.tools.ant.types.selectors.FilenameSelector; 17 18 import java.io.File ; 19 20 25 public class Utility { 26 29 private Project project; 30 31 34 private BuildLogger logger; 35 36 private boolean verbose = false; 37 38 41 public Utility() { 42 project = new Project(); 43 logger = new DefaultLogger(); 44 logger.setMessageOutputLevel(0); 45 logger.setOutputPrintStream(System.out); 46 logger.setErrorPrintStream(System.err); 47 project.addBuildListener(logger); 48 } 49 50 53 public void setVerbose(boolean verbose) { 54 if (verbose) { 55 logger.setMessageOutputLevel(2); 56 verbose = true; 57 } else { 58 logger.setMessageOutputLevel(-1); 59 verbose = false; 60 } 61 } 62 63 66 public void deleteDir(File dir) { 67 Delete task = new Delete(); 68 task.setProject(project); 69 task.setTaskName("delete"); 70 FilenameSelector fns = new FilenameSelector(); 71 fns.setName("**/*"); 72 FileSet fs = new FileSet(); 73 fs.setDir(dir); 74 fs.addFilename(fns); 75 task.addFileset(fs); 76 task.setIncludeEmptyDirs(true); 77 task.perform(); 78 dir.delete(); 79 } 80 81 84 public void backupFile(File source, File dest) { 85 Copy task = new Copy(); 86 task.setProject(project); 87 task.setTaskName("backup"); 88 task.setVerbose(verbose); 89 90 if (source.isDirectory()) { 93 FilenameSelector fns = new FilenameSelector(); 94 fns.setName("**/*"); 95 FileSet fs = new FileSet(); 96 fs.setDir(source); 97 fs.addFilename(fns); 98 task.addFileset(fs); 99 task.setTodir(dest); 100 task.setIncludeEmptyDirs(true); 101 } else { 102 task.setFile(source); 103 task.setTofile(dest); 104 } 105 task.setOverwrite(true); 106 task.setPreserveLastModified(true); 107 task.execute(); 108 } 109 110 public void log(String msg) { 111 project.log(msg); 112 } 113 } | Popular Tags |