Search in sources :

Example 1 with Delombok

use of lombok.delombok.Delombok in project lombok by rzwitserloot.

the class DelombokTaskImpl method execute.

public void execute(Location location) 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, location);
    }
    if (classpath != null)
        delombok.setClasspath(classpath.toString());
    if (sourcepath != null)
        delombok.setSourcepath(sourcepath.toString());
    try {
        delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));
    } catch (InvalidFormatOptionException e) {
        throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help.");
    }
    delombok.setOutput(toDir);
    try {
        if (fromDir != null)
            delombok.addDirectory(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();
                    delombok.addFile(file.getParentFile(), file.getName());
                } else {
                    delombok.addFile(baseDir, fileResource.getName());
                }
            }
        }
        delombok.delombok();
    } catch (IOException e) {
        throw new BuildException("I/O problem during delombok", e, location);
    }
}
Also used : InvalidFormatOptionException(lombok.delombok.Delombok.InvalidFormatOptionException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) FileResource(org.apache.tools.ant.types.resources.FileResource) Delombok(lombok.delombok.Delombok) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 Delombok (lombok.delombok.Delombok)1 InvalidFormatOptionException (lombok.delombok.Delombok.InvalidFormatOptionException)1 BuildException (org.apache.tools.ant.BuildException)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1