org.eclipse.aether.resolution.ArtifactDescriptorResult Java Examples
The following examples show how to use
org.eclipse.aether.resolution.ArtifactDescriptorResult.
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: ExtensionDescriptorMojo.java From quarkus with Apache License 2.0 | 6 votes |
private CollectRequest newCollectRequest(DefaultArtifact projectArtifact) throws MojoExecutionException { final ArtifactDescriptorResult projectDescr; try { projectDescr = repoSystem.readArtifactDescriptor(repoSession, new ArtifactDescriptorRequest() .setArtifact(projectArtifact) .setRepositories(repos)); } catch (ArtifactDescriptorException e) { throw new MojoExecutionException("Failed to read descriptor of " + projectArtifact, e); } final CollectRequest request = new CollectRequest().setRootArtifact(projectArtifact) .setRepositories(repos) .setManagedDependencies(projectDescr.getManagedDependencies()); for (Dependency dep : projectDescr.getDependencies()) { if ("test".equals(dep.getScope()) || "provided".equals(dep.getScope()) || dep.isOptional()) { continue; } request.addDependency(dep); } return request; }
Example #2
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 #3
Source File: GithubImporter.java From scava with Eclipse Public License 2.0 | 6 votes |
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 #4
Source File: ParentPOMPropagatingArtifactDescriptorReaderDelegate.java From mvn2nix-maven-plugin with MIT License | 6 votes |
@Override public void populateResult(RepositorySystemSession session, ArtifactDescriptorResult result, Model model) { super.populateResult(session, result, model); Parent parent = model.getParent(); if (parent != null) { DefaultArtifact art = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion()); Dependency dep = new Dependency(art, "compile"); result.addDependency(dep); } }
Example #5
Source File: ExternalBomResolver.java From sundrio with Apache License 2.0 | 6 votes |
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 #6
Source File: Cadfael.java From Poseidon with Apache License 2.0 | 5 votes |
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; }
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(); }
Example #8
Source File: MavenResolverDependencyManagementVersionResolver.java From initializr with Apache License 2.0 | 5 votes |
private ArtifactDescriptorResult resolveBom(String groupId, String artifactId, String version) { synchronized (this.monitor) { try { return this.repositorySystem.readArtifactDescriptor(this.repositorySystemSession, new ArtifactDescriptorRequest(new DefaultArtifact(groupId, artifactId, "pom", version), repositories, null)); } catch (ArtifactDescriptorException ex) { throw new IllegalStateException( "Bom '" + groupId + ":" + artifactId + ":" + version + "' could not be resolved", ex); } } }
Example #9
Source File: MavenResolverDependencyManagementVersionResolver.java From initializr with Apache License 2.0 | 5 votes |
@Override public Map<String, String> resolve(String groupId, String artifactId, String version) { ArtifactDescriptorResult bom = resolveBom(groupId, artifactId, version); Map<String, String> managedVersions = new HashMap<>(); bom.getManagedDependencies().stream().map(Dependency::getArtifact).forEach((artifact) -> managedVersions .putIfAbsent(artifact.getGroupId() + ":" + artifact.getArtifactId(), artifact.getVersion())); return managedVersions; }
Example #10
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 #11
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 #12
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 #13
Source File: RepackageExtensionMojo.java From syndesis with Apache License 2.0 | 5 votes |
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); }
Example #14
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
private ArtifactDescriptorResult resolveDescriptorInternal(final Artifact artifact, List<RemoteRepository> aggregatedRepos) throws BootstrapMavenException { try { return repoSystem.readArtifactDescriptor(repoSession, new ArtifactDescriptorRequest() .setArtifact(artifact) .setRepositories( aggregatedRepos)); } catch (ArtifactDescriptorException e) { throw new BootstrapMavenException("Failed to read descriptor of " + artifact, e); } }
Example #15
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 #16
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 4 votes |
public ArtifactDescriptorResult resolveDescriptor(final Artifact artifact, List<RemoteRepository> mainRepos) throws BootstrapMavenException { return resolveDescriptorInternal(artifact, aggregateRepositories(mainRepos, remoteRepos)); }
Example #17
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 4 votes |
public ArtifactDescriptorResult resolveDescriptor(final Artifact artifact) throws BootstrapMavenException { return resolveDescriptorInternal(artifact, remoteRepos); }