throw new IllegalStateException("Unable to get active profiles from Maven settings.");
}
for (Profile p : activeProfiles) {
for (Repository repository : p.getRepositories()) {
RemoteRepository repo = MavenConverter.asRemoteRepository(repository);
// add remote repository from model only if not overridden by code
if (!isIdIncluded(additionalRemoteRepositories, repo)) {
enhancedRepos.add(repo);
}
}
}
// add remote repositories
for (RemoteRepository repo : remoteRepositories) {
// add remote repository from model only if not overridden by code
if (!isIdIncluded(additionalRemoteRepositories, repo)) {
enhancedRepos.add(repo);
}
}
// add maven central if selected but if not overridden by API
if (useMavenCentralRepository) {
if (!isIdIncluded(additionalRemoteRepositories, MAVEN_CENTRAL)) {
enhancedRepos.add(MAVEN_CENTRAL);
}
} else {
List<RemoteRepository> reposToRemove = new ArrayList<RemoteRepository>();
// Attempt a remove
for (final RemoteRepository repo : enhancedRepos) {
// Because there are a lot of aliases for Maven Central, we have to approximate that anything named
// "central" with URL containing "maven" is what we're looking to ban. For instance Central could be
// http://repo.maven.apache.org/maven2 or http://repo1.maven.org/maven2
final String repoUrl = repo.getUrl();
if ((repoUrl.contains("maven.org") || repoUrl.contains("apache.org"))
&& repo.getId().equalsIgnoreCase(MAVEN_CENTRAL_NAME)) {
// remote this "might-be" central repository, but only if not specified by hand
if (!isIdIncluded(additionalRemoteRepositories, MAVEN_CENTRAL)) {
reposToRemove.add(repo);
}
}
}
// We have to search on URL criteria, because .equals on RemoteRepository is too strict for us to call a
// simple remove operation on the enhancedRepos Collection
enhancedRepos.removeAll(reposToRemove);
}
// use mirrors if any to do the mirroring stuff
DefaultMirrorSelector dms = new DefaultMirrorSelector();
// fill in mirrors
for (Mirror mirror : settings.getMirrors()) {
// Repository manager flag is set to false
// Maven does not support specifying it in the settings.xml
dms.add(mirror.getId(), mirror.getUrl(), mirror.getLayout(), false, mirror.getMirrorOf(),
mirror.getMirrorOfLayouts());
}
Set<RemoteRepository> mirroredRepos = new LinkedHashSet<RemoteRepository>();
for (RemoteRepository repository : enhancedRepos) {
RemoteRepository mirror = dms.getMirror(repository);
if (mirror != null) {
mirroredRepos.add(mirror);
} else {
mirroredRepos.add(repository);
}