Example #1
0
    private void logSummary(
        final ExceptionSummary summary,
        final Map<String, String> references,
        String indent,
        final boolean showErrors) {
      assert summary != null;

      String referenceKey = "";

      // TODO: i18n

      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 = indent + summary.getMessage();

      if (StringUtils.isNotEmpty(referenceKey)) {
        if (msg.indexOf('\n') < 0) {
          msg += " -> " + referenceKey;
        } else {
          msg += '\n' + indent + "-> " + referenceKey;
        }
      }

      if (showErrors) {
        //noinspection ThrowableResultOfMethodCallIgnored
        logger.error(msg, summary.getException());
      } else {
        logger.error(msg);
      }

      indent += "  ";

      for (ExceptionSummary child : summary.getChildren()) {
        logSummary(child, references, indent, showErrors);
      }
    }
Example #2
0
    private int doExecute(final MavenExecutionRequest request) throws Exception {
      assert request != null;
      assert config != null;

      if (config.isDebug() || config.isShowVersion()) {
        CLIReportingUtils.showVersion(config.getStreams().out);
      }

      //
      // TODO: i18n all of this
      //

      if (request.isShowErrors()) {
        logger.info("Error stack-traces are turned on.");
      }
      if (MavenExecutionRequest.CHECKSUM_POLICY_WARN.equals(request.getGlobalChecksumPolicy())) {
        logger.info("Disabling strict checksum verification on all artifact downloads.");
      } else if (MavenExecutionRequest.CHECKSUM_POLICY_FAIL.equals(
          request.getGlobalChecksumPolicy())) {
        logger.info("Enabling strict checksum verification on all artifact downloads.");
      }

      if (log.isDebugEnabled()) {
        log.debug("Executing request: {}", Yarn.render(request, Yarn.Style.MULTI));
      }

      MavenExecutionResult result;
      Maven maven = container.lookup(Maven.class);
      try {
        result = maven.execute(request);
      } finally {
        container.release(maven);
      }

      if (!result.hasExceptions()) {
        return 0;
      }
      // else process exceptions

      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, "", request.isShowErrors());

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

      logger.error("");

      if (!request.isShowErrors()) {
        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(request.getReactorFailureBehavior())) {
        logger.info("Build failures were ignored.");
        return 0;
      } else {
        return 1;
      }
    }