Explicitly apply mirror and auth settings to remote repos in the CLI

Previously, the CLI relied on Aether using the session's mirror
selector and authentication selector to customize the configured
repositories. These selectors are only used to configure what Aether
calls recessive repositories (repositories discovered when resolving
an artifact), rather than the explicitly configured repositories that
are typically used.

This commit updates AetherGrapeEngine to apply mirror and
authentication configuration to every added repository, bringing its
behaviour for these two settings into line with what it already does
for proxy configuration.

Fixes #1354
This commit is contained in:
Andy Wilkinson
2014-08-19 16:27:21 +01:00
parent 8e84151f8f
commit 5f9fddd44a
3 changed files with 113 additions and 13 deletions

View File

@@ -263,12 +263,41 @@ public class AetherGrapeEngine implements GrapeEngine {
if (this.repositories.contains(repository)) {
return;
}
repository = getPossibleMirror(repository);
repository = applyProxy(repository);
repository = applyAuthentication(repository);
this.repositories.add(0, repository);
}
private RemoteRepository getPossibleMirror(RemoteRepository remoteRepository) {
RemoteRepository mirror = this.session.getMirrorSelector().getMirror(
remoteRepository);
if (mirror != null) {
return mirror;
}
return remoteRepository;
}
private RemoteRepository applyProxy(RemoteRepository repository) {
if (repository.getProxy() == null) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(repository);
builder.setProxy(this.session.getProxySelector().getProxy(repository));
repository = builder.build();
}
this.repositories.add(0, repository);
return repository;
}
private RemoteRepository applyAuthentication(RemoteRepository repository) {
if (repository.getAuthentication() == null) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(repository);
builder.setAuthentication(this.session.getAuthenticationSelector()
.getAuthentication(repository));
repository = builder.build();
}
return repository;
}
@Override

View File

@@ -58,12 +58,10 @@ import org.springframework.boot.cli.util.Log;
public class SettingsXmlRepositorySystemSessionAutoConfiguration implements
RepositorySystemSessionAutoConfiguration {
private static final String DEFAULT_HOME_DIR = System.getProperty("user.home");
private final String homeDir;
public SettingsXmlRepositorySystemSessionAutoConfiguration() {
this(DEFAULT_HOME_DIR);
this(System.getProperty("user.home"));
}
SettingsXmlRepositorySystemSessionAutoConfiguration(String homeDir) {