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

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

Introduction

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

Prototype

public BuildFailure(MavenProject project, long time, Throwable cause) 

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./*from  ww w  .  j a  v  a  2 s  . com*/
 * 
 * @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;
}