@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; }
/** * Logs the paths for each dependency not found * * @param node root {@link DependencyNode}, can be a "null" root (imaginary root) * @param e {@link DependencyResolutionException} the error to collect paths. */ private void logUnresolvedArtifacts(DependencyNode node, DependencyResolutionException e) { List<ArtifactResult> artifactResults = e.getResult().getArtifactResults().stream() .filter(artifactResult -> !artifactResult.getExceptions().isEmpty()).collect(toList()); final List<String> patternInclusion = artifactResults.stream().map(artifactResult -> toId(artifactResult.getRequest().getArtifact())).collect(toList()); PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(new PatternInclusionsDependencyFilter(patternInclusion), node.getArtifact() != null); node.accept(visitor); visitor.getPaths().stream().forEach(path -> { List<DependencyNode> unresolvedArtifactPath = path.stream().filter(dependencyNode -> dependencyNode.getArtifact() != null).collect(toList()); if (!unresolvedArtifactPath.isEmpty()) { logger.warn("Dependency path to not resolved artifacts -> {}", unresolvedArtifactPath.toString()); } }); }
private String formatNode( DependencyNode node ) Artifact a = node.getArtifact(); Dependency d = node.getDependency(); buffer.append( a ); if ( winner != null && !ArtifactIdUtils.equalsId( a, winner.getArtifact() ) ) Artifact w = winner.getArtifact(); buffer.append( " (conflicts with " ); if ( ArtifactIdUtils.toVersionlessId( a ).equals( ArtifactIdUtils.toVersionlessId( w ) ) )
private static DependencyNode generateNode(String groupId, String artifactId, String version) { DependencyNode node = Mockito.mock(DependencyNode.class); Artifact artifact = Mockito.mock(Artifact.class); Mockito.when(node.getArtifact()).thenReturn(artifact); // mock artifact Mockito.when(artifact.getGroupId()).thenReturn(groupId); Mockito.when(artifact.getArtifactId()).thenReturn(artifactId); Mockito.when(artifact.getVersion()).thenReturn(version); return node; }
@Override public boolean visitEnter(DependencyNode node) { for (int i = 0; i < level.get(); i++) { strPrint.print("!..."); } level.incrementAndGet(); strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact()); dependencies.add(node.getArtifact()); return true; }
@Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { return node.getArtifact().getArtifactId().equals(artifactId) && node.getArtifact().getGroupId().equals(groupId); } });
private static URL getURL(DependencyNode dependencyNode) { File f = dependencyNode.getArtifact().getFile(); URL url = null; try { url = f.toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); return null; } return url; }
@Override public boolean accept(final DependencyNode node, final List<DependencyNode> parents) { return classifier.equals(node.getArtifact().getClassifier()); }
@Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { if (accept(node.getArtifact())) { return false; } for (DependencyNode parent : parents) { if (accept(parent.getArtifact())) { return false; } } return true; }
ConflictItem( DependencyNode parent, DependencyNode node, String scope, boolean optional ) { if ( parent != null ) { this.parent = parent.getChildren(); this.artifact = parent.getArtifact(); } else { this.parent = null; this.artifact = null; } this.node = node; this.scopes = scope; this.optionalities = optional ? OPTIONAL_TRUE : OPTIONAL_FALSE; }
ConflictItem( DependencyNode parent, DependencyNode node, String scope, boolean optional ) { if ( parent != null ) { this.parent = parent.getChildren(); this.artifact = parent.getArtifact(); } else { this.parent = null; this.artifact = null; } this.node = node; this.scopes = scope; this.optionalities = optional ? OPTIONAL_TRUE : OPTIONAL_FALSE; }
private static NodeResolution determineResolution(org.eclipse.aether.graph.DependencyNode dependencyNode) { org.eclipse.aether.graph.DependencyNode winner = (org.eclipse.aether.graph.DependencyNode) dependencyNode.getData().get(ConflictResolver.NODE_DATA_WINNER); if (winner != null) { if (winner.getArtifact().getVersion().equals(dependencyNode.getArtifact().getVersion())) { return OMITTED_FOR_DUPLICATE; } return OMITTED_FOR_CONFLICT; } return INCLUDED; }
/** * Convenience function for determining if the 2 specified dependency * nodes' artifacts match (i.e. if their group and artifact ids match) * * @param nodeA {@link org.eclipse.aether.graph.DependencyNode dependency node} to match against * @param nodeB {@link org.eclipse.aether.graph.DependencyNode dependency node} to match against * @return {@code true} if the groupId and artifactId of the provided DependencyNode objects match, {@code false} otherwise. * @since 3.5.2 */ private boolean nodeArtifactsMatch (org.eclipse.aether.graph.DependencyNode nodeA, org.eclipse.aether.graph.DependencyNode nodeB) { if (nodeA == null || nodeB == null) { return false; } return nodeA.getArtifact().getGroupId ().equals(nodeB.getArtifact().getGroupId()) && nodeA.getArtifact().getArtifactId ().equals(nodeB.getArtifact().getArtifactId()); }
private static String determineEffectiveVersion(org.eclipse.aether.graph.DependencyNode dependencyNode) { org.eclipse.aether.graph.DependencyNode winner = (org.eclipse.aether.graph.DependencyNode) dependencyNode.getData().get(ConflictResolver.NODE_DATA_WINNER); if (winner != null) { return winner.getArtifact().getVersion(); } return dependencyNode.getArtifact().getVersion(); } }
/** * Gets the set strings of the form "<groupId>:<artifactId>" representing the specified nodes direct dependencies (immediate children). * * @param rootNode {@link org.eclipse.aether.graph.DependencyNode root node} of the tree to fetch the direct dependencies from. * @return {@link HashSet<String>} of the form "<groupId>:<artifactId>" containing all direct dependencies of the parameter specified by rootNode. * @since 3.5.3 */ protected HashSet<String> getDirectDepsSet(org.eclipse.aether.graph.DependencyNode rootNode) { HashSet<String> directDepsSet = new HashSet<String> (); List <org.eclipse.aether.graph.DependencyNode> directDepsList = rootNode.getChildren(); ListIterator <org.eclipse.aether.graph.DependencyNode> iter = directDepsList.listIterator(); // Accumulate set that represents the collection of direct deps while(iter.hasNext()){ org.eclipse.aether.artifact.Artifact art = iter.next().getArtifact(); directDepsSet.add(createArtifactString(art)); } return directDepsSet; }
@Override public boolean accept(DependencyNode dependencyNode, List<DependencyNode> list) { Dependency dependency = dependencyNode.getDependency(); if (dependency == null) { return false; } if (allowedScopes != null && !allowedScopes.contains(dependency.getScope())) { return false; } Artifact artifact = dependencyNode.getArtifact(); String extension = artifact.getExtension(); return allowedTypes != null && allowedTypes.contains(extension); } });
public static DependencyId newInstance(DependencyNode node) { Dependency dependency = node.getDependency(); return (dependency != null) ? newInstance(dependency) : newInstance(node.getArtifact()); }
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); } } }
DefaultDependencyCycle( NodeStack nodes, int cycleEntry, Dependency dependency ) { // skip root node unless it actually has a dependency or is considered the cycle entry (due to its label) int offset = ( cycleEntry > 0 && nodes.get( 0 ).getDependency() == null ) ? 1 : 0; Dependency[] dependencies = new Dependency[nodes.size() - offset + 1]; for ( int i = 0, n = dependencies.length - 1; i < n; i++ ) { DependencyNode node = nodes.get( i + offset ); dependencies[i] = node.getDependency(); // when cycle starts at root artifact as opposed to root dependency, synthesize a dependency if ( dependencies[i] == null ) { dependencies[i] = new Dependency( node.getArtifact(), null ); } } dependencies[dependencies.length - 1] = dependency; this.dependencies = Collections.unmodifiableList( Arrays.asList( dependencies ) ); this.cycleEntry = cycleEntry; }
public DefaultDependencyCycle( NodeStack nodes, int cycleEntry, Dependency dependency ) { // skip root node unless it actually has a dependency or is considered the cycle entry (due to its label) int offset = ( cycleEntry > 0 && nodes.get( 0 ).getDependency() == null ) ? 1 : 0; Dependency[] dependencies = new Dependency[nodes.size() - offset + 1]; for ( int i = 0, n = dependencies.length - 1; i < n; i++ ) { DependencyNode node = nodes.get( i + offset ); dependencies[i] = node.getDependency(); // when cycle starts at root artifact as opposed to root dependency, synthesize a dependency if ( dependencies[i] == null ) { dependencies[i] = new Dependency( node.getArtifact(), null ); } } dependencies[dependencies.length - 1] = dependency; this.dependencies = Collections.unmodifiableList( Arrays.asList( dependencies ) ); this.cycleEntry = cycleEntry; }