[java-mvn-enforcer] 01/03: JMVN-89 Dependency check fails on idp-distiribution

Codeberg noreply at shibboleth.net
Thu Oct 8 13:23:22 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch main
in repository java-mvn-enforcer.

View the commit online:
https://codeberg.org/Shibboleth/java-mvn-enforcer/commit/cfa37d8321d03233e860583c1518c917a8057680

commit cfa37d8321d03233e860583c1518c917a8057680
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Oct 4 15:54:06 2026 +0100

    JMVN-89 Dependency check fails on idp-distiribution
    
    https://shibboleth.atlassian.net/browse/JMVN-89
    
    Code tidy.  Mostly structure details behind trivial objects to help
    readbility
---
 .../mvn/enforcer/impl/DependencyChecker.java       | 127 +++++++++++++--------
 1 file changed, 77 insertions(+), 50 deletions(-)

diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
index 350c381..44c3af0 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/DependencyChecker.java
@@ -62,12 +62,12 @@ public class DependencyChecker {
     /** The parent project, suitable digested. */
     private final ProjectPomContext projectContext;
 
-    /** The accumulated <artifactId, classifier> to Versions we have found. */
-    private final Map<NameKey, String> nameToVersion = new HashMap<>();
+    /** The accumulated <artifactId, classifier> to Versions we have found. */
+    private final Map<ClassifiedArtifactId, String> nameToVersion = new HashMap<>();
 
     /** The accumulated Map from artifactId to another Map from version to
      * all the files that specify it. */
-    private final Map<NameKey, Map<String, Set<String>>> dependencySource = new HashMap<>();
+    private final Map<ClassifiedArtifactId, VersionToSources> dependencySource = new HashMap<>();
 
     /** Accumulated count of jar files with the same name and different versions or sources. */
     private int duplicateJars;
@@ -201,7 +201,7 @@ public class DependencyChecker {
         DependencyPomArtifact last = null;
 
         for (final DependencyPomArtifact artifact : dependencies) {
-        	final NameKey key = new NameKey(artifact);
+            final ClassifiedArtifactId key = new ClassifiedArtifactId(artifact);
             final String id = key.toString();
             final String ver = artifact.getVersion();
             final String sourcePomFilename = "(from " + artifact.getSourcePomFilename() + ")";
@@ -240,30 +240,28 @@ public class DependencyChecker {
         int noSource = 0;
 
         report.format("Dependency sources for jars found but not explicitly defined as a dependency:\n\n");
-        final List<NameKey> contributedKeys = new ArrayList<>(nameToVersion.keySet());
+        final List<ClassifiedArtifactId> contributedKeys = new ArrayList<>(nameToVersion.keySet());
         Collections.sort(contributedKeys);
 
-        for (final NameKey dependency: contributedKeys) {
-        	final String artifactId = dependency.getFirst();
-            final Map<String, Set<String>> map = dependencySource.get(dependency);
-            final String version = nameToVersion.get(dependency);
+        for (final ClassifiedArtifactId dependency: contributedKeys) {
+            final String artifactId = dependency.getFirst();
+            final VersionToSources map = dependencySource.get(dependency);
+            final String ourVersion = nameToVersion.get(dependency);
             if (map == null) {
                 if (!artifactId.startsWith("idp-")) {
-                    report.format("%-22s\t: %-12s\tNo source artifact found\n", dependency, version);
+                    report.format("%-22s\t: %-12s\tNo source artifact found\n", dependency, ourVersion);
                     noSource++;
                 }
             } else {
-                final Set<String> sources = map.remove(version);
-                if (sources == null) {
-                    report.format("%-22s\t: %-12s\tNO Dependency contributes this version (or \n", dependency, version);
+                if (!map.containsVersion(ourVersion)) {
+                    report.format("%-22s\t: %-12s\tNO Dependency contributes this version (or \n",
+                                  dependency, ourVersion);
                     noSource ++;
-                } else {
-                    reportContributions(dependency.toString(), version, sources);
                 }
-                final List<String> versions = new ArrayList<>(map.keySet());
+                final List<String> versions = new ArrayList<>(map.versionsSpecified());
                 Collections.sort(versions);
-                for (final String ver:versions) {
-                    reportContributions(dependency.toString(), ver, map.get(ver));
+                for (final String version:versions) {
+                    reportContributions(dependency.toString(), version, map.sourcesForVersion(version));
                 }
             }
         }
@@ -302,7 +300,7 @@ public class DependencyChecker {
             return;
         }
         final PomArtifact artifact = projectContext.splitFileName(jarPath);
-        final NameKey key = new NameKey(artifact);
+        final ClassifiedArtifactId key = new ClassifiedArtifactId(artifact);
         final String oldVersion = nameToVersion.put(key, artifact.getVersion());
         if (oldVersion == null) {
             return;
@@ -405,7 +403,7 @@ public class DependencyChecker {
      * @param fileName the file name of the dependency which was down-loaded
      * @param artifact the artifact which provoked the download
      */
-    private void addDep(final Map<NameKey, Map<String, Set<String>>> dependencySources,
+    private void addDep(final Map<ClassifiedArtifactId, VersionToSources> dependencySources,
                         final String fileName,
                         final DependencyPomArtifact artifact) {
         final PomArtifact nameAsArtifact = projectContext.splitFileName(fileName);
@@ -414,12 +412,12 @@ public class DependencyChecker {
             // it's us.  Not interesting
             return;
         }
-        final NameKey nameAsKey = new NameKey(nameAsArtifact);
+        final ClassifiedArtifactId nameAsKey = new ClassifiedArtifactId(nameAsArtifact);
         
         // for each version, what contributed this dependency
-        Map<String, Set<String>> depEntry = dependencySources.get(nameAsKey);
+        VersionToSources depEntry = dependencySources.get(nameAsKey);
         if (depEntry == null) {
-            depEntry = new HashMap<>();
+            depEntry = new VersionToSources();
             dependencySources.put(nameAsKey, depEntry);
         }
         Set<String> provider = depEntry.get(nameAsArtifact.getVersion());
@@ -494,34 +492,63 @@ public class DependencyChecker {
     }
     
     /**
-     * Sortable Pair.
+     * The "thing* that defines a shippable artifact.  Slightly different from an artifact because
+     * we can have two things of the same name shipp together (for instance ....linux-aarch_64 and
+     * ....linux-x86_64).  We hide the details but make it sortable (on artifactId) and with a
+     * sensible {@link #toString()}.
      */
-    private static class NameKey extends Pair<String, String> implements Comparable<NameKey> {
-
-		/**
-		 * Constructor.
-		 *
-		 * @param artifactId the artifactID (sorted on)
-		 * @param classifier the classified (to  distinguish)
-		 */
-		public NameKey(final PomArtifact artifact) {
-			super(artifact.getArtifactId(), artifact.getClassifier());
-		}
-
-		/** {@inheritDoc} */
-		public int compareTo(NameKey o) {
-			return getFirst().compareTo(o.getFirst());
-		}
-		
-		
-		/** {@inheritDoc} */
-		public String toString() {
-			if (getSecond().isEmpty()) {
-				return getFirst();
-			}
-			return getFirst() + "(" + getSecond() + ")";
-		}
-    	
+    private static final class ClassifiedArtifactId extends Pair<String, String>
+                                                   implements Comparable<ClassifiedArtifactId> {
+
+       /** Constructor.
+         * @param artifact the artifact
+        */
+        public ClassifiedArtifactId(final PomArtifact artifact) {
+            super(artifact.getArtifactId(), artifact.getClassifier());
+        }
+
+        /** {@inheritDoc} */
+        public int compareTo(final ClassifiedArtifactId o) {
+            return getFirst().compareTo(o.getFirst());
+        }
+
+        /** {@inheritDoc} */
+        public String toString() {
+            if (getSecond().isEmpty()) {
+                return getFirst();
+            }
+            return getFirst() + "(" + getSecond() + ")";
+        }
     }
 
+    /**
+     * Object to hide the complexity of the lookup from a artifact declaration to where is it specified.
+     * The Key of the hash is a specific version and the values are the poms that specified that version.
+     */
+    @SuppressWarnings("serial")
+    private static final class VersionToSources extends HashMap<String, Set<String>> {
+
+        /** Do we have the specification for this specific version?
+         * @param version what to lookup.
+         * @return Whether we have the versiob.
+         */
+        public boolean containsVersion(final String version) {
+                return containsKey(version);
+        }
+
+        /** What versions do we have specifications for?
+         * @return the versions.
+         */
+        public Collection<String> versionsSpecified() {
+                return keySet();
+        }
+
+        /** What versions does the specified version have support for?
+         * @param version what to look for
+         * @return the sources.
+         */
+        public Collection<String> sourcesForVersion(final String version) {
+                return get(version);
+        }
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list