private void init() throws Exception { log.debug("Initializing"); // Make sure maven.home is absolute to avoid confusion on windows String mavenHome = System.getProperty(MAVEN_HOME); if (mavenHome != null) { System.setProperty(MAVEN_HOME, new File(mavenHome).getAbsolutePath()); } // Setup defaults if (config.getClassWorld() == null) { config.setClassWorld(plexus.getClassWorld()); } if (config.getBaseDirectory() == null) { config.setBaseDirectory(new File(System.getProperty("user.dir"))); } StreamSet streams = config.getStreams(); if (streams == null) { streams = StreamSet.system(); } config.setStreams(streams); // Configure logging this.logger = config.getLogger(); if (logger == null) { logger = new PrintStreamLogger(streams.out); } else { logger.setStream(streams.out); } config.setLogger(logger); int level = MavenExecutionRequest.LOGGING_LEVEL_INFO; if (config.isDebug()) { level = MavenExecutionRequest.LOGGING_LEVEL_DEBUG; } else if (config.isQuiet()) { level = MavenExecutionRequest.LOGGING_LEVEL_ERROR; } logger.setThreshold(level); File logFile = config.getLogFile(); if (logFile != null) { logFile = resolveFile(logFile, config.getBaseDirectory()); try { logStream = new PrintStream(logFile); logger.setStream(logStream); } catch (FileNotFoundException e) { log.warn("Failed to open logging stream for file: " + logFile, e); logger.setStream(streams.out); } } // Setup the container this.container = createContainer(); log.debug("Using container: {}", container); }
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; } }
private void configureRequest(final MavenExecutionRequest request) throws Exception { assert request != null; assert config != null; File dir = new File(config.getBaseDirectory(), "").getAbsoluteFile(); request.setBaseDirectory(dir); // HACK: Some bits need user.dir to be set, or use un-rooted File's :-( System.setProperty("user.dir", dir.getAbsolutePath()); // Configure profiles for (String profile : config.getProfiles()) { profile = profile.trim(); if (profile.startsWith("-") || profile.startsWith("!")) { request.addInactiveProfile(profile.substring(1)); } else if (profile.startsWith("+")) { request.addActiveProfile(profile.substring(1)); } else { request.addActiveProfile(profile); } } // Configure user toolchains File userToolchainsFile = request.getUserToolchainsFile(); if (userToolchainsFile != null) { userToolchainsFile = resolveFile(userToolchainsFile, config.getBaseDirectory()); } else { userToolchainsFile = DEFAULT_USER_TOOLCHAINS_FILE; } request.setUserToolchainsFile(userToolchainsFile); // Configure the pom File alternatePomFile = config.getPomFile(); if (alternatePomFile != null) { request.setPom(resolveFile(alternatePomFile, config.getBaseDirectory())); } else if (request.getPom() != null && !request.getPom().isAbsolute()) { request.setPom(request.getPom().getAbsoluteFile()); } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } else if (request.getPom() == null && request.getBaseDirectory() != null) { ModelProcessor modelProcessor = container.lookup(ModelProcessor.class); try { File pom = modelProcessor.locatePom(new File(request.getBaseDirectory())); request.setPom(pom); } finally { container.release(modelProcessor); } } else if (request.getBaseDirectory() == null) { request.setBaseDirectory(config.getBaseDirectory()); } // Configure the local repo path String localRepoPath = request.getUserProperties().getProperty(LOCAL_REPO); if (localRepoPath == null) { localRepoPath = request.getSystemProperties().getProperty(LOCAL_REPO); } if (localRepoPath != null) { request.setLocalRepositoryPath(localRepoPath); } // Setup the xfr listener ArtifactTransferListener transferListener; if (request.isInteractiveMode()) { transferListener = new ConsoleMavenTransferListener(config.getStreams().out); } else { transferListener = new BatchModeMavenTransferListener(config.getStreams().out); } transferListener.setShowChecksumEvents(false); request.setTransferListener(transferListener); // Configure request logging request.setLoggingLevel(logger.getThreshold()); request.setExecutionListener(new ExecutionEventLogger(terminal.get(), logger)); }