Search in sources :

Example 56 with Artifact

use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.

the class SharedProcessManager method addTest.

private String addTest(String testId, List<Artifact> artifactList) {
    StringBuilder mavenDependencyInfo = new StringBuilder();
    mavenDependencyInfo.append(testId);
    mavenDependencyInfo.append('=');
    for (Artifact artifact : artifactList) {
        String str = ArtifactIdUtils.artifactToString(artifact);
        if (StringUtils.hasText(str)) {
            mavenDependencyInfo.append(str);
            mavenDependencyInfo.append(ArtifactIdUtils.ARTIFACT_SEPARATOR);
        }
    }
    return mavenDependencyInfo.toString();
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact)

Example 57 with Artifact

use of org.eclipse.aether.artifact.Artifact in project pinpoint by naver.

the class DependencyResolver method resolveDependencySets.

public Map<String, List<Artifact>> resolveDependencySets(String... dependencies) {
    List<List<Artifact>> companions = resolve(dependencies);
    List<List<List<Artifact>>> xxx = new ArrayList<>();
    for (List<Artifact> companion : companions) {
        Artifact representative = companion.get(0);
        List<Version> versions;
        try {
            versions = getVersions(representative);
        } catch (VersionRangeResolutionException e) {
            throw new IllegalArgumentException("Fail to resolve version of: " + representative);
        }
        if (versions.isEmpty()) {
            throw new IllegalArgumentException("No version in the given range: " + representative);
        }
        List<List<Artifact>> companionVersions = new ArrayList<>(versions.size());
        for (Version version : versions) {
            List<Artifact> companionVersion = new ArrayList<>(companion.size());
            for (Artifact artifact : companion) {
                Artifact verArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version.toString());
                companionVersion.add(verArtifact);
            }
            companionVersions.add(companionVersion);
        }
        xxx.add(companionVersions);
    }
    Map<String, List<Artifact>> result = combination(xxx);
    return result;
}
Also used : ArrayList(java.util.ArrayList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Version(org.eclipse.aether.version.Version) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 58 with Artifact

use of org.eclipse.aether.artifact.Artifact in project druid by druid-io.

the class PullDependencies method run.

@Override
public void run() {
    if (aether == null) {
        aether = getAetherClient();
    }
    final File extensionsDir = new File(extensionsConfig.getDirectory());
    final File hadoopDependenciesDir = new File(extensionsConfig.getHadoopDependenciesDir());
    try {
        if (clean) {
            FileUtils.deleteDirectory(extensionsDir);
            FileUtils.deleteDirectory(hadoopDependenciesDir);
        }
        FileUtils.mkdirp(extensionsDir);
        FileUtils.mkdirp(hadoopDependenciesDir);
    } catch (IOException e) {
        log.error(e, "Unable to clear or create extension directory at [%s]", extensionsDir);
        throw new RuntimeException(e);
    }
    log.info("Start pull-deps with local repository [%s] and remote repositories [%s]", localRepository, remoteRepositories);
    try {
        log.info("Start downloading dependencies for extension coordinates: [%s]", coordinates);
        for (String coordinate : coordinates) {
            coordinate = coordinate.trim();
            final Artifact versionedArtifact = getArtifact(coordinate);
            File currExtensionDir = new File(extensionsDir, versionedArtifact.getArtifactId());
            createExtensionDirectory(coordinate, currExtensionDir);
            downloadExtension(versionedArtifact, currExtensionDir);
        }
        log.info("Finish downloading dependencies for extension coordinates: [%s]", coordinates);
        if (!noDefaultHadoop && hadoopCoordinates.isEmpty()) {
            hadoopCoordinates.addAll(TaskConfig.DEFAULT_DEFAULT_HADOOP_COORDINATES);
        }
        log.info("Start downloading dependencies for hadoop extension coordinates: [%s]", hadoopCoordinates);
        for (final String hadoopCoordinate : hadoopCoordinates) {
            final Artifact versionedArtifact = getArtifact(hadoopCoordinate);
            File currExtensionDir = new File(hadoopDependenciesDir, versionedArtifact.getArtifactId());
            createExtensionDirectory(hadoopCoordinate, currExtensionDir);
            // add a version folder for hadoop dependency directory
            currExtensionDir = new File(currExtensionDir, versionedArtifact.getVersion());
            createExtensionDirectory(hadoopCoordinate, currExtensionDir);
            downloadExtension(versionedArtifact, currExtensionDir, hadoopExclusions);
        }
        log.info("Finish downloading dependencies for hadoop extension coordinates: [%s]", hadoopCoordinates);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 59 with Artifact

use of org.eclipse.aether.artifact.Artifact in project druid by druid-io.

the class PullDependencies method downloadExtension.

private void downloadExtension(Artifact versionedArtifact, File toLocation, Dependencies exclusions) {
    final CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
    final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), (node, parents) -> {
        String scope = node.getDependency().getScope();
        if (scope != null) {
            scope = StringUtils.toLowerCase(scope);
            if ("provided".equals(scope)) {
                return false;
            }
            if ("test".equals(scope)) {
                return false;
            }
            if ("system".equals(scope)) {
                return false;
            }
        }
        if (exclusions.contain(node.getArtifact())) {
            return false;
        }
        for (DependencyNode parent : parents) {
            if (exclusions.contain(parent.getArtifact())) {
                return false;
            }
        }
        return true;
    }));
    try {
        log.info("Start downloading extension [%s]", versionedArtifact);
        final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
        for (Artifact artifact : artifacts) {
            if (exclusions.contain(artifact)) {
                log.debug("Skipped Artifact[%s]", artifact);
            } else {
                log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
                org.apache.commons.io.FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
            }
        }
    } catch (Exception e) {
        log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
        throw new RuntimeException(e);
    }
    log.info("Finish downloading extension [%s]", versionedArtifact);
}
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) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 60 with Artifact

