aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-11-27 11:46:40 +0100
committerReinier Zwitserloot <reinier@tipit.to>2009-11-27 11:46:40 +0100
commit6d29e0c745428b36cc8f8f9d2e0d77ec15f45808 (patch)
treecfa852504d5f12881289feb1c26bbbe16c322230 /src
parentfb71e1bee37af989c7ff8d6df635b7ab3c5b5710 (diff)
downloadlombok-6d29e0c745428b36cc8f8f9d2e0d77ec15f45808.tar.gz
lombok-6d29e0c745428b36cc8f8f9d2e0d77ec15f45808.tar.bz2
lombok-6d29e0c745428b36cc8f8f9d2e0d77ec15f45808.zip
Preliminary version of the delombok ant task.
Diffstat (limited to 'src')
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java
new file mode 100644
index 00000000..89ea7c4d
--- /dev/null
+++ b/src/delombok/lombok/delombok/ant/DelombokTask.java
@@ -0,0 +1,80 @@
+package lombok.delombok.ant;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.Iterator;
+
+import lombok.delombok.Delombok;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.resources.FileResource;
+
+public class DelombokTask extends Task {
+ private File fromDir, toDir;
+ private boolean verbose;
+ private String encoding;
+ private Path path;
+
+ public void setFrom(File dir) {
+ this.fromDir = dir;
+ }
+
+ public void setTo(File dir) {
+ this.toDir = dir;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ public void addFileset(FileSet set) {
+ if (path == null) path = new Path(getProject());
+ path.add(set);
+ }
+
+ @Override
+ public void execute() throws BuildException {
+ if (fromDir == null && path == null) throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required.");
+ if (fromDir != null && path != null) throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other.");
+ if (toDir == null) throw new BuildException("The to attribute is required.");
+
+ Delombok delombok = new Delombok();
+ if (verbose) delombok.setVerbose(true);
+ try {
+ if (encoding != null) delombok.setCharset(encoding);
+ } catch (UnsupportedCharsetException e) {
+ throw new BuildException("Unknown charset: " + encoding, getLocation());
+ }
+
+ delombok.setOutput(toDir);
+ try {
+ if (fromDir != null) delombok.delombok(fromDir);
+ else {
+ Iterator<?> it = path.iterator();
+ while (it.hasNext()) {
+ FileResource fileResource = (FileResource) it.next();
+ File baseDir = fileResource.getBaseDir();
+ if (baseDir == null) {
+ File file = fileResource.getFile();
+ System.out.printf("Processing raw file: %s\n", file);
+ delombok.delombok(file.getParentFile(), file.getName());
+ } else {
+ System.out.printf("Processing based file: %s -- %s\n", baseDir, fileResource.getName());
+ delombok.delombok(baseDir, fileResource.getName());
+
+ }
+ }
+ }
+ } catch (IOException e) {
+ throw new BuildException("I/O problem during delombok", e, getLocation());
+ }
+ }
+}