org.eclipse.aether.resolution.DependencyResolutionException Java Examples
The following examples show how to use
org.eclipse.aether.resolution.DependencyResolutionException.
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: PinpointPluginTestSuite.java From pinpoint with Apache License 2.0 | 6 votes |
private List<PinpointPluginTestInstance> createCasesWithDependencies(PinpointPluginTestContext context) throws ArtifactResolutionException, DependencyResolutionException { List<PinpointPluginTestInstance> cases = new ArrayList<PinpointPluginTestInstance>(); DependencyResolver resolver = getDependencyResolver(repositories); Map<String, List<Artifact>> dependencyCases = resolver.resolveDependencySets(dependencies); for (Map.Entry<String, List<Artifact>> dependencyCase : dependencyCases.entrySet()) { List<String> libs = new ArrayList<String>(); for (File lib : resolver.resolveArtifactsAndDependencies(dependencyCase.getValue())) { libs.add(lib.getAbsolutePath()); } if (testOnSystemClassLoader) { cases.add(new NormalPluginTestCase(context, dependencyCase.getKey(), libs, true)); } if (testOnChildClassLoader) { cases.add(new NormalPluginTestCase(context, dependencyCase.getKey(), libs, false)); } } return cases; }
Example #2
Source File: ArtifactResolver.java From migration-tooling with Apache License 2.0 | 6 votes |
/** * Given a set of coordinates, resolves the transitive dependencies, and then returns the root * node to the resolved dependency graph. The root node is a sentinel node with direct edges * on the artifacts users declared explicit on. */ public DependencyNode resolveArtifacts(List<String> artifactCoords) { List<Dependency> directDependencies = createDirectDependencyList(artifactCoords); CollectRequest collectRequest = aether.createCollectRequest(directDependencies, managedDependencies); DependencyRequest dependencyRequest = aether.createDependencyRequest(collectRequest); DependencyResult dependencyResult; try { dependencyResult = aether.requestDependencyResolution(dependencyRequest); } catch (DependencyResolutionException e) { //FIXME(petros): This is very fragile. If one artifact doesn't resolve, no artifacts resolve. logger.warning("Unable to resolve transitive dependencies: " + e.getMessage()); return null; } // root is a sentinel node whose direct children are the requested artifacts. return dependencyResult.getRoot(); }
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: AbstractPinpointPluginTestSuite.java From pinpoint with Apache License 2.0 | 6 votes |
public AbstractPinpointPluginTestSuite(Class<?> testClass) throws InitializationError, ArtifactResolutionException, DependencyResolutionException { super(testClass, Collections.<Runner> emptyList()); PinpointAgent agent = testClass.getAnnotation(PinpointAgent.class); this.agentJar = resolveAgentPath(agent); PinpointConfig config = testClass.getAnnotation(PinpointConfig.class); this.configFile = config == null ? null : resolveConfigFileLocation(config.value()); PinpointProfile profile = testClass.getAnnotation(PinpointProfile.class); this.profile = resolveProfile(profile); JvmArgument jvmArgument = testClass.getAnnotation(JvmArgument.class); this.jvmArguments = getJvmArguments(jvmArgument); JvmVersion jvmVersion = testClass.getAnnotation(JvmVersion.class); this.jvmVersions = jvmVersion == null ? new int[] { NO_JVM_VERSION } : jvmVersion.value(); ImportPlugin importPlugin = testClass.getAnnotation(ImportPlugin.class); this.importPluginIds = getImportPlugin(importPlugin); this.requiredLibraries = getClassPathList(REQUIRED_CLASS_PATHS); this.mavenDependencyLibraries = getClassPathList(MAVEN_DEPENDENCY_CLASS_PATHS); this.testClassLocation = resolveTestClassLocation(testClass); this.debug = isDebugMode(); }
Example #5
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 #6
Source File: DependencyGraphBuilder.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private DependencyGraph buildDependencyGraph( List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session) { try { DependencyNode node = resolveCompileTimeDependencies(dependencyNodes, session); return DependencyGraph.from(node); } catch (DependencyResolutionException ex) { DependencyResult result = ex.getResult(); DependencyGraph graph = DependencyGraph.from(result.getRoot()); for (ArtifactResult artifactResult : result.getArtifactResults()) { Artifact resolvedArtifact = artifactResult.getArtifact(); if (resolvedArtifact == null) { Artifact requestedArtifact = artifactResult.getRequest().getArtifact(); graph.addUnresolvableArtifactProblem(requestedArtifact); } } return graph; } }
Example #7
Source File: DependencyResolver.java From pinpoint with Apache License 2.0 | 6 votes |
public List<File> resolveArtifactsAndDependencies(List<Artifact> artifacts) throws DependencyResolutionException { List<Dependency> dependencies = new ArrayList<Dependency>(); for (Artifact artifact : artifacts) { dependencies.add(new Dependency(artifact, JavaScopes.RUNTIME)); } CollectRequest collectRequest = new CollectRequest((Dependency) null, dependencies, repositories); DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); DependencyResult result = system.resolveDependencies(session, dependencyRequest); List<File> files = new ArrayList<File>(); for (ArtifactResult artifactResult : result.getArtifactResults()) { files.add(artifactResult.getArtifact().getFile()); } return files; }
Example #8
Source File: DependencyResolver.java From start.spring.io with Apache License 2.0 | 6 votes |
static List<String> resolveDependencies(String groupId, String artifactId, String version, List<BillOfMaterials> boms, List<RemoteRepository> repositories) { DependencyResolver instance = instanceForThread.get(); List<Dependency> managedDependencies = instance.getManagedDependencies(boms, repositories); Dependency aetherDependency = new Dependency(new DefaultArtifact(groupId, artifactId, "pom", instance.getVersion(groupId, artifactId, version, managedDependencies)), "compile"); CollectRequest collectRequest = new CollectRequest((org.eclipse.aether.graph.Dependency) null, Collections.singletonList(aetherDependency), repositories); collectRequest.setManagedDependencies(managedDependencies); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME)); try { return instance.resolveDependencies(dependencyRequest).getArtifactResults().stream() .map(ArtifactResult::getArtifact) .map((artifact) -> artifact.getGroupId() + ":" + artifact.getArtifactId()) .collect(Collectors.toList()); } catch (DependencyResolutionException ex) { throw new RuntimeException(ex); } }
Example #9
Source File: DependencyResolverTest.java From pinpoint with Apache License 2.0 | 6 votes |
@Test public void resolveArtifactsAndDependencies() throws DependencyResolutionException, ArtifactResolutionException { DependencyResolverFactory factory = new DependencyResolverFactory(); DependencyResolver resolver = factory.get(); Map<String, List<Artifact>> sets = resolver.resolveDependencySets("org.eclipse.aether:aether-util:[0,)", "org.eclipse.aether:aether-spi"); int i = 0; for (Map.Entry<String, List<Artifact>> set : sets.entrySet()) { logger.debug("{}", i++); List<File> results = resolver.resolveArtifactsAndDependencies(set.getValue()); logger.debug(set.getKey()); for (File result : results) { logger.debug("{}", result); } } }
Example #10
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 #11
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 #12
Source File: MavenResolver.java From Orienteer with Apache License 2.0 | 5 votes |
private List<Artifact> resolveDependenciesInArtifacts(String groupArtifactVersion) { List<Artifact> results = null; try { results = resolveDependencies(groupArtifactVersion); } catch (ArtifactDescriptorException | DependencyCollectionException | DependencyResolutionException e) { LOG.debug(e.getMessage(), e); } return results != null ? results : Lists.<Artifact>newArrayList(); }
Example #13
Source File: PinpointPluginTestSuite.java From pinpoint with Apache License 2.0 | 5 votes |
private List<PinpointPluginTestInstance> createSharedCasesWithDependencies(PinpointPluginTestContext context) throws ArtifactResolutionException, DependencyResolutionException { List<PinpointPluginTestInstance> cases = new ArrayList<PinpointPluginTestInstance>(); DependencyResolver resolver = getDependencyResolver(this.repositories); Map<String, List<Artifact>> dependencyMap = resolver.resolveDependencySets(dependencies); SharedProcessManager sharedProcessManager = new SharedProcessManager(context); for (Map.Entry<String, List<Artifact>> artifactEntry : dependencyMap.entrySet()) { final String testKey = artifactEntry.getKey(); final List<Artifact> artifacts = artifactEntry.getValue(); List<String> libs = new ArrayList<String>(); for (File lib : resolver.resolveArtifactsAndDependencies(artifacts)) { libs.add(lib.getAbsolutePath()); } PinpointPluginTestInstance testInstance = null; if (testOnSystemClassLoader) { testInstance = new SharedProcessPluginTestCase(context, testKey, libs, true, sharedProcessManager); } if (testOnChildClassLoader) { testInstance = new SharedProcessPluginTestCase(context, testKey, libs, false, sharedProcessManager); } if (testInstance != null) { cases.add(testInstance); sharedProcessManager.registerTest(testInstance.getTestId(), artifacts); } } return cases; }
Example #14
Source File: PinpointPluginTestSuite.java From pinpoint with Apache License 2.0 | 5 votes |
public PinpointPluginTestSuite(Class<?> testClass, boolean sharedProcess) throws InitializationError, ArtifactResolutionException, DependencyResolutionException { super(testClass); OnClassLoader onClassLoader = testClass.getAnnotation(OnClassLoader.class); this.testOnChildClassLoader = onClassLoader == null ? true : onClassLoader.child(); this.testOnSystemClassLoader = onClassLoader == null ? false : onClassLoader.system(); Dependency deps = testClass.getAnnotation(Dependency.class); this.dependencies = deps == null ? null : deps.value(); TestRoot lib = testClass.getAnnotation(TestRoot.class); if (lib == null) { this.libraryPath = null; this.librarySubDirs = null; } else { String path = lib.value(); if (path.isEmpty()) { path = lib.path(); } this.libraryPath = path; this.librarySubDirs = lib.libraryDir(); } if (deps != null && lib != null) { throw new IllegalArgumentException("@Dependency and @TestRoot can not annotate a class at the same time"); } Repository repos = testClass.getAnnotation(Repository.class); this.repositories = repos == null ? new String[0] : repos.value(); this.sharedProcess = sharedProcess; }
Example #15
Source File: MavenResolver.java From Orienteer with Apache License 2.0 | 5 votes |
private List<Artifact> resolveDependencies(String groupArtifactVersion) throws ArtifactDescriptorException, DependencyCollectionException, DependencyResolutionException { if (Strings.isNullOrEmpty(groupArtifactVersion)) return Lists.newArrayList(); Artifact artifact = new DefaultArtifact(groupArtifactVersion); return OrienteerClassLoaderUtil.resolveAndGetArtifactDependencies(artifact); }
Example #16
Source File: RemotePluginLoader.java From digdag with Apache License 2.0 | 5 votes |
private List<ArtifactResult> resolveArtifacts(List<RemoteRepository> repositories, String dep) { DependencyRequest depRequest = buildDependencyRequest(repositories, dep, JavaScopes.RUNTIME); try { return system.resolveDependencies(session, depRequest).getArtifactResults(); } catch (DependencyResolutionException ex) { throw Throwables.propagate(ex); } }
Example #17
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 #18
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 #19
Source File: AbstractScanMojo.java From LicenseScout with Apache License 2.0 | 5 votes |
/** * @return the scan location */ public final ScanLocation getScanLocation() { if (scanDirectory != null) { return new ScanLocation(scanDirectory); } else if (scanArtifacts != null) { try { List<File> scanFiles = ArtifactHelper.getDependencies(this, scanArtifacts, scanArtifactScope); return new ScanLocation(scanFiles); } catch (DependencyResolutionException e) { throw new IllegalStateException(e); } } else { return null; } }
Example #20
Source File: ArtifactHelperTest.java From LicenseScout with Apache License 2.0 | 5 votes |
private List<File> callGetDependencies(ArtifactItem artifactItem, final ArtifactScope artifactScope) throws DependencyResolutionException { final IRepositoryParameters repositoryParameters = createRepositoryParameters(); final List<File> resultFiles = ArtifactHelper.getDependencies(repositoryParameters, Arrays.asList(artifactItem), artifactScope); return resultFiles; }
Example #21
Source File: ArtifactHelperTest.java From LicenseScout with Apache License 2.0 | 5 votes |
/** * @param artifactItem * @param scope * @param expectedDependencyCount * @throws DependencyResolutionException */ private void assertGetDependencies(final ArtifactItem artifactItem, final ArtifactScope scope, final int expectedDependencyCount) throws DependencyResolutionException { final List<File> resultFiles = callGetDependencies(artifactItem, scope); Assert.assertNotNull("result list of ependencies existing", resultFiles); Assert.assertEquals("result list of dependencies size", expectedDependencyCount, resultFiles.size()); }
Example #22
Source File: MavenDependencyResolver.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
public List<com.baidu.formula.launcher.model.Dependency> getArtifactsDependencies( MavenProject project, String scope) throws DependencyCollectionException, DependencyResolutionException { DefaultArtifact pomArtifact = new DefaultArtifact(project.getId()); List<RemoteRepository> remoteRepos = project.getRemoteProjectRepositories(); List<Dependency> ret = new ArrayList<Dependency>(); Dependency dependency = new Dependency(pomArtifact, scope); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); collectRequest.setRepositories(remoteRepos); DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot(); DependencyRequest projectDependencyRequest = new DependencyRequest(node, null); repositorySystem.resolveDependencies(session, projectDependencyRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept(nlg); ret.addAll(nlg.getDependencies(true)); return ret.stream().map(d -> { com.baidu.formula.launcher.model.Dependency dep = new com.baidu.formula.launcher.model.Dependency(); dep.setArtifactId(d.getArtifact().getArtifactId()); dep.setGroupId(d.getArtifact().getGroupId()); dep.setVersion(d.getArtifact().getVersion()); return dep; }).collect(Collectors.toList()); }
Example #23
Source File: DependencyGraphBuilder.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
private DependencyNode resolveCompileTimeDependencies( List<DependencyNode> dependencyNodes, DefaultRepositorySystemSession session) throws DependencyResolutionException { ImmutableList.Builder<Dependency> dependenciesBuilder = ImmutableList.builder(); for (DependencyNode dependencyNode : dependencyNodes) { Dependency dependency = dependencyNode.getDependency(); if (dependency == null) { // Root DependencyNode has null dependency field. dependenciesBuilder.add(new Dependency(dependencyNode.getArtifact(), "compile")); } else { // The dependency field carries exclusions dependenciesBuilder.add(dependency.setScope("compile")); } } ImmutableList<Dependency> dependencyList = dependenciesBuilder.build(); if (localRepository != null) { LocalRepository local = new LocalRepository(localRepository.toAbsolutePath().toString()); session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, local)); } CollectRequest collectRequest = new CollectRequest(); if (dependencyList.size() == 1) { // With setRoot, the result includes dependencies with `optional:true` or `provided` collectRequest.setRoot(dependencyList.get(0)); } else { collectRequest.setDependencies(dependencyList); } for (RemoteRepository repository : repositories) { collectRequest.addRepository(repository); } DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setCollectRequest(collectRequest); // resolveDependencies equals to calling both collectDependencies (build dependency tree) and // resolveArtifacts (download JAR files). DependencyResult dependencyResult = system.resolveDependencies(session, dependencyRequest); return dependencyResult.getRoot(); }
Example #24
Source File: AbstractReportMojo.java From LicenseScout with Apache License 2.0 | 5 votes |
/** * @return the scan location */ public final ScanLocation getScanLocation() { if (scanDirectory != null) { return new ScanLocation(scanDirectory); } else if (scanArtifacts != null) { try { List<File> scanFiles = ArtifactHelper.getDependencies(this, scanArtifacts, scanArtifactScope); return new ScanLocation(scanFiles); } catch (DependencyResolutionException e) { throw new IllegalStateException(e); } } else { return null; } }
Example #25
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
public DependencyResult resolveDependencies(Artifact artifact, List<Dependency> deps, List<RemoteRepository> mainRepos) throws BootstrapMavenException { final CollectRequest request = newCollectRequest(artifact, mainRepos); request.setDependencies(deps); try { return repoSystem.resolveDependencies(repoSession, new DependencyRequest().setCollectRequest(request)); } catch (DependencyResolutionException e) { throw new BootstrapMavenException("Failed to resolve dependencies for " + artifact, e); } }
Example #26
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
public DependencyResult resolveManagedDependencies(Artifact artifact, List<Dependency> deps, List<Dependency> managedDeps, List<RemoteRepository> mainRepos, String... excludedScopes) throws BootstrapMavenException { try { return repoSystem.resolveDependencies(repoSession, new DependencyRequest().setCollectRequest( newCollectManagedRequest(artifact, deps, managedDeps, mainRepos, excludedScopes))); } catch (DependencyResolutionException e) { throw new BootstrapMavenException("Failed to resolve dependencies for " + artifact, e); } }
Example #27
Source File: PinpointPluginTestSuite.java From pinpoint with Apache License 2.0 | 4 votes |
public PinpointPluginTestSuite(Class<?> testClass) throws InitializationError, ArtifactResolutionException, DependencyResolutionException { this(testClass, true); }
Example #28
Source File: DependencyResolver.java From pinpoint with Apache License 2.0 | 4 votes |
public List<File> resolveArtifactsAndDependencies(String artifactsAsString) throws DependencyResolutionException { List<Artifact> artifactList = getArtifactList(artifactsAsString); return resolveArtifactsAndDependencies(artifactList); }
Example #29
Source File: DependencyResolver.java From start.spring.io with Apache License 2.0 | 4 votes |
private DependencyResult resolveDependencies(DependencyRequest dependencyRequest) throws DependencyResolutionException { DependencyResult resolved = this.repositorySystem.resolveDependencies(this.repositorySystemSession, dependencyRequest); return resolved; }
Example #30
Source File: ArtifactRetriever.java From maven-repository-tools with Eclipse Public License 1.0 | 4 votes |
private List<ArtifactResult> getArtifactResults( List<String> artifactCoordinates, boolean includeProvidedScope, boolean includeTestScope, boolean includeRuntimeScope ) { List<Artifact> artifacts = new ArrayList<Artifact>(); for ( String artifactCoordinate : artifactCoordinates ) { artifacts.add( new DefaultArtifact( artifactCoordinate ) ); } List<ArtifactResult> artifactResults = new ArrayList<ArtifactResult>(); DependencyFilter depFilter = DependencyFilterUtils.classpathFilter( JavaScopes.TEST ); Collection<String> includes = new ArrayList<String>(); // we always include compile scope, not doing that makes no sense includes.add( JavaScopes.COMPILE ); Collection<String> excludes = new ArrayList<String>(); // always exclude system scope since it is machine specific and wont work in 99% of cases excludes.add( JavaScopes.SYSTEM ); if ( includeProvidedScope ) { includes.add( JavaScopes.PROVIDED ); } else { excludes.add( JavaScopes.PROVIDED ); } if ( includeTestScope ) { includes.add( JavaScopes.TEST ); } else { excludes.add( JavaScopes.TEST ); } if ( includeRuntimeScope ) { includes.add( JavaScopes.RUNTIME ); } DependencySelector selector = new AndDependencySelector( new ScopeDependencySelector( includes, excludes ), new OptionalDependencySelector(), new ExclusionDependencySelector() ); session.setDependencySelector( selector ); for ( Artifact artifact : artifacts ) { CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) ); collectRequest.addRepository( sourceRepository ); DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, depFilter ); try { DependencyResult resolvedDependencies = system.resolveDependencies( session, dependencyRequest ); artifactResults.addAll( resolvedDependencies.getArtifactResults() ); for ( ArtifactResult result : resolvedDependencies.getArtifactResults() ) { successfulRetrievals.add( result.toString() ); } } catch ( DependencyResolutionException e ) { String extension = artifact.getExtension(); if ( MavenConstants.packagingUsesJarOnly( extension ) ) { logger.info( "Not reporting as failure due to " + artifact.getExtension() + " extension." ); } else { logger.info( "DependencyResolutionException ", e ); failedRetrievals.add( e.getMessage() ); } } catch ( NullPointerException npe ) { logger.info( "NullPointerException resolving dependencies for " + artifact + ":" + npe ); if ( npe.getMessage() != null ) { failedRetrievals.add( npe.getMessage() ); } else { failedRetrievals.add( "NPE retrieving " + artifact ); } } } return artifactResults; }