use of org.apache.maven.model.profile.DefaultProfileActivationContext 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;
}
Aggregations