Search in sources :

Example 11 with Repository

use of org.apache.maven.settings.Repository in project fabric8 by jboss-fuse.

the class MavenConfigurationImpl method buildSettings.

private Settings buildSettings(String localRepoPath, String settingsPath, boolean useFallbackRepositories) {
    Settings settings;
    if (settingsPath == null) {
        settings = new Settings();
    } else {
        DefaultSettingsBuilderFactory factory = new DefaultSettingsBuilderFactory();
        DefaultSettingsBuilder builder = factory.newInstance();
        SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();
        request.setUserSettingsFile(new File(settingsPath));
        try {
            SettingsBuildingResult result = builder.build(request);
            settings = result.getEffectiveSettings();
        } catch (SettingsBuildingException exc) {
            throw new AssertionError("cannot build settings", exc);
        }
    }
    if (useFallbackRepositories) {
        Profile fallbackProfile = new Profile();
        Repository central = new Repository();
        central.setId("central");
        central.setUrl("http://repo1.maven.org/maven2");
        fallbackProfile.setId("fallback");
        fallbackProfile.setRepositories(Arrays.asList(central));
        settings.addProfile(fallbackProfile);
        settings.addActiveProfile("fallback");
    }
    if (localRepoPath != null) {
        settings.setLocalRepository(localRepoPath);
    }
    return settings;
}
Also used : SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) Repository(org.apache.maven.settings.Repository) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingResult(org.apache.maven.settings.building.SettingsBuildingResult) DefaultSettingsBuilder(org.apache.maven.settings.building.DefaultSettingsBuilder) DefaultSettingsBuilderFactory(org.apache.maven.settings.building.DefaultSettingsBuilderFactory) File(java.io.File) Settings(org.apache.maven.settings.Settings) Profile(org.apache.maven.settings.Profile) DefaultSettingsBuildingRequest(org.apache.maven.settings.building.DefaultSettingsBuildingRequest) SettingsBuildingRequest(org.apache.maven.settings.building.SettingsBuildingRequest)

Example 12 with Repository

use of org.apache.maven.settings.Repository in project fabric8 by jboss-fuse.

the class MavenConfigurationImpl method getRepositories.

/**
 * Repository is a comma separated list of repositories to be used. If repository acces requests
 * authentication the user name and password must be specified in the repository url as for
 * example http://user:password@repository.ops4j.org/maven2.<br/>
 * If the repository from 1/2 bellow starts with a plus (+) the option 3 is also used and the
 * repositories from settings.xml will be cummulated.<br/>
 * Repository resolution:<br/>
 * 1. looks for a configuration property named repository;<br/>
 * 2. looks for a framework property/system setting repository;<br/>
 * 3. looks in settings.xml (see settings.xml resolution). in this case all configured
 * repositories will be used including configured user/password. In this case the central
 * repository is also added. Note that the local repository is added as the first repository if
 * exists.
 *
 * @see MavenConfiguration#getRepositories()
 * @see MavenConfiguration#getLocalRepository()
 */
