@Test public void testAnnotate_dependencyInSpringRepository() throws IOException { DependencyGraphBuilder dependencyGraphBuilder = new DependencyGraphBuilder( ImmutableList.of( "https: ClassPathBuilder classPathBuilderWithSpring = new ClassPathBuilder(dependencyGraphBuilder); ClassPathResult classPathResult = classPathBuilderWithSpring.resolve( ImmutableList.of( new DefaultArtifact("io.projectreactor:reactor-core:3.4.0-M2"), new DefaultArtifact("org.reactivestreams:reactive-streams:0.4.0")), false); ClassPathEntry reactorCore = classPathResult.getClassPath().get(0); LinkageProblem problem = new ClassNotFoundProblem( new ClassFile(reactorCore, "reactor.util.Metrics"), new ClassSymbol("org.reactivestreams.Subscriber")); LinkageProblemCauseAnnotator.annotate( classPathBuilderWithSpring, classPathResult, ImmutableSet.of(problem)); LinkageProblemCause cause = problem.getCause(); assertEquals(DependencyConflict.class, cause.getClass()); DependencyConflict conflict = (DependencyConflict) cause; assertEquals( "org.reactivestreams:reactive-streams:0.4.0", Artifacts.toCoordinates(conflict.getPathToSelectedArtifact().getLeaf())); assertEquals( "org.reactivestreams:reactive-streams:1.0.3", Artifacts.toCoordinates(conflict.getPathToArtifactThruSource().getLeaf())); }
public static void annotate( ClassPathBuilder classPathBuilder, ClassPathResult rootResult, Iterable<LinkageProblem> linkageProblems) throws IOException { checkNotNull(classPathBuilder); checkNotNull(rootResult); checkNotNull(linkageProblems); Map<Artifact, ClassPathResult> cache = new HashMap<>(); for (LinkageProblem linkageProblem : linkageProblems) { ClassFile sourceClass = linkageProblem.getSourceClass(); ClassPathEntry sourceEntry = sourceClass.getClassPathEntry(); Artifact sourceArtifact = sourceEntry.getArtifact(); ClassPathResult subtreeResult = cache.get(sourceArtifact); if (subtreeResult == null) { subtreeResult = classPathBuilder.resolveWithMaven(sourceArtifact); cache.put(sourceArtifact, subtreeResult); } Symbol symbol = linkageProblem.getSymbol(); ClassPathEntry entryInSubtree = subtreeResult.findEntryBySymbol(symbol); if (entryInSubtree == null) { linkageProblem.setCause(UnknownCause.getInstance()); } else { Artifact artifactInSubtree = entryInSubtree.getArtifact(); DependencyPath pathToSourceEntry = rootResult.getDependencyPaths(sourceEntry).get(0); DependencyPath pathFromSourceEntryToUnselectedEntry = subtreeResult.getDependencyPaths(entryInSubtree).get(0); DependencyPath pathToUnselectedEntry = pathToSourceEntry.concat(pathFromSourceEntryToUnselectedEntry); ClassPathEntry selectedEntry = rootResult.findEntryById( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (selectedEntry != null) { Artifact selectedArtifact = selectedEntry.getArtifact(); if (!selectedArtifact.getVersion().equals(artifactInSubtree.getVersion())) { linkageProblem.setCause( new DependencyConflict( linkageProblem, rootResult.getDependencyPaths(selectedEntry).get(0), pathToUnselectedEntry)); } else { linkageProblem.setCause(UnknownCause.getInstance()); } } else { Artifact excludingArtifact = pathToSourceEntry.findExclusion( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (excludingArtifact != null) { linkageProblem.setCause( new ExcludedDependency(pathToUnselectedEntry, excludingArtifact)); } else { linkageProblem.setCause(new MissingDependency(pathToUnselectedEntry)); } } } } }
LinkageProblemCauseAnnotator { public static void annotate( ClassPathBuilder classPathBuilder, ClassPathResult rootResult, Iterable<LinkageProblem> linkageProblems) throws IOException { checkNotNull(classPathBuilder); checkNotNull(rootResult); checkNotNull(linkageProblems); Map<Artifact, ClassPathResult> cache = new HashMap<>(); for (LinkageProblem linkageProblem : linkageProblems) { ClassFile sourceClass = linkageProblem.getSourceClass(); ClassPathEntry sourceEntry = sourceClass.getClassPathEntry(); Artifact sourceArtifact = sourceEntry.getArtifact(); ClassPathResult subtreeResult = cache.get(sourceArtifact); if (subtreeResult == null) { subtreeResult = classPathBuilder.resolveWithMaven(sourceArtifact); cache.put(sourceArtifact, subtreeResult); } Symbol symbol = linkageProblem.getSymbol(); ClassPathEntry entryInSubtree = subtreeResult.findEntryBySymbol(symbol); if (entryInSubtree == null) { linkageProblem.setCause(UnknownCause.getInstance()); } else { Artifact artifactInSubtree = entryInSubtree.getArtifact(); DependencyPath pathToSourceEntry = rootResult.getDependencyPaths(sourceEntry).get(0); DependencyPath pathFromSourceEntryToUnselectedEntry = subtreeResult.getDependencyPaths(entryInSubtree).get(0); DependencyPath pathToUnselectedEntry = pathToSourceEntry.concat(pathFromSourceEntryToUnselectedEntry); ClassPathEntry selectedEntry = rootResult.findEntryById( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (selectedEntry != null) { Artifact selectedArtifact = selectedEntry.getArtifact(); if (!selectedArtifact.getVersion().equals(artifactInSubtree.getVersion())) { linkageProblem.setCause( new DependencyConflict( linkageProblem, rootResult.getDependencyPaths(selectedEntry).get(0), pathToUnselectedEntry)); } else { linkageProblem.setCause(UnknownCause.getInstance()); } } else { Artifact excludingArtifact = pathToSourceEntry.findExclusion( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (excludingArtifact != null) { linkageProblem.setCause( new ExcludedDependency(pathToUnselectedEntry, excludingArtifact)); } else { linkageProblem.setCause(new MissingDependency(pathToUnselectedEntry)); } } } } } }
LinkageProblemCauseAnnotator { public static void annotate( ClassPathBuilder classPathBuilder, ClassPathResult rootResult, Iterable<LinkageProblem> linkageProblems) throws IOException { checkNotNull(classPathBuilder); checkNotNull(rootResult); checkNotNull(linkageProblems); Map<Artifact, ClassPathResult> cache = new HashMap<>(); for (LinkageProblem linkageProblem : linkageProblems) { ClassFile sourceClass = linkageProblem.getSourceClass(); ClassPathEntry sourceEntry = sourceClass.getClassPathEntry(); Artifact sourceArtifact = sourceEntry.getArtifact(); ClassPathResult subtreeResult = cache.get(sourceArtifact); if (subtreeResult == null) { subtreeResult = classPathBuilder.resolveWithMaven(sourceArtifact); cache.put(sourceArtifact, subtreeResult); } Symbol symbol = linkageProblem.getSymbol(); ClassPathEntry entryInSubtree = subtreeResult.findEntryBySymbol(symbol); if (entryInSubtree == null) { linkageProblem.setCause(UnknownCause.getInstance()); } else { Artifact artifactInSubtree = entryInSubtree.getArtifact(); DependencyPath pathToSourceEntry = rootResult.getDependencyPaths(sourceEntry).get(0); DependencyPath pathFromSourceEntryToUnselectedEntry = subtreeResult.getDependencyPaths(entryInSubtree).get(0); DependencyPath pathToUnselectedEntry = pathToSourceEntry.concat(pathFromSourceEntryToUnselectedEntry); ClassPathEntry selectedEntry = rootResult.findEntryById( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (selectedEntry != null) { Artifact selectedArtifact = selectedEntry.getArtifact(); if (!selectedArtifact.getVersion().equals(artifactInSubtree.getVersion())) { linkageProblem.setCause( new DependencyConflict( linkageProblem, rootResult.getDependencyPaths(selectedEntry).get(0), pathToUnselectedEntry)); } else { linkageProblem.setCause(UnknownCause.getInstance()); } } else { Artifact excludingArtifact = pathToSourceEntry.findExclusion( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (excludingArtifact != null) { linkageProblem.setCause( new ExcludedDependency(pathToUnselectedEntry, excludingArtifact)); } else { linkageProblem.setCause(new MissingDependency(pathToUnselectedEntry)); } } } } } private  LinkageProblemCauseAnnotator(); }
LinkageProblemCauseAnnotator { public static void annotate( ClassPathBuilder classPathBuilder, ClassPathResult rootResult, Iterable<LinkageProblem> linkageProblems) throws IOException { checkNotNull(classPathBuilder); checkNotNull(rootResult); checkNotNull(linkageProblems); Map<Artifact, ClassPathResult> cache = new HashMap<>(); for (LinkageProblem linkageProblem : linkageProblems) { ClassFile sourceClass = linkageProblem.getSourceClass(); ClassPathEntry sourceEntry = sourceClass.getClassPathEntry(); Artifact sourceArtifact = sourceEntry.getArtifact(); ClassPathResult subtreeResult = cache.get(sourceArtifact); if (subtreeResult == null) { subtreeResult = classPathBuilder.resolveWithMaven(sourceArtifact); cache.put(sourceArtifact, subtreeResult); } Symbol symbol = linkageProblem.getSymbol(); ClassPathEntry entryInSubtree = subtreeResult.findEntryBySymbol(symbol); if (entryInSubtree == null) { linkageProblem.setCause(UnknownCause.getInstance()); } else { Artifact artifactInSubtree = entryInSubtree.getArtifact(); DependencyPath pathToSourceEntry = rootResult.getDependencyPaths(sourceEntry).get(0); DependencyPath pathFromSourceEntryToUnselectedEntry = subtreeResult.getDependencyPaths(entryInSubtree).get(0); DependencyPath pathToUnselectedEntry = pathToSourceEntry.concat(pathFromSourceEntryToUnselectedEntry); ClassPathEntry selectedEntry = rootResult.findEntryById( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (selectedEntry != null) { Artifact selectedArtifact = selectedEntry.getArtifact(); if (!selectedArtifact.getVersion().equals(artifactInSubtree.getVersion())) { linkageProblem.setCause( new DependencyConflict( linkageProblem, rootResult.getDependencyPaths(selectedEntry).get(0), pathToUnselectedEntry)); } else { linkageProblem.setCause(UnknownCause.getInstance()); } } else { Artifact excludingArtifact = pathToSourceEntry.findExclusion( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (excludingArtifact != null) { linkageProblem.setCause( new ExcludedDependency(pathToUnselectedEntry, excludingArtifact)); } else { linkageProblem.setCause(new MissingDependency(pathToUnselectedEntry)); } } } } } private  LinkageProblemCauseAnnotator(); static void annotate(
      ClassPathBuilder classPathBuilder,
      ClassPathResult rootResult,
      Iterable<LinkageProblem> linkageProblems); }
LinkageProblemCauseAnnotator { public static void annotate( ClassPathBuilder classPathBuilder, ClassPathResult rootResult, Iterable<LinkageProblem> linkageProblems) throws IOException { checkNotNull(classPathBuilder); checkNotNull(rootResult); checkNotNull(linkageProblems); Map<Artifact, ClassPathResult> cache = new HashMap<>(); for (LinkageProblem linkageProblem : linkageProblems) { ClassFile sourceClass = linkageProblem.getSourceClass(); ClassPathEntry sourceEntry = sourceClass.getClassPathEntry(); Artifact sourceArtifact = sourceEntry.getArtifact(); ClassPathResult subtreeResult = cache.get(sourceArtifact); if (subtreeResult == null) { subtreeResult = classPathBuilder.resolveWithMaven(sourceArtifact); cache.put(sourceArtifact, subtreeResult); } Symbol symbol = linkageProblem.getSymbol(); ClassPathEntry entryInSubtree = subtreeResult.findEntryBySymbol(symbol); if (entryInSubtree == null) { linkageProblem.setCause(UnknownCause.getInstance()); } else { Artifact artifactInSubtree = entryInSubtree.getArtifact(); DependencyPath pathToSourceEntry = rootResult.getDependencyPaths(sourceEntry).get(0); DependencyPath pathFromSourceEntryToUnselectedEntry = subtreeResult.getDependencyPaths(entryInSubtree).get(0); DependencyPath pathToUnselectedEntry = pathToSourceEntry.concat(pathFromSourceEntryToUnselectedEntry); ClassPathEntry selectedEntry = rootResult.findEntryById( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (selectedEntry != null) { Artifact selectedArtifact = selectedEntry.getArtifact(); if (!selectedArtifact.getVersion().equals(artifactInSubtree.getVersion())) { linkageProblem.setCause( new DependencyConflict( linkageProblem, rootResult.getDependencyPaths(selectedEntry).get(0), pathToUnselectedEntry)); } else { linkageProblem.setCause(UnknownCause.getInstance()); } } else { Artifact excludingArtifact = pathToSourceEntry.findExclusion( artifactInSubtree.getGroupId(), artifactInSubtree.getArtifactId()); if (excludingArtifact != null) { linkageProblem.setCause( new ExcludedDependency(pathToUnselectedEntry, excludingArtifact)); } else { linkageProblem.setCause(new MissingDependency(pathToUnselectedEntry)); } } } } } private  LinkageProblemCauseAnnotator(); static void annotate(
      ClassPathBuilder classPathBuilder,
      ClassPathResult rootResult,
      Iterable<LinkageProblem> linkageProblems);  }