Example #1
0
  private int execute(CliRequest cliRequest) {
    MavenExecutionResult result = maven.execute(cliRequest.request);

    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.showErrors);

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

      logger.error("");

      if (!cliRequest.showErrors) {
        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 (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(
          cliRequest.request.getReactorFailureBehavior())) {
        logger.info("Build failures were ignored.");

        return 0;
      } else {
        return 1;
      }
    } else {
      return 0;
    }
  }
Example #2
0
  private 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);
    }
  }