From 6d29e0c745428b36cc8f8f9d2e0d77ec15f45808 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 27 Nov 2009 11:46:40 +0100 Subject: Preliminary version of the delombok ant task. --- src/delombok/lombok/delombok/ant/DelombokTask.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/delombok/lombok/delombok/ant/DelombokTask.java (limited to 'src') 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 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()); + } + } +} -- cgit