Search in sources :

Example 1 with DefaultDependencyResolutionRequest

use of org.apache.maven.project.DefaultDependencyResolutionRequest in project meecrowave by apache.

the class MeecrowaveBundleMojo method addTransitiveDependencies.

private void addTransitiveDependencies(final File distroFolder, final Collection<String> includedArtifacts, final Dependency dependency) {
    final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
    request.setMavenProject(new MavenProject() {

        {
            getDependencies().add(dependency);
        }
    });
    request.setRepositorySession(session);
    try {
        dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor() {

            @Override
            public boolean visitEnter(final DependencyNode node) {
                return true;
            }

            @Override
            public boolean visitLeave(final DependencyNode node) {
                final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
                if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId())) {
                    addLib(distroFolder, artifact.getFile());
                }
                return true;
            }
        });
    } catch (final DependencyResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) MavenProject(org.apache.maven.project.MavenProject) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 2 with DefaultDependencyResolutionRequest

use of org.apache.maven.project.DefaultDependencyResolutionRequest in project bnd by bndtools.

the class DependencyResolver method resolve.

public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
    if (resolvedDependencies != null) {
        return resolvedDependencies;
    }
    DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
    request.setResolutionFilter(new DependencyFilter() {

        @Override
        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            if (node.getDependency() != null) {
                return scopes.contains(node.getDependency().getScope());
            }
            return false;
        }
    });
    DependencyResolutionResult result;
    try {
        result = resolver.resolve(request);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    Map<File, ArtifactResult> dependencies = new HashMap<>();
    DependencyNode dependencyGraph = result.getDependencyGraph();
    if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
        List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
        ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
        if (deployRepo != null) {
            remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
        }
        discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
    }
    return resolvedDependencies = dependencies;
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) File(java.io.File)

Aggregations

DefaultDependencyResolutionRequest (org.apache.maven.project.DefaultDependencyResolutionRequest)2 DependencyResolutionException (org.apache.maven.project.DependencyResolutionException)2 DependencyResolutionRequest (org.apache.maven.project.DependencyResolutionRequest)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 DependencyResolutionResult (org.apache.maven.project.DependencyResolutionResult)1 MavenProject (org.apache.maven.project.MavenProject)1 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)1 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)1 DependencyVisitor (org.eclipse.aether.graph.DependencyVisitor)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)1