Search in sources :

Example 1 with ProjectDependenciesResolver

use of org.apache.maven.project.ProjectDependenciesResolver in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolveDependencies.

/**
   * copied from {@link DefaultProjectBuilder#resolveDependencies(MavenProject, org.sonatype.aether.RepositorySystemSession)}
   */
private DependencyResolutionResult resolveDependencies(MavenProject project, RepositorySystemSession session) {
    DependencyResolutionResult resolutionResult;
    try {
        ProjectDependenciesResolver dependencyResolver = getComponent(ProjectDependenciesResolver.class);
        DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequest(project, session);
        resolutionResult = dependencyResolver.resolve(resolution);
    } catch (DependencyResolutionException e) {
        resolutionResult = e.getResult();
    }
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    if (resolutionResult.getDependencyGraph() != null) {
        RepositoryUtils.toArtifacts(artifacts, resolutionResult.getDependencyGraph().getChildren(), Collections.singletonList(project.getArtifact().getId()), null);
        // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
        LocalRepositoryManager lrm = session.getLocalRepositoryManager();
        for (Artifact artifact : artifacts) {
            if (!artifact.isResolved()) {
                String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
                artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            }
        }
    }
    project.setResolvedArtifacts(artifacts);
    project.setArtifacts(artifacts);
    return resolutionResult;
}
Also used : LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ProjectDependenciesResolver

use of org.apache.maven.project.ProjectDependenciesResolver in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method resolveDependencies.

/**
   * copied from {@link DefaultProjectBuilder#resolveDependencies(MavenProject, RepositorySystemSession)}
   */
private DependencyResolutionResult resolveDependencies(MavenProject project, RepositorySystemSession session) {
    DependencyResolutionResult resolutionResult;
    try {
        ProjectDependenciesResolver dependencyResolver = getComponent(ProjectDependenciesResolver.class);
        DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequest(project, session);
        resolutionResult = dependencyResolver.resolve(resolution);
    } catch (DependencyResolutionException e) {
        resolutionResult = e.getResult();
    }
    Set<Artifact> artifacts = new LinkedHashSet<Artifact>();
    if (resolutionResult.getDependencyGraph() != null) {
        RepositoryUtils.toArtifacts(artifacts, resolutionResult.getDependencyGraph().getChildren(), Collections.singletonList(project.getArtifact().getId()), null);
        // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
        LocalRepositoryManager lrm = session.getLocalRepositoryManager();
        for (Artifact artifact : artifacts) {
            if (!artifact.isResolved()) {
                String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
                artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            }
        }
    }
    project.setResolvedArtifacts(artifacts);
    project.setArtifacts(artifacts);
    return resolutionResult;
}
Also used : LocalRepositoryManager(org.sonatype.aether.repository.LocalRepositoryManager) ProjectDependenciesResolver(org.apache.maven.project.ProjectDependenciesResolver) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)2 Artifact (org.apache.maven.artifact.Artifact)2 ProjectDependenciesResolver (org.apache.maven.project.ProjectDependenciesResolver)2 LocalRepositoryManager (org.eclipse.aether.repository.LocalRepositoryManager)1 LocalRepositoryManager (org.sonatype.aether.repository.LocalRepositoryManager)1