use of org.apache.karaf.maven.core.MavenRepositoryURL in project karaf by apache.
the class RepositoryAddCommand method edit.
@Override
protected void edit(String prefix, Dictionary<String, Object> config, MavenRepositoryURL[] allRepos, MavenRepositoryURL[] pidRepos, MavenRepositoryURL[] settingsRepos) throws Exception {
if (idx > pidRepos.length) {
// TOCONSIDER: should we allow to add repository to settings.xml too?
System.err.printf("List of %s repositories has %d elements. Can't insert at position %s.\n", (defaultRepository ? "default" : "remote"), pidRepos.length, id);
return;
}
Optional<MavenRepositoryURL> first = Arrays.stream(allRepos).filter((repo) -> id.equals(repo.getId())).findAny();
if (first.isPresent()) {
System.err.printf("Repository with ID \"%s\" is already configured for URL %s\n", id, first.get().getURL());
return;
}
SourceAnd<String> up = updatePolicy(updatePolicy);
if (!up.valid) {
System.err.println("Unknown value of update policy: \"" + updatePolicy + "\"");
return;
}
SourceAnd<String> cp = checksumPolicy(checksumPolicy);
if (!cp.valid) {
System.err.println("Unknown value of checksum policy: \"" + checksumPolicy + "\"");
return;
}
SourceAnd<String> urlResolved = validateRepositoryURL(uri, defaultRepository);
if (!urlResolved.valid) {
return;
}
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
}
// credentials for remote repository can be stored only in settings.xml
if (!defaultRepository && hasCredentials) {
if (!updateCredentials(force, id, username, password, prefix, config)) {
return;
}
updateSettings(prefix, config);
}
StringBuilder sb = new StringBuilder();
sb.append(urlResolved.val());
sb.append(ServiceConstants.SEPARATOR_OPTIONS).append(ServiceConstants.OPTION_ID).append("=").append(id);
if (snapshots) {
sb.append(ServiceConstants.SEPARATOR_OPTIONS).append(ServiceConstants.OPTION_ALLOW_SNAPSHOTS);
}
if (noReleases) {
sb.append(ServiceConstants.SEPARATOR_OPTIONS).append(ServiceConstants.OPTION_DISALLOW_RELEASES);
}
sb.append(ServiceConstants.SEPARATOR_OPTIONS).append(ServiceConstants.OPTION_UPDATE).append("=").append(updatePolicy);
sb.append(ServiceConstants.SEPARATOR_OPTIONS).append(ServiceConstants.OPTION_CHECKSUM).append("=").append(checksumPolicy);
MavenRepositoryURL newRepository = new MavenRepositoryURL(sb.toString());
List<MavenRepositoryURL> newRepos = new LinkedList<>(Arrays.asList(pidRepos));
if (idx >= 0) {
newRepos.add(idx, newRepository);
} else {
newRepos.add(newRepository);
}
updatePidRepositories(prefix, config, defaultRepository, newRepos, settingsRepos.length > 0);
Configuration cmConfig = cm.getConfiguration(PID);
cmConfig.update(config);
success = true;
}
Aggregations