use of org.apache.maven.settings.building.SettingsBuilder in project drools by kiegroup.
the class MavenSettings method initSettings.
private static Settings initSettings(SettingsSource userSettingsSource) {
SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
if (userSettingsSource != null) {
request.setUserSettingsSource(userSettingsSource);
}
String mavenHome = System.getenv("M2_HOME");
if (mavenHome != null) {
File globalSettingsFile = new File(mavenHome + "/conf/settings.xml");
if (globalSettingsFile.exists()) {
request.setGlobalSettingsFile(globalSettingsFile);
}
} else {
log.warn("Environment variable M2_HOME is not set");
}
request.setSystemProperties(System.getProperties());
Settings settings = null;
try {
settings = settingsBuilder.build(request).getEffectiveSettings();
} catch (SettingsBuildingException e) {
throw new RuntimeException(e);
}
if (settings.getLocalRepository() == null) {
String userHome = System.getProperty("user.home");
if (userHome != null) {
settings.setLocalRepository(userHome + "/.m2/repository");
} else {
log.error("Cannot find maven local repository");
}
}
return settings;
}
use of org.apache.maven.settings.building.SettingsBuilder in project pom-manipulation-ext by release-engineering.
the class Cli method parseSettings.
private Settings parseSettings(File settings) throws PlexusContainerException, ComponentLookupException, SettingsBuildingException {
PlexusContainer container = new DefaultPlexusContainer();
DefaultSettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest();
settingsRequest.setUserSettingsFile(settings);
settingsRequest.setGlobalSettingsFile(DEFAULT_GLOBAL_SETTINGS_FILE);
settingsRequest.setUserProperties(session.getUserProperties());
settingsRequest.setSystemProperties(System.getProperties());
SettingsBuilder settingsBuilder = container.lookup(SettingsBuilder.class);
SettingsBuildingResult settingsResult = settingsBuilder.build(settingsRequest);
Settings effectiveSettings = settingsResult.getEffectiveSettings();
ProfileSelector profileSelector = container.lookup(ProfileSelector.class);
ProfileActivationContext profileActivationContext = new DefaultProfileActivationContext().setActiveProfileIds(effectiveSettings.getActiveProfiles());
List<org.apache.maven.model.Profile> modelProfiles = new ArrayList<>();
for (Profile profile : effectiveSettings.getProfiles()) {
modelProfiles.add(SettingsUtils.convertFromSettingsProfile(profile));
}
List<org.apache.maven.model.Profile> activeModelProfiles = profileSelector.getActiveProfiles(modelProfiles, profileActivationContext, new ModelProblemCollector() {
@Override
public void add(ModelProblem.Severity severity, String message, InputLocation location, Exception cause) {
// do nothing
}
});
List<String> activeProfiles = new ArrayList<>();
for (org.apache.maven.model.Profile profile : activeModelProfiles) {
activeProfiles.add(profile.getId());
}
effectiveSettings.setActiveProfiles(activeProfiles);
return effectiveSettings;
}
use of org.apache.maven.settings.building.SettingsBuilder in project acceptance-test-harness by jenkinsci.
the class ArtifactResolverUtil method resolve.
/**
* @param artifact The artifact to be resolved
*
* @return artifact resolution result
*/
public ArtifactResult resolve(DefaultArtifact artifact) {
Builder repoBuilder = new RemoteRepository.Builder("repo.jenkins-ci.org", "default", "https://repo.jenkins-ci.org/public/");
DefaultSettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
File userHome = new File(System.getProperty("user.home"));
File userSettingsFile = new File(new File(userHome, ".m2"), "settings.xml");
request.setUserSettingsFile(userSettingsFile);
if (userSettingsFile.exists()) {
LOGGER.config("Found maven settings file - " + userSettingsFile.getAbsolutePath());
SettingsBuilder settingsBuilder = new DefaultSettingsBuilderFactory().newInstance();
try {
Settings settings = settingsBuilder.build(request).getEffectiveSettings();
org.apache.maven.settings.Proxy mavenActiveproxy = settings.getActiveProxy();
if (mavenActiveproxy != null) {
LOGGER.config("Found maven proxy settings. Will use for artifact resolution");
repoBuilder.setProxy(asProxy(mavenActiveproxy));
} else {
LOGGER.config("Did not find an active proxy in maven settings xml file");
}
} catch (SettingsBuildingException e) {
LOGGER.log(Level.WARNING, "Could not find or load settings.xml to attempt to user proxy settings.", e);
}
}
RemoteRepository repo = repoBuilder.build();
ArtifactResult r;
try {
r = repoSystem.resolveArtifact(repoSystemSession, new ArtifactRequest(artifact, Arrays.asList(repo), null));
} catch (ArtifactResolutionException e) {
throw new RuntimeException("Could not resolve " + artifact + " from Maven repository", e);
}
LOGGER.config("Found " + r);
return r;
}
Aggregations