Search in sources :

Example 6 with Repository

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

the class RepositoryChangeCommand 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())).findFirst();
    if (!first.isPresent()) {
        System.err.printf("Can't find %s repository with ID \"%s\"\n", (defaultRepository ? "default" : "remote"), id);
        return;
    }
    MavenRepositoryURL changedRepository = first.get();
    changedRepository.setSnapshotsEnabled(snapshots);
    changedRepository.setReleasesEnabled(!noReleases);
    if (updatePolicy != null) {
        SourceAnd<String> up = updatePolicy(updatePolicy);
        if (!up.valid) {
            System.err.println("Unknown value of update policy: \"" + updatePolicy + "\"");
            return;
        }
        changedRepository.setReleasesUpdatePolicy(up.val());
        changedRepository.setSnapshotsUpdatePolicy(up.val());
    }
    if (checksumPolicy != null) {
        SourceAnd<String> cp = checksumPolicy(checksumPolicy);
        if (!cp.valid) {
            System.err.println("Unknown value of checksum policy: \"" + checksumPolicy + "\"");
            return;
        }
        changedRepository.setReleasesChecksumPolicy(cp.val());
        changedRepository.setSnapshotsChecksumPolicy(cp.val());
    }
    if (uri != null) {
        SourceAnd<String> urlResolved = validateRepositoryURL(uri, defaultRepository);
        if (!urlResolved.valid) {
            return;
        }
        changedRepository.setURL(new URL(urlResolved.val()));
    }
    boolean hasUsername = username != null && !"".equals(username.trim());
    boolean hasPassword = password != null && !"".equals(password.trim());
    boolean hasCredentials = hasUsername && hasPassword;
    if ((hasUsername && !hasPassword) || (!hasUsername && hasPassword)) {
        System.err.println("Please specify both username and password");
        return;
    }
    if (defaultRepository && hasCredentials) {
        System.out.println("User credentials won't be used for default repository");
    // no return
    }
    boolean credentialsUpdated = false;
    // credentials for remote repository can be stored only in settings.xml
    if (!defaultRepository && hasCredentials) {
        if (!updateCredentials(force, id, username, password, prefix, config)) {
            return;
        }
        credentialsUpdated = true;
    }
    if (!defaultRepository && changedRepository.getFrom() == MavenRepositoryURL.FROM.SETTINGS) {
        // find <repository> in any active profile to change it
        for (Profile profile : mavenSettings.getProfiles()) {
            Optional<Repository> repository = profile.getRepositories().stream().filter((r) -> id.equals(r.getId())).findFirst();
            if (repository.isPresent()) {
                // I can't imagine it's not...
                Repository r = repository.get();
                r.setUrl(changedRepository.getURL().toString());
                if (!changedRepository.isSnapshotsEnabled()) {
                    r.setSnapshots(new RepositoryPolicy());
                    r.getSnapshots().setEnabled(false);
                } else {
                    RepositoryPolicy rp = r.getSnapshots() == null ? new RepositoryPolicy() : r.getSnapshots();
                    rp.setEnabled(true);
                    if (checksumPolicy != null) {
                        rp.setChecksumPolicy(changedRepository.getSnapshotsChecksumPolicy());
                    } else if (rp.getChecksumPolicy() == null) {
                        rp.setChecksumPolicy("warn");
                    }
                    if (updatePolicy != null) {
                        rp.setUpdatePolicy(changedRepository.getSnapshotsUpdatePolicy());
                    } else if (rp.getUpdatePolicy() == null) {
                        rp.setUpdatePolicy("daily");
                    }
                    r.setSnapshots(rp);
                }
                if (!changedRepository.isReleasesEnabled()) {
                    r.setReleases(new RepositoryPolicy());
                    r.getReleases().setEnabled(false);
                } else {
                    RepositoryPolicy rp = r.getReleases() == null ? new RepositoryPolicy() : r.getReleases();
                    rp.setEnabled(true);
                    if (checksumPolicy != null) {
                        rp.setChecksumPolicy(changedRepository.getReleasesChecksumPolicy());
                    } else if (rp.getChecksumPolicy() == null) {
                        rp.setChecksumPolicy("warn");
                    }
                    if (updatePolicy != null) {
                        rp.setUpdatePolicy(changedRepository.getReleasesUpdatePolicy());
                    } else if (rp.getUpdatePolicy() == null) {
                        rp.setUpdatePolicy("daily");
                    }
                    r.setReleases(rp);
                }
                updateSettings(prefix, config);
                break;
            }
        }
    } else if (changedRepository.getFrom() == MavenRepositoryURL.FROM.PID) {
        List<MavenRepositoryURL> newRepos = new LinkedList<>();
        for (MavenRepositoryURL repo : pidRepos) {
            MavenRepositoryURL _r = repo;
            if (id.equals(repo.getId())) {
                _r = changedRepository;
            }
            newRepos.add(_r);
        }
        updatePidRepositories(prefix, config, defaultRepository, newRepos, settingsRepos.length > 0);
        if (credentialsUpdated) {
            updateSettings(prefix, config);
        }
    }
    Configuration cmConfig = cm.getConfiguration(PID);
    cmConfig.update(config);
    success = true;
}
Also used : Arrays(java.util.Arrays) Repository(org.apache.maven.settings.Repository) URL(java.net.URL) Argument(org.apache.karaf.shell.api.action.Argument) Command(org.apache.karaf.shell.api.action.Command) List(java.util.List) MavenRepositoryURL(org.apache.karaf.maven.core.MavenRepositoryURL) Configuration(org.osgi.service.cm.Configuration) Profile(org.apache.maven.settings.Profile) Service(org.apache.karaf.shell.api.action.lifecycle.Service) Optional(java.util.Optional) RepositoryPolicy(org.apache.maven.settings.RepositoryPolicy) LinkedList(java.util.LinkedList) Option(org.apache.karaf.shell.api.action.Option) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) RepositoryPolicy(org.apache.maven.settings.RepositoryPolicy) URL(java.net.URL) MavenRepositoryURL(org.apache.karaf.maven.core.MavenRepositoryURL) Profile(org.apache.maven.settings.Profile) Repository(org.apache.maven.settings.Repository) List(java.util.List) LinkedList(java.util.LinkedList) MavenRepositoryURL(org.apache.karaf.maven.core.MavenRepositoryURL)

