Java Code Examples for org.eclipse.aether.resolution.ArtifactDescriptorResult#getManagedDependencies()

The following examples show how to use org.eclipse.aether.resolution.ArtifactDescriptorResult#getManagedDependencies() . 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: GithubImporter.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
private List<String> getMavenParentDependencies(String parent)
		throws DependencyResolutionException, ArtifactDescriptorException {
	List<String> dependencies = new ArrayList<>();
	DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
	RepositorySystem system = newRepositorySystem(locator);
	RepositorySystemSession session = newSession(system);

	RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/")
			.build();

	org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(parent);
	ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(artifact, Arrays.asList(central), null);
	try {
		ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);
		for (org.eclipse.aether.graph.Dependency dependency : result.getManagedDependencies()) {
			dependencies.add(dependency.getArtifact().getGroupId() + ":" + dependency.getArtifact().getGroupId());
		}
	} catch (Exception e) {
		logger.error(e.getMessage());
	}
	return dependencies;

}
 
Example 2
Source File: ExternalBomResolver.java    From sundrio with Apache License 2.0 6 votes vote down vote up
private Map<Artifact, Dependency> resolveDependencies(BomImport bom) throws Exception {
    org.eclipse.aether.artifact.Artifact artifact = new org.eclipse.aether.artifact.DefaultArtifact(bom.getGroupId(), bom.getArtifactId(), "pom", bom.getVersion());

    List<RemoteRepository> repositories = remoteRepositories;
    if (bom.getRepository() != null) {
        // Include the additional repository into the copy
        repositories = new LinkedList<RemoteRepository>(repositories);
        RemoteRepository repo = new RemoteRepository.Builder(bom.getArtifactId() + "-repository", "default", bom.getRepository()).build();
        repositories.add(0, repo);
    }

    ArtifactRequest artifactRequest = new ArtifactRequest(artifact, repositories, null);
    system.resolveArtifact(session, artifactRequest); // To get an error when the artifact does not exist

    ArtifactDescriptorRequest req = new ArtifactDescriptorRequest(artifact, repositories, null);
    ArtifactDescriptorResult res = system.readArtifactDescriptor(session, req);

    Map<Artifact, Dependency> mavenDependencies = new LinkedHashMap<Artifact, Dependency>();
    if (res.getManagedDependencies() != null) {
        for (org.eclipse.aether.graph.Dependency dep : res.getManagedDependencies()) {
            mavenDependencies.put(toMavenArtifact(dep), toMavenDependency(dep));
        }
    }

    return mavenDependencies;
}
 
Example 3
Source File: ManagedDependencyLister.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws ArtifactDescriptorException {
  DefaultArtifact artifact =
      new DefaultArtifact("com.google.cloud:libraries-bom:pom:1.0.0");

  RepositorySystemSession session = RepositoryUtility.newSession(system);

  ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
  request.addRepository(RepositoryUtility.CENTRAL);
  request.setArtifact(artifact);

  ArtifactDescriptorResult resolved = system.readArtifactDescriptor(session, request);
  for (Dependency dependency : resolved.getManagedDependencies()) {
    System.out.println(dependency);
  }
}
 
Example 4
Source File: Bom.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the dependencyManagement section of an artifact and returns
 * the artifacts included there.
 *
 * @param mavenRepositoryUrls URLs of Maven repositories to search for BOM members
 */
public static Bom readBom(String coordinates, List<String> mavenRepositoryUrls)
    throws ArtifactDescriptorException {
  Artifact artifact = new DefaultArtifact(coordinates);

  RepositorySystem system = RepositoryUtility.newRepositorySystem();
  RepositorySystemSession session = RepositoryUtility.newSession(system);

  ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();

  for (String repositoryUrl : mavenRepositoryUrls) {
    request.addRepository(RepositoryUtility.mavenRepositoryFromUrl(repositoryUrl));
  }

  request.setArtifact(artifact);

  ArtifactDescriptorResult resolved = system.readArtifactDescriptor(session, request);
  List<Exception> exceptions = resolved.getExceptions();
  if (!exceptions.isEmpty()) {
    throw new ArtifactDescriptorException(resolved, exceptions.get(0).getMessage());
  }
  
  List<Artifact> managedDependencies = new ArrayList<>();
  for (Dependency dependency : resolved.getManagedDependencies()) {
    Artifact managed = dependency.getArtifact();
    if (!shouldSkipBomMember(managed) && !managedDependencies.contains(managed)) {
      managedDependencies.add(managed);
    }
  }
  
  Bom bom = new Bom(coordinates, ImmutableList.copyOf(managedDependencies));
  return bom;
}
 
Example 5
Source File: Cadfael.java    From Poseidon with Apache License 2.0 5 votes vote down vote up
public Set<Dependency> getAllDependencies(Artifact artifact) throws ArtifactDescriptorException {
    ArtifactDescriptorRequest request = new ArtifactDescriptorRequest(artifact, repositories, null);
    ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);

    Set<Dependency> dependencies = new HashSet<>(result.getManagedDependencies());
    dependencies.addAll(result.getDependencies());

    return dependencies;
}