use of org.eclipse.aether.artifact.Artifact in project druid by druid-io.

the class PullDependenciesTest method getExpectedJarFiles.

private List<File> getExpectedJarFiles(Artifact artifact) {
    final String artifactId = artifact.getArtifactId();
    final List<String> names = extensionToDependency.get(artifact);
    final List<File> expectedJars;
    if ("hadoop-client".equals(artifactId)) {
        final String version = artifact.getVersion();
        expectedJars = names.stream().filter(name -> !HADOOP_CLIENT_VULNERABLE_ARTIFACTIDS.contains(name)).map(name -> new File(StringUtils.format("%s/%s/%s/%s", rootHadoopDependenciesDir, artifactId, version, name + ".jar"))).collect(Collectors.toList());
    } else {
        expectedJars = names.stream().map(name -> new File(StringUtils.format("%s/%s/%s", rootExtensionsDir, artifactId, name + ".jar"))).collect(Collectors.toList());
    }
    return expectedJars;
}
Also used : DependencyFilter(org.eclipse.aether.graph.DependencyFilter) CoreMatchers(org.hamcrest.CoreMatchers) Arrays(java.util.Arrays) Dependency(org.eclipse.aether.graph.Dependency) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) 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) Test(org.junit.Test) IOException(java.io.IOException) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) Paths(java.nio.file.Paths) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) Assert(org.junit.Assert) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) File(java.io.File)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)122 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)97 File (java.io.File)51 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)34 Dependency (org.eclipse.aether.graph.Dependency)32 IOException (java.io.IOException)29 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 ArrayList (java.util.ArrayList)23 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)22 List (java.util.List)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)18 CollectRequest (org.eclipse.aether.collection.CollectRequest)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)15 DependencyNode (org.eclipse.aether.graph.DependencyNode)14 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 URL (java.net.URL)12 Map (java.util.Map)12 RepositorySystem (org.eclipse.aether.RepositorySystem)11