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;
}
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;
}
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()));
}
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;
}
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;
}
Aggregations