Java Code Examples for org.eclipse.aether.RepositorySystem#resolveDependencies()
The following examples show how to use
org.eclipse.aether.RepositorySystem#resolveDependencies() .
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: ArtifactHelper.java From LicenseScout with Apache License 2.0 | 6 votes |
/** * Calculates the set of transitive dependencies of the passed artifacts. * * @param repositoryParameters * @param artifacts * @param artifactScope * @return a list of File locations where the JARs of the dependencies are located in the local file system * @throws DependencyResolutionException */ public static List<File> getDependencies(final IRepositoryParameters repositoryParameters, final List<ArtifactItem> artifacts, final ArtifactScope artifactScope) throws DependencyResolutionException { final RepositorySystem system = repositoryParameters.getRepositorySystem(); final RepositorySystemSession session = repositoryParameters.getRepositorySystemSession(); final DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(artifactScope.getScopeValue()); final Set<File> artifactFiles = new HashSet<>(); for (final ArtifactItem artifactItem : artifacts) { Artifact artifact = createDefaultArtifact(artifactItem); final CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, artifactScope.getScopeValue())); collectRequest.setRepositories(repositoryParameters.getRemoteRepositories()); final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter); final DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest); final List<ArtifactResult> artifactResults = dependencyResult.getArtifactResults(); for (final ArtifactResult artifactResult : artifactResults) { artifactFiles.add(artifactResult.getArtifact().getFile()); } } return new ArrayList<>(artifactFiles); }
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: PluginAddCommand.java From gyro with Apache License 2.0 | 5 votes |
private boolean validate(String plugin) { try { DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); locator.addService(TransporterFactory.class, FileTransporterFactory.class); locator.addService(TransporterFactory.class, HttpTransporterFactory.class); RepositorySystem system = locator.getService(RepositorySystem.class); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); String localDir = Paths.get(System.getProperty("user.home"), ".m2", "repository").toString(); LocalRepository local = new LocalRepository(localDir); LocalRepositoryManager manager = system.newLocalRepositoryManager(session, local); session.setLocalRepositoryManager(manager); Artifact artifact = new DefaultArtifact(plugin); Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME); DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); CollectRequest collectRequest = new CollectRequest(dependency, repositories); DependencyRequest request = new DependencyRequest(collectRequest, filter); system.resolveDependencies(session, request); return true; } catch (DependencyResolutionException e) { GyroCore.ui().write("@|bold %s|@ was not installed for the following reason(s):\n", plugin); for (Exception ex : e.getResult().getCollectExceptions()) { GyroCore.ui().write(" @|red %s|@\n", ex.getMessage()); } GyroCore.ui().write("\n"); return false; } }
Example 4
Source File: SimpleMavenCache.java From gate-core with GNU Lesser General Public License v3.0 | 5 votes |
public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException { // setup a maven resolution hierarchy that uses the main local repo as // a remote repo and then cache into a new local repo List<RemoteRepository> repos = Utils.getRepositoryList(); RepositorySystem repoSystem = Utils.getRepositorySystem(); DefaultRepositorySystemSession repoSession = Utils.getRepositorySession(repoSystem, null); // treat the usual local repository as if it were a remote, ignoring checksum // failures as the local repo doesn't have checksums as a rule RemoteRepository localAsRemote = new RemoteRepository.Builder("localAsRemote", "default", repoSession.getLocalRepository().getBasedir().toURI().toString()) .setPolicy(new RepositoryPolicy(true, RepositoryPolicy.UPDATE_POLICY_NEVER, RepositoryPolicy.CHECKSUM_POLICY_IGNORE)) .build(); repos.add(0, localAsRemote); repoSession.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager( repoSession, new LocalRepository(head.getAbsolutePath()))); Dependency dependency = new Dependency(artifact, "runtime"); CollectRequest collectRequest = new CollectRequest(dependency, repos); DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot(); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setRoot(node); repoSystem.resolveDependencies(repoSession, dependencyRequest); }
Example 5
Source File: ModifiedClassPathRunner.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
private List<URL> resolveCoordinates(String[] coordinates) throws Exception { DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils .newServiceLocator(); serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class); RepositorySystem repositorySystem = serviceLocator .getService(RepositorySystem.class); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); LocalRepository localRepository = new LocalRepository( System.getProperty("user.home") + "/.m2/repository"); session.setLocalRepositoryManager( repositorySystem.newLocalRepositoryManager(session, localRepository)); CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build())); collectRequest.setDependencies(createDependencies(coordinates)); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null); DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest); List<URL> resolvedArtifacts = new ArrayList<>(); for (ArtifactResult artifact : result.getArtifactResults()) { resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL()); } return resolvedArtifacts; }
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: PluginPreprocessor.java From gyro with Apache License 2.0 | 4 votes |
@Override public List<Node> preprocess(List<Node> nodes, RootScope scope) { PluginSettings settings = scope.getSettings(PluginSettings.class); List<String> artifactCoords = new ArrayList<>(); List<Node> repositoryNodes = new ArrayList<>(); for (Node node : nodes) { if (node instanceof DirectiveNode) { if ("plugin".equals(((DirectiveNode) node).getName())) { artifactCoords.add(getArtifactCoord((DirectiveNode) node)); } else if ("repository".equals(((DirectiveNode) node).getName())) { repositoryNodes.add(node); } } } if (artifactCoords.stream().allMatch(settings::pluginInitialized)) { return nodes; } NodeEvaluator evaluator = new NodeEvaluator(); evaluator.evaluate(scope, repositoryNodes); for (String ac : artifactCoords) { if (settings.pluginInitialized(ac)) { continue; } try { GyroCore.ui().write("@|magenta ↓ Loading plugin:|@ %s\n", ac); DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator(); locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class); locator.addService(TransporterFactory.class, FileTransporterFactory.class); locator.addService(TransporterFactory.class, HttpTransporterFactory.class); RepositorySystem system = locator.getService(RepositorySystem.class); DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); String localDir = Paths.get(System.getProperty("user.home"), ".m2", "repository").toString(); LocalRepository local = new LocalRepository(localDir); LocalRepositoryManager manager = system.newLocalRepositoryManager(session, local); session.setLocalRepositoryManager(manager); Artifact artifact = new DefaultArtifact(ac); Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME); DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); List<RemoteRepository> repositories = scope.getSettings(RepositorySettings.class).getRepositories(); CollectRequest collectRequest = new CollectRequest(dependency, repositories); DependencyRequest request = new DependencyRequest(collectRequest, filter); DependencyResult result = system.resolveDependencies(session, request); settings.putDependencyResult(ac, result); for (ArtifactResult ar : result.getArtifactResults()) { settings.putArtifactIfNewer(ar.getArtifact()); } } catch (Exception error) { throw new GyroException( String.format("Can't load the @|bold %s|@ plugin!", ac), error); } } settings.addAllUrls(); return nodes; }