org.eclipse.aether.util.artifact.JavaScopes Java Examples
The following examples show how to use
org.eclipse.aether.util.artifact.JavaScopes.
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: Resolver.java From buck with Apache License 2.0 | 6 votes |
private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords) throws RepositoryException { CollectRequest collectRequest = new CollectRequest(); collectRequest.setRequestContext(JavaScopes.RUNTIME); collectRequest.setRepositories(repos); for (Dependency dep : mavenCoords) { collectRequest.addDependency(dep); } DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter); DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest); ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder(); for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) { Artifact node = artifactResult.getArtifact(); knownDeps.put(buildKey(node), node); } return knownDeps.build(); }
Example #2
Source File: DeploymentInjectingDependencyVisitor.java From quarkus with Apache License 2.0 | 6 votes |
private void processPlatformArtifact(DependencyNode node, Path descriptor) throws BootstrapDependencyProcessingException { final Properties rtProps = resolveDescriptor(descriptor); if (rtProps == null) { return; } final String value = rtProps.getProperty(BootstrapConstants.PROP_DEPLOYMENT_ARTIFACT); appBuilder.handleExtensionProperties(rtProps, node.getArtifact().toString()); if (value == null) { return; } Artifact deploymentArtifact = toArtifact(value); if (deploymentArtifact.getVersion() == null || deploymentArtifact.getVersion().isEmpty()) { deploymentArtifact = deploymentArtifact.setVersion(node.getArtifact().getVersion()); } node.setData(QUARKUS_DEPLOYMENT_ARTIFACT, deploymentArtifact); runtimeNodes.add(node); Dependency dependency = new Dependency(node.getArtifact(), JavaScopes.COMPILE); runtimeExtensionDeps.add(dependency); managedDeps.add(new Dependency(deploymentArtifact, JavaScopes.COMPILE)); }
Example #3
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 #4
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 #5
Source File: GenerateMetadataMojo.java From syndesis with Apache License 2.0 | 5 votes |
private void includeDependencies() { List<Artifact> artifacts; if (Boolean.TRUE.equals(listAllArtifacts)) { artifacts = project.getArtifacts().stream() .filter(artifact -> JavaScopes.PROVIDED.equals(artifact.getScope())).map(this::toArtifact) .collect(Collectors.toList()); } else { artifacts = project.getDependencies().stream() .filter(dependency -> JavaScopes.PROVIDED.equals(dependency.getScope())).map(this::toArtifact) .collect(Collectors.toList()); } final Set<String> bomVersionlessArtifacts = artifacts.stream().map(MavenUtils::versionlessKey) .collect(Collectors.toSet()); final List<io.syndesis.common.model.Dependency> jsonDependencies = extensionBuilder.build().getDependencies(); final List<Artifact> jsonFilteredArtifacts = jsonDependencies.stream() .filter(io.syndesis.common.model.Dependency::isMaven).map(io.syndesis.common.model.Dependency::getId) .map(MavenUtils::artifactFromId).filter(a -> !bomVersionlessArtifacts.contains(versionlessKey(a))) .collect(Collectors.toList()); final List<io.syndesis.common.model.Dependency> mavenDependencies = Stream .concat(jsonFilteredArtifacts.stream(), artifacts.stream()).map(MavenUtils::toGav).sorted() .map(io.syndesis.common.model.Dependency::maven).collect(Collectors.toList()); extensionBuilder.dependencies( Stream.concat(mavenDependencies.stream(), jsonDependencies.stream().filter(d -> !d.isMaven())) .collect(Collectors.toList())); }
Example #6
Source File: Resolver.java From buck with Apache License 2.0 | 5 votes |
private List<Dependency> getDependenciesOf(Artifact dep) throws ArtifactDescriptorException { ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(); descriptorRequest.setArtifact(dep); descriptorRequest.setRepositories(repos); descriptorRequest.setRequestContext(JavaScopes.RUNTIME); ArtifactDescriptorResult result = repoSys.readArtifactDescriptor(session, descriptorRequest); return result.getDependencies(); }
Example #7
Source File: MavenAddonDependencyResolver.java From furnace with Eclipse Public License 1.0 | 5 votes |
/** * @param scope the scope to be tested upon * @return <code>true</code> if the scope indicates an exported dependency */ public static boolean isExported(String scope) { String artifactScope = Strings.isNullOrEmpty(scope) ? JavaScopes.COMPILE : scope; switch (artifactScope) { case JavaScopes.COMPILE: case JavaScopes.RUNTIME: return true; case JavaScopes.PROVIDED: default: return false; } }
Example #8
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 #9
Source File: MavenArtifactResolver.java From spring-cloud-deployer with Apache License 2.0 | 5 votes |
/** * Resolve an artifact and return its location in the local repository. Aether performs the normal * Maven resolution process ensuring that the latest update is cached to the local repository. * In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>, * the POM is also resolved and cached. * @param resource the {@link MavenResource} representing the artifact * @return a {@link FileSystemResource} representing the resolved artifact in the local repository * @throws IllegalStateException if the artifact does not exist or the resolution fails */ Resource resolve(MavenResource resource) { Assert.notNull(resource, "MavenResource must not be null"); validateCoordinates(resource); RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository()); ArtifactResult resolvedArtifact; try { List<ArtifactRequest> artifactRequests = new ArrayList<>(2); if (properties.isResolvePom()) { artifactRequests.add(new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); } artifactRequests.add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME)); List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests); resolvedArtifact = results.get(results.size() - 1); } catch (ArtifactResolutionException e) { ChoiceFormat pluralizer = new ChoiceFormat( new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " }); MessageFormat messageFormat = new MessageFormat( "Failed to resolve MavenResource: {0}. Configured remote {1}: {2}"); messageFormat.setFormat(1, pluralizer); String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]"); throw new IllegalStateException( messageFormat.format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e); } return toResource(resolvedArtifact); }
Example #10
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 #11
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 #12
Source File: AetherGraphTraverserTest.java From migration-tooling with Apache License 2.0 | 4 votes |
/** Helper for creating a dependency node */ private DependencyNode dependencyNode(String coordinate) { Dependency dependency = new Dependency(new DefaultArtifact(coordinate), JavaScopes.COMPILE); return new DefaultDependencyNode(dependency); }
Example #13
Source File: GraphSerializerTest.java From migration-tooling with Apache License 2.0 | 4 votes |
/** Helper for creating a dependency node */ private DependencyNode dependencyNode(String coordinate) { Dependency dependency = new Dependency(new DefaultArtifact(coordinate), JavaScopes.COMPILE); return new DefaultDependencyNode(dependency); }
Example #14
Source File: ClasspathQuery.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private static Set<File> getJarFiles(final Collection<String> gavs) { Set<File> jars = new HashSet<>(); for (final String gav : gavs) { Artifact artifact = new DefaultArtifact(gav); DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE)); collectRequest.setRepositories(Booter.newRepositories()); DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter); List<ArtifactResult> artifactResults = null; try { artifactResults = _mavenRepositorySystem.resolveDependencies(_mavenRepositorySession, dependencyRequest) .getArtifactResults(); } catch (DependencyResolutionException e) { throw new RuntimeException(String.format("Error while dependency resolution for '%s'", gav), e); } if (artifactResults == null) { throw new RuntimeException(String.format("Could not resolve dependency for '%s'", gav)); } for (ArtifactResult artifactResult : artifactResults) { System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile()); } jars.addAll(artifactResults.stream() .map(result -> result.getArtifact().getFile()) .collect(Collectors.toSet())); } return jars; }
Example #15
Source File: ArtifactResolver.java From migration-tooling with Apache License 2.0 | 4 votes |
private List<Dependency> createDirectDependencyList(List<String> artifactCoords) { Function<String, Dependency> coordinateToDependencyNode = a -> new Dependency(new DefaultArtifact(a), JavaScopes.COMPILE); return artifactCoords.stream().map(coordinateToDependencyNode).collect(toList()); }
Example #16
Source File: Aether.java From migration-tooling with Apache License 2.0 | 4 votes |
DependencyRequest createDependencyRequest(CollectRequest collectRequest) { DependencyFilter compileFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); return createDependencyRequest(collectRequest, compileFilter); }
Example #17
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; }
Example #18
Source File: DevMojo.java From quarkus with Apache License 2.0 | 4 votes |
private void addQuarkusDevModeDeps(StringBuilder classPathManifest) throws MojoExecutionException, DependencyResolutionException { final String pomPropsPath = "META-INF/maven/io.quarkus/quarkus-core-deployment/pom.properties"; final InputStream devModePomPropsIs = DevModeMain.class.getClassLoader().getResourceAsStream(pomPropsPath); if (devModePomPropsIs == null) { throw new MojoExecutionException("Failed to locate " + pomPropsPath + " on the classpath"); } final Properties devModeProps = new Properties(); try (InputStream is = devModePomPropsIs) { devModeProps.load(is); } catch (IOException e) { throw new MojoExecutionException("Failed to load " + pomPropsPath + " from the classpath", e); } final String devModeGroupId = devModeProps.getProperty("groupId"); if (devModeGroupId == null) { throw new MojoExecutionException("Classpath resource " + pomPropsPath + " is missing groupId"); } final String devModeArtifactId = devModeProps.getProperty("artifactId"); if (devModeArtifactId == null) { throw new MojoExecutionException("Classpath resource " + pomPropsPath + " is missing artifactId"); } final String devModeVersion = devModeProps.getProperty("version"); if (devModeVersion == null) { throw new MojoExecutionException("Classpath resource " + pomPropsPath + " is missing version"); } final DefaultArtifact devModeJar = new DefaultArtifact(devModeGroupId, devModeArtifactId, "jar", devModeVersion); final DependencyResult cpRes = repoSystem.resolveDependencies(repoSession, new DependencyRequest() .setCollectRequest( new CollectRequest() .setRoot(new org.eclipse.aether.graph.Dependency(devModeJar, JavaScopes.RUNTIME)) .setRepositories(repos))); for (ArtifactResult appDep : cpRes.getArtifactResults()) { //we only use the launcher for launching from the IDE, we need to exclude it if (!(appDep.getArtifact().getGroupId().equals("io.quarkus") && appDep.getArtifact().getArtifactId().equals("quarkus-ide-launcher"))) { addToClassPaths(classPathManifest, appDep.getArtifact().getFile()); } } }
Example #19
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 4 votes |
private CollectRequest newCollectRequest(Artifact artifact, List<RemoteRepository> mainRepos) throws BootstrapMavenException { return new CollectRequest() .setRoot(new Dependency(artifact, JavaScopes.RUNTIME)) .setRepositories(aggregateRepositories(mainRepos, remoteRepos)); }
Example #20
Source File: Resolver.java From buck with Apache License 2.0 | 4 votes |
private Dependency getDependencyFromString(String artifact) { return new Dependency(new DefaultArtifact(artifact), JavaScopes.RUNTIME); }
Example #21
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; }