Search in sources :

Example 1 with MavenExecutionResult

use of org.jetbrains.idea.maven.server.embedder.MavenExecutionResult in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method resolveProject.

@NotNull
@Override
public Collection<MavenServerExecutionResult> resolveProject(@NotNull final Collection<File> files, @NotNull Collection<String> activeProfiles, @NotNull Collection<String> inactiveProfiles) throws RemoteException, MavenServerProcessCanceledException {
    final DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener(myConsoleWrapper);
    Collection<MavenExecutionResult> results = doResolveProject(files, new ArrayList<String>(activeProfiles), new ArrayList<String>(inactiveProfiles), Collections.<ResolutionListener>singletonList(listener));
    return ContainerUtil.mapNotNull(results, new Function<MavenExecutionResult, MavenServerExecutionResult>() {

        @Override
        public MavenServerExecutionResult fun(MavenExecutionResult result) {
            try {
                return createExecutionResult(result.getPomFile(), result, listener.getRootNode());
            } catch (RemoteException e) {
                ExceptionUtil.rethrowAllAsUnchecked(e);
            }
            return null;
        }
    });
}
Also used : MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) DependencyTreeResolutionListener(org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener) RemoteException(java.rmi.RemoteException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with MavenExecutionResult

use of org.jetbrains.idea.maven.server.embedder.MavenExecutionResult in project intellij-community by JetBrains.

the class Maven3ServerEmbedder method addMvn2CompatResults.

protected void addMvn2CompatResults(MavenProject project, List<Exception> exceptions, List<ResolutionListener> listeners, ArtifactRepository localRepository, Collection<MavenExecutionResult> executionResults) {
    ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
    resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
    resolutionRequest.setArtifact(project.getArtifact());
    resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
    resolutionRequest.setLocalRepository(localRepository);
    resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
    resolutionRequest.setListeners(listeners);
    resolutionRequest.setResolveRoot(false);
    resolutionRequest.setResolveTransitively(true);
    ArtifactResolver resolver = getComponent(ArtifactResolver.class);
    ArtifactResolutionResult result = resolver.resolve(resolutionRequest);
    project.setArtifacts(result.getArtifacts());
    executionResults.add(new MavenExecutionResult(project, exceptions));
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver)

Example 3 with MavenExecutionResult

use of org.jetbrains.idea.maven.server.embedder.MavenExecutionResult in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolveProject.

@NotNull
@Override
public Collection<MavenServerExecutionResult> resolveProject(@NotNull Collection<File> files, @NotNull Collection<String> activeProfiles, @NotNull Collection<String> inactiveProfiles) throws RemoteException, MavenServerProcessCanceledException {
    final DependencyTreeResolutionListener listener = new DependencyTreeResolutionListener(myConsoleWrapper);
    Collection<MavenExecutionResult> results = doResolveProject(files, new ArrayList<String>(activeProfiles), new ArrayList<String>(inactiveProfiles), Collections.<ResolutionListener>singletonList(listener));
    return ContainerUtil.mapNotNull(results, new Function<MavenExecutionResult, MavenServerExecutionResult>() {

        @Override
        public MavenServerExecutionResult fun(MavenExecutionResult result) {
            try {
                return createExecutionResult(result.getPomFile(), result, listener.getRootNode());
            } catch (RemoteException e) {
                ExceptionUtil.rethrowAllAsUnchecked(e);
            }
            return null;
        }
    });
}
Also used : MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) DependencyTreeResolutionListener(org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener) RemoteException(java.rmi.RemoteException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with MavenExecutionResult

use of org.jetbrains.idea.maven.server.embedder.MavenExecutionResult in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method doResolveProject.

@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
    final File file = files.size() == 1 ? files.iterator().next() : null;
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
    final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
    executeWithMavenSession(request, new Runnable() {

        @Override
        public void run() {
            try {
                RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    DefaultRepositorySystemSession session = (DefaultRepositorySystemSession) repositorySession;
                    session.setTransferListener(new TransferListenerAdapter(myCurrentIndicator));
                    if (myWorkspaceMap != null) {
                        session.setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
                    }
                    session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, true);
                    session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
                }
                List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
                for (ProjectBuildingResult buildingResult : buildingResults) {
                    MavenProject project = buildingResult.getProject();
                    if (project == null) {
                        List<Exception> exceptions = new ArrayList<Exception>();
                        for (ModelProblem problem : buildingResult.getProblems()) {
                            exceptions.add(problem.getException());
                        }
                        MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
                        executionResults.add(mavenExecutionResult);
                        continue;
                    }
                    List<Exception> exceptions = new ArrayList<Exception>();
                    loadExtensions(project, exceptions);
                    //Artifact projectArtifact = project.getArtifact();
                    //Map managedVersions = project.getManagedVersionMap();
                    //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                    project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                        addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
                    } else {
                        final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
                        final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
                        final Map<Dependency, Artifact> winnerDependencyMap = new IdentityHashMap<Dependency, Artifact>();
                        Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                        dependencyResolutionResult.getDependencyGraph().accept(new TreeDependencyVisitor(new DependencyVisitor() {

                            @Override
                            public boolean visitEnter(org.eclipse.aether.graph.DependencyNode node) {
                                final Object winner = node.getData().get(ConflictResolver.NODE_DATA_WINNER);
                                final Dependency dependency = node.getDependency();
                                if (dependency != null && winner == null) {
                                    Artifact winnerArtifact = Maven3AetherModelConverter.toArtifact(dependency);
                                    winnerDependencyMap.put(dependency, winnerArtifact);
                                }
                                return true;
                            }

                            @Override
                            public boolean visitLeave(org.eclipse.aether.graph.DependencyNode node) {
                                return true;
                            }
                        }));
                        for (Dependency dependency : dependencies) {
                            final Artifact artifact = winnerDependencyMap.get(dependency);
                            if (artifact != null) {
                                artifacts.add(artifact);
                                resolveAsModule(artifact);
                            }
                        }
                        project.setArtifacts(artifacts);
                        executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                    }
                }
            } catch (Exception e) {
                executionResults.add(handleException(e));
            }
        }
    });
    return executionResults;
}
Also used : THashSet(gnu.trove.THashSet) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) ModelProblem(org.apache.maven.model.building.ModelProblem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) Dependency(org.eclipse.aether.graph.Dependency) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Artifact(org.apache.maven.artifact.Artifact) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject) File(java.io.File) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with MavenExecutionResult

