Search in sources :

Example 41 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class DependencyGraphParserTest method testOptionalScope.

@Test
public void testOptionalScope() throws IOException {
    String def = "gid:aid:jar:1";
    DependencyNode node = parser.parseLiteral(def);
    assertNotNull(node);
    assertEquals(0, node.getChildren().size());
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    assertEquals("", dependency.getScope());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) Test(org.junit.Test)

Example 42 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class DependencyGraphParserTest method assertNodeProperties.

private void assertNodeProperties(DependencyNode node, String suffix) {
    assertNotNull(node);
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    if (!"".equals(dependency.getScope())) {
        assertEquals("scope" + suffix, dependency.getScope());
    }
    Artifact artifact = dependency.getArtifact();
    assertNotNull(artifact);
    assertEquals("gid" + suffix, artifact.getGroupId());
    assertEquals("aid" + suffix, artifact.getArtifactId());
    assertEquals("ext" + suffix, artifact.getExtension());
    assertEquals("ver" + suffix, artifact.getVersion());
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 43 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class ConflictMarker method mark.

private Map<DependencyNode, Object> mark(Collection<DependencyNode> nodes, Map<Object, ConflictGroup> groups) {
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>(nodes.size() + 1);
    for (DependencyNode node : nodes) {
        Dependency dependency = node.getDependency();
        if (dependency != null) {
            Object key = toKey(dependency.getArtifact());
            conflictIds.put(node, groups.get(key).keys);
        }
    }
    return conflictIds;
}
Also used : IdentityHashMap(java.util.IdentityHashMap) DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency)

Example 44 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class JavaDependencyContextRefiner method getClasspathScope.

private String getClasspathScope(DependencyNode node) {
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        return null;
    }
    String scope = dependency.getScope();
    if (JavaScopes.COMPILE.equals(scope) || JavaScopes.SYSTEM.equals(scope) || JavaScopes.PROVIDED.equals(scope)) {
        return JavaScopes.COMPILE;
    } else if (JavaScopes.RUNTIME.equals(scope)) {
        return JavaScopes.RUNTIME;
    } else if (JavaScopes.TEST.equals(scope)) {
        return JavaScopes.TEST;
    }
    return null;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency)

Example 45 with Dependency

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

Dependency (org.sonatype.aether.graph.Dependency)45 Artifact (org.sonatype.aether.artifact.Artifact)22 Test (org.junit.Test)14 CollectRequest (org.sonatype.aether.collection.CollectRequest)14 DependencyNode (org.sonatype.aether.graph.DependencyNode)14 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 Exclusion (org.sonatype.aether.graph.Exclusion)9 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)9 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)7 ArrayList (java.util.ArrayList)5 RepositorySystem (org.sonatype.aether.RepositorySystem)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)4 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)4 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)4 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)4 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)4 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 HashMap (java.util.HashMap)2