Package org.hybridlabs.source.formatter.ant

Source Code of org.hybridlabs.source.formatter.ant.JavaImportBeautifierAntTask

package org.hybridlabs.source.formatter.ant;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.hybridlabs.source.beautifier.JavaImportBeautifierImpl;

public class JavaImportBeautifierAntTask extends Task {

    private FileSet fileSet;
    private String conventionFilePath;

    private boolean organizeImport;
    private boolean format;

    private boolean debugMode;

    public void execute() throws BuildException {
        super.execute();

        JavaImportBeautifierImpl beautifier = new JavaImportBeautifierImpl();
        beautifier.setConventionFilePath(conventionFilePath);
        beautifier.setFormat(format);
        beautifier.setOrganizeImports(organizeImport);

        // find all .java files in the specified path
        String[] fileList = fileSet.getDirectoryScanner(getProject()).getIncludedFiles();

        for (int i = 0; i < fileList.length; i++) {
            File file = new File(fileSet.getDir(getProject()).getAbsolutePath() + "/" + fileList[i]);
            try {
                beautifier.beautify(file, debugMode ? new File(file.getAbsoluteFile()+"_debug") : null);
            } catch (FileNotFoundException e) {
                throw new BuildException(e.getMessage(), e);
            } catch (IOException e) {
                throw new BuildException(e.getMessage(), e);
            }
        }

    }

    public String getConventionFilePath() {
        return conventionFilePath;
    }

    public void setConventionFilePath(String configuration) {
        this.conventionFilePath = configuration;
    }

    public FileSet getFileSet() {
        return fileSet;
    }

    public void addFileset(FileSet fileSet) {
        this.fileSet = fileSet;
    }

    public boolean isFormat() {
        return format;
    }

    public void setFormat(boolean format) {
        this.format = format;
    }

    public boolean isOrganizeImport() {
        return organizeImport;
    }

    public void setOrganizeImport(boolean organizeImport) {
        this.organizeImport = organizeImport;
    }

    public boolean isDebugMode() {
        return debugMode;
    }

    public void setDebugMode(boolean debugMode) {
        this.debugMode = debugMode;
    }



}
TOP

Related Classes of org.hybridlabs.source.formatter.ant.JavaImportBeautifierAntTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.