Search in sources :

Example 6 with ExceptionSummary

use of org.apache.maven.exception.ExceptionSummary in project kie-wb-common by kiegroup.

the class AFMavenCli method execute.

protected int execute(AFCliRequest cliRequest) throws MavenExecutionRequestPopulationException {
    MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.getRequest());
    eventSpyDispatcher.onEvent(request);
    MavenExecutionResult result = maven.execute(request);
    eventSpyDispatcher.onEvent(result);
    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;
    }
}
Also used : DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) ExceptionHandler(org.apache.maven.exception.ExceptionHandler) ExceptionSummary(org.apache.maven.exception.ExceptionSummary) MavenProject(org.apache.maven.project.MavenProject) LifecycleExecutionException(org.apache.maven.lifecycle.LifecycleExecutionException) MavenExecutionResult(org.apache.maven.execution.MavenExecutionResult) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) DefaultExceptionHandler(org.apache.maven.exception.DefaultExceptionHandler) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ExceptionSummary (org.apache.maven.exception.ExceptionSummary)6 LinkedHashMap (java.util.LinkedHashMap)3 InternalErrorException (org.apache.maven.InternalErrorException)3 DefaultExceptionHandler (org.apache.maven.exception.DefaultExceptionHandler)3 ExceptionHandler (org.apache.maven.exception.ExceptionHandler)3 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 MavenExecutionResult (org.apache.maven.execution.MavenExecutionResult)3 LifecycleExecutionException (org.apache.maven.lifecycle.LifecycleExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3