@Test public void testAnnotate_dom4jOptionalDependency() throws IOException { ClassPathBuilder builder = new ClassPathBuilder(); ClassPathResult classPathResult = builder.resolve(ImmutableList.of(new DefaultArtifact("org.dom4j:dom4j:2.1.3")), false); ImmutableList<ClassPathEntry> dom4jDependencies = TestHelper.resolve("org.dom4j:dom4j:2.1.3"); ClassPathEntry dom4jEntry = dom4jDependencies.get(0); LinkageProblem problem = new ClassNotFoundProblem( new ClassFile(dom4jEntry, "org.dom4j.DocumentHelper"), new ClassSymbol("org.jaxen.VariableContext")); LinkageProblemCauseAnnotator.annotate( classPathBuilder, classPathResult, ImmutableSet.of(problem)); LinkageProblemCause cause = problem.getCause(); assertEquals(MissingDependency.class, cause.getClass()); DependencyPath pathToMissingArtifact = ((MissingDependency) cause).getPathToMissingArtifact(); Artifact leaf = pathToMissingArtifact.getLeaf(); assertEquals("jaxen", leaf.getArtifactId()); }
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);  }