private void reportMissingDependencies( String type, ListMultimap<Artifact, DependencyNode> artifactNotFoundMap, ReportEntryType reportEntryType, TestSetStats testSuite) { for (Artifact artifact : sortArtifacts(artifactNotFoundMap.keySet())) { List<DependencyNode> roots = sortDependencyNodes(artifactNotFoundMap.get(artifact)); if (roots.size() == 1) { String msg = "Miss " + artifact + " in " + roots.get(0).getArtifact() + " (path " + findPathToDependency(artifact, roots.get(0)) + ")"; reportTestCase(type, reportEntryType, msg, null, testSuite); } else { String msg = "Miss " + artifact + " in " + roots.size() + " artifacts ..."; StringBuilder dsc = new StringBuilder(); dsc.append("Miss " + artifact + " in ..."); dsc.append(LINE_SEPARATOR).append(LINE_SEPARATOR); for (DependencyNode root : roots) { dsc.append(root.getArtifact() + " (path " + findPathToDependency(artifact, root) + ")"); dsc.append(LINE_SEPARATOR).append(LINE_SEPARATOR); } reportTestCase(type, reportEntryType, msg, dsc.toString(), testSuite); } } }
private void assertSequence(List<DependencyNode> actual, String... expected) { assertEquals(actual.toString(), expected.length, actual.size()); for (int i = 0; i < expected.length; i++) { DependencyNode node = actual.get(i); assertEquals( actual.toString(), expected[i], node.getDependency().getArtifact().getArtifactId()); } }
@Test public void testDuplicateSuppression() throws Exception { DependencyNode root = parse("cycles.txt"); PreorderNodeListGenerator visitor = new PreorderNodeListGenerator(); root.accept(visitor); assertSequence(visitor.getNodes(), "a", "b", "c", "d", "e"); }
@Test public void testOrdering() throws Exception { DependencyNode root = parse("simple.txt"); PreorderNodeListGenerator visitor = new PreorderNodeListGenerator(); root.accept(visitor); assertSequence(visitor.getNodes(), "a", "b", "c", "d", "e"); }
@Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { AntClient.getInstance().log("Filtering - " + super.toString() + "...", Project.MSG_DEBUG); for (Filter filter : filters) { if (filter.accept(node, parents)) { return result(true, node.toString()); } } return result(false, node.toString()); }
public boolean visitEnter(DependencyNode node) { if (node.getDependency() != null) { ArtifactRequest request = new ArtifactRequest(node); request.setTrace(trace); requests.add(request); } return true; }
protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException { final List<Artifact> dependencies = new LinkedList<>(); CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos); CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest); final AtomicInteger level = new AtomicInteger(0); DependencyNode node = result.getRoot(); StringWriter writer = new StringWriter(); final PrintWriter strPrint = new PrintWriter(writer); strPrint.println("Dependencies explored for " + artifact + ":"); if (node != null) { node.accept( new DependencyVisitor() { @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 visitLeave(DependencyNode node) { level.decrementAndGet(); return true; } }); } getLog().info(writer.toString()); return dependencies; }
@Override public boolean accept(final DependencyNode node, final List<DependencyNode> parents) { final Dependency dependency = node.getDependency(); if (dependency == null) { return false; } final String scope = dependency.getScope(); final boolean accept = !("test".equals(scope)); if (!accept) { DependencyFlagger.INSTANCE.flag(node); } return accept; }
List<URL> createMavenGavRecursiveURLs(String artifactGav, String... excludes) throws MalformedURLException, DependencyCollectionException, DependencyResolutionException { Artifact artifact = new DefaultArtifact(artifactGav); if (artifact.getVersion() == null) { throw new IllegalArgumentException("Null version"); } VersionScheme versionScheme = new GenericVersionScheme(); try { versionScheme.parseVersion(artifact.getVersion()); } catch (InvalidVersionSpecificationException e) { throw new IllegalArgumentException(e); } try { versionScheme.parseVersionRange(artifact.getVersion()); throw new IllegalArgumentException( artifact.getVersion() + " is a version range. A specific version is needed"); } catch (InvalidVersionSpecificationException expected) { } RepositorySystemSession session = newRepositorySystemSession(); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); for (RemoteRepository remoteRepo : remoteRepositories) { artifactRequest.addRepository(remoteRepo); } ArtifactResult artifactResult; try { artifactResult = REPOSITORY_SYSTEM.resolveArtifact(session, artifactRequest); } catch (ArtifactResolutionException e) { throw new RuntimeException(e); } List<URL> urls = new ArrayList<>(); urls.add(artifactToUrl(artifactResult.getArtifact())); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(artifact, "compile")); for (RemoteRepository remoteRepo : remoteRepositories) { collectRequest.addRepository(remoteRepo); } DependencyNode node = REPOSITORY_SYSTEM.collectDependencies(session, collectRequest).getRoot(); DependencyFilter filter = new ExclusionsDependencyFilter(Arrays.asList(excludes)); DependencyRequest dependencyRequest = new DependencyRequest(node, filter); REPOSITORY_SYSTEM.resolveDependencies(session, dependencyRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept(nlg); for (Artifact cur : nlg.getArtifacts(false)) { urls.add(artifactToUrl(cur)); } log.debug("--------------------"); log.debug(nlg.getClassPath()); log.debug("--------------------"); return urls; }
private Set<Artifact> processTransientDependencies(Dependency dependency, boolean sharedLibraries) throws MojoExecutionException { try { final Set<Artifact> artifacts = new LinkedHashSet<Artifact>(); final CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); collectRequest.setRepositories(projectRepos); final DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot(); Collection<String> exclusionPatterns = new ArrayList<String>(); if (dependency.getExclusions() != null && !dependency.getExclusions().isEmpty()) { for (Exclusion exclusion : dependency.getExclusions()) { exclusionPatterns.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId()); } } final DependencyRequest dependencyRequest = new DependencyRequest( node, new AndDependencyFilter( new ExclusionsDependencyFilter(exclusionPatterns), new AndDependencyFilter( new ScopeDependencyFilter( Arrays.asList("compile", "runtime"), Arrays.asList("test")), // Also exclude any optional dependencies new DependencyFilter() { @Override public boolean accept( DependencyNode dependencyNode, List<DependencyNode> dependencyNodes) { return !dependencyNode.getDependency().isOptional(); } }))); repoSystem.resolveDependencies(repoSession, dependencyRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept(nlg); final List<Dependency> dependencies = nlg.getDependencies(false); for (Dependency dep : dependencies) { final org.eclipse.aether.artifact.Artifact depAetherArtifact = dep.getArtifact(); if (isNativeLibrary(sharedLibraries, depAetherArtifact.getExtension())) { final Artifact mavenArtifact = artifactFactory.createDependencyArtifact( depAetherArtifact.getGroupId(), depAetherArtifact.getArtifactId(), VersionRange.createFromVersion(depAetherArtifact.getVersion()), depAetherArtifact.getExtension(), depAetherArtifact.getClassifier(), dep.getScope()); mavenArtifact.setFile(depAetherArtifact.getFile()); artifacts.add(mavenArtifact); } } return artifacts; } catch (Exception e) { throw new MojoExecutionException("Error while processing transient dependencies", e); } }