Search in sources :

Example 1 with Repository

use of io.tesla.aether.Repository in project druid by druid-io.

the class PullDependencies method getAetherClient.

@SuppressForbidden(reason = "System#out")
private DefaultTeslaAether getAetherClient() {
    /*
    DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying.  We choose to disable that
    unless debug logging is turned on.  "Disabling" it, however, is kinda bass-ackwards.  We copy out a reference
    to the current System.out, and set System.out to a noop output stream.  Then after DefaultTeslaAether has pulled
    The reference we swap things back.

    This has implications for other things that are running in parallel to this.  Namely, if anything else also grabs
    a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
    to nothingness.  Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
    alongside anything else that's grabbing System.out.  But who knows.
    */
    final List<String> remoteUriList = new ArrayList<>();
    if (!noDefaultRemoteRepositories) {
        remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
    }
    remoteUriList.addAll(remoteRepositories);
    List<Repository> remoteRepositories = new ArrayList<>();
    for (String uri : remoteUriList) {
        try {
            URI u = new URI(uri);
            Repository r = new Repository(uri);
            if (u.getUserInfo() != null) {
                String[] auth = u.getUserInfo().split(":", 2);
                if (auth.length == 2) {
                    r.setUsername(auth[0]);
                    r.setPassword(auth[1]);
                } else {
                    log.warn("Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]", u.getUserInfo(), uri);
                }
            }
            remoteRepositories.add(r);
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
    if (log.isTraceEnabled() || log.isDebugEnabled()) {
        return createTeslaAether(remoteRepositories);
    }
    PrintStream oldOut = System.out;
    try {
        System.setOut(new PrintStream(new OutputStream() {

            @Override
            public void write(int b) {
            }

            @Override
            public void write(byte[] b) {
            }

            @Override
            public void write(byte[] b, int off, int len) {
            }
        }, false, StringUtils.UTF8_STRING));
        return createTeslaAether(remoteRepositories);
    } catch (UnsupportedEncodingException e) {
        // should never happen
        throw new IllegalStateException(e);
    } finally {
        System.setOut(oldOut);
    }
}
Also used : PrintStream(java.io.PrintStream) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Repository(io.tesla.aether.Repository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) SuppressForbidden(io.netty.util.SuppressForbidden)

Example 2 with Repository

use of io.tesla.aether.Repository in project druid by druid-io.

the class PullDependencies method getAetherClient.

private DefaultTeslaAether getAetherClient() {
    /*
    DefaultTeslaAether logs a bunch of stuff to System.out, which is annoying.  We choose to disable that
    unless debug logging is turned on.  "Disabling" it, however, is kinda bass-ackwards.  We copy out a reference
    to the current System.out, and set System.out to a noop output stream.  Then after DefaultTeslaAether has pulled
    The reference we swap things back.

    This has implications for other things that are running in parallel to this.  Namely, if anything else also grabs
    a reference to System.out or tries to log to it while we have things adjusted like this, then they will also log
    to nothingness.  Fortunately, the code that calls this is single-threaded and shouldn't hopefully be running
    alongside anything else that's grabbing System.out.  But who knows.
    */
    final List<String> remoteUriList = Lists.newArrayList();
    if (!noDefaultRemoteRepositories) {
        remoteUriList.addAll(DEFAULT_REMOTE_REPOSITORIES);
    }
    remoteUriList.addAll(remoteRepositories);
    List<Repository> remoteRepositories = Lists.newArrayList();
    for (String uri : remoteUriList) {
        try {
            URI u = new URI(uri);
            Repository r = new Repository(uri);
            if (u.getUserInfo() != null) {
                String[] auth = u.getUserInfo().split(":", 2);
                if (auth.length == 2) {
                    r.setUsername(auth[0]);
                    r.setPassword(auth[1]);
                } else {
                    log.warn("Invalid credentials in repository URI, expecting [<user>:<password>], got [%s] for [%s]", u.getUserInfo(), uri);
                }
            }
            remoteRepositories.add(r);
        } catch (URISyntaxException e) {
            throw Throwables.propagate(e);
        }
    }
    if (log.isTraceEnabled() || log.isDebugEnabled()) {
        return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
    }
    PrintStream oldOut = System.out;
    try {
        System.setOut(new PrintStream(new OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }

            @Override
            public void write(byte[] b) throws IOException {
            }

            @Override
            public void write(byte[] b, int off, int len) throws IOException {
            }
        }, false, StringUtils.UTF8_STRING));
        return new DefaultTeslaAether(localRepository, remoteRepositories.toArray(new Repository[remoteRepositories.size()]));
    } catch (UnsupportedEncodingException e) {
        // should never happen
        throw new IllegalStateException(e);
    } finally {
        System.setOut(oldOut);
    }
}
Also used : PrintStream(java.io.PrintStream) Repository(io.tesla.aether.Repository) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) URI(java.net.URI)

Example 3 with Repository

use of io.tesla.aether.Repository 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)

Aggregations

Repository (io.tesla.aether.Repository)3 OutputStream (java.io.OutputStream)3 PrintStream (java.io.PrintStream)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 SuppressForbidden (io.netty.util.SuppressForbidden)2 DefaultTeslaAether (io.tesla.aether.internal.DefaultTeslaAether)2 ArrayList (java.util.ArrayList)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 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 TeslaAether (io.tesla.aether.TeslaAether)1 RepositorySystemSessionProvider (io.tesla.aether.guice.RepositorySystemSessionProvider)1