Example usage for org.apache.maven.settings SettingsUtils convertFromSettingsProfile

List of usage examples for org.apache.maven.settings SettingsUtils convertFromSettingsProfile

Introduction

In this page you can find the example usage for org.apache.maven.settings SettingsUtils convertFromSettingsProfile.

Prototype

public static org.apache.maven.model.Profile convertFromSettingsProfile(Profile settingsProfile) 

Source Link

Usage

From source file:net.oneandone.maven.embedded.Maven.java

License:Apache License

private static List<ArtifactRepository> repositoriesLegacy(LegacyRepositorySystem legacy, Settings settings)
        throws InvalidRepositoryException {
    boolean central;
    List<ArtifactRepository> result;
    List<String> actives;
    ArtifactRepository artifactRepository;

    central = false;//from   www . ja v  a  2  s .com
    result = new ArrayList<>();
    actives = settings.getActiveProfiles();
    for (Profile profile : settings.getProfiles()) {
        if (actives.contains(profile.getId()) || profile.getActivation().isActiveByDefault()) {
            for (org.apache.maven.model.Repository repository : SettingsUtils
                    .convertFromSettingsProfile(profile).getRepositories()) {
                artifactRepository = legacy.buildArtifactRepository(repository);
                if ("central".equals(artifactRepository.getId())) {
                    central = true;
                }
                result.add(artifactRepository);
            }
        }
    }
    if (!central) {
        /* Maven defines the default central repository in its master parent - and not in the default settings, which I'd prefer.
           As a consequent, central is not always defined when loading the settings.
           I first added central to repositories only, because legacy repositories are used to load poms which ultimatly load the
           master parent with it's repository definition. However, the parent might have to be loaded from central, so repositories
           also need a central definition. */
        result.add(legacy.createDefaultRemoteRepository());
    }
    return result;
}

From source file:org.commonjava.maven.ext.cli.Cli.java

License:Apache License

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));
    }/* w w w.  j  a va 2  s  . c o  m*/
    List<org.apache.maven.model.Profile> activeModelProfiles = profileSelector.getActiveProfiles(modelProfiles,
            profileActivationContext, new ModelProblemCollector() {

                @Override
                public void add(ModelProblemCollectorRequest modelProblemCollectorRequest) {
                    // do nothing
                }
            });
    List<String> activeProfiles = new ArrayList<>();
    for (org.apache.maven.model.Profile profile : activeModelProfiles) {
        activeProfiles.add(profile.getId());
    }
    effectiveSettings.setActiveProfiles(activeProfiles);

    return effectiveSettings;
}

From source file:org.commonjava.maven.ext.manip.Cli.java

License:Apache License

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);

    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));
    }//  www  .  j a  v  a2s  . c  o  m
    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;
}

From source file:org.ebayopensource.turmeric.eclipse.mavenapi.impl.AbstractMavenApi.java

License:Open Source License

/**
 * Return the Maven remote repositories defined in the Maven settings.xml
 * file. The returned list of repositories depend on the pacakgeType.
 * /*from ww  w .j a va2 s .  c  om*/
 * For <code>maven-plugin</code> package type, it will return
 * pluginRepositories, and all other types will return Mirrors and
 * Repositories.
 *
 * @param plexus the plexus
 * @param settings the settings.xml file to use
 * @param packagingType the pom packaging type to return.
 * @return the remote repositories defined in the Maven settings.xml file.
 * @throws MavenEclipseApiException the maven eclipse api exception
 */
