This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git
The following commit(s) were added to refs/heads/master by this push: new 86c5aa2 [MSHARED-47] Don't flag xml-apis:xml-apis as undeclared (#135) 86c5aa2 is described below commit 86c5aa2077e64eabb3afd157f108647adaf0f8ec Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Mon Nov 25 22:11:19 2024 +0000 [MSHARED-47] Don't flag xml-apis:xml-apis as undeclared (#135) * [MSHARED-47] Don't flag xml-apis:xml-apis as undeclared --- src/it/jarWithXmlTransitiveDependency/verify.groovy | 2 -- src/it/usedUndeclaredReference/verify.groovy | 2 -- .../analyzer/DefaultProjectDependencyAnalyzer.java | 18 +++++++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/it/jarWithXmlTransitiveDependency/verify.groovy b/src/it/jarWithXmlTransitiveDependency/verify.groovy index 4d7483a..088383c 100644 --- a/src/it/jarWithXmlTransitiveDependency/verify.groovy +++ b/src/it/jarWithXmlTransitiveDependency/verify.groovy @@ -24,8 +24,6 @@ UsedDeclaredArtifacts: dom4j:dom4j:jar:1.6.1:compile UsedUndeclaredArtifactsWithClasses: - xml-apis:xml-apis:jar:1.0.b2:compile - org.xml.sax.Parser UnusedDeclaredArtifacts: diff --git a/src/it/usedUndeclaredReference/verify.groovy b/src/it/usedUndeclaredReference/verify.groovy index ea59292..e0bc731 100644 --- a/src/it/usedUndeclaredReference/verify.groovy +++ b/src/it/usedUndeclaredReference/verify.groovy @@ -23,8 +23,6 @@ def expected = ''' UsedDeclaredArtifacts: UsedUndeclaredArtifactsWithClasses: - xml-apis:xml-apis:jar:1.0.b2:compile - org.apache.xmlcommons.Version UnusedDeclaredArtifacts: dom4j:dom4j:jar:1.6.1:compile diff --git a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java index f4e2274..e5f02e4 100644 --- a/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java +++ b/src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java @@ -99,6 +99,7 @@ public class DefaultProjectDependencyAnalyzer implements ProjectDependencyAnalyz Map<Artifact, Set<DependencyUsage>> usedUndeclaredArtifactsWithClasses = new LinkedHashMap<>(usedArtifacts); Set<Artifact> usedUndeclaredArtifacts = removeAll(usedUndeclaredArtifactsWithClasses.keySet(), declaredArtifacts); + usedUndeclaredArtifactsWithClasses.keySet().retainAll(usedUndeclaredArtifacts); Set<Artifact> unusedDeclaredArtifacts = new LinkedHashSet<>(declaredArtifacts); @@ -242,7 +243,7 @@ public class DefaultProjectDependencyAnalyzer implements ProjectDependencyAnalyz for (DependencyUsage classUsage : dependencyClasses) { Artifact artifact = findArtifactForClassName(artifactClassMap, classUsage.getDependencyClass()); - if (artifact != null) { + if (artifact != null && !includedInJDK(artifact)) { Set<DependencyUsage> classesFromArtifact = usedArtifacts.get(artifact); if (classesFromArtifact == null) { classesFromArtifact = new HashSet<>(); @@ -255,6 +256,21 @@ public class DefaultProjectDependencyAnalyzer implements ProjectDependencyAnalyz return usedArtifacts; } + // MSHARED-47 an uncommon case where a commonly used + // third party dependency was added to the JDK + private static boolean includedInJDK(Artifact artifact) { + if ("xml-apis".equals(artifact.getGroupId())) { + if ("xml-apis".equals(artifact.getArtifactId())) { + return true; + } + } else if ("xerces".equals(artifact.getGroupId())) { + if ("xmlParserAPIs".equals(artifact.getArtifactId())) { + return true; + } + } + return false; + } + private static Artifact findArtifactForClassName(Map<Artifact, Set<String>> artifactClassMap, String className) { for (Map.Entry<Artifact, Set<String>> entry : artifactClassMap.entrySet()) { if (entry.getValue().contains(className)) {