Search in sources :

Example 1 with DefaultTeslaAether

use of io.tesla.aether.internal.DefaultTeslaAether in project druid by druid-io.

the class PullDependenciesTest method setUp.

@Before
public void setUp() throws Exception {
    localRepo = temporaryFolder.newFolder();
    extensionToJars = new HashMap<>();
    extensionToJars.put(extension_A, ImmutableList.of("a.jar", "b.jar", "c.jar"));
    extensionToJars.put(extension_B, ImmutableList.of("d.jar", "e.jar"));
    extensionToJars.put(hadoop_client_2_3_0, ImmutableList.of("f.jar", "g.jar"));
    extensionToJars.put(hadoop_client_2_4_0, ImmutableList.of("h.jar", "i.jar"));
    rootExtensionsDir = new File(temporaryFolder.getRoot(), "extensions");
    rootHadoopDependenciesDir = new File(temporaryFolder.getRoot(), "druid_hadoop_dependencies");
    pullDependencies = new PullDependencies(new DefaultTeslaAether() {

        @Override
        public List<Artifact> resolveArtifacts(DependencyRequest request) throws DependencyResolutionException {
            return getArtifactsForExtension(request.getCollectRequest().getRoot().getArtifact());
        }
    }, new ExtensionsConfig() {

        @Override
        public String getDirectory() {
            return rootExtensionsDir.getAbsolutePath();
        }

        @Override
        public String getHadoopDependenciesDir() {
            return rootHadoopDependenciesDir.getAbsolutePath();
        }
    });
    pullDependencies.coordinates = ImmutableList.of(EXTENSION_A_COORDINATE, EXTENSION_B_COORDINATE);
    pullDependencies.hadoopCoordinates = ImmutableList.of(HADOOP_CLIENT_2_3_0_COORDINATE, HADOOP_CLIENT_2_4_0_COORDINATE);
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) ExtensionsConfig(io.druid.guice.ExtensionsConfig) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Before(org.junit.Before)

Example 2 with DefaultTeslaAether

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

Aggregations

DefaultTeslaAether (io.tesla.aether.internal.DefaultTeslaAether)2 ExtensionsConfig (io.druid.guice.ExtensionsConfig)1 Repository (io.tesla.aether.Repository)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Artifact (org.eclipse.aether.artifact.Artifact)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)1 Before (org.junit.Before)1