Refine search
public boolean accept( DependencyNode node, List<DependencyNode> parents ) { Dependency dependency = node.getDependency(); if ( dependency != null ) { org.eclipse.aether.artifact.Artifact a = dependency.getArtifact(); String key = ArtifactUtils.key( a.getGroupId(), a.getArtifactId(), a.getVersion() ); return !keys.contains( key ); } return false; }
CollectRequest collect = new CollectRequest(); collect.setRootArtifact( RepositoryUtils.toArtifact( project.getArtifact() ) ); collect.setRequestContext( "project" ); collect.setRepositories( project.getRemoteProjectRepositories() ); Collection<Exclusion> exclusions = dependency != null ? dependency.getExclusions() : null; org.eclipse.aether.graph.Dependency dep = RepositoryUtils.toDependency( artifact, exclusions ); if ( !JavaScopes.SYSTEM.equals( dep.getScope() ) && dep.getArtifact().getFile() != null ) org.eclipse.aether.artifact.Artifact art = dep.getArtifact(); art = art.setFile( null ).setVersion( art.getBaseVersion() ); dep = dep.setArtifact( art ); for ( DependencyNode child : node.getChildren() ) if ( !child.getRelocations().isEmpty() ) logger.warn( "The artifact " + child.getRelocations().get( 0 ) + " has been relocated to " + child.getDependency().getArtifact() ); node.accept( new GraphLogger( project ) );
@Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { String scope = node.getDependency().getScope(); if (scope != null) { scope = StringUtils.toLowerCase(scope); if ("provided".equals(scope)) { return false; } if ("test".equals(scope)) { return false; } if ("system".equals(scope)) { return false; } } if (accept(node.getArtifact())) { return false; } for (DependencyNode parent : parents) { if (accept(parent.getArtifact())) { return false; } } return true; }
private DependencyNode findPlexusUtils( DependencyNode node ) { Artifact artifact = node.getDependency().getArtifact(); if ( AID.equals( artifact.getArtifactId() ) && GID.equals( artifact.getGroupId() ) && EXT.equals( artifact.getExtension() ) && "".equals( artifact.getClassifier() ) ) { return node; } for ( DependencyNode child : node.getChildren() ) { DependencyNode result = findPlexusUtils( child ); if ( result != null ) { return result; } } return null; }
public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { if ( findPlexusUtils( node ) == null ) { Artifact pu = new DefaultArtifact( GID, AID, null, EXT, VER ); DefaultDependencyNode child = new DefaultDependencyNode( new Dependency( pu, JavaScopes.RUNTIME ) ); child.setRepositories( node.getRepositories() ); child.setRequestContext( node.getRequestContext() ); node.getChildren().add( child ); } return node; }
continue; Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile"); DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous); if (!dependency2.getArtifact().isSnapshot()) { if (dependency2.getArtifact().getFile() != null) { bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath())); loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader); } else { ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRootArtifact(descriptorResult.getArtifact()); collectRequest.setDependencies(descriptorResult.getDependencies()); collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies()); collectRequest.setRepositories(descriptorResult.getRepositories()); collectResult.getRoot().accept(nlg);
final CollectRequest request = new CollectRequest(); request.setRepositories(this.remoteRepositories); .addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), result.getRoot().accept(gen); .filter(node -> !"system".equals(node.getDependency().getScope())) .map(node -> { final Artifact artifact = node.getArtifact(); return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(),
public static Dependency convertToDependency(ResourceFactory factory, DependencyNode node) { org.eclipse.aether.graph.Dependency artifactDependency = node.getDependency(); Artifact artifact = artifactDependency.getArtifact(); File file = artifact.getFile(); @SuppressWarnings("unchecked") FileResource<?> artifactResource = factory.create(FileResource.class, file); Dependency d = DependencyBuilder.create().setArtifactId(artifact.getArtifactId()) .setGroupId(artifact.getGroupId()).setVersion(artifact.getBaseVersion()) .setPackaging(artifact.getExtension()).setArtifact(artifactResource) .setOptional(artifactDependency.isOptional()) .setClassifier(artifact.getClassifier()) .setScopeType(artifactDependency.getScope()); return d; }
private String formatNode( DependencyNode node ) Artifact a = node.getArtifact(); Dependency d = node.getDependency(); buffer.append( a ); if ( d != null && d.getScope().length() > 0 ) buffer.append( " [" ).append( d.getScope() ); if ( d.isOptional() ) if ( premanaged != null && !premanaged.equals( a.getBaseVersion() ) ) DependencyNode winner = (DependencyNode) node.getData().get( ConflictResolver.NODE_DATA_WINNER ); if ( winner != null && !ArtifactIdUtils.equalsId( a, winner.getArtifact() ) ) Artifact w = winner.getArtifact(); buffer.append( " (conflicts with " ); if ( ArtifactIdUtils.toVersionlessId( a ).equals( ArtifactIdUtils.toVersionlessId( w ) ) ) buffer.append( w.getVersion() );
Artifact toArtifact(final ArtifactResult ar) { if (ar == null) return null; final Artifact artifact = new org.apache.maven.artifact.DefaultArtifact( ar.getArtifact().getGroupId(), ar.getArtifact().getArtifactId(), ar.getArtifact().getVersion(), null, "jar", ar.getArtifact().getClassifier(), null); if (ar.getRequest().getDependencyNode() != null && ar.getRequest().getDependencyNode().getDependency() != null) { artifact.setScope(ar.getRequest().getDependencyNode().getDependency().getScope()); artifact.setOptional(ar.getRequest().getDependencyNode().getDependency().isOptional()); } if (artifact.getScope() == null || artifact.getScope().isEmpty()) artifact.setScope("compile"); artifact.setFile(ar.getArtifact().getFile()); return artifact; }
private static Artifact createMavenArtifact(org.eclipse.aether.graph.DependencyNode dependencyNode) { org.eclipse.aether.artifact.Artifact artifact = dependencyNode.getArtifact(); String scope = null; boolean optional = false; if (dependencyNode.getDependency() != null) { scope = dependencyNode.getDependency().getScope(); optional = dependencyNode.getDependency().isOptional(); } DefaultArtifact mavenArtifact = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), scope, artifact.getProperty("type", artifact.getExtension()), artifact.getClassifier(), null ); mavenArtifact.setOptional(optional); return mavenArtifact; }
private PreorderNodeListGenerator resolveInternal(String spec) throws DependencyCollectionException, DependencyResolutionException { Dependency dependency = new Dependency(new DefaultArtifact(spec), "compile"); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); for (RemoteRepository remote : remoteRepositories) { collectRequest.addRepository(remote); } DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot(); DependencyRequest dependencyRequest = new DependencyRequest(); dependencyRequest.setRoot( node ); repositorySystem.resolveDependencies(session, dependencyRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept(nlg); return nlg; }
public List<DependencyDescriptor> getArtifactDependecies( String artifactName ) { Artifact artifact = new DefaultArtifact( artifactName ); CollectRequest collectRequest = new CollectRequest(); Dependency root = new Dependency( artifact, "" ); collectRequest.setRoot( root ); for ( RemoteRepository repo : remoteRepositoriesForRequest ) { collectRequest.addRepository( repo ); } CollectResult collectResult; try { collectResult = aether.getSystem().collectDependencies( aether.getSession(), collectRequest ); } catch ( DependencyCollectionException e ) { throw new RuntimeException( e ); } CollectDependencyVisitor visitor = new CollectDependencyVisitor(); collectResult.getRoot().accept( visitor ); List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>(); for ( DependencyNode node : visitor.getDependencies() ) { // skip root to not add artifact as dependency if ( node.getDependency().equals( root ) ) { continue; } descriptors.add( new DependencyDescriptor( node.getDependency().getArtifact() ) ); } return descriptors; }
public static void main( String[] args ) throws Exception { System.out.println( "------------------------------------------------------------" ); System.out.println( GetDependencyTree.class.getSimpleName() ); RepositorySystem system = Booter.newRepositorySystem(); RepositorySystemSession session = Booter.newRepositorySystemSession( system ); Artifact artifact = new DefaultArtifact( "org.apache.maven:maven-aether-provider:3.1.0" ); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, "" ) ); collectRequest.setRepositories( Booter.newRepositories( system, session ) ); CollectResult collectResult = system.collectDependencies( session, collectRequest ); collectResult.getRoot().accept( new ConsoleDependencyGraphDumper() ); }
public List<File> createMavenGavRecursiveFiles(String artifactGav, String... excludes) throws MalformedURLException, DependencyCollectionException, DependencyResolutionException { Artifact artifact = new DefaultArtifact(artifactGav); if (artifact.getVersion() == null) { throw new IllegalArgumentException("Null version"); versionScheme.parseVersion(artifact.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new IllegalArgumentException(e); versionScheme.parseVersionRange(artifact.getVersion()); throw new IllegalArgumentException(artifact.getVersion() + " is a version range. A specific version is needed"); } catch (InvalidVersionSpecificationException expected) { urls.add(artifactResult.getArtifact().getFile()); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, "compile")); for (RemoteRepository remoteRepo : remoteRepositories) { collectRequest.addRepository(remoteRepo); node.accept(nlg); for (Artifact cur : nlg.getArtifacts(false)) { urls.add(cur.getFile());
/** * Gets the files of resolved artifacts seen during the graph traversal. * * @return The list of artifact files, never {@code null}. */ public List<File> getFiles() { List<File> files = new ArrayList<File>( getNodes().size() ); for ( DependencyNode node : getNodes() ) { if ( node.getDependency() != null ) { File file = node.getDependency().getArtifact().getFile(); if ( file != null ) { files.add( file ); } } } return files; }
pluginSession.setDependencyGraphTransformer( transformer ); CollectRequest request = new CollectRequest(); request.setRequestContext( REPOSITORY_CONTEXT ); request.setRepositories( repositories ); request.setRoot( new org.eclipse.aether.graph.Dependency( pluginArtifact, null ) ); for ( Dependency dependency : plugin.getDependencies() ) if ( !JavaScopes.SYSTEM.equals( pluginDep.getScope() ) ) pluginDep = pluginDep.setScope( JavaScopes.RUNTIME ); request.addDependency( pluginDep ); node.accept( new GraphLogger() );
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())); }
private void processDependencyNode(DependencyNode dependencyNode) { Artifact artifact = dependencyNode.getArtifact(); if (!aetherPlugin.getVersionMap().containsKey(artifact.getGroupId())) aetherPlugin.getVersionMap().put(artifact.getGroupId(), new HashMap<>()); aetherPlugin.getVersionMap().get(artifact.getGroupId()).put(artifact.getArtifactId(), artifact.getVersion()); for (DependencyNode node : dependencyNode.getChildren()) { processDependencyNode(node); } } }
org.eclipse.aether.graph.Dependency dep = node.getDependency(); if ( dep != null ) org.eclipse.aether.artifact.Artifact art = dep.getArtifact(); buffer.append( ':' ).append( dep.getScope() ); if ( ( node.getManagedBits() & DependencyNode.MANAGED_SCOPE ) == DependencyNode.MANAGED_SCOPE ) if ( ( node.getManagedBits() & DependencyNode.MANAGED_VERSION ) == DependencyNode.MANAGED_VERSION ) if ( ( node.getManagedBits() & DependencyNode.MANAGED_OPTIONAL ) == DependencyNode.MANAGED_OPTIONAL ) if ( ( node.getManagedBits() & DependencyNode.MANAGED_EXCLUSIONS ) == DependencyNode.MANAGED_EXCLUSIONS ) if ( ( node.getManagedBits() & DependencyNode.MANAGED_PROPERTIES ) == DependencyNode.MANAGED_PROPERTIES ) if ( dep.isOptional() )