use of org.jetbrains.idea.maven.server.embedder.MavenExecutionResult in project intellij-community by JetBrains.

the class Maven30ServerEmbedderImpl method doResolveProject.

@NotNull
public Collection<MavenExecutionResult> doResolveProject(@NotNull final Collection<File> files, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, final List<ResolutionListener> listeners) throws RemoteException {
    final File file = files.size() == 1 ? files.iterator().next() : null;
    final MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
    request.setUpdateSnapshots(myAlwaysUpdateSnapshots);
    final Collection<MavenExecutionResult> executionResults = ContainerUtil.newArrayList();
    executeWithMavenSession(request, new Runnable() {

        @Override
        public void run() {
            try {
                RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
                if (repositorySession instanceof DefaultRepositorySystemSession) {
                    ((DefaultRepositorySystemSession) repositorySession).setTransferListener(new Maven30TransferListenerAdapter(myCurrentIndicator));
                    if (myWorkspaceMap != null) {
                        ((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new Maven30WorkspaceReader(myWorkspaceMap));
                    }
                }
                List<ProjectBuildingResult> buildingResults = getProjectBuildingResults(request, files);
                for (ProjectBuildingResult buildingResult : buildingResults) {
                    MavenProject project = buildingResult.getProject();
                    if (project == null) {
                        List<Exception> exceptions = new ArrayList<Exception>();
                        for (ModelProblem problem : buildingResult.getProblems()) {
                            exceptions.add(problem.getException());
                        }
                        MavenExecutionResult mavenExecutionResult = new MavenExecutionResult(buildingResult.getPomFile(), exceptions);
                        executionResults.add(mavenExecutionResult);
                        continue;
                    }
                    List<Exception> exceptions = new ArrayList<Exception>();
                    loadExtensions(project, exceptions);
                    //Artifact projectArtifact = project.getArtifact();
                    //Map managedVersions = project.getManagedVersionMap();
                    //ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
                    project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
                    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING) {
                        addMvn2CompatResults(project, exceptions, listeners, myLocalRepository, executionResults);
                    } else {
                        final DependencyResolutionResult dependencyResolutionResult = resolveDependencies(project, repositorySession);
                        final List<Dependency> dependencies = dependencyResolutionResult.getDependencies();
                        Set<Artifact> artifacts = new LinkedHashSet<Artifact>(dependencies.size());
                        for (Dependency dependency : dependencies) {
                            final Artifact artifact = RepositoryUtils.toArtifact(dependency.getArtifact());
                            artifact.setScope(dependency.getScope());
                            artifact.setOptional(dependency.isOptional());
                            artifacts.add(artifact);
                            resolveAsModule(artifact);
                        }
                        project.setArtifacts(artifacts);
                        executionResults.add(new MavenExecutionResult(project, dependencyResolutionResult, exceptions));
                    }
                }
            } catch (Exception e) {
                executionResults.add(handleException(e));
            }
        }
    });
    return executionResults;
}
Also used : DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) THashSet(gnu.trove.THashSet) MavenExecutionResult(org.jetbrains.idea.maven.server.embedder.MavenExecutionResult) Dependency(org.sonatype.aether.graph.Dependency) 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) SettingsBuildingException(org.apache.maven.settings.building.SettingsBuildingException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) Artifact(org.apache.maven.artifact.Artifact) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) ModelProblem(org.apache.maven.model.building.ModelProblem) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MavenExecutionResult (org.jetbrains.idea.maven.server.embedder.MavenExecutionResult)5 RemoteException (java.rmi.RemoteException)4 NotNull (org.jetbrains.annotations.NotNull)4 THashSet (gnu.trove.THashSet)2 File (java.io.File)2 Artifact (org.apache.maven.artifact.Artifact)2 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)2 ArtifactFactory (org.apache.maven.artifact.factory.ArtifactFactory)2 ModelProblem (org.apache.maven.model.building.ModelProblem)2 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)2 DependencyTreeResolutionListener (org.apache.maven.shared.dependency.tree.DependencyTreeResolutionListener)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 ContextException (org.codehaus.plexus.context.ContextException)2 InitializationException (org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException)2 THashMap (gnu.trove.THashMap)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1