[java-mvn-enforcer] 02/02: JMVN-1 Exbed Keyrings from tested repository

Rod Widdowson rdw at steadingsoftware.com
Fri Dec 10 15:09:26 UTC 2021


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=54c8ce435cffe745894c1d357560324de5c831aa

commit 54c8ce435cffe745894c1d357560324de5c831aa
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Dec 10 15:08:26 2021 +0000

    JMVN-1 Exbed Keyrings from tested repository
    
    https://shibboleth.atlassian.net/browse/JMVN-1
    
    Move the artifactMap.properties file into the enforcer data.
---
 .../shibboleth/mvn/enforcer/impl/JarEnforcer.java  | 26 ++------------
 .../mvn/enforcer/impl/ProjectPomContext.java       | 42 ++++++++--------------
 2 files changed, 18 insertions(+), 50 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 6c64898..aaa6e9b 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -78,8 +78,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
     private String dataVersion = "";
     /** The key rings for the data .*/
     private String dataKeyRing;
-    /** Where to get the mapping of artifact to group. */
-    private String artifactMap = "";
     /** Will we check that all jars we distribute jars have valid signatures? */
     private boolean checkSignatures = true;
     /** Will we check that the jars we distribute are versions we expected? */
@@ -156,13 +154,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
             if (Files.notExists(pom)) {
                 throw new EnforcerRuleException("Pom File " + parentPomDir + "/pom.xml does not exist");
             }
-            final Path tmp = Files.createTempDirectory("EnforcerCLI");
-            final Path map;
-            if (artifactMap != null && !artifactMap.isEmpty()) {
-                map = Path.of(artifactMap);
-            } else {
-                map = null;
-            }
             final BasicParserPool pool = new BasicParserPool();
             pool.initialize();
 
@@ -171,8 +162,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
                                           EnforcerLogger.getLogger(ProjectPomContext.class),
                                           pool,
                                           getGPGDataClassLoader(),
-                                          tmp,
-                                          map, 
                                           StringSupport.stringToList(versionExtensions, XMLConstants.LIST_DELIMITERS))) {
 
                 pomContext.initialize(pom);
@@ -207,11 +196,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
      */
     private ClassLoader getGPGDataClassLoader() throws Exception {
 
-        // Only do this if we are sig checking
-        if (!checkSignatures) {
-            return null;
-        }
-
         final File jar = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "jar");
         if (jar == null || !jar.exists()) {
             log.error("Could not locate data artifact {}:{}:{}", dataGroupId, dataArtifactId, dataVersion);
@@ -252,18 +236,14 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
     private boolean performM2Check(final ProjectPomContext pomContext, final Path target) throws Exception {
         boolean m2Result = true;
         if (checkM2) {
-            final String group = "org.opensaml";
-            final String id = "opensaml-parent";
-            final String version = "4.1.0";
-
-            final Path resolvedPom = downloadArtifact(group, id, version, "pom").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
-            int index = group.indexOf('.');
+            int index = dataGroupId.indexOf('.');
             while (index > 0) {
                 root = root.getParent();
-                index = group.indexOf('.', index+1);
+                index = dataGroupId.indexOf('.', index+1);
             }
             root = root.getParent();
             log.info("Inferred M2 Root at {}", root);
diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
index bc8871a..113d176 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
@@ -17,9 +17,8 @@
 
 package net.shibboleth.mvn.enforcer.impl;
 
-import java.io.BufferedInputStream;
-import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.nio.file.FileVisitResult;
 import java.nio.file.FileVisitor;
 import java.nio.file.Files;
@@ -48,7 +47,7 @@ import net.shibboleth.utilities.java.support.xml.ParserPool;
 public final class ProjectPomContext implements AutoCloseable {
 
     /** Where the keyrings live when on the classpath. */
-    public final static String CLASSPATH_ROOT = "net/shibboleth/mvn/enforcer/";
+    public final static String CLASSPATH_ROOT = "net/shibboleth/mvn/enforcer/data/";
 
     /** Our log. */
     private final Logger log;
@@ -77,9 +76,6 @@ public final class ProjectPomContext implements AutoCloseable {
     /** The ArtifactId to GroupId mapping. */
     private final Map<String, String> artifactToGroup = new HashMap<>();
 
-    /** If non-null the path to a  {@link Properties} file which maps artifacts to groups */
-    private Path artifactMap;
-
     /** The string which can be appended to a version.*/
     @Nonnull private final List<String> extensionGarnish;
 
@@ -88,25 +84,19 @@ public final class ProjectPomContext implements AutoCloseable {
      * @param logger where to log or null if we are using out own.
      * @param pool a parser pool
      * @param classLoader source for extra info (like keyrings)
-     * @param tmpDir where to put stuff.
-     * @param mapFile artifact to group mapping {@link Properties} file
      * @param extensions the known additions to the project extensions
+     * @throws IOException if we cannit create the temp dir
      */
     public ProjectPomContext(final MavenLoader loader,
             @Nonnull final Logger logger,
             @Nonnull final ParserPool pool,
             @Nonnull final ClassLoader classLoader,
-            @Nonnull final Path tmpDir,
-            @Nonnull final Path mapFile,
-            @Nonnull final List<String> extensions) {
+            @Nonnull final List<String> extensions) throws IOException {
         mavenLoader = Constraint.isNotNull(loader, "Loader must not be null");
         log = Constraint.isNotNull(logger, "Logger must not be null");
-        workingDir = Constraint.isNotNull(tmpDir, "Working dir must not be null");
-        Constraint.isTrue(Files.exists(tmpDir), "Working dir must exist");
+        workingDir = Files.createTempDirectory("EnforcerCLI");
         enforcerLoader = Constraint.isNotNull(classLoader, "Class Loader must not be null");;
-        Constraint.isTrue(Files.exists(tmpDir), "Enforcer dir must exist");
         parserPool = Constraint.isNotNull(pool, "Parse Pool must not be null");
-        artifactMap = mapFile;
         extensionGarnish = Constraint.isNotNull(extensions, "Extensions must not be null");
     }
     
@@ -259,20 +249,18 @@ public final class ProjectPomContext implements AutoCloseable {
                 artifactToGroup.put(artifact.getArtifactId(), artifact.getGroupId());
             }
         }
-        if (artifactMap != null) {
-            final Properties props = new Properties();
-            try (final BufferedInputStream stream = new BufferedInputStream(
-                            new FileInputStream(artifactMap.toFile()))) {
-                props.load(stream);
-            } catch (IOException e) {
-                log.error("Could not load artifact map properties file {}", artifactMap, e);
+        final Properties props = new Properties();
+        final String path = CLASSPATH_ROOT + "artifactMap.properties";
+        try (final InputStream stream = enforcerLoader.getResourceAsStream(path)) {
+            props.load(stream);
+        } catch (IOException e) {
+            log.error("Could not load artifact map properties from {}", path, e);
+            return false;
+        }
+        for (final Entry<Object, Object> entry : props.entrySet()) {
+            if (!addMapping(entry.getKey().toString(), entry.getValue().toString())) {
                 return false;
             }
-            for (final Entry<Object, Object> entry : props.entrySet()) {
-                if (!addMapping(entry.getKey().toString(), entry.getValue().toString())) {
-                    return false;
-                }
-            }
         }
         return true;
     }

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


More information about the commits mailing list