MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
MavenExecutionRequestPopulator populator = plexus.lookup(MavenExecutionRequestPopulator.class);
populator.populateFromSettings(executionRequest, container.getSettings());
populator.populateDefaults(executionRequest);
RepositorySystem system = plexus.lookup(RepositorySystem.class);
ProjectBuildingRequest request = executionRequest.getProjectBuildingRequest();
ArtifactRepository localRepository = RepositoryUtils.toArtifactRepository("local",
new File(settings.getLocalRepository()).toURI().toURL().toString(), null, true, true);
request.setLocalRepository(localRepository);
List<ArtifactRepository> settingsRepos = new ArrayList<ArtifactRepository>(request.getRemoteRepositories());
List<String> activeProfiles = settings.getActiveProfiles();
Map<String, Profile> profiles = settings.getProfilesAsMap();
for (String id : activeProfiles)
{
Profile profile = profiles.get(id);
if (profile != null)
{
List<Repository> repositories = profile.getRepositories();
for (Repository repository : repositories)
{
settingsRepos.add(RepositoryUtils.convertFromMavenSettingsRepository(repository));
}
}
}
request.setRemoteRepositories(settingsRepos);
request.setSystemProperties(System.getProperties());
DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
Proxy activeProxy = settings.getActiveProxy();
if (activeProxy != null)
{
DefaultProxySelector dps = new DefaultProxySelector();
dps.add(RepositoryUtils.convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts());
repositorySession.setProxySelector(dps);
}
LocalRepository localRepo = new LocalRepository(settings.getLocalRepository());
repositorySession.setLocalRepositoryManager(system.newLocalRepositoryManager(repositorySession, localRepo));
repositorySession.setOffline(offline);
List<Mirror> mirrors = executionRequest.getMirrors();
if (mirrors != null)
{
DefaultMirrorSelector mirrorSelector = new DefaultMirrorSelector();
for (Mirror mirror : mirrors)
{
mirrorSelector.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(),
mirror.getMirrorOfLayouts());
}
repositorySession.setMirrorSelector(mirrorSelector);
}
request.setRepositorySession(repositorySession);
request.setProcessPlugins(false);
request.setResolveDependencies(false);
return request;
}
catch (RuntimeException e)
{
throw e;