Search in sources :

Example 1 with ExceptionSummary

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

the class AFMavenCli method logSummary.

protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
    String referenceKey = "";
    if (StringUtils.isNotEmpty(summary.getReference())) {
        referenceKey = references.get(summary.getReference());
        if (referenceKey == null) {
            referenceKey = "[Help " + (references.size() + 1) + "]";
            references.put(summary.getReference(), referenceKey);
        }
    }
    String msg = summary.getMessage();
    if (StringUtils.isNotEmpty(referenceKey)) {
        if (msg.indexOf('\n') < 0) {
            msg += " -> " + referenceKey;
        } else {
            msg += "\n-> " + referenceKey;
        }
    }
    String[] lines = msg.split("(\r\n)|(\r)|(\n)");
    for (int i = 0; i < lines.length; i++) {
        String line = indent + lines[i].trim();
        if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
            slf4jLogger.error(line, summary.getException());
        } else {
            slf4jLogger.error(line);
        }
    }
    indent += "  ";
    for (ExceptionSummary child : summary.getChildren()) {
        logSummary(child, references, indent, showErrors);
    }
}
Also used : ExceptionSummary(org.apache.maven.exception.ExceptionSummary) InternalErrorException(org.apache.maven.InternalErrorException)

Example 2 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)

Example 3 with ExceptionSummary

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

the class AFMavenCli method logSummary.

protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
    String referenceKey = "";
    if (StringUtils.isNotEmpty(summary.getReference())) {
        referenceKey = references.get(summary.getReference());
        if (referenceKey == null) {
            referenceKey = "[Help " + (references.size() + 1) + "]";
            references.put(summary.getReference(), referenceKey);
        }
    }
    String msg = summary.getMessage();
    if (StringUtils.isNotEmpty(referenceKey)) {
        if (msg.indexOf('\n') < 0) {
            msg += " -> " + referenceKey;
        } else {
            msg += "\n-> " + referenceKey;
        }
    }
    String[] lines = msg.split("(\r\n)|(\r)|(\n)");
    for (int i = 0; i < lines.length; i++) {
        String line = indent + lines[i].trim();
        if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
            slf4jLogger.error(line, summary.getException());
        } else {
            slf4jLogger.error(line);
        }
    }
    indent += "  ";
    for (ExceptionSummary child : summary.getChildren()) {
        logSummary(child, references, indent, showErrors);
    }
}
Also used : ExceptionSummary(org.apache.maven.exception.ExceptionSummary) InternalErrorException(org.apache.maven.InternalErrorException)

Example 4 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)

Example 5 with ExceptionSummary

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

the class ReusableAFMavenCli method logSummary.

protected void logSummary(ExceptionSummary summary, Map<String, String> references, String indent, boolean showErrors) {
    String referenceKey = "";
    if (StringUtils.isNotEmpty(summary.getReference())) {
        referenceKey = references.get(summary.getReference());
        if (referenceKey == null) {
            referenceKey = "[Help " + (references.size() + 1) + "]";
            references.put(summary.getReference(), referenceKey);
        }
    }
    String msg = summary.getMessage();
    if (StringUtils.isNotEmpty(referenceKey)) {
        if (msg.indexOf('\n') < 0) {
            msg += " -> " + referenceKey;
        } else {
            msg += "\n-> " + referenceKey;
        }
    }
    String[] lines = msg.split("(\r\n)|(\r)|(\n)");
    for (int i = 0; i < lines.length; i++) {
        String line = indent + lines[i].trim();
        if ((i == lines.length - 1) && (showErrors || (summary.getException() instanceof InternalErrorException))) {
            reusableSlf4jLogger.error(line, summary.getException());
        } else {
            reusableSlf4jLogger.error(line);
        }
    }
    indent += "  ";
    for (ExceptionSummary child : summary.getChildren()) {
        logSummary(child, references, indent, showErrors);
    }
}
Also used : ExceptionSummary(org.apache.maven.exception.ExceptionSummary) InternalErrorException(org.apache.maven.InternalErrorException)

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