Search in sources :

Example 1 with DependencyResolutionResult

use of org.apache.maven.project.DependencyResolutionResult in project che by eclipse.

the class MavenServerImpl method createResult.

private MavenServerResult createResult(File pom, MavenResult mavenResult) throws RemoteException {
    List<MavenProjectProblem> problems = new ArrayList<>();
    Set<MavenKey> unresolvedArtifacts = new HashSet<>();
    validate(pom, mavenResult.getExceptions(), problems);
    MavenProject project = mavenResult.getMavenProject();
    if (project == null) {
        return new MavenServerResult(null, problems, unresolvedArtifacts);
    }
    MavenModel model = null;
    try {
        DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
        org.eclipse.aether.graph.DependencyNode dependencyNode = null;
        if (resolutionResult != null) {
            dependencyNode = resolutionResult.getDependencyGraph();
        }
        List<org.eclipse.aether.graph.DependencyNode> dependencyNodes = null;
        if (dependencyNode != null) {
            dependencyNodes = dependencyNode.getChildren();
        }
        model = MavenModelUtil.convertProjectToModel(project, dependencyNodes, new File(localRepo.getBasedir()));
    } catch (Exception e) {
        validate(project.getFile(), Collections.singletonList(e), problems);
    }
    List<String> activeProfiles = getActiveProfiles(project);
    MavenProjectInfo projectInfo = new MavenProjectInfo(model, null, activeProfiles);
    return new MavenServerResult(projectInfo, problems, unresolvedArtifacts);
}
Also used : MavenKey(org.eclipse.che.maven.data.MavenKey) DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) ArrayList(java.util.ArrayList) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenExecutionException(org.apache.maven.MavenExecutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) MavenProject(org.apache.maven.project.MavenProject) MavenModel(org.eclipse.che.maven.data.MavenModel) File(java.io.File) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 2 with DependencyResolutionResult

use of org.apache.maven.project.DependencyResolutionResult 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

File (java.io.File)2 ArrayList (java.util.ArrayList)2 DependencyResolutionResult (org.apache.maven.project.DependencyResolutionResult)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1 MavenExecutionRequestPopulationException (org.apache.maven.execution.MavenExecutionRequestPopulationException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 DefaultDependencyResolutionRequest (org.apache.maven.project.DefaultDependencyResolutionRequest)1 DependencyResolutionException (org.apache.maven.project.DependencyResolutionException)1 DependencyResolutionRequest (org.apache.maven.project.DependencyResolutionRequest)1 InvalidProjectModelException (org.apache.maven.project.InvalidProjectModelException)1 MavenProject (org.apache.maven.project.MavenProject)1 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)1 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)1