Example usage for org.apache.maven.execution BuildSuccess BuildSuccess

List of usage examples for org.apache.maven.execution BuildSuccess BuildSuccess

Introduction

In this page you can find the example usage for org.apache.maven.execution BuildSuccess BuildSuccess.

Prototype

public BuildSuccess(MavenProject project, long time) 

Source Link

Document

Creates a new build summary for the specified project.

Usage

From source file:net.java.jpatch.maven.common.AbstractMavenMojo.java

License:Apache License

/**
 * Build MAVEN project./*w w  w  .j  av  a 2 s .c  om*/
 * 
 * @param project the MAVEN project.
 * @param buildGoals the goals;
 * @param buildProfiles the profiles;
 * 
 * @return the build summary.
 */
private BuildSummary buildMavenProject(MavenProject project, List<String> buildGoals,
        List<String> buildProfiles) {
    BuildSummary result;
    InvocationRequest request = new InvocationBuildRequest();
    request.setPomFile(project.getFile());
    request.setGoals(buildGoals);
    request.setRecursive(false);
    request.setProfiles(buildProfiles);
    request.setProperties(properties);

    Date startTime = new Date();
    try {
        getLog().info("");
        getLog().info("Build project [" + project.getId() + "]");
        getLog().info("Command " + new MavenCommandLineBuilder().build(request));
        getLog().info("");

        InvocationResult invokerResult = invoker.execute(request);
        if (invokerResult.getExecutionException() != null) {
            throw invokerResult.getExecutionException();
        }
        if (invokerResult.getExitCode() != 0) {
            throw new MojoFailureException("Exit code was " + invokerResult.getExitCode());
        }
        result = new BuildSuccess(project, new Date().getTime() - startTime.getTime());
    } catch (Exception e) {
        Date finished = new Date();
        result = new BuildFailure(project, finished.getTime() - startTime.getTime(), e);
    }
    return result;
}