protected List<ArtifactRepository> _getKnownRepositories(PlexusContainer plexus, Settings settings,
        String packagingType) throws MavenEclipseApiException {
    final boolean needPluginRepo = PACKAGING_TYPE_MAVENPLUGIN.equalsIgnoreCase(packagingType);
    if (settings == null) {
        throw new MavenEclipseApiException(Messages.ERROR_NULL_SETTINGS);
    }

    List<String> activeProfiles = (List<String>) settings.getActiveProfiles();
    if (activeProfiles == null || activeProfiles.size() < 1) {
        throw new MavenEclipseApiException(Messages.ERROR_NO_ACTIVE_PROFILES);
    }

    List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(8);
    try {
        // MavenTools mtools = (MavenTools) plexus
        // .lookup(org.apache.maven.MavenTools.class);
        RepositorySystem rs = plexus.lookup(RepositorySystem.class);
        if (needPluginRepo == false) {
            for (Mirror mirror : (List<Mirror>) settings.getMirrors()) {
                final org.apache.maven.model.Repository repo = new org.apache.maven.model.Repository();
                repo.setId(mirror.getId());
                // repo.setModelEncoding(mirror.getModelEncoding());
                repo.setUrl(mirror.getUrl());
                final RepositoryPolicy snapshotPolicty = new RepositoryPolicy();
                snapshotPolicty.setEnabled(false);
                // snapshotPolicty.setModelEncoding(mirror.getModelEncoding());
                repo.setSnapshots(snapshotPolicty);
                final RepositoryPolicy releasedPolicty = new RepositoryPolicy();
                releasedPolicty.setEnabled(true);
                // releasedPolicty.setModelEncoding(mirror.getModelEncoding());
                repo.setReleases(releasedPolicty);
                // repositories.add(mtools.buildArtifactRepository(repo));
                repositories.add(rs.buildArtifactRepository(repo));
            }
        }

        List<Profile> profiles = (List<Profile>) settings.getProfiles();
        for (Profile p : profiles) {
            if (activeProfiles.contains(p.getId())) {
                org.apache.maven.model.Profile mp = SettingsUtils.convertFromSettingsProfile(p);
                if (needPluginRepo == true) {
                    // requires plugin repositories
                    final List<org.apache.maven.model.Repository> pluginRepos = mp.getPluginRepositories();
                    // repositories
                    // .addAll((List<ArtifactRepository>) mtools
                    // .buildArtifactRepositories(pluginRepos));
                    for (org.apache.maven.model.Repository repo : pluginRepos) {
                        repositories.add(rs.buildArtifactRepository(repo));
                    }
                } else {
                    final List<org.apache.maven.model.Repository> repos = mp.getRepositories();
                    // repositories
                    // .addAll((List<ArtifactRepository>) mtools
                    // .buildArtifactRepositories(repos));
                    for (org.apache.maven.model.Repository repo : repos) {
                        repositories.add(rs.buildArtifactRepository(repo));
                    }
                }
            }
        }
        return repositories;

    } catch (Exception anyEx) {
        anyEx.printStackTrace();
        throw new MavenEclipseApiException(anyEx);
    }
}

From source file:org.eclipse.m2e.core.internal.embedder.MavenImpl.java

License:Open Source License

private List<Profile> getActiveProfiles() throws CoreException {
    Settings settings = getSettings();//w w  w  . ja  v  a 2  s .  com
    List<String> activeProfilesIds = settings.getActiveProfiles();
    ArrayList<Profile> activeProfiles = new ArrayList<Profile>();
    for (org.apache.maven.settings.Profile settingsProfile : settings.getProfiles()) {
        if ((settingsProfile.getActivation() != null && settingsProfile.getActivation().isActiveByDefault())
                || activeProfilesIds.contains(settingsProfile.getId())) {
            Profile profile = SettingsUtils.convertFromSettingsProfile(settingsProfile);
            activeProfiles.add(profile);
        }
    }
    return activeProfiles;
}

From source file:org.eclipse.m2e.profiles.core.internal.management.ProfileManager.java

License:Open Source License

public Map<Profile, Boolean> getAvailableSettingsProfiles() throws CoreException {
    Map<Profile, Boolean> settingsProfiles = new LinkedHashMap<Profile, Boolean>();
    Settings settings = MavenPlugin.getMaven().getSettings();
    List<String> activeProfiles = settings.getActiveProfiles();

    for (org.apache.maven.settings.Profile sp : settings.getProfiles()) {
        Profile p = SettingsUtils.convertFromSettingsProfile(sp);
        boolean isAutomaticallyActivated = isActive(sp, activeProfiles);
        settingsProfiles.put(p, isAutomaticallyActivated);
    }//from  www  .j ava  2  s .c o  m
    return Collections.unmodifiableMap(settingsProfiles);
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFConfigurationProcessor.java

License:Apache License

private MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings)
        throws MavenExecutionRequestPopulationException {
    if (settings == null) {
        return request;
    } else {/*from w  w w. j a  v a 2 s.c om*/
        request.setOffline(settings.isOffline());
        request.setInteractiveMode(settings.isInteractiveMode());
        request.setPluginGroups(settings.getPluginGroups());
        request.setLocalRepositoryPath(settings.getLocalRepository());
        Iterator i$ = settings.getServers().iterator();

        while (i$.hasNext()) {
            Server server = (Server) i$.next();
            server = server.clone();
            request.addServer(server);
        }

        i$ = settings.getProxies().iterator();

        while (i$.hasNext()) {
            Proxy proxy = (Proxy) i$.next();
            if (proxy.isActive()) {
                proxy = proxy.clone();
                request.addProxy(proxy);
            }
        }

        i$ = settings.getMirrors().iterator();

        while (i$.hasNext()) {
            Mirror mirror = (Mirror) i$.next();
            mirror = mirror.clone();
            request.addMirror(mirror);
        }

        request.setActiveProfiles(settings.getActiveProfiles());
        i$ = settings.getProfiles().iterator();

        while (true) {
            Profile rawProfile;
            do {
                if (!i$.hasNext()) {
                    return request;
                }

                rawProfile = (Profile) i$.next();
                request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile));
            } while (!settings.getActiveProfiles().contains(rawProfile.getId()));

            List<Repository> remoteRepositories = rawProfile.getRepositories();
            Iterator i$2 = remoteRepositories.iterator();

            while (i$2.hasNext()) {
                Repository remoteRepository = (Repository) i$.next();

                try {
                    request.addRemoteRepository(
                            MavenRepositorySystem.buildArtifactRepository(remoteRepository));
                } catch (InvalidRepositoryException var10) {
                    logger.error(var10.getMessage());
                }
            }

            List<Repository> pluginRepositories = rawProfile.getPluginRepositories();
            Iterator i$3 = pluginRepositories.iterator();

            while (i$3.hasNext()) {
                Repository pluginRepository = (Repository) i$.next();

                try {
                    request.addPluginArtifactRepository(
                            MavenRepositorySystem.buildArtifactRepository(pluginRepository));
                } catch (InvalidRepositoryException var11) {
                    logger.error(var11.getMessage());
                }
            }
        }
    }
}

