[java-mvn-enforcer] 02/03: JMVN-25 Artifact deriver gives wrong version information for garnished jar names

Rod Widdowson rdw at steadingsoftware.com
Mon Feb 7 15:17:42 UTC 2022


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

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

View the commit online:
http://git.shibboleth.net/view/?p=java-mvn-enforcer.git;a=commit;h=f6f3221acb59fea9dc3083cbbce4a80f568b64e7

commit f6f3221acb59fea9dc3083cbbce4a80f568b64e7
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Feb 6 13:50:27 2022 +0000

    JMVN-25 Artifact deriver gives wrong version information for garnished jar names
    
    https://shibboleth.atlassian.net/browse/JMVN-25
    
    Teach M2 sig resolver how to handle artifact classifiers (properly)
    <classifier> to the artifact class
---
 .../net/shibboleth/mvn/enforcer/impl/JarEnforcer.java   | 14 +++++++-------
 .../net/shibboleth/mvn/enforcer/impl/M2SigChecker.java  | 17 +++++++++--------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
index d7ad7c1..dd2c066 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -205,18 +205,18 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
      */
     private ClassLoader getGPGDataClassLoader() throws Exception {
 
-        final File pom = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "pom");
+        final File pom = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "pom");
         if (pom == null || !pom.exists()) {
             log.error("Could not locate data artifact {}:{}:{}", dataGroupId, dataArtifactId, dataVersion);
             throw new FileNotFoundException("Could not locate data artifact");
         }
-        final File jar = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "jar");
+        final File jar = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "jar");
         if (jar == null || !jar.exists()) {
             log.error("Could not locate data artifact {}:{}:{}", dataGroupId, dataArtifactId, dataVersion);
             throw new FileNotFoundException("Could not locate data artifact");
         }
         if (!isGPGDataASnapshot()) {
-            final File asc = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "jar.asc");
+            final File asc = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "jar.asc");
             if (jar == null || !jar.exists()) {
                 log.error("Could not locate data artifact signature for {}:{}:{}", dataGroupId, dataArtifactId, dataVersion);
                 throw new FileNotFoundException("Could not locate data artifact signature");
@@ -250,7 +250,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
     private boolean performM2Check(final ProjectPomContext pomContext, final Path target) throws Exception {
         boolean m2Result = true;
         if (checkM2) {
-            final Path resolvedPom = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "jar").toPath();
+            final Path resolvedPom = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "jar").toPath();
             // Resolved pom path is <pathTpM2Repo>/group1/group2/..../artifact/version/pomfilename
             log.debug("Resolved Pom = {}", resolvedPom);
             Path root = resolvedPom.getParent().getParent().getParent(); // strip version, artifact
@@ -406,8 +406,8 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
      * @return a file or null i
      * @throws Exception
      */
-    @Nullable public File downloadArtifact(final String groupId, final String artifactId, final String version, final String type) throws Exception {
-        final Artifact mavenArtifact = repositorySystem.createArtifact(groupId,artifactId, version, "", type);
+    @Nullable public File downloadArtifact(final String groupId, final String artifactId, final String version, final String classifier, final String type) throws Exception {
+        final Artifact mavenArtifact = repositorySystem.createArtifactWithClassifier(groupId,artifactId, version, type, classifier);
 
         if (mavenArtifact == null) {
             log.error("Could not create {}:{}:{}:{}", groupId, artifactId, version, type);
@@ -429,7 +429,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
 
     /** {@inheritDoc} */
     public Path downloadArtifact(final PomArtifact artifact, final String type) throws Exception {
-        final File file = downloadArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), type);
+        final File file = downloadArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getClassifier(), type);
         if (file == null) {
             return null;
         }
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
index 968de85..7d3b111 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/M2SigChecker.java
@@ -123,24 +123,25 @@ public class M2SigChecker extends BaseSigChecker {
             }
             final String version = versionDir.getFileName().toString();
             final String fileName = path.getFileName().toString();
-            final String garnish;
+            final String classifier;
             if (version.endsWith("SNAPSHOT")) {
                 // The version garnish isn't real version garnish:
                 //   org/opensaml/opensaml-core/4.2.0-SNAPSHOT/opensaml-core-4.2.0-20220109.011317-203
                 //
-                garnish = "";
+                classifier = "";
             } else if (fileName.length() > artifactId.length() + 1 + version.length() + 4) {
-                // Need to be able to handle garnished versions:
+                // Need to be able to handle classifier
                 //   org/sonatype/sisu/sisu-guice/2.1.7/sisu-guice-2.1.7-noapp.jar
-                garnish = fileName.substring(
+                classifier = fileName.substring(
                         artifactId.length()     // "sisu-guice"
-                        + 1 //                  // "-"
-                        + version.length(),     // "2.1.7"
+                        + 1                     // "-"
+                        + version.length()      // "2.1.7"
+                        + 1,                    // "-"
                         fileName.length() - 4); // ".jar"
             } else {
                 // usual version:
                 //   org/hsqldb/hrsqldb/2.5.1/hsqldb-2.5.1.jar
-                garnish = "";
+                classifier = "";
             }
 
             final StringBuffer buf = new StringBuffer();
@@ -150,7 +151,7 @@ public class M2SigChecker extends BaseSigChecker {
             if (buf.length() > 0) {
                 buf.deleteCharAt(buf.length()-1);
             }
-            return getProjectContext().getParentPom().new PomArtifact(buf.toString(), artifactId, version + garnish);
+            return getProjectContext().getParentPom().new PomArtifact(buf.toString(), artifactId, version, classifier);
         }
     }
 

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


More information about the commits mailing list