Java Code Examples for org.eclipse.aether.resolution.ArtifactDescriptorRequest#setArtifact()
The following examples show how to use
org.eclipse.aether.resolution.ArtifactDescriptorRequest#setArtifact() .
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 |
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: ManagedDependencyLister.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
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 3
Source File: Bom.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
/** * 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 4
Source File: DependencyResolver.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
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 5
Source File: MavenPluginLocation.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
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 6
Source File: MavenAddonDependencyResolver.java From furnace with Eclipse Public License 1.0 | 5 votes |
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 7
Source File: Resolver.java From buck with Apache License 2.0 | 5 votes |
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(); }