Search in sources :

Example 26 with RepositorySystemSession

use of org.sonatype.aether.RepositorySystemSession 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

RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)26 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)15 Artifact (org.sonatype.aether.artifact.Artifact)13 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)11 RepositorySystem (org.sonatype.aether.RepositorySystem)10 Test (org.junit.Test)8 Dependency (org.sonatype.aether.graph.Dependency)8 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)7 CollectRequest (org.sonatype.aether.collection.CollectRequest)6 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)6 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)6 File (java.io.File)5 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)5 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)5 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)4 CollectResult (org.sonatype.aether.collection.CollectResult)4 VersionResolver (org.sonatype.aether.impl.VersionResolver)4 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)4 LocalMetadataRegistration (org.sonatype.aether.repository.LocalMetadataRegistration)4 VersionRequest (org.sonatype.aether.resolution.VersionRequest)4