public ProjectBuildingRequest getBuildingRequest(final boolean offline)
{
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try
{
Settings settings = container.getSettings();
// TODO this needs to be configurable via .forge
// TODO this reference to the M2_REPO should probably be centralized
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
plexus.lookup(MavenExecutionRequestPopulator.class).populateFromSettings(executionRequest,
container.getSettings());
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>();
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));
}
}
}
// No repository set, enable central
if (!offline && settingsRepos.isEmpty())
{
settingsRepos.add(RepositoryUtils.toArtifactRepository("CENTRAL", "http://repo1.maven.org/maven2/", null,
true, false));
}
request.setRemoteRepositories(settingsRepos);
request.setSystemProperties(System.getProperties());
MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
Proxy activeProxy = settings.getActiveProxy();
if (activeProxy != null)
{
DefaultProxySelector dps = new DefaultProxySelector();
dps.add(RepositoryUtils.convertFromMavenProxy(activeProxy), activeProxy.getNonProxyHosts());
repositorySession.setProxySelector(dps);
}
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(settings.getLocalRepository()));
repositorySession.setOffline(offline);
request.setRepositorySession(repositorySession);
request.setProcessPlugins(false);
// request.setPluginArtifactRepositories(Arrays.asList(localRepository));