Search in sources :

Example 21 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project pinpoint by naver.

the class DependencyResolver method get.

public static DependencyResolver get(String... repositoryUrls) {
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    List<RemoteRepository> repositories = newRepositories(repositoryUrls);
    return new DependencyResolver(system, session, repositories);
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) RemoteRepository(org.eclipse.aether.repository.RemoteRepository)

Example 22 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolvePlugin.

@Override
public Collection<MavenArtifact> resolvePlugin(@NotNull final MavenPlugin plugin, @NotNull final List<MavenRemoteRepository> repositories, int nativeMavenProjectId, final boolean transitive) throws RemoteException, MavenServerProcessCanceledException {
    try {
        Plugin mavenPlugin = new Plugin();
        mavenPlugin.setGroupId(plugin.getGroupId());
        mavenPlugin.setArtifactId(plugin.getArtifactId());
        mavenPlugin.setVersion(plugin.getVersion());
        MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);
        Plugin pluginFromProject = project.getBuild().getPluginsAsMap().get(plugin.getGroupId() + ':' + plugin.getArtifactId());
        if (pluginFromProject != null) {
            mavenPlugin.setDependencies(pluginFromProject.getDependencies());
        }
        final MavenExecutionRequest request = createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
        DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
        RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
        PluginDependenciesResolver pluginDependenciesResolver = getComponent(PluginDependenciesResolver.class);
        org.eclipse.aether.artifact.Artifact pluginArtifact = pluginDependenciesResolver.resolve(mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);
        org.eclipse.aether.graph.DependencyNode node = pluginDependenciesResolver.resolve(mavenPlugin, pluginArtifact, null, project.getRemotePluginRepositories(), repositorySystemSession);
        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        node.accept(nlg);
        List<MavenArtifact> res = new ArrayList<MavenArtifact>();
        for (org.eclipse.aether.artifact.Artifact artifact : nlg.getArtifacts(true)) {
            if (!Comparing.equal(artifact.getArtifactId(), plugin.getArtifactId()) || !Comparing.equal(artifact.getGroupId(), plugin.getGroupId())) {
                res.add(MavenModelConverter.convertArtifact(RepositoryUtils.toArtifact(artifact), getLocalRepositoryFile()));
            }
        }
        return res;
    } catch (Exception e) {
        Maven3ServerGlobals.getLogger().info(e);
        return Collections.emptyList();
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) 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) PluginDependenciesResolver(org.apache.maven.plugin.internal.PluginDependenciesResolver) Plugin(org.apache.maven.model.Plugin)

Example 23 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolve.

private Artifact resolve(@NotNull final Artifact artifact, @NotNull final List<ArtifactRepository> repos) throws ArtifactResolutionException, ArtifactNotFoundException, RemoteException, org.eclipse.aether.resolution.ArtifactResolutionException {
    final String mavenVersion = getMavenVersion();
    // see https://youtrack.jetbrains.com/issue/IDEA-140208 for details
    if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING || StringUtil.compareVersionNumbers(mavenVersion, "3.2.5") < 0) {
        MavenExecutionRequest request = new DefaultMavenExecutionRequest();
        request.setRemoteRepositories(repos);
        try {
            getComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, myMavenSettings);
            getComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
        } catch (MavenExecutionRequestPopulationException e) {
            throw new RuntimeException(e);
        }
        getComponent(ArtifactResolver.class).resolve(artifact, request.getRemoteRepositories(), myLocalRepository);
        return artifact;
    } else {
        final MavenExecutionRequest request = createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
        for (ArtifactRepository artifactRepository : repos) {
            request.addRemoteRepository(artifactRepository);
        }
        DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
        RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
        final org.eclipse.aether.impl.ArtifactResolver artifactResolver = getComponent(org.eclipse.aether.impl.ArtifactResolver.class);
        final MyLoggerFactory loggerFactory = new MyLoggerFactory();
        if (artifactResolver instanceof DefaultArtifactResolver) {
            ((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
        }
        final org.eclipse.aether.RepositorySystem repositorySystem = getComponent(org.eclipse.aether.RepositorySystem.class);
        if (repositorySystem instanceof DefaultRepositorySystem) {
            ((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
        }
        List<RemoteRepository> repositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
        repositories = repositorySystem.newResolutionRepositories(repositorySystemSession, repositories);
        final ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), repositories, null));
        return RepositoryUtils.toArtifact(artifactResult.getArtifact());
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolver(org.apache.maven.artifact.resolver.ArtifactResolver) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver)

Example 24 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession 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 25 with RepositorySystemSession

use of org.eclipse.aether.RepositorySystemSession in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method executeWithMavenSession.

public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
    DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
    RepositorySystemSession repositorySession = maven.newRepositorySession(request);
    request.getProjectBuildingRequest().setRepositorySession(repositorySession);
    MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
    LegacySupport legacySupport = getComponent(LegacySupport.class);
    MavenSession oldSession = legacySupport.getSession();
    legacySupport.setSession(mavenSession);
    /** adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)} */
    try {
        for (AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(Collections.<MavenProject>emptyList())) {
            listener.afterSessionStart(mavenSession);
        }
    } catch (MavenExecutionException e) {
        throw new RuntimeException(e);
    }
    try {
        runnable.run();
    } finally {
        legacySupport.setSession(oldSession);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) LegacySupport(org.apache.maven.plugin.LegacySupport)

Aggregations

RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)38 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)19 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)14 RepositorySystem (org.eclipse.aether.RepositorySystem)13 Artifact (org.eclipse.aether.artifact.Artifact)13 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)13 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)12 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)11 ArrayList (java.util.ArrayList)10 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)10 File (java.io.File)8 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)7 List (java.util.List)5 Artifact (org.apache.maven.artifact.Artifact)5 MavenSession (org.apache.maven.execution.MavenSession)5 IOException (java.io.IOException)4 DefaultMaven (org.apache.maven.DefaultMaven)4 Maven (org.apache.maven.Maven)4 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)4