Search in sources :

Example 1 with InputLocation

use of org.apache.maven.model.InputLocation 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;
}
Also used : InputLocation(org.apache.maven.model.InputLocation) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) PlexusContainer(org.codehaus.plexus.PlexusContainer) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) ArrayList(java.util.ArrayList) Profile(org.apache.maven.settings.Profile) SettingsBuilder(org.apache.maven.settings.building.SettingsBuilder) ModelProblem(org.apache.maven.model.building.ModelProblem) ProfileSelector(org.apache.maven.model.profile.ProfileSelector) Settings(org.apache.maven.settings.Settings) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext) ProfileActivationContext(org.apache.maven.model.profile.ProfileActivationContext) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) RestException(org.commonjava.maven.ext.io.rest.exception.RestException) ManipulationException(org.commonjava.maven.ext.common.ManipulationException) ParseException(org.apache.commons.cli.ParseException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) ModelProblemCollector(org.apache.maven.model.building.ModelProblemCollector) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultProfileActivationContext(org.apache.maven.model.profile.DefaultProfileActivationContext)

Aggregations

ArrayList (java.util.ArrayList)1 ParseException (org.apache.commons.cli.ParseException)1 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)1 InputLocation (org.apache.maven.model.InputLocation)1 ModelProblem (org.apache.maven.model.building.ModelProblem)1 ModelProblemCollector (org.apache.maven.model.building.ModelProblemCollector)1 DefaultProfileActivationContext (org.apache.maven.model.profile.DefaultProfileActivationContext)1 ProfileActivationContext (org.apache.maven.model.profile.ProfileActivationContext)1 ProfileSelector (org.apache.maven.model.profile.ProfileSelector)1 Profile (org.apache.maven.settings.Profile)1 Settings (org.apache.maven.settings.Settings)1 DefaultSettingsBuildingRequest (org.apache.maven.settings.building.DefaultSettingsBuildingRequest)1 SettingsBuilder (org.apache.maven.settings.building.SettingsBuilder)1 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)1 SettingsBuildingResult (org.apache.maven.settings.building.SettingsBuildingResult)1 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)1 PlexusContainer (org.codehaus.plexus.PlexusContainer)1 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)1 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)1 ManipulationException (org.commonjava.maven.ext.common.ManipulationException)1