Example usage for org.apache.maven.execution MavenExecutionResult getTopologicallySortedProjects

List of usage examples for org.apache.maven.execution MavenExecutionResult getTopologicallySortedProjects

Introduction

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

Prototype

List<MavenProject> getTopologicallySortedProjects();

Source Link

Usage

From source file:com.soebes.maven.extensions.BuildTimeProfiler.java

License:Apache License

private void executionResultEventHandler(MavenExecutionResult event) {
    if (lifeCyclePhases.isEmpty()) {
        return;/*from www . j av a  2  s.  c  o  m*/
    }

    orderLifeCycleOnPreparedOrder(lifeCyclePhases);

    LOGGER.debug("MBTP: executionResultEventHandler: {}", event.getProject());

    // TODO: Use better formatting
    LOGGER.info("--             Maven Build Time Profiler Summary                      --");
    LOGGER.info("------------------------------------------------------------------------");

    discoveryTimer.report();
    LOGGER.info("Project Build Time (reactor order):");
    LOGGER.info("");
    List<MavenProject> topologicallySortedProjects = event.getTopologicallySortedProjects();
    for (MavenProject mavenProject : topologicallySortedProjects) {
        LOGGER.info("{}:", mavenProject.getName());

        for (String phase : lifeCyclePhases) {
            ProjectKey proKey = mavenProjectToProjectKey(mavenProject);

            if (!mojoTimer.hasTimeForProjectAndPhase(proKey, phase)) {
                continue;
            }

            long timeForPhaseAndProjectInMillis = mojoTimer.getTimeForProjectAndPhaseInMillis(proKey, phase);
            LOGGER.info("    {} ms : {}", String.format("%8d", timeForPhaseAndProjectInMillis), phase);

        }

    }

    // LifecyclePhase.CLEAN.ordinal();
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info("Lifecycle Phase summary:");
    LOGGER.info("");
    for (String phase : lifeCyclePhases) {
        long timeForPhaseInMillis = mojoTimer.getTimeForPhaseInMillis(phase);
        LOGGER.info("{} ms : {}", String.format("%8d", timeForPhaseInMillis), phase);
    }

    // List all plugins per phase
    LOGGER.info("------------------------------------------------------------------------");
    LOGGER.info("Plugins in lifecycle Phases:");
    LOGGER.info("");
    for (String phase : lifeCyclePhases) {
        LOGGER.info("{}:", phase);
        Map<ProjectMojo, SystemTime> plugisInPhase = mojoTimer.getPluginsInPhase(phase);
        for (Entry<ProjectMojo, SystemTime> pluginInPhase : plugisInPhase.entrySet()) {
            LOGGER.info("{} ms: {}", String.format("%8d", pluginInPhase.getValue().getElapsedTime()),
                    pluginInPhase.getKey().getMojo().getFullId());
        }

    }
    LOGGER.info("------------------------------------------------------------------------");

    installTimer.report();
    downloadTimer.report();
    deployTimer.report();
    metadataInstallTimer.report();
    metadataDownloadTimer.report();
    metadataDeploymentTimer.report();

    forkTimer.report();
    forkProject.report();
}

From source file:org.commonjava.emb.boot.embed.EMBEmbedder.java

License:Apache License

