package ch.sbb.maven.plugins.iib.mojos;
import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration;
import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo;
import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment;
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal;
import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId;
import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin;
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
import java.io.File;
import java.io.IOException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
/**
* Creates a .zip file from a iib-classloader Project which contains the
*
* Implemented with help from: https://github.com/TimMoore/mojo-executor/blob/master/README.md
*/
@Mojo(name = "package-udn-jar")
public class PackageUserDefinedNodeJarMojo extends AbstractMojo {
/**
* The Maven Project Object
*/
@Parameter(property = "project", required = true, readonly = true)
protected MavenProject project;
/**
* The Maven Session Object
*/
@Parameter(property = "session", required = true, readonly = true)
protected MavenSession session;
/**
* The Maven PluginManager Object
*/
@Component
protected BuildPluginManager buildPluginManager;
public void execute() throws MojoFailureException, MojoExecutionException {
executeMojo(plugin(groupId("org.apache.maven.plugins"), artifactId("maven-jar-plugin"), version("2.6")), goal("jar"),
configuration(element(name("finalName"), project.getArtifactId()), element(name("classesDirectory"), "bin")),
executionEnvironment(project, session, buildPluginManager));
// delete the archive-tmp directory
try {
FileUtils.deleteDirectory(new File(project.getBuild().getDirectory(), "archive-tmp"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}