KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > importscrubber > ant > ImportScrubberTask


1 package net.sourceforge.importscrubber.ant;
2
3 import java.io.File JavaDoc;
4
5 import net.sourceforge.importscrubber.*;
6
7 import org.apache.tools.ant.BuildException;
8 import org.apache.tools.ant.Task;
9
10
11 /**
12  * Example:
13  *
14  * <PRE>
15  * <importscrubber root="/home/tom/project/src" recurse="true" verbose="true"/>
16  * </PRE>
17  */

18 public class ImportScrubberTask extends Task {
19     private boolean verbose;
20     private boolean recurse;
21     private String JavaDoc rootString;
22     private String JavaDoc classRoot;
23     private String JavaDoc formatID;
24     private boolean sortjavalibshigh;
25     private String JavaDoc 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 JavaDoc rootString) {
40         this.rootString = rootString;
41     }
42
43     public void setClassRoot(String JavaDoc classRootString) {
44         this.classRoot = classRootString;
45     }
46
47     public void setFormat(String JavaDoc format) {
48         this.formatID = format;
49     }
50
51     public void setEncoding(String JavaDoc 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 JavaDoc root = new File JavaDoc(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 JavaDoc ex) {
80             ex.printStackTrace();
81             throw new BuildException(ex);
82         }
83     }
84 }
Popular Tags