01: package net.sourceforge.importscrubber.ant;
02:
03: import java.io.File;
04:
05: import net.sourceforge.importscrubber.*;
06:
07: import org.apache.tools.ant.BuildException;
08: import org.apache.tools.ant.Task;
09:
10: /**
11: * Example:
12: *
13: * <PRE>
14: * <importscrubber root="/home/tom/project/src" recurse="true" verbose="true"/>
15: * </PRE>
16: */
17: public class ImportScrubberTask extends Task {
18: private boolean verbose;
19: private boolean recurse;
20: private String rootString;
21: private String classRoot;
22: private String formatID;
23: private boolean sortjavalibshigh;
24: private String encoding;
25:
26: public void setVerbose(boolean verbose) {
27: this .verbose = verbose;
28: }
29:
30: public void setSortjavalibshigh(boolean sortjavalibshigh) {
31: this .sortjavalibshigh = sortjavalibshigh;
32: }
33:
34: public void setRecurse(boolean recurse) {
35: this .recurse = recurse;
36: }
37:
38: public void setRoot(String rootString) {
39: this .rootString = rootString;
40: }
41:
42: public void setClassRoot(String classRootString) {
43: this .classRoot = classRootString;
44: }
45:
46: public void setFormat(String format) {
47: this .formatID = format;
48: }
49:
50: public void setEncoding(String encoding) {
51: this .encoding = encoding;
52: }
53:
54: public void execute() throws BuildException {
55: if ((rootString == null) || (rootString.length() == 0)) {
56: throw new BuildException(
57: "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
67: + " does not exist");
68: }
69:
70: try {
71: ImportScrubber scrubber = new ImportScrubber(encoding);
72: StatementFormat format = new StatementFormat(
73: sortjavalibshigh, formatIndex, 5, true);
74: scrubber.setFormat(format);
75: scrubber.setFileRoot(rootString, classRoot, recurse);
76: scrubber.buildTasks(scrubber.getFilesIterator());
77: scrubber.runTasks(new IProgressMonitor() {
78: public void taskStarted(ScrubTask task) {
79: }
80:
81: public void taskComplete(ScrubTask task) {
82: }
83: });
84: } catch (Exception ex) {
85: ex.printStackTrace();
86: throw new BuildException(ex);
87: }
88: }
89: }
|