List of usage examples for org.apache.maven.execution MavenExecutionRequest setLocalRepository
MavenExecutionRequest setLocalRepository(ArtifactRepository repository);
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 ww . j a va 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:org.apache.sling.ide.eclipse.m2e.EmbeddedArchetypeInstaller.java
License:Apache License
public void installArchetype() throws CoreException { try {/*from ww w.j av a 2 s.c o m*/ IMaven maven = MavenPlugin.getMaven(); // first get the plexus container PlexusContainer container = ((MavenImpl) MavenPlugin.getMaven()).getPlexusContainer(); // then get the DefaultMaven DefaultMaven mvn = (DefaultMaven) container.lookup(Maven.class); // now create a RepositorySystemSession MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setLocalRepository(maven.getLocalRepository()); // We need to support Maven 3.0.x as well, so we use reflection to // access Aether APIs in a manner which is compatible with all Maven 3.x versions // See https://maven.apache.org/docs/3.1.0/release-notes.html MavenSession session = reflectiveCreateMavenSession(container, mvn, request); LegacySupport legacy = container.lookup(LegacySupport.class); legacy.setSession(session); // then lookup the DefaultArtifactInstaller DefaultArtifactInstaller dai = (DefaultArtifactInstaller) container.lookup(ArtifactInstaller.class); final Set<Entry<String, InputStream>> entries = origins.entrySet(); for (Iterator<Entry<String, InputStream>> it = entries.iterator(); it.hasNext();) { final Entry<String, InputStream> entry = it.next(); final String fileExtension = entry.getKey(); File tmpFile = File.createTempFile("slingClipseTmp", fileExtension); try (InputStream in = entry.getValue(); FileOutputStream fos = new FileOutputStream(tmpFile)) { IOUtils.copy(in, fos); // the below code uses the fileExtension as a type. Most of the time this is correct // and should be fine for our usage Artifact jarArtifact = new DefaultArtifact(groupId, artifactId, version, "", fileExtension, "", new DefaultArtifactHandler(fileExtension)); dai.install(tmpFile, jarArtifact, maven.getLocalRepository()); } finally { FileUtils.deleteQuietly(tmpFile); } } Archetype archetype = new Archetype(); archetype.setGroupId(groupId); archetype.setArtifactId(artifactId); archetype.setVersion(version); org.apache.maven.archetype.Archetype archetyper = MavenPluginActivator.getDefault().getArchetype(); archetyper.updateLocalCatalog(archetype); } catch (CoreException | RuntimeException e) { throw e; } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); } }
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())); }// www.java 2s. c om 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.commonjava.maven.ext.cli.Cli.java
License:Apache License
private void createSession(File target, File settings) { try {// www . j a v a2s. c o m final DefaultContainerConfiguration config = new DefaultContainerConfiguration(); config.setClassPathScanning(PlexusConstants.SCANNING_ON); config.setComponentVisibility(PlexusConstants.GLOBAL_VISIBILITY); config.setName("PME-CLI"); PlexusContainer container = new DefaultPlexusContainer(config); pomIO = container.lookup(PomIO.class); session = container.lookup(ManipulationSession.class); manipulationManager = container.lookup(ManipulationManager.class); final MavenExecutionRequest req = new DefaultMavenExecutionRequest() .setUserProperties(System.getProperties()).setUserProperties(userProps) .setRemoteRepositories(Collections.<ArtifactRepository>emptyList()); ArtifactRepository ar = null; if (settings == null) { // No, this is not a typo. If current default is null, supply new local and global. // This function passes in settings to make it easier to test. this.settings = settings = new File(System.getProperty("user.home"), ".m2/settings.xml"); ar = new MavenArtifactRepository(); ar.setUrl("file://" + System.getProperty("user.home") + "/.m2/repository"); req.setLocalRepository(ar); } req.setUserSettingsFile(settings); req.setGlobalSettingsFile(settings); MavenExecutionRequestPopulator executionRequestPopulator = container .lookup(MavenExecutionRequestPopulator.class); executionRequestPopulator.populateFromSettings(req, parseSettings(settings)); executionRequestPopulator.populateDefaults(req); if (ar != null) { ar.setUrl("file://" + req.getLocalRepositoryPath()); } if (userProps != null && userProps.containsKey("maven.repo.local")) { if (ar == null) { ar = new MavenArtifactRepository(); } ar.setUrl("file://" + userProps.getProperty("maven.repo.local")); req.setLocalRepository(ar); } final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult()); mavenSession.getRequest().setPom(target); session.setMavenSession(mavenSession); } catch (ComponentLookupException e) { logger.debug("Caught problem instantiating ", e); System.err.println("Unable to start Cli subsystem"); System.exit(100); } catch (PlexusContainerException e) { logger.debug("Caught problem instantiating ", e); System.err.println("Unable to start Cli subsystem"); System.exit(100); } catch (SettingsBuildingException e) { logger.debug("Caught problem parsing settings file ", e); System.err.println("Unable to parse settings.xml file"); System.exit(100); } catch (MavenExecutionRequestPopulationException e) { logger.debug("Caught problem populating maven request from settings file ", e); System.err.println("Unable to create maven execution request from settings.xml file"); System.exit(100); } }
From source file:org.commonjava.maven.ext.manip.Cli.java
License:Apache License
private void createSession(File target, File settings) { try {/*from www . j a va 2 s . c o m*/ PlexusContainer container = new DefaultPlexusContainer(); final MavenExecutionRequest req = new DefaultMavenExecutionRequest() .setUserProperties(System.getProperties()).setUserProperties(userProps) .setRemoteRepositories(Collections.<ArtifactRepository>emptyList()); if (userProps != null && userProps.containsKey("maven.repo.local")) { ArtifactRepository ar = new MavenArtifactRepository(); ar.setUrl("file://" + userProps.getProperty("maven.repo.local")); req.setLocalRepository(ar); } if (settings != null) { req.setUserSettingsFile(settings); req.setGlobalSettingsFile(settings); MavenExecutionRequestPopulator executionRequestPopulator = container .lookup(MavenExecutionRequestPopulator.class); executionRequestPopulator.populateFromSettings(req, parseSettings(settings)); executionRequestPopulator.populateDefaults(req); } final MavenSession mavenSession = new MavenSession(container, null, req, new DefaultMavenExecutionResult()); mavenSession.getRequest().setPom(target); pomIO = container.lookup(PomIO.class); session = container.lookup(ManipulationSession.class); manipulationManager = container.lookup(ManipulationManager.class); session.setMavenSession(mavenSession); } catch (ComponentLookupException e) { logger.debug("Caught problem instantiating ", e); System.err.println("Unable to start Cli subsystem"); System.exit(100); e.printStackTrace(); } catch (PlexusContainerException e) { logger.debug("Caught problem instantiating ", e); System.err.println("Unable to start Cli subsystem"); System.exit(100); } catch (SettingsBuildingException e) { logger.debug("Caught problem parsing settings file ", e); System.err.println("Unable to parse settings.xml file"); System.exit(100); } catch (MavenExecutionRequestPopulationException e) { logger.debug("Caught problem populating maven request from settings file ", e); System.err.println("Unable to create maven execution request from settings.xml file"); System.exit(100); } }
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 ww. j a v a 2 s . co 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.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.java
License:Open Source License
MavenExecutionRequest configureExecutionRequest(MavenExecutionRequest request, IProjectRegistry state, IFile pom, ResolverConfiguration resolverConfiguration) throws CoreException { request.setPom(pom.getLocation().toFile()); request.addActiveProfiles(resolverConfiguration.getActiveProfileList()); request.addInactiveProfiles(resolverConfiguration.getInactiveProfileList()); // eclipse workspace repository implements both workspace dependency resolution // and inter-module dependency resolution for multi-module projects. request.setLocalRepository(getMaven().getLocalRepository()); request.setWorkspaceReader(getWorkspaceReader(state, pom, resolverConfiguration)); return request; }
From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java
License:Open Source License
protected MavenExecutionRequest newMavenExecutionRequest(File pom) throws Exception { Properties systemProps = new Properties(); systemProps.putAll(System.getProperties()); Properties userProps = new Properties(); userProps.put("tycho-version", "0.0.0"); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParentFile()); request.setPom(pom);//from w ww . j a v a 2 s . c o m request.setSystemProperties(systemProps); request.setUserProperties(userProps); request.setLocalRepository(getLocalRepository()); request.setGoals(Arrays.asList("validate")); return request; }
From source file:org.eclipse.tycho.testing.AbstractTychoMojoTestCase.java
License:Open Source License
protected List<MavenProject> getSortedProjects(File basedir, Properties userProperties, File platform) throws Exception { File pom = new File(basedir, "pom.xml"); MavenExecutionRequest request = newMavenExecutionRequest(pom); request.getProjectBuildingRequest().setProcessPlugins(false); request.setLocalRepository(getLocalRepository()); if (platform != null) { request.getUserProperties().put("tycho.targetPlatform", platform.getCanonicalPath()); }// www . j a v a2 s. c o m if (userProperties != null) { request.getUserProperties().putAll(userProperties); } MavenExecutionResult result = maven.execute(request); if (result.hasExceptions()) { throw new CompoundRuntimeException(result.getExceptions()); } return result.getTopologicallySortedProjects(); }
From source file:org.jvnet.hudson.plugins.mavendepsupdate.MavenUpdateChecker.java
License:Apache License
ProjectBuildingRequest getProjectBuildingRequest(Properties userProperties, PlexusContainer plexusContainer)
throws ComponentLookupException, SettingsBuildingException, MavenExecutionRequestPopulationException,
InvalidRepositoryException {/* w ww. ja v a 2s.c o m*/
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_DEBUG);
request.setWorkspaceReader(new ReactorReader(new HashMap<String, MavenProject>(0)));
SettingsBuilder settingsBuilder = plexusContainer.lookup(SettingsBuilder.class);
RepositorySystem repositorySystem = plexusContainer.lookup(RepositorySystem.class);
org.sonatype.aether.RepositorySystem repoSystem = plexusContainer
.lookup(org.sonatype.aether.RepositorySystem.class);
SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
if (globalSettings != null) {
mavenUpdateCheckerResult.addDebugLine("globalSettings " + globalSettings.getRemote());
settingsRequest.setGlobalSettingsFile(new File(globalSettings.getRemote()));
} else {
File globalSettings = new File(mavenHome, "conf/settings.xml");
if (globalSettings.exists()) {
settingsRequest.setGlobalSettingsFile(globalSettings);
}
}
if (alternateSettings != null) {
mavenUpdateCheckerResult.addDebugLine("alternateSettings " + alternateSettings.getRemote());
settingsRequest.setUserSettingsFile(new File(alternateSettings.getRemote()));
request.setUserSettingsFile(new File(alternateSettings.getRemote()));
} else {
File defaultUserSettings = new File(new File(System.getProperty("user.home"), ".m2"), "settings.xml");
settingsRequest.setUserSettingsFile(defaultUserSettings);
request.setUserSettingsFile(defaultUserSettings);
}
settingsRequest.setSystemProperties(System.getProperties());
settingsRequest.setUserProperties(userProperties);
SettingsBuildingResult settingsBuildingResult = settingsBuilder.build(settingsRequest);
MavenExecutionRequestPopulator executionRequestPopulator = plexusContainer
.lookup(MavenExecutionRequestPopulator.class);
executionRequestPopulator.populateFromSettings(request, settingsBuildingResult.getEffectiveSettings());
executionRequestPopulator.populateDefaults(request);
MavenRepositorySystemSession session = new MavenRepositorySystemSession();
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS);
SnapshotTransfertListener snapshotTransfertListener = new SnapshotTransfertListener(this.lastBuildTime);
session.setTransferListener(snapshotTransfertListener);
LocalRepository localRepo = getLocalRepo(settingsBuildingResult);
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(localRepo));
ArtifactRepository localArtifactRepository = getLocalArtifactRepo(settingsBuildingResult, repositorySystem);
request.setLocalRepository(localArtifactRepository);
if (this.activeProfiles != null && !this.activeProfiles.isEmpty()) {
for (String id : this.activeProfiles) {
Profile p = new Profile();
p.setId(id);
p.setSource("cli");
request.addProfile(p);
request.addActiveProfile(id);
}
}
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
return projectBuildingRequest.setRepositorySession(session);
}