public int formatErrorOutput(final EMBExecutionRequest request, final MavenExecutionResult result) {
    if (result.hasExceptions()) {
        final ExceptionHandler handler = new DefaultExceptionHandler();

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

        MavenProject project = null;//from  www .  java  2 s. c om

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

            logSummary(summary, references, "", shouldShowErrors);

            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }
        }

        logger.error("");

        if (!shouldShowErrors) {
            logger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!logger.isDebugEnabled()) {
            logger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }

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

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

        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            logger.error("");
            logger.error("After correcting the problems, you can resume the build with the command");
            logger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }

        if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(request.getReactorFailureBehavior())) {
            logger.info("Build failures were ignored.");

            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

From source file:org.commonjava.sjbi.maven3.builder.M3BuildResult.java

License:Open Source License

M3BuildResult(final MavenExecutionResult mavenResult) {
    if (mavenResult.hasExceptions()) {
        setErrors(mavenResult.getExceptions());
    }/*from  ww w  .j  a  v a2 s  .c o  m*/

    final List<ArtifactSetRef> ars = new ArrayList<ArtifactSetRef>();
    for (final MavenProject project : mavenResult.getTopologicallySortedProjects()) {
        final ProjectRef pr = new ProjectRef(project.getGroupId(), project.getArtifactId(),
                project.getVersion());
        pr.setPomFile(project.getFile());

        final ArtifactSetRef ar = new ArtifactSetRef(pr);

        final Artifact mainArtifact = project.getArtifact();
        ar.addArtifactRef(mainArtifact.getType(), mainArtifact.getClassifier(), mainArtifact.getFile());

        for (final Artifact a : project.getAttachedArtifacts()) {
            ar.addArtifactRef(a.getType(), a.getClassifier(), a.getFile());
        }

        ars.add(ar);
    }

    setArtifactSets(ars);
}

From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java

License:Open Source License

protected List<MavenProject> getSortedProjects(File basedir, Properties userProperties, File platform)
        throws Exception {
    File pom = new File(basedir, "pom.xml");
    MavenExecutionRequest request = newMavenExecutionRequest(pom);
    request.getProjectBuildingRequest().setProcessPlugins(false);
    request.setLocalRepository(getLocalRepository());
    if (platform != null) {
        request.getUserProperties().put("tycho.targetPlatform", platform.getCanonicalPath());
    }/*from  w ww .j av a  2s.c  o  m*/
    if (userProperties != null) {
        request.getUserProperties().putAll(userProperties);
    }
    MavenExecutionResult result = maven.execute(request);
    if (result.hasExceptions()) {
        throw new CompoundRuntimeException(result.getExceptions());
    }
    return result.getTopologicallySortedProjects();
}

From source file:org.hudsonci.maven.eventspy_30.MavenProjectConverter.java

License:Open Source License

public static ArrayList<MavenProjectDTO> extractFrom(final MavenExecutionResult event) {
    ArrayList<MavenProjectDTO> participatingProjects = new ArrayList<MavenProjectDTO>();

    List<MavenProject> projects = event.getTopologicallySortedProjects();

    for (MavenProject mavenProject : projects) {
        MavenProjectDTO projectDTO = convertMavenProject(mavenProject);
        updateWithBuildSummary(projectDTO, event.getBuildSummary(mavenProject));
        participatingProjects.add(projectDTO);
    }/*from   www.ja  v a2s. c  o  m*/
    return participatingProjects;
}

From source file:org.jenkinsci.plugins.pipeline.maven.eventspy.handler.MavenExecutionResultHandler.java

License:Open Source License

@Override
protected boolean _handle(MavenExecutionResult result) {
    Xpp3Dom root = new Xpp3Dom("MavenExecutionResult");
    root.setAttribute("class", result.getClass().getName());

    for (MavenProject project : result.getTopologicallySortedProjects()) {
        BuildSummary summary = result.getBuildSummary(project);
        if (summary == null) {
            Xpp3Dom comment = new Xpp3Dom("comment");
            comment.setValue("No build summary found for maven project: " + project);
            root.addChild(comment);/*  w w w  .  j a v  a2s  .  c  o m*/
        } else {
            Xpp3Dom buildSummary = newElement("buildSummary", project);
            root.addChild(buildSummary);
            buildSummary.setAttribute("class", summary.getClass().getName());
            buildSummary.setAttribute("time", Long.toString(summary.getTime()));
        }
    }
    reporter.print(root);
    return true;
}

From source file:org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult.java

License:Apache License

public HudsonMavenExecutionResult(MavenExecutionResult mavenExecutionResult) {
    if (mavenExecutionResult == null) {
        return;//w ww .  ja va  2 s . c om
    }
    throwables = mavenExecutionResult.getExceptions();

    List<MavenProject> mavenProjects = mavenExecutionResult.getTopologicallySortedProjects();
    if (mavenProjects != null) {
        for (MavenProject mavenProject : mavenProjects) {
            MavenProjectInfo mavenProjectInfo = new MavenProjectInfo(mavenProject);
            mavenProjectInfos.add(mavenProjectInfo);
            BuildSummary buildSummary = mavenExecutionResult.getBuildSummary(mavenProject);
            // NPE free : looks to have null here when the projects is not finished ie tests failures 
            if (buildSummary != null) {
                mavenProjectInfo.setBuildTime(buildSummary.getTime());
            }
        }
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFMavenCli.java

License:Apache License

protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
    MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());

    eventSpyDispatcher.onEvent(request);

    MavenExecutionResult result = maven.execute(request);

    eventSpyDispatcher.onEvent(result);//from  www.  j a  v a 2 s.  c  o m

    eventSpyDispatcher.close();

    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();

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

        MavenProject project = null;

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

            logSummary(summary, references, "", cliRequest.isShowErrors());

            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }
        }

        slf4jLogger.error("");

        if (!cliRequest.isShowErrors()) {
            slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!slf4jLogger.isDebugEnabled()) {
            slf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }

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

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

        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            slf4jLogger.error("");
            slf4jLogger.error("After correcting the problems, you can resume the build with the command");
            slf4jLogger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }

        if (MavenExecutionRequest.REACTOR_FAIL_NEVER
                .equals(cliRequest.getRequest().getReactorFailureBehavior())) {
            slf4jLogger.info("Build failures were ignored.");
            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.AFMavenCli.java

License:Apache License

protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {

    MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());

    eventSpyDispatcher.onEvent(request);

    MavenExecutionResult result = maven.execute(request);

    eventSpyDispatcher.onEvent(result);/*  w w w. j  a  va  2 s.c om*/

    eventSpyDispatcher.close();

    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();

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

        MavenProject project = null;

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

            logSummary(summary, references, "", cliRequest.isShowErrors());

            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }
        }

        slf4jLogger.error("");

        if (!cliRequest.isShowErrors()) {
            slf4jLogger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!slf4jLogger.isDebugEnabled()) {
            slf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }

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

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

        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            slf4jLogger.error("");
            slf4jLogger.error("After correcting the problems, you can resume the build with the command");
            slf4jLogger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }

        if (MavenExecutionRequest.REACTOR_FAIL_NEVER
                .equals(cliRequest.getRequest().getReactorFailureBehavior())) {
            slf4jLogger.info("Build failures were ignored.");
            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java

License:Apache License

protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
    MavenExecutionRequest request = reusableExecutionRequestPopulator.populateDefaults(cliRequest.getRequest());

    reusableEventSpyDispatcher.onEvent(request);

    MavenExecutionResult result = reusableMaven.execute(request);

    reusableEventSpyDispatcher.onEvent(result);

    reusableEventSpyDispatcher.close();//  w w  w.j a va 2 s  . com

    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();

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

        MavenProject project = null;

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

            logSummary(summary, references, "", cliRequest.isShowErrors());

            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }
        }

        reusableSlf4jLogger.error("");

        if (!cliRequest.isShowErrors()) {
            reusableSlf4jLogger
                    .error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!reusableSlf4jLogger.isDebugEnabled()) {
            reusableSlf4jLogger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }

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

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

        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            reusableSlf4jLogger.error("");
            reusableSlf4jLogger
                    .error("After correcting the problems, you can resume the build with the command");
            reusableSlf4jLogger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }

        if (MavenExecutionRequest.REACTOR_FAIL_NEVER
                .equals(cliRequest.getRequest().getReactorFailureBehavior())) {
            reusableSlf4jLogger.info("Build failures were ignored.");
            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}