List of usage examples for org.apache.maven.execution MavenExecutionRequest getSystemProperties
Properties getSystemProperties();
From source file:co.leantechniques.maven.h2.H2TestRepository.java
License:Apache License
public void assertMachineInfoStored(MavenSession session) { MavenExecutionRequest request = session.getRequest(); Map<String, Object> machineInfo = handle.createQuery( "select * from machine_info mi inner join build b on mi.id = b.machine_info_id and b.id = ?") .bind(0, request.getStartTime().getTime()).first(); assertNotNull("we did not find machine info for the build", machineInfo); Properties systemProperties = request.getSystemProperties(); assertEquals(systemProperties.get("maven.version"), machineInfo.get("maven_version")); assertEquals(systemProperties.get("java.version"), machineInfo.get("java_version")); assertEquals(systemProperties.get("env.COMPUTERNAME"), machineInfo.get("computer_name")); assertEquals(systemProperties.get("os.name"), machineInfo.get("os")); assertEquals(systemProperties.get("user.name"), machineInfo.get("username")); assertEquals(systemProperties.get("os.arch"), machineInfo.get("os_arch")); }
From source file:com.cloudbees.eclipse.m2e.CBMavenUtils.java
License:Open Source License
public static IFile runMaven(IProject project, IProgressMonitor monitor, String[] goals) throws CloudBeesException { boolean pomExists = project.exists(new Path("/pom.xml")); if (!pomExists) { return null; }/*w ww. j ava 2s .c o m*/ IMaven maven = MavenPlugin.getMaven(); String version = MavenPlugin.getMavenRuntimeManager().getDefaultRuntime().getVersion(); MavenExecutionRequest request; IMavenProjectFacade mpr = MavenPlugin.getMavenProjectRegistry().getProject(project); try { if (mpr == null) { // maven not configured for the project. But as pom.xml existed, let's configure. NatureUtil.addNatures(project, new String[] { CloudBeesNature.NATURE_ID, JavaCore.NATURE_ID, "org.eclipse.m2e.core.maven2Nature" }, monitor); project.refreshLocal(IProject.DEPTH_INFINITE, monitor); mpr = MavenPlugin.getMavenProjectRegistry().getProject(project); } request = maven.createExecutionRequest(monitor); } catch (CoreException e) { throw new CloudBeesException("Failed to prepare maven war preparation request", e); } //IMavenProjectFacade facade = projectManager.create(pomFile, true, new SubProgressMonitor(monitor, 1)); //ResolverConfiguration config = mpr.getResolverConfiguration(); request.setPom(project.getFile(new Path("/pom.xml")).getRawLocation().toFile()); //request.setBaseDirectory(project.getRawLocation().toFile()); request.getSystemProperties().put("maven.test.skip", "true"); //MavenExecutionRequest request = projectManager.createExecutionRequest(pomFile, config, new SubProgressMonitor(monitor, 1)); //request.getUserProperties().setProperty("m2e.version", MavenPlugin.getVersion()); //goals.add("package"); //goals.add("eclipse:eclipse"); request.setGoals(Arrays.asList(goals)); //MavenPlugin.getConsole().showConsole(); MavenExecutionResult result = maven.execute(request, monitor); if (result.hasExceptions()) { // Throw CoreException //System.out.println("Got exceptions while running!"); Iterator<Throwable> it = result.getExceptions().iterator(); Throwable e = null; while (it.hasNext()) { Throwable throwable = (Throwable) it.next(); throwable.printStackTrace(); e = throwable; } throw new CloudBeesException("Maven build failed!", e); } BuildSummary summary = result.getBuildSummary(result.getProject()); MavenProject proj = summary.getProject(); Artifact artifact = proj.getArtifact(); File f = artifact.getFile(); //System.out.println("Artifact: " + f); //System.out.println("Artifact name: " + f.getName()); if (f == null) { return null; } if (BeesSDK.hasSupportedExtension(f.getName())) { String apath = f.getAbsolutePath().substring(project.getLocation().toFile().getAbsolutePath().length()); //System.out.println("APATH: " + apath); return project.getFile(apath); } return null; }
From source file:hudson.maven.MavenEmbedder.java
License:Apache License
protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); if (mavenRequest.getGlobalSettingsFile() != null) { mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile())); }/*from w w w . ja v a 2 s. c o m*/ if (mavenExecutionRequest.getUserSettingsFile() != null) { mavenExecutionRequest.setUserSettingsFile(new File(mavenRequest.getUserSettingsFile())); } try { lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings()); lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest); } catch (MavenExecutionRequestPopulationException e) { throw new MavenEmbedderException(e.getMessage(), e); } ArtifactRepository localRepository = getLocalRepository(); mavenExecutionRequest.setLocalRepository(localRepository); mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir()); mavenExecutionRequest.setOffline(mavenRequest.isOffline()); mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots()); // TODO check null and create a console one ? mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener()); mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound()); mavenExecutionRequest.setCacheTransferError(true); mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties()); mavenExecutionRequest.getSystemProperties().putAll(System.getProperties()); if (mavenRequest.getSystemProperties() != null) { mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties()); } mavenExecutionRequest.getSystemProperties().putAll(getEnvVars()); if (this.mavenHome != null) { mavenExecutionRequest.getSystemProperties().put("maven.home", this.mavenHome.getAbsolutePath()); } if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { for (String id : mavenRequest.getProfiles()) { Profile p = new Profile(); p.setId(id); p.setSource("cli"); mavenExecutionRequest.addProfile(p); mavenExecutionRequest.addActiveProfile(id); } } mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel()); lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel()); mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()) .setInteractiveMode(mavenRequest.isInteractive()) .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals()); if (mavenRequest.getPom() != null) { mavenExecutionRequest.setPom(new File(mavenRequest.getPom())); } if (mavenRequest.getWorkspaceReader() != null) { mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader()); } // FIXME inactive profiles //this.mavenExecutionRequest.set return mavenExecutionRequest; }
From source file:io.takari.maven.testing.Maven30xRuntime.java
License:Open Source License
@SuppressWarnings("deprecation") protected MavenExecutionRequest newExecutionRequest() throws Exception { // system properties Properties buildProperties = getMavenBuildProperties(); String mavenVersion = buildProperties.getProperty("version"); Properties systemProperties = new Properties(); systemProperties.putAll(System.getProperties()); // TODO not thread safe systemProperties.setProperty("maven.version", mavenVersion); systemProperties.setProperty("maven.build.version", mavenVersion); // request with initial configuration MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setLocalRepositoryPath(properties.getLocalRepository()); request.setUserSettingsFile(properties.getUserSettings()); request.setGlobalSettingsFile(properties.getGlobalSettings()); request.setOffline(properties.getOffline()); request.setUpdateSnapshots(properties.getUpdateSnapshots()); request.setSystemProperties(systemProperties); // read settings SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest(); settingsRequest.setGlobalSettingsFile(request.getGlobalSettingsFile()); settingsRequest.setUserSettingsFile(request.getUserSettingsFile()); settingsRequest.setSystemProperties(request.getSystemProperties()); settingsRequest.setUserProperties(request.getUserProperties()); Settings settings = lookup(SettingsBuilder.class).build(settingsRequest).getEffectiveSettings(); MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class); request = populator.populateFromSettings(request, settings); return populator.populateDefaults(request); }
From source file:org.appformer.maven.integration.embedder.MavenEmbedder.java
License:Apache License
protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); if (mavenRequest.getGlobalSettingsFile() != null) { mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile())); }/*from w w w . j a v a 2 s .c o m*/ SettingsSource userSettings = mavenRequest.getUserSettingsSource(); if (userSettings != null) { if (userSettings instanceof FileSettingsSource) { mavenExecutionRequest.setUserSettingsFile(((FileSettingsSource) userSettings).getSettingsFile()); } else { try { mavenExecutionRequest.setUserSettingsFile(copyInTempFile(userSettings.getInputStream(), "xml")); } catch (IOException ioe) { log.warn("Unable to use maven settings defined in " + userSettings, ioe); } } } try { componentProvider.lookup(MavenExecutionRequestPopulator.class) .populateFromSettings(mavenExecutionRequest, getSettings()); componentProvider.lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest); } catch (MavenExecutionRequestPopulationException e) { throw new MavenEmbedderException(e.getMessage(), e); } ArtifactRepository localRepository = getLocalRepository(); mavenExecutionRequest.setLocalRepository(localRepository); mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir()); mavenExecutionRequest.setOffline(mavenRequest.isOffline()); mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots()); // TODO check null and create a console one ? mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener()); mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound()); mavenExecutionRequest.setCacheTransferError(true); mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties()); mavenExecutionRequest.getSystemProperties().putAll(System.getProperties()); if (mavenRequest.getSystemProperties() != null) { mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties()); } mavenExecutionRequest.getSystemProperties().putAll(getEnvVars()); if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { for (String id : mavenRequest.getProfiles()) { Profile p = new Profile(); p.setId(id); p.setSource("cli"); mavenExecutionRequest.addProfile(p); mavenExecutionRequest.addActiveProfile(id); } } MavenRepositoryConfiguration mavenRepoConf = getMavenRepositoryConfiguration(); //DROOLS-899: Copy repositories defined in settings to execution request for (ArtifactRepository artifactRepository : mavenRepoConf.getArtifactRepositoriesForRequest()) { mavenExecutionRequest.addRemoteRepository(artifactRepository); } mavenExecutionRequest.setProxies(mavenRepoConf.getProxies()); mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel()); componentProvider.lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel()); mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()) .setInteractiveMode(mavenRequest.isInteractive()) .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals()); if (mavenRequest.getPom() != null) { mavenExecutionRequest.setPom(new File(mavenRequest.getPom())); } if (mavenRequest.getWorkspaceReader() != null) { mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader()); } return mavenExecutionRequest; }
From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java
License:Open Source License
MavenExecutionRequest createExecutionRequest() throws CoreException { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); // this causes problems with unexpected "stale project configuration" error markers // need to think how to manage ${maven.build.timestamp} properly inside workspace //request.setStartTime( new Date() ); if (mavenConfiguration.getGlobalSettingsFile() != null) { request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile())); }//w w w.j av a2s .c o m if (mavenConfiguration.getUserSettingsFile() != null) { request.setUserSettingsFile(new File(mavenConfiguration.getUserSettingsFile())); } try { lookup(MavenExecutionRequestPopulator.class).populateFromSettings(request, getSettings()); } catch (MavenExecutionRequestPopulationException ex) { throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenImpl_error_no_exec_req, ex)); } ArtifactRepository localRepository = getLocalRepository(); request.setLocalRepository(localRepository); request.setLocalRepositoryPath(localRepository.getBasedir()); request.setOffline(mavenConfiguration.isOffline()); request.getUserProperties().put("m2e.version", MavenPluginActivator.getVersion()); //$NON-NLS-1$ request.getUserProperties().put(ConfigurationProperties.USER_AGENT, MavenPluginActivator.getUserAgent()); EnvironmentUtils.addEnvVars(request.getSystemProperties()); request.getSystemProperties().putAll(System.getProperties()); request.setCacheNotFound(true); request.setCacheTransferError(true); // the right way to disable snapshot update // request.setUpdateSnapshots(false); return request; }
From source file:org.kie.scanner.embedder.MavenEmbedder.java
License:Apache License
protected MavenExecutionRequest buildMavenExecutionRequest(MavenRequest mavenRequest) throws MavenEmbedderException, ComponentLookupException { MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); if (mavenRequest.getGlobalSettingsFile() != null) { mavenExecutionRequest.setGlobalSettingsFile(new File(mavenRequest.getGlobalSettingsFile())); }//from w w w . j a va 2s .co m if (mavenExecutionRequest.getUserSettingsFile() != null) { mavenExecutionRequest.setUserSettingsFile(new File(mavenRequest.getUserSettingsFile())); } try { lookup(MavenExecutionRequestPopulator.class).populateFromSettings(mavenExecutionRequest, getSettings()); lookup(MavenExecutionRequestPopulator.class).populateDefaults(mavenExecutionRequest); } catch (MavenExecutionRequestPopulationException e) { throw new MavenEmbedderException(e.getMessage(), e); } ArtifactRepository localRepository = getLocalRepository(); mavenExecutionRequest.setLocalRepository(localRepository); mavenExecutionRequest.setLocalRepositoryPath(localRepository.getBasedir()); mavenExecutionRequest.setOffline(mavenRequest.isOffline()); mavenExecutionRequest.setUpdateSnapshots(mavenRequest.isUpdateSnapshots()); // TODO check null and create a console one ? mavenExecutionRequest.setTransferListener(mavenRequest.getTransferListener()); mavenExecutionRequest.setCacheNotFound(mavenRequest.isCacheNotFound()); mavenExecutionRequest.setCacheTransferError(true); mavenExecutionRequest.setUserProperties(mavenRequest.getUserProperties()); mavenExecutionRequest.getSystemProperties().putAll(System.getProperties()); if (mavenRequest.getSystemProperties() != null) { mavenExecutionRequest.getSystemProperties().putAll(mavenRequest.getSystemProperties()); } mavenExecutionRequest.getSystemProperties().putAll(getEnvVars()); if (this.mavenHome != null) { mavenExecutionRequest.getSystemProperties().put("maven.home", this.mavenHome.getAbsolutePath()); } if (mavenRequest.getProfiles() != null && !mavenRequest.getProfiles().isEmpty()) { for (String id : mavenRequest.getProfiles()) { Profile p = new Profile(); p.setId(id); p.setSource("cli"); mavenExecutionRequest.addProfile(p); mavenExecutionRequest.addActiveProfile(id); } } mavenExecutionRequest.setLoggingLevel(mavenRequest.getLoggingLevel()); lookup(Logger.class).setThreshold(mavenRequest.getLoggingLevel()); mavenExecutionRequest.setExecutionListener(mavenRequest.getExecutionListener()) .setInteractiveMode(mavenRequest.isInteractive()) .setGlobalChecksumPolicy(mavenRequest.getGlobalChecksumPolicy()).setGoals(mavenRequest.getGoals()); if (mavenRequest.getPom() != null) { mavenExecutionRequest.setPom(new File(mavenRequest.getPom())); } if (mavenRequest.getWorkspaceReader() != null) { mavenExecutionRequest.setWorkspaceReader(mavenRequest.getWorkspaceReader()); } return mavenExecutionRequest; }
From source file:org.kie.workbench.common.services.backend.compiler.external339.AFMavenCli.java
License:Apache License
protected MavenExecutionRequest populateRequest(AFCliRequest cliRequest, MavenExecutionRequest request) { CommandLine commandLine = cliRequest.getCommandLine(); String workingDirectory = cliRequest.getWorkingDirectory(); boolean quiet = cliRequest.isQuiet(); boolean showErrors = cliRequest.isShowErrors(); String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { slf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }/*w w w . j a va 2 s .c o m*/ } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<String>(); List<String> inactiveProfiles = new ArrayList<String>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (String profileOptionValue : profileOptionValues) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode() && !cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) { // // If we're logging to a file then we don't want the console transfer listener as it will spew // download progress all over the place // transferListener = getConsoleTransferListener(); } else { transferListener = getBatchTransferListener(); } ExecutionListener executionListener = new ExecutionEventLogger(); if (eventSpyDispatcher != null) { executionListener = eventSpyDispatcher.chainListener(executionListener); } String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } request.setBaseDirectory(baseDirectory).setGoals(goals) .setSystemProperties(cliRequest.getSystemProperties()) .setUserProperties(cliRequest.getUserProperties()) .setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setMultiModuleProjectDirectory(new File(cliRequest.getMultiModuleProjectDirectory())); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile.trim()), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); } request.setPom(pom); } else if (modelProcessor != null) { File pom = modelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> inclProjects = new ArrayList<String>(); List<String> exclProjects = new ArrayList<String>(); if (projectOptionValues != null) { for (String projectOptionValue : projectOptionValues) { StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ","); while (projectTokens.hasMoreTokens()) { String projectAction = projectTokens.nextToken().trim(); if (projectAction.startsWith("-") || projectAction.startsWith("!")) { exclProjects.add(projectAction.substring(1)); } else if (projectAction.startsWith("+")) { inclProjects.add(projectAction.substring(1)); } else { inclProjects.add(projectAction); } } } } request.setSelectedProjects(inclProjects); request.setExcludedProjects(exclProjects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } request.setCacheNotFound(true); request.setCacheTransferError(false); // // Builder, concurrency and parallelism // // We preserve the existing methods for builder selection which is to look for various inputs in the threading // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration // parameters but this is sufficient for now. Ultimately we want components like Builders to provide a way to // extend the command line to accept its own configuration parameters. // final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { // // Default to the standard multithreaded builder // request.setBuilderId("multithreaded"); if (threadConfiguration.contains("C")) { request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration)); } else { request.setDegreeOfConcurrency(Integer.valueOf(threadConfiguration)); } } // // Allow the builder to be overriden by the user if requested. The builders are now pluggable. // if (commandLine.hasOption(CLIManager.BUILDER)) { request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER)); } return request; }
From source file:org.kie.workbench.common.services.backend.compiler.impl.external339.ReusableAFMavenCli.java
License:Apache License
protected MavenExecutionRequest populateRequest(AFCliRequest cliRequest, MavenExecutionRequest request) { CommandLine commandLine = cliRequest.getCommandLine(); String workingDirectory = cliRequest.getWorkingDirectory(); boolean quiet = cliRequest.isQuiet(); boolean showErrors = cliRequest.isShowErrors(); String[] deprecatedOptions = { "up", "npu", "cpu", "npr" }; for (String deprecatedOption : deprecatedOptions) { if (commandLine.hasOption(deprecatedOption)) { reusableSlf4jLogger.warn("Command line option -" + deprecatedOption + " is deprecated and will be removed in future Maven versions."); }/*from www . java 2 s . c om*/ } // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and // bring the maven component to life for use. // ---------------------------------------------------------------------- if (commandLine.hasOption(CLIManager.BATCH_MODE)) { request.setInteractiveMode(false); } boolean noSnapshotUpdates = false; if (commandLine.hasOption(CLIManager.SUPRESS_SNAPSHOT_UPDATES)) { noSnapshotUpdates = true; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @SuppressWarnings("unchecked") List<String> goals = commandLine.getArgList(); boolean recursive = true; // this is the default behavior. String reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; if (commandLine.hasOption(CLIManager.NON_RECURSIVE)) { recursive = false; } if (commandLine.hasOption(CLIManager.FAIL_FAST)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_FAST; } else if (commandLine.hasOption(CLIManager.FAIL_AT_END)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_AT_END; } else if (commandLine.hasOption(CLIManager.FAIL_NEVER)) { reactorFailureBehaviour = MavenExecutionRequest.REACTOR_FAIL_NEVER; } if (commandLine.hasOption(CLIManager.OFFLINE)) { request.setOffline(true); } boolean updateSnapshots = false; if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { updateSnapshots = true; } String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_FAIL; } else if (commandLine.hasOption(CLIManager.CHECKSUM_WARNING_POLICY)) { globalChecksumPolicy = MavenExecutionRequest.CHECKSUM_POLICY_WARN; } File baseDirectory = new File(workingDirectory, "").getAbsoluteFile(); // ---------------------------------------------------------------------- // Profile Activation // ---------------------------------------------------------------------- List<String> activeProfiles = new ArrayList<String>(); List<String> inactiveProfiles = new ArrayList<String>(); if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); if (profileOptionValues != null) { for (String profileOptionValue : profileOptionValues) { StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); while (profileTokens.hasMoreTokens()) { String profileAction = profileTokens.nextToken().trim(); if (profileAction.startsWith("-") || profileAction.startsWith("!")) { inactiveProfiles.add(profileAction.substring(1)); } else if (profileAction.startsWith("+")) { activeProfiles.add(profileAction.substring(1)); } else { activeProfiles.add(profileAction); } } } } } TransferListener transferListener; if (quiet) { transferListener = new QuietMavenTransferListener(); } else if (request.isInteractiveMode() && !cliRequest.getCommandLine().hasOption(CLIManager.LOG_FILE)) { // // If we're logging to a file then we don't want the console transfer listener as it will spew // download progress all over the place // transferListener = getConsoleTransferListener(); } else { transferListener = getBatchTransferListener(); } ExecutionListener executionListener = new ExecutionEventLogger(); if (reusableEventSpyDispatcher != null) { executionListener = reusableEventSpyDispatcher.chainListener(executionListener); } String alternatePomFile = null; if (commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)) { alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } request.setBaseDirectory(baseDirectory).setGoals(goals) .setSystemProperties(cliRequest.getSystemProperties()) .setUserProperties(cliRequest.getUserProperties()) .setReactorFailureBehavior(reactorFailureBehaviour) // default: fail fast .setRecursive(recursive) // default: true .setShowErrors(showErrors) // default: false .addActiveProfiles(activeProfiles) // optional .addInactiveProfiles(inactiveProfiles) // optional .setExecutionListener(executionListener).setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setMultiModuleProjectDirectory(new File(cliRequest.getMultiModuleProjectDirectory())); if (alternatePomFile != null) { File pom = resolveFile(new File(alternatePomFile.trim()), workingDirectory); if (pom.isDirectory()) { pom = new File(pom, "pom.xml"); } request.setPom(pom); } else if (reusableModelProcessor != null) { File pom = reusableModelProcessor.locatePom(baseDirectory); if (pom.isFile()) { request.setPom(pom); } } if ((request.getPom() != null) && (request.getPom().getParentFile() != null)) { request.setBaseDirectory(request.getPom().getParentFile()); } if (commandLine.hasOption(CLIManager.RESUME_FROM)) { request.setResumeFrom(commandLine.getOptionValue(CLIManager.RESUME_FROM)); } if (commandLine.hasOption(CLIManager.PROJECT_LIST)) { String[] projectOptionValues = commandLine.getOptionValues(CLIManager.PROJECT_LIST); List<String> inclProjects = new ArrayList<String>(); List<String> exclProjects = new ArrayList<String>(); if (projectOptionValues != null) { for (String projectOptionValue : projectOptionValues) { StringTokenizer projectTokens = new StringTokenizer(projectOptionValue, ","); while (projectTokens.hasMoreTokens()) { String projectAction = projectTokens.nextToken().trim(); if (projectAction.startsWith("-") || projectAction.startsWith("!")) { exclProjects.add(projectAction.substring(1)); } else if (projectAction.startsWith("+")) { inclProjects.add(projectAction.substring(1)); } else { inclProjects.add(projectAction); } } } } request.setSelectedProjects(inclProjects); request.setExcludedProjects(exclProjects); } if (commandLine.hasOption(CLIManager.ALSO_MAKE) && !commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_UPSTREAM); } else if (!commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_DOWNSTREAM); } else if (commandLine.hasOption(CLIManager.ALSO_MAKE) && commandLine.hasOption(CLIManager.ALSO_MAKE_DEPENDENTS)) { request.setMakeBehavior(MavenExecutionRequest.REACTOR_MAKE_BOTH); } String localRepoProperty = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); if (localRepoProperty == null) { localRepoProperty = request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); } if (localRepoProperty != null) { request.setLocalRepositoryPath(localRepoProperty); } request.setCacheNotFound(true); request.setCacheTransferError(false); // // Builder, concurrency and parallelism // // We preserve the existing methods for builder selection which is to look for various inputs in the threading // configuration. We don't have an easy way to allow a pluggable builder to provide its own configuration // parameters but this is sufficient for now. Ultimately we want components like Builders to provide a way to // extend the command line to accept its own configuration parameters. // final String threadConfiguration = commandLine.hasOption(CLIManager.THREADS) ? commandLine.getOptionValue(CLIManager.THREADS) : request.getSystemProperties().getProperty(MavenCli.THREADS_DEPRECATED); // TODO: Remove this setting. Note that the int-tests use it if (threadConfiguration != null) { // // Default to the standard multithreaded builder // request.setBuilderId("multithreaded"); if (threadConfiguration.contains("C")) { request.setDegreeOfConcurrency(calculateDegreeOfConcurrencyWithCoreMultiplier(threadConfiguration)); } else { request.setDegreeOfConcurrency(Integer.valueOf(threadConfiguration)); } } // // Allow the builder to be overriden by the user if requested. The builders are now pluggable. // if (commandLine.hasOption(CLIManager.BUILDER)) { request.setBuilderId(commandLine.getOptionValue(CLIManager.BUILDER)); } return request; }
From source file:org.phpmaven.eclipse.core.internal.mvn.PhpmavenLauncher.java
License:Open Source License
/** * @see org.phpmaven.eclipse.core.mvn.ILauncher#launch() *//*from ww w. ja v a 2 s . c o m*/ @Override public String launch() { final IMavenJobData data = new IMavenJobData() { @Override public void manipulateRequest(final MavenExecutionRequest request) { final Properties props = request.getSystemProperties(); if (!"php".equals(PhpmavenLauncher.this.getPhpExe())) { //$NON-NLS-1$ props.setProperty("phpExecutable", PhpmavenLauncher.this.getPhpExe()); //$NON-NLS-1$ } props.setProperty("phpFile", PhpmavenLauncher.this.getPhpScript().getAbsolutePath()); //$NON-NLS-1$ props.setProperty("testIncludePath", "true"); //$NON-NLS-1$ //$NON-NLS-2$ final String[] cmdline = PhpmavenLauncher.this.getCmdLine(); if (cmdline.length > 0) { final StringBuffer buffer = new StringBuffer(); for (final String line : cmdline) { if (buffer.length() > 0) { buffer.append(" "); //$NON-NLS-1$ } if (line.contains(" ")) { //$NON-NLS-1$ buffer.append("\""); //$NON-NLS-1$ buffer.append(line); buffer.append("\""); //$NON-NLS-1$ } else { buffer.append(line); } } props.setProperty("phpFileArguments", buffer.toString()); //$NON-NLS-1$ } } @Override public IProject getProject() { return PhpmavenLauncher.this.project; } @Override public String[] getMavenCommands() { return new String[] { "exec" }; //$NON-NLS-1$ } @Override public boolean canProcessRequest(final MavenExecutionRequest request, final IMavenProjectFacade projectFacade) { return true; } }; final MavenJob job = new MavenJob(data); final IStatus status = job.execute(new NullProgressMonitor()); if (status.isOK()) { // TODO } return this.stdOut; }