Java Code Examples for org.eclipse.aether.DefaultRepositorySystemSession#setDependencySelector()
The following examples show how to use
org.eclipse.aether.DefaultRepositorySystemSession#setDependencySelector() .
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: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private static DefaultRepositorySystemSession newSession( RepositorySystem system, DependencySelector dependencySelector) { DefaultRepositorySystemSession session = createDefaultRepositorySystemSession(system); session.setDependencySelector(dependencySelector); // By default, Maven's MavenRepositorySystemUtils.newSession() returns a session with // ChainedDependencyGraphTransformer(ConflictResolver(...), JavaDependencyContextRefiner()). // Because the full dependency graph does not resolve conflicts of versions, this session does // not use ConflictResolver. session.setDependencyGraphTransformer( new ChainedDependencyGraphTransformer( new CycleBreakerGraphTransformer(), // Avoids StackOverflowError new JavaDependencyContextRefiner())); // No dependency management in the full dependency graph session.setDependencyManager(null); return session; }
Example 2
Source File: CycleBreakerGraphTransformerTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
@Test public void testCycleBreaking() throws DependencyResolutionException { RepositorySystem system = RepositoryUtility.newRepositorySystem(); DefaultRepositorySystemSession session = RepositoryUtility.createDefaultRepositorySystemSession(system); // This dependencySelector selects everything except test scope. This creates a dependency tree // with a cycle of dom4j:dom4j:jar:1.6.1 (optional) and jaxen:jaxen:jar:1.1-beta-6 (optional). session.setDependencySelector(new ScopeDependencySelector("test")); session.setDependencyGraphTransformer( new ChainedDependencyGraphTransformer( new CycleBreakerGraphTransformer(), // This prevents StackOverflowError new JavaDependencyContextRefiner())); // dom4j:1.6.1 is known to have a cycle CollectRequest collectRequest = new CollectRequest(); collectRequest.setRepositories(ImmutableList.of(RepositoryUtility.CENTRAL)); collectRequest.setRoot(new Dependency(new DefaultArtifact("dom4j:dom4j:1.6.1"), "compile")); DependencyRequest request = new DependencyRequest(collectRequest, null); // This should not raise StackOverflowError system.resolveDependencies(session, request); }
Example 3
Source File: MavenSystemManager.java From archiva with Apache License 2.0 | 6 votes |
/** * Creates a new aether repository system session for the given directory and assigns the * repository to this session. * * @param localRepoDir The repository directory * @return The newly created session object. */ public static RepositorySystemSession newRepositorySystemSession(String localRepoDir) { DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository repo = new LocalRepository(localRepoDir); DependencySelector depFilter = new AndDependencySelector(new ExclusionDependencySelector()); session.setDependencySelector(depFilter); SimpleLocalRepositoryManagerFactory repFactory = new SimpleLocalRepositoryManagerFactory(); try { LocalRepositoryManager manager = repFactory.newInstance(session, repo); session.setLocalRepositoryManager(manager); } catch (NoLocalRepositoryManagerException e) { log.error("Could not assign the repository manager to the session: {}", e.getMessage(), e); } return session; }
Example 4
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 5
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 6
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 7
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 8
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 9
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); }