Esempio n. 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;
    }
  }
Esempio n. 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;
      }
    }