Skip to content

Commit 86c5aa2

Browse files
authored
[MSHARED-47] Don't flag xml-apis:xml-apis as undeclared (#135)
* [MSHARED-47] Don't flag xml-apis:xml-apis as undeclared
1 parent 3676865 commit 86c5aa2

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/it/jarWithXmlTransitiveDependency/verify.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ UsedDeclaredArtifacts:
2424
dom4j:dom4j:jar:1.6.1:compile
2525
2626
UsedUndeclaredArtifactsWithClasses:
27-
xml-apis:xml-apis:jar:1.0.b2:compile
28-
org.xml.sax.Parser
2927
3028
UnusedDeclaredArtifacts:
3129

src/it/usedUndeclaredReference/verify.groovy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ def expected = '''
2323
UsedDeclaredArtifacts:
2424
2525
UsedUndeclaredArtifactsWithClasses:
26-
xml-apis:xml-apis:jar:1.0.b2:compile
27-
org.apache.xmlcommons.Version
2826
2927
UnusedDeclaredArtifacts:
3028
dom4j:dom4j:jar:1.6.1:compile

src/main/java/org/apache/maven/shared/dependency/analyzer/DefaultProjectDependencyAnalyzer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public ProjectDependencyAnalysis analyze(MavenProject project, Collection<String
9999
Map<Artifact, Set<DependencyUsage>> usedUndeclaredArtifactsWithClasses = new LinkedHashMap<>(usedArtifacts);
100100
Set<Artifact> usedUndeclaredArtifacts =
101101
removeAll(usedUndeclaredArtifactsWithClasses.keySet(), declaredArtifacts);
102+
102103
usedUndeclaredArtifactsWithClasses.keySet().retainAll(usedUndeclaredArtifacts);
103104

104105
Set<Artifact> unusedDeclaredArtifacts = new LinkedHashSet<>(declaredArtifacts);
@@ -242,7 +243,7 @@ private static Map<Artifact, Set<DependencyUsage>> buildUsedArtifacts(
242243
for (DependencyUsage classUsage : dependencyClasses) {
243244
Artifact artifact = findArtifactForClassName(artifactClassMap, classUsage.getDependencyClass());
244245

245-
if (artifact != null) {
246+
if (artifact != null && !includedInJDK(artifact)) {
246247
Set<DependencyUsage> classesFromArtifact = usedArtifacts.get(artifact);
247248
if (classesFromArtifact == null) {
248249
classesFromArtifact = new HashSet<>();
@@ -255,6 +256,21 @@ private static Map<Artifact, Set<DependencyUsage>> buildUsedArtifacts(
255256
return usedArtifacts;
256257
}
257258

259+
// MSHARED-47 an uncommon case where a commonly used
260+
// third party dependency was added to the JDK
261+
private static boolean includedInJDK(Artifact artifact) {
262+
if ("xml-apis".equals(artifact.getGroupId())) {
263+
if ("xml-apis".equals(artifact.getArtifactId())) {
264+
return true;
265+
}
266+
} else if ("xerces".equals(artifact.getGroupId())) {
267+
if ("xmlParserAPIs".equals(artifact.getArtifactId())) {
268+
return true;
269+
}
270+
}
271+
return false;
272+
}
273+
258274
private static Artifact findArtifactForClassName(Map<Artifact, Set<String>> artifactClassMap, String className) {
259275
for (Map.Entry<Artifact, Set<String>> entry : artifactClassMap.entrySet()) {
260276
if (entry.getValue().contains(className)) {

0 commit comments

Comments
 (0)