All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.technologybrewery.fermenter.mda.CleanMojo Maven / Gradle / Ivy

The newest version!
package org.technologybrewery.fermenter.mda;

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

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
 * Removes transient code generated by Fermenter.
 */
@Mojo(name = "clean", threadSafe = true)
public class CleanMojo extends AbstractMojo {

    /**
     * Base generated main source directory. All generated source code will wind up underneath this folder. This folder
     * will be cleaned as part of the clean target, and its contents should not be put under version control.
     */
    @Parameter(required = true, defaultValue = "${project.basedir}/src/generated")
    private File generatedBasedir;

    /**
     * Base generated test source directory. All generated test source code will wind up underneath this folder. This
     * folder will be cleaned as part of the clean target, and its contents should not be put under version control.
     */
    @Parameter(required = true, defaultValue = "${project.basedir}/src/generated-test")
    private File generatedTestBasedir;

    /**
     * {@inheritDoc}
     */
    public void execute() throws MojoExecutionException, MojoFailureException {
        removeDirectory(generatedBasedir);
        removeDirectory(generatedTestBasedir);
    }

    private void removeDirectory(File dir) {
        if (dir != null && dir.exists() && dir.isDirectory()) {
            getLog().info("Deleting " + dir.getAbsolutePath());
            try {
                FileUtils.deleteDirectory(dir);
            } catch (IOException e) {
                getLog().error("Problem encountered removing a directory!", e);
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy