1 package net.sourceforge.importscrubber.ant; 2 3 import java.io.File ; 4 5 import net.sourceforge.importscrubber.*; 6 7 import org.apache.tools.ant.BuildException; 8 import org.apache.tools.ant.Task; 9 10 11 18 public class ImportScrubberTask extends Task { 19 private boolean verbose; 20 private boolean recurse; 21 private String rootString; 22 private String classRoot; 23 private String formatID; 24 private boolean sortjavalibshigh; 25 private String encoding; 26 27 public void setVerbose(boolean verbose) { 28 this.verbose = verbose; 29 } 30 31 public void setSortjavalibshigh(boolean sortjavalibshigh) { 32 this.sortjavalibshigh = sortjavalibshigh; 33 } 34 35 public void setRecurse(boolean recurse) { 36 this.recurse = recurse; 37 } 38 39 public void setRoot(String rootString) { 40 this.rootString = rootString; 41 } 42 43 public void setClassRoot(String classRootString) { 44 this.classRoot = classRootString; 45 } 46 47 public void setFormat(String format) { 48 this.formatID = format; 49 } 50 51 public void setEncoding(String encoding) { 52 this.encoding = encoding; 53 } 54 55 public void execute() throws BuildException { 56 if ((rootString == null) || (rootString.length() == 0)) { 57 throw new BuildException("You must set a root for the ImportScrubber task to work"); 58 } 59 60 int formatIndex = StatementFormat.BREAK_NONE; 61 if (formatID.equals("each")) { 62 formatIndex = StatementFormat.BREAK_EACH_PACKAGE; 63 } 64 File root = new File (rootString); 65 if (!root.exists()) { 66 throw new BuildException("The root " + rootString + " does not exist"); 67 } 68 69 try { 70 ImportScrubber scrubber = new ImportScrubber(encoding); 71 StatementFormat format = new StatementFormat(sortjavalibshigh, formatIndex, 5, true); 72 scrubber.setFormat(format); 73 scrubber.setFileRoot(rootString, classRoot, recurse); 74 scrubber.buildTasks(scrubber.getFilesIterator()); 75 scrubber.runTasks(new IProgressMonitor() { 76 public void taskStarted(ScrubTask task) {} 77 public void taskComplete(ScrubTask task) {} 78 }); 79 } catch (Exception ex) { 80 ex.printStackTrace(); 81 throw new BuildException(ex); 82 } 83 } 84 } | Popular Tags |