Example usage for org.apache.maven.execution MavenSession getResult

List of usage examples for org.apache.maven.execution MavenSession getResult

Introduction

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

Prototype

public MavenExecutionResult getResult() 

Source Link

Usage

From source file:example.LoggingListener.java

License:Apache License

@Override
public void sessionEnded(BuildListener.Event event) {
    event.log.info("Properties passed to listener:");
    for (Map.Entry<Object, Object> entry : event.listenerProperties.entrySet()) {
        event.log.info(entry.getKey() + " = " + entry.getValue());
    }/*  w w w.j a va2 s.com*/

    MavenSession session = event.event.getSession();
    MavenProject project = session.getTopLevelProject();
    if (session.getResult().getBuildSummary(project) instanceof BuildSuccess) {
        event.log.info("FINISHED -- PASSED -- " + BuildUtil.calculateBuildTimeFor(session));
    } else {
        event.log.info("FINISHED -- FAILED -- " + BuildUtil.calculateBuildTimeFor(session));
    }
}

From source file:hudson.gridmaven.util.ExecutionEventLogger.java

License:Apache License

private void logReactorSummary(MavenSession session) {
    logger.info(chars('-', LINE_LENGTH));

    logger.info("Reactor Summary:");

    logger.info("");

    MavenExecutionResult result = session.getResult();

    for (MavenProject project : session.getProjects()) {
        StringBuilder buffer = new StringBuilder(128);

        buffer.append(project.getName());

        buffer.append(' ');
        while (buffer.length() < LINE_LENGTH - 21) {
            buffer.append('.');
        }/*from  w w w .j a v a  2s . c  o m*/
        buffer.append(' ');

        BuildSummary buildSummary = result.getBuildSummary(project);

        if (buildSummary == null) {
            buffer.append("SKIPPED");
        } else if (buildSummary instanceof BuildSuccess) {
            buffer.append("SUCCESS [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        } else if (buildSummary instanceof BuildFailure) {
            buffer.append("FAILURE [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        }

        logger.info(buffer.toString());
    }
}

From source file:hudson.gridmaven.util.ExecutionEventLogger.java

License:Apache License

private void logResult(MavenSession session) {
    logger.info(chars('-', LINE_LENGTH));

    if (session.getResult().hasExceptions()) {
        logger.info("BUILD FAILURE");
    } else {//  w  ww. j a v a  2 s.  c o m
        logger.info("BUILD SUCCESS");
    }
}

From source file:hudson.maven.util.ExecutionEventLogger.java

License:Apache License

private void logErrors(MavenSession session) {
    MavenExecutionResult result = session.getResult();

    // show all errors and them references as in MavenCli
    if (!result.getExceptions().isEmpty()) {
        ExceptionHandler handler = new DefaultExceptionHandler();

        Map<String, String> references = new LinkedHashMap<String, String>();

        for (Throwable exception : result.getExceptions()) {
            ExceptionSummary summary = handler.handleException(exception);

            logErrorSummary(summary, references, "", logger.isDebugEnabled());
        }//  w  w  w  . ja  va 2  s.  c o  m

        if (!references.isEmpty()) {
            logger.error("For more information about the errors and possible solutions"
                    + ", please read the following articles:");

            for (Map.Entry<String, String> entry : references.entrySet()) {
                logger.error(entry.getValue() + " " + entry.getKey());
            }
        }
    }
}

From source file:info.ronjenkins.maven.rtr.RTR.java

License:Apache License

@Override
public void afterSessionEnd(final MavenSession session) throws MavenExecutionException {
    // Don't allow double-execution due to double-classloading.
    if (this.disabledDueToDoubleLoad) {
        return;//www . j  a v a 2s .  co  m
    }
    if (this.disabled) {
        return;
    }
    if (session.getResult().hasExceptions()) {
        this.executeSteps(this.endFailureSteps, session, this.components);
    } else {
        this.executeSteps(this.endSuccessSteps, session, this.components);
    }
}

From source file:io.sundr.maven.GenerateBomMojo.java

License:Apache License

private void build(MavenSession session, MavenProject project, List<MavenProject> allProjects, GoalSet goals)
        throws MojoExecutionException {
    session.setProjects(allProjects);/*from ww  w . j  a  va  2  s . com*/
    ProjectIndex projectIndex = new ProjectIndex(session.getProjects());
    try {
        ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus(
                new BomDependencyGraph(session.getProjects()));
        ReactorContext reactorContext = new ReactorContextFactory(new MavenVersion(mavenVersion)).create(
                session.getResult(), projectIndex, Thread.currentThread().getContextClassLoader(),
                reactorBuildStatus, builder);
        List<TaskSegment> segments = segmentCalculator.calculateTaskSegments(session);
        for (TaskSegment segment : segments) {
            builder.buildProject(session, reactorContext, project, filterSegment(segment, goals));
        }
    } catch (Throwable t) {
        throw new MojoExecutionException("Error building generated bom:" + project.getArtifactId(), t);
    }
}

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

License:Apache License

/**
 * Executes the build of the list of projects.
 * /*from ww  w .ja  v  a 2s .com*/
 * @param projects the list of projects.
 * 
 * @throws MojoExecutionException if the method fails.
 * @throws MojoFailureException if the method fails.
 */
protected void executeBuildProjects(List<MavenProject> projects)
        throws MojoExecutionException, MojoFailureException {
    // Execute projects
    getLog().info("Execute build projects");
    MavenSession mavenSession = createMavenSession(projects);
    buildMavenSession(mavenSession);

    // Check the build result
    if (mavenSession.getResult().hasExceptions()) {
        Throwable throwable = mavenSession.getResult().getExceptions().get(0);
        throw new MojoFailureException("Error by executing the build!", throwable);
    }
}

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

License:Apache License

/**
 * Builds the MAVEN session.//from w  w w  .  j av a2 s  .  co m
 * 
 * @param session the MAVEN session.
 * 
 */
protected void buildMavenSession(MavenSession session) {
    List<String> buildGoals = Arrays.asList(goals.split(","));
    List<String> buildProfiles = null;
    if (profiles != null) {
        buildProfiles = Arrays.asList(profiles.split(","));
    }

    eventCatapult.fire(ExecutionEvent.Type.SessionStarted, session, null);
    for (MavenProject project : session.getProjects()) {
        BuildSummary buildSummary = buildMavenProject(project, buildGoals, buildProfiles);
        session.getResult().addBuildSummary(buildSummary);
        if (buildSummary instanceof BuildFailure) {
            BuildFailure bf = (BuildFailure) buildSummary;
            session.getResult().addException(bf.getCause());
            break;
        }
    }
    eventCatapult.fire(ExecutionEvent.Type.SessionEnded, session, null);
}

From source file:org.commonjava.emb.boot.log.EventLogger.java

License:Apache License

private void logReactorSummary(final MavenSession session) {
    logger.info(chars('-', LINE_LENGTH));

    logger.info("Reactor Summary:");

    logger.info("");

    final MavenExecutionResult result = session.getResult();

    for (final MavenProject project : session.getProjects()) {
        final StringBuilder buffer = new StringBuilder(128);

        buffer.append(project.getName());

        buffer.append(' ');
        while (buffer.length() < LINE_LENGTH - 21) {
            buffer.append('.');
        }//from  ww w  .j  av  a2  s  .co m
        buffer.append(' ');

        final BuildSummary buildSummary = result.getBuildSummary(project);

        if (buildSummary == null) {
            buffer.append("SKIPPED");
        } else if (buildSummary instanceof BuildSuccess) {
            buffer.append("SUCCESS [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        } else if (buildSummary instanceof BuildFailure) {
            buffer.append("FAILURE [");
            buffer.append(getFormattedTime(buildSummary.getTime()));
            buffer.append("]");
        }

        logger.info(buffer.toString());
    }
}

From source file:org.commonjava.emb.boot.log.EventLogger.java

License:Apache License

private void logResult(final MavenSession session) {
    logger.info(chars('-', LINE_LENGTH));

    if (session.getResult().hasExceptions()) {
        logger.info("BUILD FAILURE");
    } else {//w ww  .ja  va 2 s.c  o m
        logger.info("BUILD SUCCESS");
    }
}