Search in sources :

Example 21 with Artifact

use of org.eclipse.aether.artifact.Artifact in project atlasmap by atlasmap.

the class GenerateInspectionsMojo method resolveClasspath.

private List<URL> resolveClasspath(List<String> artifacts) throws MojoFailureException {
    final List<URL> urls = new ArrayList<>();
    try {
        for (String gav : artifacts) {
            Artifact artifact = new DefaultArtifact(gav);
            getLog().debug("Resolving dependencies for artifact: " + artifact);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRoot(new Dependency(artifact, ""));
            collectRequest.setRepositories(remoteRepos);
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setCollectRequest(collectRequest);
            DependencyResult dependencyResult = system.resolveDependencies(repoSession, dependencyRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            dependencyResult.getRoot().accept(nlg);
            Iterator<DependencyNode> it = nlg.getNodes().iterator();
            while (it.hasNext()) {
                DependencyNode node = it.next();
                if (node.getDependency() != null) {
                    Artifact x = node.getDependency().getArtifact();
                    if (x.getFile() != null) {
                        getLog().debug("Found dependency: " + x + " for artifact: " + artifact);
                        urls.add(x.getFile().toURI().toURL());
                    }
                }
            }
        }
    } catch (IllegalArgumentException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (DependencyResolutionException e) {
        throw new MojoFailureException(e.getMessage(), e);
    } catch (MalformedURLException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
    return urls;
}
Also used : MalformedURLException(java.net.MalformedURLException) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 22 with Artifact

use of org.eclipse.aether.artifact.Artifact in project drools by kiegroup.

the class KieRepositoryScannerImpl method addDependencies.

private void addDependencies(InternalKieModule kieModule, ArtifactResolver resolver, List<DependencyDescriptor> dependencies) {
    for (DependencyDescriptor dep : dependencies) {
        InternalKieModule dependency = (InternalKieModule) KieServices.Factory.get().getRepository().getKieModule(adapt(dep.getReleaseId()));
        if (dependency != null) {
            kieModule.addKieDependency(dependency);
        } else {
            Artifact depArtifact = resolver.resolveArtifact(dep.getReleaseId());
            if (depArtifact != null && isKJar(depArtifact.getFile())) {
                ReleaseId depReleaseId = adapt(new DependencyDescriptor(depArtifact).getReleaseId());
                InternalKieModule zipKieModule = createKieModule(depReleaseId, depArtifact.getFile());
                if (zipKieModule != null) {
                    kieModule.addKieDependency(zipKieModule);
                }
            }
        }
    }
}
Also used : DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) ReleaseId(org.kie.api.builder.ReleaseId) Artifact(org.eclipse.aether.artifact.Artifact) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 23 with Artifact

use of org.eclipse.aether.artifact.Artifact in project bazel by bazelbuild.

the class Resolver method resolveArtifact.

/**
   * Resolves an artifact as a root of a dependency graph.
   */
public void resolveArtifact(String artifactCoord) {
    Artifact artifact;
    ModelSource modelSource;
    try {
        artifact = getArtifact(artifactCoord);
        modelSource = modelResolver.resolveModel(artifact);
    } catch (UnresolvableModelException | InvalidArtifactCoordinateException e) {
        handler.handle(Event.error(e.getMessage()));
        return;
    }
    Rule rule = new Rule(artifact);
    // add the artifact rule to the workspace
    deps.put(rule.name(), rule);
    resolveEffectiveModel(modelSource, Sets.<String>newHashSet(), rule);
}
Also used : UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) FileModelSource(org.apache.maven.model.building.FileModelSource) ModelSource(org.apache.maven.model.building.ModelSource)

Example 24 with Artifact

use of org.eclipse.aether.artifact.Artifact in project buck by facebook.

the class ResolverIntegrationTest method shouldDetectNewestJar.

@Test
public void shouldDetectNewestJar() throws Exception {
    Path groupDir = thirdParty.resolve("example");
    Path existingNewerJar = groupDir.resolve("no-deps-1.1.jar");
    Path existingNewestJar = groupDir.resolve("no-deps-1.2.jar");
    Files.createDirectories(groupDir);
    Path sourceJar = repo.resolve("com/example/no-deps/1.0/no-deps-1.0.jar");
    Files.copy(sourceJar, existingNewerJar);
    Files.copy(sourceJar, existingNewestJar);
    Artifact artifact = new DefaultArtifact("com.example", "no-deps", "jar", "1.0");
    Optional<Path> result = new Resolver(newConfig()).getNewerVersionFile(artifact, groupDir);
    assertTrue(result.isPresent());
    assertThat(result.get(), equalTo(existingNewestJar));
}
Also used : Path(java.nio.file.Path) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 25 with Artifact

use of org.eclipse.aether.artifact.Artifact in project buck by facebook.

the class Resolver method buildDependencyGraph.

private MutableDirectedGraph<Artifact> buildDependencyGraph(Map<String, Artifact> knownDeps) throws ArtifactDescriptorException {
    MutableDirectedGraph<Artifact> graph;
    graph = new MutableDirectedGraph<>();
    for (Map.Entry<String, Artifact> entry : knownDeps.entrySet()) {
        String key = entry.getKey();
        Artifact artifact = entry.getValue();
        graph.addNode(artifact);
        List<Dependency> dependencies = getDependenciesOf(artifact);
        for (Dependency dependency : dependencies) {
            if (dependency.getArtifact() == null) {
                System.out.println("Skipping because artifact missing: " + dependency);
                continue;
            }
            String depKey = buildKey(dependency.getArtifact());
            Artifact actualDep = knownDeps.get(depKey);
            if (actualDep == null) {
                continue;
            }
            // It's possible that the runtime dep of an artifact is the test time dep of another.
            if (isTestTime(dependency)) {
                continue;
            }
            // TODO(shs96c): Do we always want optional dependencies?
            //        if (dependency.isOptional()) {
            //          continue;
            //        }
            Preconditions.checkNotNull(actualDep, key + " -> " + artifact + " in " + knownDeps.keySet());
            graph.addNode(actualDep);
            graph.addEdge(actualDep, artifact);
        }
    }
    return graph;
}
Also used : STGroupString(org.stringtemplate.v4.STGroupString) Dependency(org.eclipse.aether.graph.Dependency) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)30 File (java.io.File)11 Dependency (org.eclipse.aether.graph.Dependency)9 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)9 IOException (java.io.IOException)8 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)8 ArrayList (java.util.ArrayList)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)7 Path (java.nio.file.Path)6 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)6 CollectRequest (org.eclipse.aether.collection.CollectRequest)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 STGroupString (org.stringtemplate.v4.STGroupString)5 Jar (aQute.bnd.osgi.Jar)4 URISyntaxException (java.net.URISyntaxException)4 URL (java.net.URL)4 List (java.util.List)4 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)4