Search in sources :

Example 11 with AuthenticationBuilder

use of org.eclipse.aether.util.repository.AuthenticationBuilder in project build-info by JFrogDev.

the class ArtifactoryEclipseResolversHelper method getResolutionRepositories.

/**
 * Create a list containing one release and one snapshot resolution repositories, according to the configuration in the Artifactory plugin.
 * The list is used to override Maven's default or configured repositories, so that the build dependencies are resolved from Artifactory.
 * The list is saved and reused for further invokations to this method.
 * @param session
 * @return
 */
public List<RemoteRepository> getResolutionRepositories(RepositorySystemSession session) {
    if (resolutionRepositories == null) {
        Properties allMavenProps = new Properties();
        allMavenProps.putAll(session.getSystemProperties());
        allMavenProps.putAll(session.getUserProperties());
        resolutionHelper.init(allMavenProps);
        String releaseRepoUrl = resolutionHelper.getRepoReleaseUrl();
        String snapshotRepoUrl = resolutionHelper.getRepoSnapshotUrl();
        Authentication authentication = null;
        if (StringUtils.isNotBlank(resolutionHelper.getRepoUsername())) {
            authentication = new AuthenticationBuilder().addString("username", resolutionHelper.getRepoUsername()).addSecret("password", resolutionHelper.getRepoPassword()).build();
        }
        Proxy proxy = null;
        if (StringUtils.isNotBlank(resolutionHelper.getProxyHost())) {
            Authentication auth = new AuthenticationBuilder().addString("username", resolutionHelper.getProxyUsername()).addSecret("password", resolutionHelper.getProxyPassword()).build();
            proxy = new Proxy(null, resolutionHelper.getProxyHost(), resolutionHelper.getProxyPort(), auth);
        }
        if (StringUtils.isNotBlank(snapshotRepoUrl)) {
            logger.debug("[buildinfo] Enforcing snapshot repository for resolution: " + snapshotRepoUrl);
            RepositoryPolicy releasePolicy = new RepositoryPolicy(false, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RemoteRepository.Builder builder = new RemoteRepository.Builder("artifactory-snapshot", "default", snapshotRepoUrl);
            builder.setReleasePolicy(releasePolicy);
            builder.setSnapshotPolicy(snapshotPolicy);
            if (authentication != null) {
                logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for snapshot resolution repository");
                builder.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for snapshot resolution repository");
                builder.setProxy(proxy);
            }
            snapshotRepository = builder.build();
        }
        if (StringUtils.isNotBlank(releaseRepoUrl)) {
            logger.debug("[buildinfo] Enforcing release repository for resolution: " + releaseRepoUrl);
            boolean snapshotPolicyEnabled = snapshotRepository == null;
            String repositoryId = snapshotPolicyEnabled ? "artifactory-release-snapshot" : "artifactory-release";
            RepositoryPolicy releasePolicy = new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RepositoryPolicy snapshotPolicy = new RepositoryPolicy(snapshotPolicyEnabled, RepositoryPolicy.UPDATE_POLICY_DAILY, RepositoryPolicy.CHECKSUM_POLICY_WARN);
            RemoteRepository.Builder builder = new RemoteRepository.Builder(repositoryId, "default", releaseRepoUrl);
            builder.setReleasePolicy(releasePolicy);
            builder.setSnapshotPolicy(snapshotPolicy);
            if (authentication != null) {
                logger.debug("[buildinfo] Enforcing repository authentication: " + authentication + " for release resolution repository");
                builder.setAuthentication(authentication);
            }
            if (proxy != null) {
                logger.debug("[buildinfo] Enforcing proxy: " + proxy + " for release resolution repository");
                builder.setProxy(proxy);
            }
            releaseRepository = builder.build();
        }
        List<RemoteRepository> tempRepositories = Lists.newArrayList();
        if (releaseRepository != null) {
            tempRepositories.add(releaseRepository);
        }
        if (snapshotRepository != null) {
            tempRepositories.add(snapshotRepository);
        }
        resolutionRepositories = tempRepositories;
    }
    return resolutionRepositories;
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Authentication(org.eclipse.aether.repository.Authentication) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Properties(java.util.Properties)

Example 12 with AuthenticationBuilder

use of org.eclipse.aether.util.repository.AuthenticationBuilder in project storm by apache.

the class DependencyResolverMain method parseProxyArg.

private static Proxy parseProxyArg(String proxyUrl, String proxyUsername, String proxyPassword) throws MalformedURLException {
    URL url = new URL(proxyUrl);
    if (StringUtils.isNotEmpty(proxyUsername) && StringUtils.isNotEmpty(proxyPassword)) {
        AuthenticationBuilder authBuilder = new AuthenticationBuilder();
        authBuilder.addUsername(proxyUsername).addPassword(proxyPassword);
        return new Proxy(url.getProtocol(), url.getHost(), url.getPort(), authBuilder.build());
    } else {
        return new Proxy(url.getProtocol(), url.getHost(), url.getPort());
    }
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) URL(java.net.URL)

Example 13 with AuthenticationBuilder

use of org.eclipse.aether.util.repository.AuthenticationBuilder in project druid by druid-io.

the class PullDependencies method createTeslaAether.

private DefaultTeslaAether createTeslaAether(List<Repository> remoteRepositories) {
    if (!useProxy) {
        return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[0]));
    }
    if (!StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTP) && !StringUtils.toLowerCase(proxyType).equals(Proxy.TYPE_HTTPS)) {
        throw new IllegalArgumentException("invalid proxy type: " + proxyType);
    }
    RepositorySystemSession repositorySystemSession = new RepositorySystemSessionProvider(new File(localRepository)).get();
    List<RemoteRepository> rl = remoteRepositories.stream().map(r -> {
        RemoteRepository.Builder builder = new RemoteRepository.Builder(r.getId(), "default", r.getUrl());
        if (r.getUsername() != null && r.getPassword() != null) {
            Authentication auth = new AuthenticationBuilder().addUsername(r.getUsername()).addPassword(r.getPassword()).build();
            builder.setAuthentication(auth);
        }
        final Authentication proxyAuth;
        if (Strings.isNullOrEmpty(proxyUsername)) {
            proxyAuth = null;
        } else {
            proxyAuth = new AuthenticationBuilder().addUsername(proxyUsername).addPassword(proxyPassword).build();
        }
        builder.setProxy(new Proxy(proxyType, proxyHost, proxyPort, proxyAuth));
        return builder.build();
    }).collect(Collectors.toList());
    return new DefaultTeslaAether(rl, repositorySystemSession);
}
Also used : Option(com.github.rvesse.airline.annotations.Option) Logger(org.apache.druid.java.util.common.logger.Logger) TeslaAether(io.tesla.aether.TeslaAether) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) DependencyFilterUtils(org.eclipse.aether.util.filter.DependencyFilterUtils) Proxy(org.eclipse.aether.repository.Proxy) Inject(com.google.inject.Inject) URISyntaxException(java.net.URISyntaxException) Dependency(org.eclipse.aether.graph.Dependency) JavaScopes(org.eclipse.aether.util.artifact.JavaScopes) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) URI(java.net.URI) Repository(io.tesla.aether.Repository) Command(com.github.rvesse.airline.annotations.Command) FileUtils(org.apache.druid.java.util.common.FileUtils) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) CollectRequest(org.eclipse.aether.collection.CollectRequest) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RepositorySystemSessionProvider(io.tesla.aether.guice.RepositorySystemSessionProvider) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) StringUtils(org.apache.druid.java.util.common.StringUtils) Artifact(org.eclipse.aether.artifact.Artifact) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) SuppressForbidden(io.netty.util.SuppressForbidden) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) File(java.io.File) Authentication(org.eclipse.aether.repository.Authentication) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) List(java.util.List) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) RepositorySystemSessionProvider(io.tesla.aether.guice.RepositorySystemSessionProvider) Repository(io.tesla.aether.Repository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Proxy(org.eclipse.aether.repository.Proxy) Authentication(org.eclipse.aether.repository.Authentication) File(java.io.File)

Example 14 with AuthenticationBuilder

use of org.eclipse.aether.util.repository.AuthenticationBuilder in project zeppelin by apache.

the class InstallInterpreter method install.

public void install(String name, String artifact) {
    Proxy proxy = null;
    if (proxyUrl != null) {
        Authentication auth = new AuthenticationBuilder().addUsername(proxyUser).addPassword(proxyPassword).build();
        proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
    }
    DependencyResolver depResolver = new DependencyResolver(localRepoDir, proxy);
    File installDir = new File(interpreterBaseDir, name);
    if (installDir.exists()) {
        System.err.println("Directory " + installDir.getAbsolutePath() + " already exists" + "\n\nSkipped");
        return;
    }
    System.out.println("Install " + name + "(" + artifact + ") to " + installDir.getAbsolutePath() + " ... ");
    try {
        depResolver.load(artifact, installDir);
        System.out.println("Interpreter " + name + " installed under " + installDir.getAbsolutePath() + ".");
        startTip();
    } catch (RepositoryException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Authentication(org.eclipse.aether.repository.Authentication) RepositoryException(org.eclipse.aether.RepositoryException) IOException(java.io.IOException) File(java.io.File) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver)

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