Example 7 with Repository

use of org.apache.maven.settings.Repository in project kie-wb-common by kiegroup.

the class AFSettingsXmlConfigurationProcessor method populateFromSettings.

private MavenExecutionRequest populateFromSettings(MavenExecutionRequest request, Settings settings) throws MavenExecutionRequestPopulationException {
    if (settings == null) {
        return request;
    }
    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);
    }
    for (Proxy proxy : settings.getProxies()) {
        if (!proxy.isActive()) {
            continue;
        }
        proxy = proxy.clone();
        request.addProxy(proxy);
    }
    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;
}
Also used : Proxy(org.apache.maven.settings.Proxy) Repository(org.apache.maven.settings.Repository) Server(org.apache.maven.settings.Server) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Mirror(org.apache.maven.settings.Mirror)

Example 8 with Repository

use of org.apache.maven.settings.Repository in project pom-manipulation-ext by release-engineering.

the class MavenLocationExpanderTest method useActiveSettingsProfileRepos.

@Test
public void useActiveSettingsProfileRepos() throws Exception {
    final ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
    final ArtifactRepositoryPolicy snapshots = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final ArtifactRepositoryPolicy releases = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN);
    final File localRepo = File.createTempFile("local.repo.", ".dir");
    localRepo.deleteOnExit();
    final ArtifactRepository local = new MavenArtifactRepository("local", localRepo.toURI().toString(), layout, snapshots, releases);
    final Repository remote = new Repository();
    remote.setId("remote");
    remote.setUrl("http:///repo.maven.apache.org/maven2");
    final Profile profile = new Profile();
    profile.setId("test");
    profile.addRepository(remote);
    final Settings settings = new Settings();
    settings.addProfile(profile);
    final MavenLocationExpander ex = new MavenLocationExpander(Collections.<Location>emptyList(), Collections.<ArtifactRepository>emptyList(), local, new DefaultMirrorSelector(), settings, Collections.<String>singletonList(profile.getId()));
    final List<Location> result = ex.expand(MavenLocationExpander.EXPANSION_TARGET);
    assertThat(result.size(), equalTo(2));
    final Iterator<Location> iterator = result.iterator();
    Location loc = iterator.next();
    assertThat(loc.getName(), equalTo(local.getId()));
    assertThat(loc.getUri(), equalTo(local.getUrl()));
    loc = iterator.next();
    assertThat(loc.getName(), equalTo(remote.getId()));
    assertThat(loc.getUri(), equalTo(remote.getUrl()));
}
Also used : ArtifactRepositoryLayout(org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout) DefaultRepositoryLayout(org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) DefaultMirrorSelector(org.apache.maven.repository.DefaultMirrorSelector) Profile(org.apache.maven.settings.Profile) Repository(org.apache.maven.settings.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) Settings(org.apache.maven.settings.Settings) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test)

Example 9 with Repository

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

the class AetherTimeoutTest method settingsWithJettyRepository.

private Settings settingsWithJettyRepository() {
    Settings settings = new Settings();
    Profile defaultProfile = new Profile();
    defaultProfile.setId("default");
    Repository repo1 = new Repository();
    repo1.setId("repo1");
    repo1.setUrl("http://localhost:" + port + "/repository");
    defaultProfile.addRepository(repo1);
    settings.addProfile(defaultProfile);
    settings.addActiveProfile("default");
    return settings;
}
Also used : Repository(org.apache.maven.settings.Repository) Settings(org.apache.maven.settings.Settings) Profile(org.apache.maven.settings.Profile)

Example 10 with Repository

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

the class AetherTimeoutTest method settingsWithUnresponsiveRepository.

private Settings settingsWithUnresponsiveRepository() {
    Settings settings = new Settings();
    Profile defaultProfile = new Profile();
    defaultProfile.setId("default");
    Repository repo1 = new Repository();
    repo1.setId("repo1");
    // see:
    // - https://tools.ietf.org/html/rfc5737
    // - https://en.wikipedia.org/wiki/Reserved_IP_addresses
    repo1.setUrl("http://192.0.2.0/repository");
    defaultProfile.addRepository(repo1);
    settings.addProfile(defaultProfile);
    settings.addActiveProfile("default");
    return settings;
}
Also used : Repository(org.apache.maven.settings.Repository) Settings(org.apache.maven.settings.Settings) 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