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