public List<MavenRepositoryURL> getRepositories() throws MalformedURLException {
    if (!contains(m_pid + ServiceConstants.PROPERTY_REPOSITORIES)) {
        // look for repositories property
        String repositoriesProp = m_propertyResolver.get(m_pid + ServiceConstants.PROPERTY_REPOSITORIES);
        // if not set or starting with a plus (+) get repositories from settings xml
        if ((repositoriesProp == null || repositoriesProp.startsWith(REPOSITORIES_APPEND_SIGN)) && settings != null) {
            String init = (repositoriesProp == null) ? "" : repositoriesProp.substring(1);
            StringBuilder builder = new StringBuilder(init);
            Map<String, Profile> profiles = settings.getProfilesAsMap();
            for (String activeProfile : getActiveProfiles(true)) {
                Profile profile = profiles.get(activeProfile);
                if (profile == null) {
                    continue;
                }
                for (Repository repo : profile.getRepositories()) {
                    if (builder.length() > 0) {
                        builder.append(REPOSITORIES_SEPARATOR);
                    }
                    builder.append(repo.getUrl());
                    builder.append("@id=");
                    builder.append(repo.getId());
                    if (repo.getReleases() != null && !repo.getReleases().isEnabled()) {
                        builder.append("@noreleases");
                    }
                    if (repo.getSnapshots() != null && repo.getSnapshots().isEnabled()) {
                        builder.append("@snapshots");
                    }
                    if (repo.getReleases() != null && repo.getReleases().isEnabled()) {
                        if (repo.getReleases().getUpdatePolicy() != null) {
                            builder.append("@releasesUpdate=").append(repo.getReleases().getUpdatePolicy());
                        }
                        if (repo.getReleases().getChecksumPolicy() != null) {
                            builder.append("@releasesChecksum=").append(repo.getReleases().getChecksumPolicy());
                        }
                    }
                    if (repo.getSnapshots() != null && repo.getSnapshots().isEnabled()) {
                        if (repo.getSnapshots().getUpdatePolicy() != null) {
                            builder.append("@snapshotsUpdate=").append(repo.getSnapshots().getUpdatePolicy());
                        }
                        if (repo.getSnapshots().getChecksumPolicy() != null) {
                            builder.append("@snapshotsChecksum=").append(repo.getSnapshots().getChecksumPolicy());
                        }
                    }
                }
            }
            repositoriesProp = builder.toString();
        }
        // build repositories list
        final List<MavenRepositoryURL> repositoriesProperty = new ArrayList<MavenRepositoryURL>();
        if (m_propertyResolver.get(m_pid + ServiceConstants.PROPERTY_LOCAL_REPO_AS_REMOTE) != null) {
            MavenRepositoryURL localRepository = getDefaultLocalRepository();
            if (localRepository != null) {
                repositoriesProperty.add(localRepository);
            }
        }
        if (repositoriesProp != null && repositoriesProp.trim().length() > 0) {
            String[] repositories = repositoriesProp.split(REPOSITORIES_SEPARATOR);
            for (String repositoryURL : repositories) {
                repositoriesProperty.add(new MavenRepositoryURL(repositoryURL.trim()));
            }
        }
        LOGGER.trace("Using remote repositories [" + repositoriesProperty + "]");
        return set(m_pid + ServiceConstants.PROPERTY_REPOSITORIES, repositoriesProperty);
    }
    return get(m_pid + ServiceConstants.PROPERTY_REPOSITORIES);
}
Also used : Repository(org.apache.maven.settings.Repository) ArrayList(java.util.ArrayList) Profile(org.apache.maven.settings.Profile)

Example 13 with Repository

use of org.apache.maven.settings.Repository in project spring-boot by spring-projects.

the class RepositoryConfigurationFactory method addActiveProfileRepositories.

private static void addActiveProfileRepositories(List<Profile> activeProfiles, List<RepositoryConfiguration> configurations) {
    for (Profile activeProfile : activeProfiles) {
        Interpolator interpolator = new RegexBasedInterpolator();
        interpolator.addValueSource(new PropertiesBasedValueSource(activeProfile.getProperties()));
        for (Repository repository : activeProfile.getRepositories()) {
            configurations.add(getRepositoryConfiguration(interpolator, repository));
        }
    }
}
Also used : Repository(org.apache.maven.settings.Repository) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) Interpolator(org.codehaus.plexus.interpolation.Interpolator) RegexBasedInterpolator(org.codehaus.plexus.interpolation.RegexBasedInterpolator) PropertiesBasedValueSource(org.codehaus.plexus.interpolation.PropertiesBasedValueSource) Profile(org.apache.maven.settings.Profile)

Example 14 with Repository

use of org.apache.maven.settings.Repository in project karaf by apache.

the class RepositoryRemoveCommand method edit.

