org.eclipse.aether.collection.DependencyCollectionException Java Examples
The following examples show how to use
org.eclipse.aether.collection.DependencyCollectionException.
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: DependencyDownloader.java From go-offline-maven-plugin with Apache License 2.0 | 6 votes |
/** * Download a plugin, all of its transitive dependencies and dependencies declared on the plugin declaration. * <p> * Dependencies and plugin artifacts that refer to an artifact in the current reactor build are ignored. * Transitive dependencies that are marked as optional are ignored * Transitive dependencies with the scopes "test", "system" and "provided" are ignored. * * @param plugin the plugin to download */ public Set<ArtifactWithRepoType> resolvePlugin(Plugin plugin) { Artifact pluginArtifact = toArtifact(plugin); Dependency pluginDependency = new Dependency(pluginArtifact, null); CollectRequest collectRequest = new CollectRequest(pluginDependency, pluginRepositories); collectRequest.setRequestContext(RepositoryType.PLUGIN.getRequestContext()); List<Dependency> pluginDependencies = new ArrayList<>(); for (org.apache.maven.model.Dependency d : plugin.getDependencies()) { Dependency dependency = RepositoryUtils.toDependency(d, typeRegistry); pluginDependencies.add(dependency); } collectRequest.setDependencies(pluginDependencies); try { CollectResult collectResult = repositorySystem.collectDependencies(pluginSession, collectRequest); return getArtifactsFromCollectResult(collectResult, RepositoryType.PLUGIN); } catch (DependencyCollectionException | RuntimeException e) { log.error("Error resolving plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId()); handleRepositoryException(e); } return Collections.emptySet(); }
Example #2
Source File: BazelDeps.java From bazel-deps with MIT License | 6 votes |
public void doMain(String[] args) throws DependencyCollectionException, CmdLineException { CmdLineParser parser = new CmdLineParser(this); parser.parseArgument(args); if (artifactNames.isEmpty()) { System.out.print("Usage: java -jar bazel-deps-1.0-SNAPSHOT"); parser.printSingleLineUsage(System.out); System.out.println(); parser.printUsage(System.out); System.out.println( "\nExample: java -jar bazel-deps-1.0-SNAPSHOT com.fasterxml.jackson.core:jackson-databind:2.5.0"); System.exit(1); } System.err.println("Fetching dependencies from maven...\n"); Map<Artifact, Set<Artifact>> dependencies = fetchDependencies(artifactNames); Set<Artifact> excludeDependencies = excludeArtifact != null ? Maven.transitiveDependencies(new DefaultArtifact(excludeArtifact)) : ImmutableSet.of(); printWorkspace(dependencies, excludeDependencies); printBuildEntries(dependencies, excludeDependencies); }
Example #3
Source File: Maven.java From bazel-deps with MIT License | 6 votes |
public static Set<Artifact> transitiveDependencies(Artifact artifact) { RepositorySystem system = newRepositorySystem(); RepositorySystemSession session = newRepositorySystemSession(system); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, "")); collectRequest.setRepositories(repositories()); CollectResult collectResult = null; try { collectResult = system.collectDependencies(session, collectRequest); } catch (DependencyCollectionException e) { throw new RuntimeException(e); } PreorderNodeListGenerator visitor = new PreorderNodeListGenerator(); collectResult.getRoot().accept(visitor); return ImmutableSet.copyOf( visitor.getNodes().stream() .filter(d -> !d.getDependency().isOptional()) .map(DependencyNode::getArtifact) .collect(Collectors.toList())); }
Example #4
Source File: NbRepositorySystem.java From netbeans with Apache License 2.0 | 6 votes |
@Override public CollectResult collectDependencies(RepositorySystemSession session, CollectRequest request) throws DependencyCollectionException { DefaultRepositorySystemSession cloned = new DefaultRepositorySystemSession(session); DependencyGraphTransformer transformer = session.getDependencyGraphTransformer(); //need to reset the transformer to prevent the transformation to happen and to it below separately. cloned.setDependencyGraphTransformer(null); CollectResult res = super.collectDependencies(cloned, request); CloningDependencyVisitor vis = new CloningDependencyVisitor(); res.getRoot().accept(vis); //this part copied from DefaultDependencyCollector try { DefaultDependencyGraphTransformationContext context = new DefaultDependencyGraphTransformationContext(session); res.setRoot(transformer.transformGraph(res.getRoot(), context)); } catch (RepositoryException e) { res.addException(e); } if (!res.getExceptions().isEmpty()) { throw new DependencyCollectionException(res); } res.getRoot().setData("NB_TEST", vis.getRootNode()); return res; }
Example #5
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
public CollectResult collectManagedDependencies(Artifact artifact, List<Dependency> deps, List<Dependency> managedDeps, List<RemoteRepository> mainRepos, String... excludedScopes) throws BootstrapMavenException { try { return repoSystem.collectDependencies(repoSession, newCollectManagedRequest(artifact, deps, managedDeps, mainRepos, excludedScopes)); } catch (DependencyCollectionException e) { throw new BootstrapMavenException("Failed to collect dependencies for " + artifact, e); } }
Example #6
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
public CollectResult collectDependencies(Artifact artifact, List<Dependency> deps, List<RemoteRepository> mainRepos) throws BootstrapMavenException { final CollectRequest request = newCollectRequest(artifact, mainRepos); request.setDependencies(deps); try { return repoSystem.collectDependencies(repoSession, request); } catch (DependencyCollectionException e) { throw new BootstrapMavenException("Failed to collect dependencies for " + artifact, e); } }
Example #7
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 #8
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 #9
Source File: ArtemisAbstractPlugin.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException { ArtifactRequest request = new ArtifactRequest(); request.setArtifact(artifact); request.setRepositories(remoteRepos); ArtifactResult result; try { result = repositorySystem.resolveArtifact(repoSession, request); } catch (ArtifactResolutionException e) { throw new MojoExecutionException(e.getMessage(), e); } return result.getArtifact().getFile(); }
Example #10
Source File: DependencyDownloader.java From go-offline-maven-plugin with Apache License 2.0 | 5 votes |
/** * Download a single dependency and all of its transitive dependencies that is needed by the build without appearing in any dependency tree * <p> * Dependencies and plugin artifacts that refer to an artifact in the current reactor build are ignored. * Transitive dependencies that are marked as optional are ignored * Transitive dependencies with the scopes "test", "system" and "provided" are ignored. * * @param dynamicDependency the dependency to download */ public Set<ArtifactWithRepoType> resolveDynamicDependency(DynamicDependency dynamicDependency) { DefaultArtifact artifact = new DefaultArtifact(dynamicDependency.getGroupId(), dynamicDependency.getArtifactId(), dynamicDependency.getClassifier(), "jar", dynamicDependency.getVersion()); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, null)); RepositoryType repositoryType = dynamicDependency.getRepositoryType(); RepositorySystemSession session; switch (repositoryType) { case MAIN: session = remoteSession; collectRequest.setRepositories(remoteRepositories); collectRequest.setRequestContext(repositoryType.getRequestContext()); break; case PLUGIN: session = pluginSession; collectRequest.setRepositories(pluginRepositories); collectRequest.setRequestContext(repositoryType.getRequestContext()); break; default: throw new IllegalStateException("Unknown enum val " + repositoryType); } try { CollectResult collectResult = repositorySystem.collectDependencies(session, collectRequest); return getArtifactsFromCollectResult(collectResult, repositoryType); } catch (DependencyCollectionException | RuntimeException e) { log.error("Error resolving dynamic dependency" + dynamicDependency.getGroupId() + ":" + dynamicDependency.getArtifactId()); handleRepositoryException(e); } return Collections.emptySet(); }
Example #11
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 #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: 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 #14
Source File: Maven3DependencyTreeBuilder.java From archiva with Apache License 2.0 | 5 votes |
private void resolve( ResolveRequest resolveRequest ) { RepositorySystem system = mavenSystemManager.getRepositorySystem(); RepositorySystemSession session = MavenSystemManager.newRepositorySystemSession( resolveRequest.localRepoDir ); org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact( resolveRequest.groupId + ":" + resolveRequest.artifactId + ":" + resolveRequest.version ); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, "" ) ); // add remote repositories for ( RemoteRepository remoteRepository : resolveRequest.remoteRepositories ) { org.eclipse.aether.repository.RemoteRepository repo = new org.eclipse.aether.repository.RemoteRepository.Builder( remoteRepository.getId( ), "default", remoteRepository.getLocation( ).toString() ).build( ); collectRequest.addRepository(repo); } collectRequest.setRequestContext( "project" ); //collectRequest.addRepository( repo ); try { CollectResult collectResult = system.collectDependencies( session, collectRequest ); collectResult.getRoot().accept( resolveRequest.dependencyVisitor ); log.debug("Collected dependency results for resolve"); } catch ( DependencyCollectionException e ) { log.error( "Error while collecting dependencies (resolve): {}", e.getMessage(), e ); } }
Example #15
Source File: BazelDeps.java From bazel-deps with MIT License | 4 votes |
public static void main(String[] args) throws DependencyCollectionException, CmdLineException { new BazelDeps().doMain(args); }
Example #16
Source File: PluginBundleManager.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
private void loadDependencies(String pluginBundleVersion, boolean strictDependencyChecking, Model model, DelegatingClassLoader delegatingClassLoader) throws DependencyCollectionException, InvalidVersionSpecificationException, Exception { if (model.getRepositories() != null) { for (Repository repository : model.getRepositories()) { mavenPluginRepository.addRepository(repository.getId(), "default", repository.getUrl()); } } List<Dependency> dependenciesToResolve = new ArrayList<>(); for (org.apache.maven.model.Dependency dependency2 : model.getDependencies()) { String scope = dependency2.getScope(); if (scope != null && (scope.contentEquals("test"))) { // Skip continue; } Dependency d = new Dependency(new DefaultArtifact(dependency2.getGroupId(), dependency2.getArtifactId(), dependency2.getType(), dependency2.getVersion()), dependency2.getScope()); Set<Exclusion> exclusions = new HashSet<>(); d.setExclusions(exclusions); exclusions.add(new Exclusion("org.opensourcebim", "pluginbase", null, "jar")); exclusions.add(new Exclusion("org.opensourcebim", "shared", null, "jar")); exclusions.add(new Exclusion("org.opensourcebim", "ifcplugins", null, "jar")); dependenciesToResolve.add(d); } CollectRequest collectRequest = new CollectRequest(dependenciesToResolve, null, null); collectRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList()); CollectResult collectDependencies = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); DependencyNode rootDep = collectDependencies.getRoot(); rootDep.accept(nlg); for (Dependency dependency : nlg.getDependencies(true)) { if (dependency.getScope().contentEquals("test")) { continue; } // LOGGER.info(dependency.getArtifact().getGroupId() + "." + dependency.getArtifact().getArtifactId()); Artifact dependencyArtifact = dependency.getArtifact(); PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId()); if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) { if (strictDependencyChecking) { String version = dependencyArtifact.getVersion(); if (!version.contains("[") && !version.contains("(")) { version = "[" + version + "]"; } VersionRange versionRange = VersionRange.createFromVersionSpec(version); // String version = // pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion(); ArtifactVersion artifactVersion = new DefaultArtifactVersion(pluginBundleVersion); if (versionRange.containsVersion(artifactVersion)) { // OK } else { throw new Exception( "Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + pluginBundleVersion + ") does not comply to the required version (" + dependencyArtifact.getVersion() + ")"); } } else { LOGGER.info("Skipping strict dependency checking for dependency " + dependencyArtifact.getArtifactId()); } } else { try { if (dependencyArtifact.getGroupId().contentEquals("com.sun.xml.ws")) { continue; } MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId()); if (dependencyArtifact.getExtension().contentEquals("jar")) { Path depJarFile = mavenPluginLocation.getVersionJar(dependencyArtifact.getVersion()); FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile); jarClassLoaders.add(jarClassLoader); delegatingClassLoader.add(jarClassLoader); } } catch (Exception e) { e.printStackTrace(); throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed"); } } } }
Example #17
Source File: ClassLoaderResolverTest.java From byte-buddy with Apache License 2.0 | 4 votes |
@Test(expected = MojoExecutionException.class) public void testCollectionFailure() throws Exception { when(repositorySystem.collectDependencies(eq(repositorySystemSession), any(CollectRequest.class))) .thenThrow(new DependencyCollectionException(new CollectResult(new CollectRequest()))); classLoaderResolver.resolve(new MavenCoordinate(FOO, BAR, QUX, JAR)); }
Example #18
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); }