use of org.eclipse.aether.util.repository.AuthenticationBuilder in project spring-boot by spring-projects.
the class MavenSettings method createProxySelector.
private ProxySelector createProxySelector(SettingsDecryptionResult decryptedSettings) {
DefaultProxySelector selector = new DefaultProxySelector();
for (Proxy proxy : decryptedSettings.getProxies()) {
Authentication authentication = new AuthenticationBuilder().addUsername(proxy.getUsername()).addPassword(proxy.getPassword()).build();
selector.add(new org.eclipse.aether.repository.Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), authentication), proxy.getNonProxyHosts());
}
return selector;
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project spring-boot by spring-projects.
the class MavenSettings method createAuthenticationSelector.
private AuthenticationSelector createAuthenticationSelector(SettingsDecryptionResult decryptedSettings) {
DefaultAuthenticationSelector selector = new DefaultAuthenticationSelector();
for (Server server : decryptedSettings.getServers()) {
AuthenticationBuilder auth = new AuthenticationBuilder();
auth.addUsername(server.getUsername()).addPassword(server.getPassword());
auth.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
selector.add(server.getId(), auth.build());
}
return new ConservativeAuthenticationSelector(selector);
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project bnd by bndtools.
the class AetherRepository method init.
protected final synchronized void init() throws Exception {
if (initialised)
return;
// Initialise Aether
DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(ArtifactDescriptorReader.class, DefaultArtifactDescriptorReader.class);
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
locator.addService(TransporterFactory.class, FileTransporterFactory.class);
locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
locator.setErrorHandler(new ErrorHandler() {
@Override
public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
if (reporter != null)
reporter.error("Service creation failed for type %s using impl %s: %s", type, impl, exception.getLocalizedMessage());
exception.printStackTrace();
}
});
repoSystem = locator.getService(RepositorySystem.class);
if (repoSystem == null)
throw new IllegalArgumentException("Failed to initialise Aether repository system");
Builder builder = new RemoteRepository.Builder("remote", "default", mainUri.toString());
if (username != null) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder().addUsername(username);
if (password != null)
authBuilder.addPassword(password);
builder.setAuthentication(authBuilder.build());
}
remoteRepo = builder.build();
localRepo = new LocalRepository(new File(cacheDir, "aether-local"));
// Initialise Index
if (indexUri == null) {
indexedRepo = null;
} else {
// Test whether the index URI exists and is available.
HttpURLConnection connection = (HttpURLConnection) indexUri.toURL().openConnection();
try {
connection.setRequestMethod("HEAD");
int responseCode = connection.getResponseCode();
if (responseCode >= 400) {
indexedRepo = null;
} else {
indexedRepo = new FixedIndexedRepo();
Map<String, String> config = new HashMap<String, String>();
indexedRepo.setReporter(this.reporter);
indexedRepo.setRegistry(registry);
config.put(FixedIndexedRepo.PROP_CACHE, cacheDir.getAbsolutePath());
config.put(FixedIndexedRepo.PROP_LOCATIONS, indexUri.toString());
indexedRepo.setProperties(config);
}
} catch (UnknownHostException e) {
return;
} finally {
connection.disconnect();
}
}
initialised = true;
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project acceptance-test-harness by jenkinsci.
the class ArtifactResolverUtil method asProxy.
/**
* Converts Maven Proxy to Aether Proxy
*
* @param proxy the Maven proxy to be converted
* @return Aether proxy equivalent
*/
private static Proxy asProxy(org.apache.maven.settings.Proxy proxy) {
Authentication auth = null;
if (proxy.getUsername() != null && proxy.getPassword() != null) {
AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(proxy.getUsername());
authBuilder.addPassword(proxy.getPassword());
auth = authBuilder.build();
}
return new Proxy(proxy.getProtocol(), proxy.getHost(), proxy.getPort(), auth);
}
use of org.eclipse.aether.util.repository.AuthenticationBuilder in project wildfly-swarm by wildfly-swarm.
the class MavenArtifactResolvingHelper method buildRemoteRepository.
private RemoteRepository buildRemoteRepository(final String id, final String url, final Authentication auth, final ArtifactRepositoryPolicy releasesPolicy, final ArtifactRepositoryPolicy snapshotsPolicy) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(id, "default", url);
if (auth != null && auth.getUsername() != null && auth.getPassword() != null) {
builder.setAuthentication(new AuthenticationBuilder().addUsername(auth.getUsername()).addPassword(auth.getPassword()).build());
}
builder.setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy()));
builder.setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
RemoteRepository repository = builder.build();
final RemoteRepository mirror = session.getMirrorSelector().getMirror(repository);
if (mirror != null) {
final org.eclipse.aether.repository.Authentication mirrorAuth = session.getAuthenticationSelector().getAuthentication(mirror);
RemoteRepository.Builder mirrorBuilder = new RemoteRepository.Builder(mirror).setId(repository.getId()).setSnapshotPolicy(new RepositoryPolicy(snapshotsPolicy.isEnabled(), snapshotsPolicy.getUpdatePolicy(), snapshotsPolicy.getChecksumPolicy())).setReleasePolicy(new RepositoryPolicy(releasesPolicy.isEnabled(), releasesPolicy.getUpdatePolicy(), releasesPolicy.getChecksumPolicy()));
if (mirrorAuth != null) {
mirrorBuilder.setAuthentication(mirrorAuth);
}
repository = mirrorBuilder.build();
}
Proxy proxy = session.getProxySelector().getProxy(repository);
if (proxy != null) {
repository = new RemoteRepository.Builder(repository).setProxy(proxy).build();
}
return repository;
}
Aggregations