@Override
protected void edit(String prefix, Dictionary<String, Object> config, MavenRepositoryURL[] allRepos, MavenRepositoryURL[] pidRepos, MavenRepositoryURL[] settingsRepos) throws Exception {
    Optional<MavenRepositoryURL> first = Arrays.stream(allRepos).filter((repo) -> id.equals(repo.getId())).findAny();
    if (!first.isPresent()) {
        System.err.printf("Can't find %s repository with ID \"%s\"\n", (defaultRepository ? "default" : "remote"), id);
        return;
    }
    if (force || confirm(String.format("Are you sure to remove repository with ID \"%s\" for URL %s? (y/N) ", id, first.get().getURL()))) {
        if (!defaultRepository && first.get().getFrom() == MavenRepositoryURL.FROM.SETTINGS) {
            // remove <server> (credentials) if available
            List<Server> newServers = mavenSettings.getServers().stream().filter((s) -> !id.equals(s.getId())).collect(Collectors.toList());
            mavenSettings.setServers(newServers);
            // find <repository> in any active profile and remove it
            for (Profile profile : mavenSettings.getProfiles()) {
                if (profile.getRepositories().stream().anyMatch((r) -> id.equals(r.getId()))) {
                    List<Repository> newRepos = profile.getRepositories().stream().filter((r) -> !id.equals(r.getId())).collect(Collectors.toList());
                    profile.setRepositories(newRepos);
                    System.out.printf("Repository with ID \"%s\" was removed from profile \"%s\"\n", id, profile.getId());
                    break;
                }
            }
            updateSettings(prefix, config);
        } else if (first.get().getFrom() == MavenRepositoryURL.FROM.PID) {
            List<MavenRepositoryURL> newRepos = Arrays.stream(pidRepos).filter((r) -> !id.equals(r.getId())).collect(Collectors.toList());
            updatePidRepositories(prefix, config, defaultRepository, newRepos, settingsRepos.length > 0);
            // if there are credentials for this repository, we have to remove them from settings.xml
            if (mavenSettings != null && mavenSettings.getServers().stream().anyMatch((s) -> id.equals(s.getId()))) {
                // remove <server> (credentials) if available
                List<Server> newServers = mavenSettings.getServers().stream().filter((s) -> !id.equals(s.getId())).collect(Collectors.toList());
                mavenSettings.setServers(newServers);
                updateSettings(prefix, config);
            }
        }
        Configuration cmConfig = cm.getConfiguration(PID);
        cmConfig.update(config);
        success = true;
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) MavenRepositoryURL(org.apache.karaf.maven.core.MavenRepositoryURL) Repository(org.apache.maven.settings.Repository) Configuration(org.osgi.service.cm.Configuration) Profile(org.apache.maven.settings.Profile) Server(org.apache.maven.settings.Server) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) Collectors(java.util.stream.Collectors) Dictionary(java.util.Dictionary) Command(org.apache.karaf.shell.api.action.Command) Repository(org.apache.maven.settings.Repository) Server(org.apache.maven.settings.Server) Configuration(org.osgi.service.cm.Configuration) List(java.util.List) MavenRepositoryURL(org.apache.karaf.maven.core.MavenRepositoryURL) Profile(org.apache.maven.settings.Profile)

Aggregations

Repository (org.apache.maven.settings.Repository)14 Profile (org.apache.maven.settings.Profile)12 Settings (org.apache.maven.settings.Settings)6 MavenRepositoryURL (org.apache.karaf.maven.core.MavenRepositoryURL)3 Mirror (org.apache.maven.settings.Mirror)3 Proxy (org.apache.maven.settings.Proxy)3 Server (org.apache.maven.settings.Server)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Dictionary (java.util.Dictionary)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Optional (java.util.Optional)2 Command (org.apache.karaf.shell.api.action.Command)2 Service (org.apache.karaf.shell.api.action.lifecycle.Service)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ArtifactRepositoryPolicy (org.apache.maven.artifact.repository.ArtifactRepositoryPolicy)2