Search in sources :

Example 36 with Dependency

use of org.eclipse.aether.graph.Dependency in project fabric8 by jboss-fuse.

the class DependencyFilters method parse.

/**
 * Creates a filter from the given String
 */
public static Filter<Dependency> parse(String dependencyFilterText) {
    List<Filter<Dependency>> filters = new ArrayList<Filter<Dependency>>();
    StringTokenizer iter = new StringTokenizer(dependencyFilterText);
    while (iter.hasMoreElements()) {
        String text = iter.nextToken();
        Filter<Dependency> filter = parseSingleFilter(text);
        if (filter != null) {
            filters.add(filter);
        }
    }
    return Filters.compositeFilter(filters);
}
Also used : StringTokenizer(java.util.StringTokenizer) Filter(io.fabric8.common.util.Filter) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency)

Example 37 with Dependency

use of org.eclipse.aether.graph.Dependency in project drools by kiegroup.

the class MavenRepository method getArtifactDependecies.

public List<DependencyDescriptor> getArtifactDependecies(String artifactName) {
    Artifact artifact = new DefaultArtifact(artifactName);
    CollectRequest collectRequest = new CollectRequest();
    Dependency root = new Dependency(artifact, "");
    collectRequest.setRoot(root);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        collectRequest.addRepository(repo);
    }
    CollectResult collectResult;
    try {
        collectResult = aether.getSystem().collectDependencies(aether.getSession(), collectRequest);
    } catch (DependencyCollectionException e) {
        throw new RuntimeException(e);
    }
    CollectDependencyVisitor visitor = new CollectDependencyVisitor();
    collectResult.getRoot().accept(visitor);
    List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>();
    for (DependencyNode node : visitor.getDependencies()) {
        // skip root to not add artifact as dependency
        if (node.getDependency().equals(root)) {
            continue;
        }
        descriptors.add(new DependencyDescriptor(node.getDependency().getArtifact()));
    }
    return descriptors;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 38 with Dependency

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

the class MavenResolverGrapeEngine method resolve.

@Override
public URI[] resolve(Map args, List depsInfo, Map... dependencyMaps) {
    List<Exclusion> exclusions = createExclusions(args);
    List<Dependency> dependencies = createDependencies(dependencyMaps, exclusions);
    try {
        List<File> files = resolve(dependencies);
        List<URI> uris = new ArrayList<>(files.size());
        for (File file : files) {
            uris.add(file.toURI());
        }
        return uris.toArray(new URI[0]);
    } catch (Exception ex) {
        throw new DependencyResolutionFailedException(ex);
    }
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) File(java.io.File) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException)

Example 39 with Dependency

use of org.eclipse.aether.graph.Dependency in project atlasmap by atlasmap.

the class AbstractAtlasMapMojo method resolveClasspath.

/**
 * Resolves the classpath.
 * @param artifacts artifacts
 * @return resolved
 * @throws MojoFailureException unexpected error
 */
protected 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(getRemoteRepos());
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setCollectRequest(collectRequest);
            DependencyResult dependencyResult = getSystem().resolveDependencies(getRepoSession(), 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 40 with Dependency

use of org.eclipse.aether.graph.Dependency in project BIMserver by opensourceBIM.

the class PluginBundleManager method loadDependencies.

private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous, boolean resolveRemoteDependencies) throws FileNotFoundException, IOException {
    List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
    Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
    Path workspaceDir = Paths.get("..");
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
    bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
    while (it.hasNext()) {
        org.apache.maven.model.Dependency depend = it.next();
        try {
            if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase") || depend.getArtifactId().equals("ifcplugins"))) {
                // TODO we might want to check the version though
                continue;
            }
            if (depend.isOptional() || "test".equals(depend.getScope())) {
                continue;
            }
            Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
            DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
            if (!dependency2.getArtifact().isSnapshot()) {
                if (dependency2.getArtifact().getFile() != null) {
                    bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
                    loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
                } else {
                    ArtifactRequest request = new ArtifactRequest();
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(resolveRemoteDependencies ? mavenPluginRepository.getRepositoriesAsList() : mavenPluginRepository.getLocalRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (ArtifactResolutionException e) {
                        LOGGER.error(model.getGroupId() + "." + model.getArtifactId(), e);
                    }
                }
            } else {
                // Snapshot projects linked in Eclipse
                ArtifactRequest request = new ArtifactRequest();
                if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
                    request.setArtifact(dependency2.getArtifact());
                    request.setRepositories(mavenPluginRepository.getLocalRepositories());
                    try {
                        ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
                        if (resolveArtifact.getArtifact().getFile() != null) {
                            bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                            loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
                        } else {
                        // TODO error?
                        }
                    } catch (Exception e) {
                        LOGGER.info(dependency2.getArtifact().toString());
                        e.printStackTrace();
                    }
                // bimServerDependencies.add(new
                // org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
                }
            }
            ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
            descriptorRequest.setArtifact(dependency2.getArtifact());
            descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
            ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
            CollectRequest collectRequest = new CollectRequest();
            collectRequest.setRootArtifact(descriptorResult.getArtifact());
            collectRequest.setDependencies(descriptorResult.getDependencies());
            collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
            collectRequest.setRepositories(descriptorResult.getRepositories());
            DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
            DependencyRequest dependencyRequest = new DependencyRequest();
            dependencyRequest.setRoot(node);
            CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
            PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
            // collectResult.getRoot().accept(new
            // ConsoleDependencyGraphDumper());
            collectResult.getRoot().accept(nlg);
            try {
                mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
            } catch (DependencyResolutionException e) {
            // Ignore
            }
            for (DependencyNode dependencyNode : nlg.getNodes()) {
                ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
                newRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
                Artifact artifact = resolveArtifact.getArtifact();
                Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
                loadDependencies(jarFile, depDelLoader);
                Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
                ArtifactRequest request = new ArtifactRequest();
                request.setArtifact(versionArtifact);
                request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
                // try {
                // ArtifactResult resolveArtifact =
                // mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
                // request);
                // File depPomFile =
                // resolveArtifact.getArtifact().getFile();
                // if (depPomFile != null) {
                // MavenXpp3Reader mavenreader = new MavenXpp3Reader();
                // Model depModel = null;
                // try (FileReader reader = new FileReader(depPomFile)) {
                // try {
                // depModel = mavenreader.read(reader);
                // } catch (XmlPullParserException e) {
                // e.printStackTrace();
                // }
                // }
                // previous = loadDependencies(bimServerDependencies,
                // depModel, previous);
                // } else {
                // LOGGER.info("Artifact not found " + versionArtifact);
                // }
                // } catch (ArtifactResolutionException e1) {
                // LOGGER.error(e1.getMessage());
                // }
                // EclipsePluginClassloader depLoader = new
                // EclipsePluginClassloader(depDelLoader, projectRoot);
                bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
            }
            previous = depDelLoader;
        } catch (DependencyCollectionException e) {
            e.printStackTrace();
        } catch (ArtifactDescriptorException e2) {
            e2.printStackTrace();
        } catch (ArtifactResolutionException e) {
            e.printStackTrace();
        }
    }
    return previous;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) Path(java.nio.file.Path) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DelegatingClassLoader(org.bimserver.plugins.classloaders.DelegatingClassLoader) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) PluginException(org.bimserver.shared.exceptions.PluginException) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) UserException(org.bimserver.shared.exceptions.UserException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) IOException(java.io.IOException) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

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