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; }
/** * Parses exclusion parameter and build {@link Exclusion} object. * * @param exclusionString string representation of exclusion parameter * @return Exclusion object */ public static Exclusion createExclusion(String exclusionString) { String[] parts = exclusionString.split(":"); String artifactId = "*"; String classifier = "*"; String extension = "*"; int len = parts.length; if (len > 1) { artifactId = parts[1]; } if (len > 2) { classifier = parts[2]; } if (len > 3) { extension = parts[3]; } // length of parts should be greater than 0 String groupId = parts[0]; return new Exclusion(groupId, artifactId, classifier, extension); }
public boolean visitEnter( DependencyNode node ) { StringBuilder buffer = new StringBuilder( 128 ); buffer.append( indent ); org.eclipse.aether.graph.Dependency dep = node.getDependency(); if ( dep != null ) { Artifact art = dep.getArtifact(); buffer.append( art ); buffer.append( ':' ).append( dep.getScope() ); } logger.debug( buffer.toString() ); indent += " "; return true; }
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() )
private static org.apache.maven.artifact.Artifact toArtifact( Dependency dependency ) { if ( dependency == null ) { return null; } org.apache.maven.artifact.Artifact result = toArtifact( dependency.getArtifact() ); result.setScope( dependency.getScope() ); result.setOptional( dependency.isOptional() ); return result; }
@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 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; }
/** * Parses dependency parameter and build {@link Dependency} object. * * @param dependency string representation of dependency parameter * @return Dependency object */ public static Dependency parseDependency(String dependency) { List<String> dependencyAndExclusions = Arrays.asList(dependency.split("\\^")); Collection<Exclusion> exclusions = new ArrayList<>(); for (int idx = 1 ; idx < dependencyAndExclusions.size() ; idx++) { exclusions.add(AetherUtils.createExclusion(dependencyAndExclusions.get(idx))); } Artifact artifact = new DefaultArtifact(dependencyAndExclusions.get(0)); return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions); }
public boolean selectDependency( Dependency dependency ) { return !coreArtifact || !isWagonProvider( dependency.getArtifact() ); }
public static void toArtifacts( Collection<org.apache.maven.artifact.Artifact> artifacts, Collection<? extends DependencyNode> nodes, List<String> trail, DependencyFilter filter ) { for ( DependencyNode node : nodes ) { org.apache.maven.artifact.Artifact artifact = toArtifact( node.getDependency() ); List<String> nodeTrail = new ArrayList<>( trail.size() + 1 ); nodeTrail.addAll( trail ); nodeTrail.add( artifact.getId() ); if ( filter == null || filter.accept( node, Collections.<DependencyNode>emptyList() ) ) { artifact.setDependencyTrail( nodeTrail ); artifacts.add( artifact ); } toArtifacts( artifacts, node.getChildren(), nodeTrail, filter ); } }
private void process( DefaultDependencyResolutionResult result, Collection<ArtifactResult> results ) { for ( ArtifactResult ar : results ) { DependencyNode node = ar.getRequest().getDependencyNode(); if ( ar.isResolved() ) { result.addResolvedDependency( node.getDependency() ); } else { result.setResolutionErrors( node.getDependency(), ar.getExceptions() ); } } }
private List<Artifact> resolveExtensionArtifacts( Plugin extensionPlugin, List<RemoteRepository> repositories, RepositorySystemSession session ) throws PluginResolutionException { DependencyNode root = pluginDependenciesResolver.resolve( extensionPlugin, null, null, repositories, session ); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); root.accept( nlg ); return toMavenArtifacts( root, nlg ); }
public static Dependency toDependency( org.apache.maven.artifact.Artifact artifact, Collection<org.apache.maven.model.Exclusion> exclusions ) { if ( artifact == null ) { return null; } Artifact result = toArtifact( artifact ); List<Exclusion> excl = null; if ( exclusions != null ) { excl = new ArrayList<>( exclusions.size() ); for ( org.apache.maven.model.Exclusion exclusion : exclusions ) { excl.add( toExclusion( exclusion ) ); } } return new Dependency( result, artifact.getScope(), artifact.isOptional(), excl ); }
public DependencySelector deriveChildSelector( DependencyCollectionContext context ) { if ( coreArtifact || !isLegacyCoreArtifact( context.getDependency().getArtifact() ) ) { return this; } else { return new WagonExcluder( true ); } }
private List<Artifact> resolveExtension( CoreExtension extension, RepositorySystemSession repoSession, List<RemoteRepository> repositories, DependencyFilter dependencyFilter ) throws PluginResolutionException { Plugin plugin = new Plugin(); plugin.setGroupId( extension.getGroupId() ); plugin.setArtifactId( extension.getArtifactId() ); plugin.setVersion( extension.getVersion() ); DependencyNode root = pluginDependenciesResolver.resolveCoreExtension( plugin, dependencyFilter, repositories, repoSession ); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); root.accept( nlg ); List<Artifact> artifacts = nlg.getArtifacts( false ); return artifacts; } }
private Exclusion convert( org.apache.maven.model.Exclusion exclusion ) { return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" ); }
private boolean areAllDependenciesInReactor( Collection<MavenProject> projects, Collection<Dependency> dependencies ) { Set<String> projectKeys = getReactorProjectKeys( projects ); for ( Dependency dependency : dependencies ) { org.eclipse.aether.artifact.Artifact a = dependency.getArtifact(); String key = ArtifactUtils.key( a.getGroupId(), a.getArtifactId(), a.getVersion() ); if ( !projectKeys.contains( key ) ) { return false; } } return true; }
private static Exclusion toExclusion( org.apache.maven.model.Exclusion exclusion ) { return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" ); }
/** * Finds a Maven-based plugin JAR with its "direct" dependencies. * * @see <a href="https://github.com/eclipse/aether-demo/blob/322fa556494335faaf3ad3b7dbe8f89aaaf6222d/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/GetDirectDependencies.java">aether-demo's GetDirectDependencies.java</a> */ public final MavenPluginPaths findMavenPluginJarsWithDirectDependencies( final String groupId, final String artifactId, final String classifier, final String version) throws MavenArtifactNotFoundException { final ArtifactDescriptorResult result; try { result = this.describeMavenArtifact(groupId, artifactId, classifier, "jar", version); } catch (ArtifactDescriptorException ex) { throw new MavenArtifactNotFoundException(groupId, artifactId, classifier, version, this.givenLocalMavenRepositoryPath, this.absoluteLocalMavenRepositoryPath, ex); } final ArrayList<Path> dependencyPaths = new ArrayList<>(); for (final Dependency dependency : result.getDependencies()) { final Path dependencyPath = this.findMavenArtifact(dependency.getArtifact()); dependencyPaths.add(dependencyPath); } final Path artifactPath = this.findMavenArtifact(result.getArtifact()); return MavenPluginPaths.of(artifactPath, dependencyPaths); }