Java Code Examples for org.eclipse.aether.resolution.ArtifactDescriptorRequest#setRepositories()

The following examples show how to use org.eclipse.aether.resolution.ArtifactDescriptorRequest#setRepositories() . 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: DeployUtils.java    From vertx-deploy-tools with Apache License 2.0 6 votes vote down vote up
private boolean hasTransitiveSnapshots(Dependency dependency) throws MojoFailureException {
    ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
    descriptorRequest.setArtifact(
            new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), dependency.getType(), dependency.getVersion()));
    descriptorRequest.setRepositories(remoteRepos);

    try {
        ArtifactDescriptorResult result = repoSystem.readArtifactDescriptor(repoSession, descriptorRequest);
        Optional<org.eclipse.aether.graph.Dependency> snapshotDependency = result.getDependencies().stream()
                .filter(d -> d.getArtifact().isSnapshot())
                .findFirst();
        return snapshotDependency.isPresent();
    } catch (ArtifactDescriptorException e) {
        throw new MojoFailureException(e.getMessage(), e);
    }
}
 
Example 2
Source File: DependencyResolver.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static Collection<Dependency> _getManagedDependencies(
    IMavenExecutionContext context,
    RepositorySystem system,
    String groupId,
    String artifactId,
    String version,
    SubMonitor monitor)
    throws CoreException {
  ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
  String coords = groupId + ":" + artifactId + ":" + version;
  Artifact artifact = new DefaultArtifact(coords);
  request.setArtifact(artifact);
  request.setRepositories(centralRepository(system));

  // ensure checksum errors result in failure
  DefaultRepositorySystemSession session =
      new DefaultRepositorySystemSession(context.getRepositorySession());
  session.setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_FAIL);

  try {
    List<Dependency> managedDependencies =
        system.readArtifactDescriptor(session, request).getManagedDependencies();
    
    return managedDependencies;
  } catch (RepositoryException ex) {
    IStatus status = StatusUtil.error(DependencyResolver.class, ex.getMessage(), ex);
    throw new CoreException(status);
  }
}
 
Example 3
Source File: MavenPluginLocation.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private MavenPluginVersion createMavenVersion(Version version) throws ArtifactDescriptorException, FileNotFoundException, IOException, ArtifactResolutionException, XmlPullParserException {
	ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
	
	Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "pom", version.toString());
	
	descriptorRequest.setArtifact(versionArtifact);
	descriptorRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());
	
	MavenPluginVersion mavenPluginVersion = new MavenPluginVersion(versionArtifact, version);
	ArtifactDescriptorResult descriptorResult;
	descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
	
	try {
		ArtifactRequest request = new ArtifactRequest();
		request.setArtifact(descriptorResult.getArtifact());
		request.setRepositories(mavenPluginRepository.getRepositoriesAsList());
		ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
		File pomFile = resolveArtifact.getArtifact().getFile();
		MavenXpp3Reader mavenreader = new MavenXpp3Reader();
		
		try (FileReader fileReader = new FileReader(pomFile)) {
			Model model = mavenreader.read(fileReader);
			mavenPluginVersion.setModel(model);
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage());
	}
	
	for (org.eclipse.aether.graph.Dependency dependency : descriptorResult.getDependencies()) {
		DefaultArtifactVersion artifactVersion = new DefaultArtifactVersion(dependency.getArtifact().getVersion());
		mavenPluginVersion.addDependency(new MavenDependency(dependency.getArtifact(), artifactVersion));
	}
	return mavenPluginVersion;
}
 
Example 4
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private ArtifactDescriptorResult readArtifactDescriptor(AddonId addonId) throws ArtifactDescriptorException
{
   String coords = toMavenCoords(addonId);
   RepositorySystem system = container.getRepositorySystem();
   Settings settings = getSettings();
   DefaultRepositorySystemSession session = container.setupRepoSession(system, settings);
   List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings);
   ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();
   request.setArtifact(new DefaultArtifact(coords));
   request.setRepositories(repositories);

   ArtifactDescriptorResult result = system.readArtifactDescriptor(session, request);
   return result;
}
 
Example 5
Source File: Resolver.java    From buck with Apache License 2.0 5 votes vote down vote up
private List<Dependency> getDependenciesOf(Artifact dep) throws ArtifactDescriptorException {
  ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
  descriptorRequest.setArtifact(dep);
  descriptorRequest.setRepositories(repos);
  descriptorRequest.setRequestContext(JavaScopes.RUNTIME);

  ArtifactDescriptorResult result = repoSys.readArtifactDescriptor(session, descriptorRequest);
  return result.getDependencies();
}