Search in sources :

Example 26 with Dependency

use of org.eclipse.aether.graph.Dependency in project storm by apache.

the class DependencyResolverMain method main.

/**
 * Main entry of dependency resolver.
 *
 * @param args console arguments
 * @throws ParseException If there's parsing error on option parse.
 * @throws MalformedURLException If proxy URL is malformed.
 */
public static void main(String[] args) throws ParseException, MalformedURLException {
    Options options = buildOptions();
    CommandLineParser parser = new DefaultParser();
    CommandLine commandLine = parser.parse(options, args);
    if (!commandLine.hasOption(OPTION_ARTIFACTS_LONG)) {
        throw new IllegalArgumentException("artifacts must be presented.");
    }
    String artifactsArg = commandLine.getOptionValue(OPTION_ARTIFACTS_LONG);
    // DO NOT CHANGE THIS TO SYSOUT
    System.err.println("DependencyResolver input - artifacts: " + artifactsArg);
    List<Dependency> dependencies = parseArtifactArgs(artifactsArg);
    List<RemoteRepository> repositories;
    if (commandLine.hasOption(OPTION_ARTIFACT_REPOSITORIES_LONG)) {
        String remoteRepositoryArg = commandLine.getOptionValue(OPTION_ARTIFACT_REPOSITORIES_LONG);
        // DO NOT CHANGE THIS TO SYSOUT
        System.err.println("DependencyResolver input - repositories: " + remoteRepositoryArg);
        repositories = parseRemoteRepositoryArgs(remoteRepositoryArg);
    } else {
        repositories = Collections.emptyList();
    }
    try {
        String localMavenRepoPath = getOrDefaultLocalMavenRepositoryPath(commandLine.getOptionValue(OPTION_MAVEN_LOCAL_REPOSITORY_DIRECTORY_LONG), DEFAULT_FAILBACK_MAVEN_LOCAL_REPOSITORY_DIRECTORY);
        // create root directory if not exist
        Files.createDirectories(new File(localMavenRepoPath).toPath());
        DependencyResolver resolver = new DependencyResolver(localMavenRepoPath, repositories);
        if (commandLine.hasOption(OPTION_PROXY_URL_LONG)) {
            String proxyUrl = commandLine.getOptionValue(OPTION_PROXY_URL_LONG);
            String proxyUsername = commandLine.getOptionValue(OPTION_PROXY_USERNAME_LONG);
            String proxyPassword = commandLine.getOptionValue(OPTION_PROXY_PASSWORD_LONG);
            resolver.setProxy(parseProxyArg(proxyUrl, proxyUsername, proxyPassword));
        }
        List<ArtifactResult> artifactResults = resolver.resolve(dependencies);
        Iterable<ArtifactResult> missingArtifacts = filterMissingArtifacts(artifactResults);
        if (missingArtifacts.iterator().hasNext()) {
            printMissingArtifactsToSysErr(missingArtifacts);
            throw new RuntimeException("Some artifacts are not resolved");
        }
        System.out.println(JSONValue.toJSONString(transformArtifactResultToArtifactToPaths(artifactResults)));
        System.out.flush();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : Options(org.apache.commons.cli.Options) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) DependencyResolver(org.apache.storm.submit.dependency.DependencyResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) CommandLine(org.apache.commons.cli.CommandLine) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 27 with Dependency

use of org.eclipse.aether.graph.Dependency 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 28 with Dependency

use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.

the class MavenResolverGrapeEngine method grab.

@Override
public Object grab(Map args, Map... dependencyMaps) {
    List<Exclusion> exclusions = createExclusions(args);
    List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
    try {
        List<File> files = resolve(dependencies);
        GroovyClassLoader classLoader = getClassLoader(args);
        for (File file : files) {
            classLoader.addURL(file.toURI().toURL());
        }
    } catch (ArtifactResolutionException | MalformedURLException ex) {
        throw new DependencyResolutionFailedException(ex);
    }
    return null;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MalformedURLException(java.net.MalformedURLException) Exclusion(org.eclipse.aether.graph.Exclusion) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File)

Example 29 with Dependency

use of org.eclipse.aether.graph.Dependency in project spring-boot by spring-projects.

the class DependencyResolutionContext method addDependencyManagement.

public void addDependencyManagement(DependencyManagement dependencyManagement) {
    for (org.springframework.boot.cli.compiler.dependencies.Dependency dependency : dependencyManagement.getDependencies()) {
        List<Exclusion> aetherExclusions = new ArrayList<>();
        for (org.springframework.boot.cli.compiler.dependencies.Dependency.Exclusion exclusion : dependency.getExclusions()) {
            aetherExclusions.add(new Exclusion(exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*"));
        }
        Dependency aetherDependency = new Dependency(new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "jar", dependency.getVersion()), JavaScopes.COMPILE, false, aetherExclusions);
        this.managedDependencies.add(0, aetherDependency);
        this.managedDependencyByGroupAndArtifact.put(getIdentifier(aetherDependency), aetherDependency);
    }
    this.dependencyManagement = (this.dependencyManagement != null) ? new CompositeDependencyManagement(dependencyManagement, this.dependencyManagement) : dependencyManagement;
    this.artifactCoordinatesResolver = new DependencyManagementArtifactCoordinatesResolver(this.dependencyManagement);
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) DependencyManagementArtifactCoordinatesResolver(org.springframework.boot.cli.compiler.dependencies.DependencyManagementArtifactCoordinatesResolver) Exclusion(org.eclipse.aether.graph.Exclusion) CompositeDependencyManagement(org.springframework.boot.cli.compiler.dependencies.CompositeDependencyManagement) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 30 with Dependency

use of org.eclipse.aether.graph.Dependency in project zeppelin by apache.

the class DependencyResolver method getArtifactsWithDep.

/**
 * @param dependency
 * @param excludes list of pattern can either be of the form groupId:artifactId
 * @return
 * @throws Exception
 */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
    Artifact artifact = new DefaultArtifact(dependency);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    try {
        return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    } catch (NullPointerException | DependencyResolutionException ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) RepositoryException(org.eclipse.aether.RepositoryException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter)

Aggregations

Dependency (org.eclipse.aether.graph.Dependency)57 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)39 Artifact (org.eclipse.aether.artifact.Artifact)36 File (java.io.File)25 CollectRequest (org.eclipse.aether.collection.CollectRequest)22 ArrayList (java.util.ArrayList)19 DependencyNode (org.eclipse.aether.graph.DependencyNode)17 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)17 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)17 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)15 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)15 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 IOException (java.io.IOException)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 Exclusion (org.eclipse.aether.graph.Exclusion)13 MalformedURLException (java.net.MalformedURLException)12 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)11 List (java.util.List)10 URL (java.net.URL)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9