Java Code Examples for org.eclipse.aether.DefaultRepositorySystemSession#setDependencyTraverser()
The following examples show how to use
org.eclipse.aether.DefaultRepositorySystemSession#setDependencyTraverser() .
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: Main.java From revapi with Apache License 2.0 | 5 votes |
private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo, List<RemoteRepository> remoteRepositories) { RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem(); DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, new LocalRepository(localRepo)); session.setDependencySelector(getRevapiDependencySelector(true, false)); session.setDependencyTraverser(getRevapiDependencyTraverser(true, false)); ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories); List<FileArchive> archives = new ArrayList<>(); List<FileArchive> supplementaryArchives = new ArrayList<>(); for (String gav : gavs) { try { archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile())); ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav); res.getResolvedArtifacts(). forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile()))); if (!res.getFailures().isEmpty()) { LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString()); } } catch (RepositoryException e) { throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage()); } } return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives); }
Example 2
Source File: ArtifactResolverTest.java From revapi with Apache License 2.0 | 5 votes |
private ArtifactResolver getResolver(boolean resolveProvidedDependencies, boolean resolveTransitiveProvidedDependencies) { RepositorySystem repositorySystem = newRepositorySystem(); DefaultRepositorySystemSession session = newRepositorySystemSession(repositorySystem, localRepo()); session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); return new ArtifactResolver(repositorySystem, session, repos()); }
Example 3
Source File: MavenAddonDependencyResolver.java From furnace with Eclipse Public License 1.0 | 5 votes |
@Override public Response<File[]> resolveResources(final AddonId addonId) { RepositorySystem system = container.getRepositorySystem(); Settings settings = getSettings(); DefaultRepositorySystemSession session = container.setupRepoSession(system, settings); final String mavenCoords = toMavenCoords(addonId); Artifact queryArtifact = new DefaultArtifact(mavenCoords); session.setDependencyTraverser(new AddonDependencyTraverser(classifier)); session.setDependencySelector(new AddonDependencySelector(classifier)); Dependency dependency = new Dependency(queryArtifact, null); List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings); CollectRequest collectRequest = new CollectRequest(dependency, repositories); DependencyResult result; try { result = system.resolveDependencies(session, new DependencyRequest(collectRequest, null)); } catch (DependencyResolutionException e) { throw new RuntimeException(e); } List<Exception> collectExceptions = result.getCollectExceptions(); Set<File> files = new HashSet<File>(); List<ArtifactResult> artifactResults = result.getArtifactResults(); for (ArtifactResult artifactResult : artifactResults) { Artifact artifact = artifactResult.getArtifact(); if (isFurnaceAPI(artifact) || (this.classifier.equals(artifact.getClassifier()) && !addonId.getName().equals(artifact.getGroupId() + ":" + artifact.getArtifactId()))) { continue; } files.add(artifact.getFile()); } return new MavenResponseBuilder<File[]>(files.toArray(new File[files.size()])).setExceptions(collectExceptions); }
Example 4
Source File: ReportAggregateMojo.java From revapi with Apache License 2.0 | 4 votes |
private ProjectVersions getRunConfig(MavenProject project) { ProjectVersions ret = new ProjectVersions(); Plugin revapiPlugin = findRevapi(project); if (revapiPlugin == null) { return ret; } Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration(); String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts"); String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts"); String oldVersion = getValueOfChild(pluginConfig, "oldVersion"); if (oldVersion == null) { oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE); } String newVersion = getValueOfChild(pluginConfig, "newVersion"); if (newVersion == null) { newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion()); } String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion); String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion); if (oldArtifacts == null || oldArtifacts.length == 0) { if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) { return ret; } oldArtifacts = new String[]{defaultOldArtifact}; } if (newArtifacts == null || newArtifacts.length == 0) { if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) { return ret; } newArtifacts = new String[]{defaultNewArtifact}; } String versionRegexString = getValueOfChild(pluginConfig, "versionFormat"); Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString); DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession); session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); if (alwaysCheckForReleaseVersion) { session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); } ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories()); Function<String, Artifact> resolve = gav -> { try { return Analyzer.resolveConstrained(project, gav, versionRegex, resolver); } catch (VersionRangeResolutionException | ArtifactResolutionException e) { getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage()); return null; } }; ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new); ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new); return ret; }
Example 5
Source File: Analyzer.java From revapi with Apache License 2.0 | 4 votes |
Analyzer(PlexusConfiguration pipelineConfiguration, PlexusConfiguration analysisConfiguration, Object[] analysisConfigurationFiles, Artifact[] oldArtifacts, Artifact[] newArtifacts, String[] oldGavs, String[] newGavs, MavenProject project, RepositorySystem repositorySystem, RepositorySystemSession repositorySystemSession, Class<? extends Reporter> reporterType, Map<String, Object> contextData, Locale locale, Log log, boolean failOnMissingConfigurationFiles, boolean failOnMissingArchives, boolean failOnMissingSupportArchives, boolean alwaysUpdate, boolean resolveDependencies, boolean resolveProvidedDependencies, boolean resolveTransitiveProvidedDependencies, String versionRegex, Consumer<PipelineConfiguration.Builder> pipelineModifier, Revapi sharedRevapi) { this.pipelineConfiguration = pipelineConfiguration; this.analysisConfiguration = analysisConfiguration; this.analysisConfigurationFiles = analysisConfigurationFiles; this.oldGavs = oldGavs; this.newGavs = newGavs; this.oldArtifacts = oldArtifacts; this.newArtifacts = newArtifacts; this.project = project; this.repositorySystem = repositorySystem; this.resolveDependencies = resolveDependencies; this.versionRegex = versionRegex == null ? null : Pattern.compile(versionRegex); DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession); session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); if (alwaysUpdate) { session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); } this.repositorySystemSession = session; this.reporterType = reporterType; this.contextData = contextData; this.locale = locale; this.log = log; this.failOnMissingConfigurationFiles = failOnMissingConfigurationFiles; this.failOnMissingArchives = failOnMissingArchives; this.failOnMissingSupportArchives = failOnMissingSupportArchives; this.revapi = sharedRevapi; this.pipelineModifier = pipelineModifier; }
Example 6
Source File: MavenAddonDependencyResolver.java From furnace with Eclipse Public License 1.0 | 4 votes |
private Response<String> resolveAPIVersion(AddonId addonId, RepositorySystem system, Settings settings, DefaultRepositorySystemSession session) { List<RemoteRepository> repositories = MavenRepositories.getRemoteRepositories(container, settings); String mavenCoords = toMavenCoords(addonId); Artifact queryArtifact = new DefaultArtifact(mavenCoords); session.setDependencyTraverser(new AddonDependencyTraverser(classifier)); session.setDependencySelector(new DependencySelector() { @Override public boolean selectDependency(Dependency dependency) { Artifact artifact = dependency.getArtifact(); if (isAddon(artifact)) { return true; } return isFurnaceAPI(artifact); } @Override public DependencySelector deriveChildSelector(DependencyCollectionContext context) { return this; } }); CollectRequest request = new CollectRequest(new Dependency(queryArtifact, null), repositories); CollectResult result; try { result = system.collectDependencies(session, request); } catch (DependencyCollectionException e) { throw new RuntimeException(e); } List<Exception> exceptions = result.getExceptions(); String apiVersion = findVersion(result.getRoot().getChildren(), FURNACE_API_GROUP_ID, FURNACE_API_ARTIFACT_ID); return new MavenResponseBuilder<String>(apiVersion).setExceptions(exceptions); }