From source file:org.kie.workbench.common.services.backend.compiler.external339.AFSettingsXmlConfigurationProcessor.java

License:Apache License

private MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings)
        throws MavenExecutionRequestPopulationException {
    if (settings == null) {
        return request;
    }/* w  w  w  .ja  v a  2 s.c  om*/

    request.setOffline(settings.isOffline());

    request.setInteractiveMode(settings.isInteractiveMode());

    request.setPluginGroups(settings.getPluginGroups());

    request.setLocalRepositoryPath(settings.getLocalRepository());

    for (Server server : settings.getServers()) {
        server = server.clone();

        request.addServer(server);
    }

    //  <proxies>
    //    <proxy>
    //      <active>true</active>
    //      <protocol>http</protocol>
    //      <host>proxy.somewhere.com</host>
    //      <port>8080</port>
    //      <username>proxyuser</username>
    //      <password>somepassword</password>
    //      <nonProxyHosts>www.google.com|*.somewhere.com</nonProxyHosts>
    //    </proxy>
    //  </proxies>

    for (Proxy proxy : settings.getProxies()) {
        if (!proxy.isActive()) {
            continue;
        }

        proxy = proxy.clone();

        request.addProxy(proxy);
    }

    // <mirrors>
    //   <mirror>
    //     <id>nexus</id>
    //     <mirrorOf>*</mirrorOf>
    //     <url>http://repository.sonatype.org/content/groups/public</url>
    //   </mirror>
    // </mirrors>

    for (Mirror mirror : settings.getMirrors()) {
        mirror = mirror.clone();

        request.addMirror(mirror);
    }

    request.setActiveProfiles(settings.getActiveProfiles());

    for (org.apache.maven.settings.Profile rawProfile : settings.getProfiles()) {
        request.addProfile(SettingsUtils.convertFromSettingsProfile(rawProfile));

        if (settings.getActiveProfiles().contains(rawProfile.getId())) {
            List<Repository> remoteRepositories = rawProfile.getRepositories();
            for (Repository remoteRepository : remoteRepositories) {
                try {
                    request.addRemoteRepository(
                            MavenRepositorySystem.buildArtifactRepository(remoteRepository));
                } catch (InvalidRepositoryException e) {
                    // do nothing for now
                }
            }

            List<Repository> pluginRepositories = rawProfile.getPluginRepositories();
            for (Repository pluginRepository : pluginRepositories) {
                try {
                    request.addPluginArtifactRepository(
                            MavenRepositorySystem.buildArtifactRepository(pluginRepository));
                } catch (InvalidRepositoryException e) {
                    // do nothing for now
                }
            }
        }
    }
    return request;
}

From source file:org.springframework.ide.vscode.commons.maven.MavenBridge.java

License:Open Source License

private List<Profile> getActiveProfiles() throws MavenException {
    Settings settings = getSettings();//  w w w  .j  a v a  2 s.c om
    List<String> activeProfilesIds = settings.getActiveProfiles();
    ArrayList<Profile> activeProfiles = new ArrayList<Profile>();
    for (org.apache.maven.settings.Profile settingsProfile : settings.getProfiles()) {
        if ((settingsProfile.getActivation() != null && settingsProfile.getActivation().isActiveByDefault())
                || activeProfilesIds.contains(settingsProfile.getId())) {
            Profile profile = SettingsUtils.convertFromSettingsProfile(settingsProfile);
            activeProfiles.add(profile);
        }
    }
    return activeProfiles;
}