Search in sources :

Example 6 with AuthenticationBuilder

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;
}
Also used : Proxy(org.apache.maven.settings.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) DefaultProxySelector(org.eclipse.aether.util.repository.DefaultProxySelector) Authentication(org.eclipse.aether.repository.Authentication)

Example 7 with AuthenticationBuilder

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);
}
Also used : AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Server(org.apache.maven.settings.Server) DefaultAuthenticationSelector(org.eclipse.aether.util.repository.DefaultAuthenticationSelector) ConservativeAuthenticationSelector(org.eclipse.aether.util.repository.ConservativeAuthenticationSelector)

Example 8 with AuthenticationBuilder

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;
}
Also used : ErrorHandler(org.eclipse.aether.impl.DefaultServiceLocator.ErrorHandler) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Builder(org.eclipse.aether.repository.RemoteRepository.Builder) LocalRepository(org.eclipse.aether.repository.LocalRepository) DefaultServiceLocator(org.eclipse.aether.impl.DefaultServiceLocator) RepositorySystem(org.eclipse.aether.RepositorySystem) HttpURLConnection(java.net.HttpURLConnection) File(java.io.File) FixedIndexedRepo(aQute.bnd.deployer.repository.FixedIndexedRepo)

Example 9 with AuthenticationBuilder

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);
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Authentication(org.eclipse.aether.repository.Authentication)

Example 10 with AuthenticationBuilder

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;
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Aggregations

AuthenticationBuilder (org.eclipse.aether.util.repository.AuthenticationBuilder)14 Authentication (org.eclipse.aether.repository.Authentication)7 Proxy (org.eclipse.aether.repository.Proxy)7 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 File (java.io.File)3 RepositoryPolicy (org.eclipse.aether.repository.RepositoryPolicy)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Server (org.apache.maven.settings.Server)2 DefaultProxySelector (org.eclipse.aether.util.repository.DefaultProxySelector)2 FixedIndexedRepo (aQute.bnd.deployer.repository.FixedIndexedRepo)1 Command (com.github.rvesse.airline.annotations.Command)1 Option (com.github.rvesse.airline.annotations.Option)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Inject (com.google.inject.Inject)1 SuppressForbidden (io.netty.util.SuppressForbidden)1