Java Code Examples for org.eclipse.aether.DefaultRepositorySystemSession#setDependencyGraphTransformer()

The following examples show how to use org.eclipse.aether.DefaultRepositorySystemSession#setDependencyGraphTransformer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepositoryUtility.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
private static DefaultRepositorySystemSession newSession(
    RepositorySystem system, DependencySelector dependencySelector) {
  DefaultRepositorySystemSession session = createDefaultRepositorySystemSession(system);
  session.setDependencySelector(dependencySelector);

  // By default, Maven's MavenRepositorySystemUtils.newSession() returns a session with
  // ChainedDependencyGraphTransformer(ConflictResolver(...), JavaDependencyContextRefiner()).
  // Because the full dependency graph does not resolve conflicts of versions, this session does
  // not use ConflictResolver.
  session.setDependencyGraphTransformer(
      new ChainedDependencyGraphTransformer(
          new CycleBreakerGraphTransformer(), // Avoids StackOverflowError
          new JavaDependencyContextRefiner()));

  // No dependency management in the full dependency graph
  session.setDependencyManager(null);

  return session;
}
 
Example 2
Source File: CycleBreakerGraphTransformerTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testCycleBreaking() throws DependencyResolutionException {
  RepositorySystem system = RepositoryUtility.newRepositorySystem();
  DefaultRepositorySystemSession session =
      RepositoryUtility.createDefaultRepositorySystemSession(system);

  // This dependencySelector selects everything except test scope. This creates a dependency tree
  // with a cycle of dom4j:dom4j:jar:1.6.1 (optional) and jaxen:jaxen:jar:1.1-beta-6 (optional).
  session.setDependencySelector(new ScopeDependencySelector("test"));

  session.setDependencyGraphTransformer(
      new ChainedDependencyGraphTransformer(
          new CycleBreakerGraphTransformer(), // This prevents StackOverflowError
          new JavaDependencyContextRefiner()));

  // dom4j:1.6.1 is known to have a cycle
  CollectRequest collectRequest = new CollectRequest();
  collectRequest.setRepositories(ImmutableList.of(RepositoryUtility.CENTRAL));
  collectRequest.setRoot(new Dependency(new DefaultArtifact("dom4j:dom4j:1.6.1"), "compile"));
  DependencyRequest request = new DependencyRequest(collectRequest, null);

  // This should not raise StackOverflowError
  system.resolveDependencies(session, request);
}
 
Example 3
Source File: NbRepositorySystem.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException {
    DefaultRepositorySystemSession cloned = new DefaultRepositorySystemSession(session);
    DependencyGraphTransformer transformer = session.getDependencyGraphTransformer();
    //need to reset the transformer to prevent the transformation to happen and to it below separately.
    cloned.setDependencyGraphTransformer(null);
    CollectResult res = super.collectDependencies(cloned, request);
    CloningDependencyVisitor vis = new CloningDependencyVisitor();
    res.getRoot().accept(vis);

    //this part copied from DefaultDependencyCollector
    try {
        DefaultDependencyGraphTransformationContext context =
                new DefaultDependencyGraphTransformationContext(session);
        res.setRoot(transformer.transformGraph(res.getRoot(), context));
    } catch (RepositoryException e) {
        res.addException(e);
    }

    if (!res.getExceptions().isEmpty()) {
        throw new DependencyCollectionException(res);
    }
    res.getRoot().setData("NB_TEST", vis.getRootNode());
    return res;
}
 
Example 4
Source File: RepackageExtensionMojo.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private List<Dependency> obtainBomDependencies(final String urlLocation) {
    final Artifact artifact = downloadAndInstallArtifact(urlLocation).getArtifact();

    final Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME);

    final List<RemoteRepository> remoteRepositories = project.getRepositories().stream()
        .map(r -> new RemoteRepository.Builder(r.getId(), r.getLayout(), r.getUrl()).build())
        .collect(Collectors.toList());

    CollectResult result;
    try {
        final ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(artifact, remoteRepositories, null);
        final ArtifactDescriptorResult descriptor = repository.readArtifactDescriptor(session, descriptorRequest);

        final List<Dependency> dependencies = Stream.concat(
            descriptor.getDependencies().stream(),
            descriptor.getManagedDependencies().stream())
            .collect(Collectors.toList());

        final DefaultRepositorySystemSession sessionToUse = new DefaultRepositorySystemSession(session);
        sessionToUse.setDependencyGraphTransformer(new NoopDependencyGraphTransformer());

        final CollectRequest request = new CollectRequest(dependency, dependencies, remoteRepositories);
        result = repository.collectDependencies(sessionToUse, request);
    } catch (final DependencyCollectionException | ArtifactDescriptorException e) {
        throw new IllegalStateException("Unabele to obtain BOM dependencies for: " + urlLocation, e);
    }

    final DependencyNode root = result.getRoot();

    final PostorderNodeListGenerator visitor = new PostorderNodeListGenerator();
    root.accept(visitor);

    return visitor.getDependencies(true);
}