[java-mvn-enforcer] branch main updated: Externalize the artifact to properties mapping.
Rod Widdowson
rdw at steadingsoftware.com
Sun Sep 26 09:47:00 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=5ab050cc684869f22cc7477c1ac91d4509b442c8
The following commit(s) were added to refs/heads/main by this push:
new 5ab050c Externalize the artifact to properties mapping.
5ab050c is described below
commit 5ab050cc684869f22cc7477c1ac91d4509b442c8
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Sep 26 10:38:49 2021 +0100
Externalize the artifact to properties mapping.
Allow a properties file to do the heavy lifting. This should
stop this having to be changed so often.
---
pom.xml | 2 +-
.../shibboleth/mvn/enforcer/impl/JarEnforcer.java | 11 ++-
.../mvn/enforcer/impl/ProjectPomContext.java | 66 +++++++------
.../shibboleth/mvn/enforcer/impl/EnforcerCli.java | 105 ---------------------
4 files changed, 43 insertions(+), 141 deletions(-)
diff --git a/pom.xml b/pom.xml
index c821179..1385122 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,7 +15,7 @@
<groupId>net.shibboleth.maven.enforcer.rules</groupId>
<artifactId>maven-dist-enforcer</artifactId>
<name>Shibboleth Distribution Enforcer Rule</name>
- <version>1.1.0-SNAPSHOT</version>
+ <version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
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 6740f1b..169c880 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -58,6 +58,9 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
/** Where to get external data. */
private String enforcerData = "";
+ /** Where to get the mapping of artifact to group. */
+ private String artifactMap = "";
+
/** Will we check that all jars have signatures? */
private boolean checkSignatures = true;
@@ -113,11 +116,17 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
}
final Path pom = checkDirPath(parentPomDir).resolve("pom.xml");
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();
try (final ProjectPomContext pomContext = new ProjectPomContext(this,
- EnforcerLogger.getLogger(ProjectPomContext.class), pool, Path.of(enforcerData), tmp)) {
+ EnforcerLogger.getLogger(ProjectPomContext.class), pool, Path.of(enforcerData), tmp, map)) {
pomContext.initialize(pom);
boolean depdendencyResult = true;
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 285ad94..b92ca40 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/ProjectPomContext.java
@@ -17,6 +17,8 @@
package net.shibboleth.mvn.enforcer.impl;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
@@ -28,6 +30,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import javax.annotation.Nonnull;
@@ -75,6 +78,9 @@ 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;
+
/** Constructor.
* @param loader how to get artifacts
@@ -82,12 +88,14 @@ public final class ProjectPomContext implements AutoCloseable {
* @param pool a parser pool
* @param srcDir source for extra info (like keyrings)
* @param tmpDir where to put stuff.
+ * @param mapFile artifact to group mapping {@link Properties} file
*/
public ProjectPomContext(final MavenLoader loader,
- final Logger logger,
- final ParserPool pool,
- final Path srcDir,
- final Path tmpDir) {
+ @Nonnull final Logger logger,
+ @Nonnull final ParserPool pool,
+ @Nonnull final Path srcDir,
+ @Nonnull final Path tmpDir,
+ @Nonnull final Path mapFile) {
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");
@@ -95,19 +103,20 @@ public final class ProjectPomContext implements AutoCloseable {
enforcerDir = srcDir;
Constraint.isTrue(Files.exists(tmpDir), "Enforcer dir must exist");
parserPool = Constraint.isNotNull(pool, "Parse Pool must not be null");
+ artifactMap = mapFile;
}
/** Get our scratch file system workspace.
* @return {@link #workingDir}
*/
- public Path getWorkingDir() {
+ @Nonnull public Path getWorkingDir() {
return workingDir;
}
/** Rteunr where to get data from.
* @return Returns the parent path of all externmal data.
*/
- public Path getEnforcerDir() {
+ @Nonnull public Path getEnforcerDir() {
return enforcerDir;
}
@@ -115,7 +124,7 @@ public final class ProjectPomContext implements AutoCloseable {
* @param id the artifact id.
* @return the group
*/
- public String getGroup(final String id) {
+ @Nonnull public String getGroup(final String id) {
return artifactToGroup.get(id);
}
@@ -229,33 +238,22 @@ public final class ProjectPomContext implements AutoCloseable {
artifactToGroup.put(artifact.getArtifactId(), artifact.getGroupId());
}
}
-
- return addMapping("annotations", "org.jetbrains") &&
- addMapping("antlr", "antlr") &&
- addMapping("byte-buddy", "net.bytebuddy") &&
- addMapping("checker-qual", "org.checkerframework") &&
- addMapping("classmate", "com.fasterxml") &&
- addMapping("commons-cli", "commons-cli") &&
- addMapping("commons-compiler", "org.codehaus.janino") &&
- addMapping("commons-lang3", "org.apache.commons") &&
- addMapping("commons-pool2", "org.apache.commons") &&
- addMapping("dom4j", "org.dom4j") &&
- addMapping("error_prone_annotations", "com.google.errorprone") &&
- addMapping("failureaccess", "com.google.guava") &&
- addMapping("hibernate-commons-annotations", "org.hibernate.common") &&
- addMapping("istack-commons-runtime", "com.sun.istack") &&
- addMapping("j2objc-annotations", "com.google.j2objc") &&
- addMapping("jandex", "org.jboss") &&
- addMapping("jboss-logging", "org.jboss.logging") &&
- addMapping("jboss-transaction-api_1.2_spec", "org.jboss.spec.javax.transaction") &&
- addMapping("javassist", "org.javassist") &&
- addMapping("javax.persistence-api", "javax.persistence") &&
- addMapping("listenablefuture", "com.google.guava") &&
- addMapping("spymemcached", "net.spy") &&
- addMapping("spring-binding", "org.springframework.webflow") &&
- addMapping("stax2-api", "org.codehaus.woodstox") &&
- addMapping("txw2", "org.glassfish.jaxb") &&
- addMapping("woodstox-core", "com.fasterxml.woodstox");
+ 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);
+ return false;
+ }
+ for (final Entry<Object, Object> entry : props.entrySet()) {
+ if (!addMapping(entry.getKey().toString(), entry.getValue().toString())) {
+ return false;
+ }
+ }
+ }
+ return true;
}
// Checkstyle: CyclomaticComplexity ON
diff --git a/src/test/java/net/shibboleth/mvn/enforcer/impl/EnforcerCli.java b/src/test/java/net/shibboleth/mvn/enforcer/impl/EnforcerCli.java
deleted file mode 100644
index 689488b..0000000
--- a/src/test/java/net/shibboleth/mvn/enforcer/impl/EnforcerCli.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID licenses this file to You under the Apache
- * License, Version 2.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package net.shibboleth.mvn.enforcer.impl;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.time.Instant;
-import java.util.List;
-
-import org.slf4j.LoggerFactory;
-
-import net.shibboleth.utilities.java.support.xml.BasicParserPool;
-
-/** Class to run the enforcer from the command line. */
-public final class EnforcerCli {
-
- /** Constructor. */
- private EnforcerCli() {}
-
- /** Main program.
- * @param args from the Command line
- * @throws Exception if badness occurs
- */
- public static void main(final String[] args) throws Exception {
-
- if (System.getProperty("maven.home") == null) {
- String home = System.getenv("MAVEN_HOME");
- if (home == null) {
- home = System.getenv("_");
- }
- if (home == null) {
- System.out.println("Could not located maven home");
- return;
- }
- if (!Files.exists(Path.of(home).resolve("bin").resolve("mvn"))) {
- System.out.println("Could not find maven at maven home");
- return;
- }
-
- System.setProperty("maven.home", home);
- }
-
- final Path tmp;
- final MavenLoader loader;
- tmp = Files.createTempDirectory("EnforcerCLI");
- loader = new HTTPLoader(tmp);
-
- final BasicParserPool pool = new BasicParserPool();
- pool.initialize();
- try (final ProjectPomContext context =
- new ProjectPomContext(loader, LoggerFactory.getLogger(ProjectPomContext.class), pool, Path.of("src/enforce"), tmp)) {
-
- final Path root;
- if (args.length > 0) {
- root = Path.of(args[0]);
- } else {
- root = Path.of(".");
- }
- Path.of("../idp-parent/pom.xml");
- if (!context.initialize(root.resolve("..").resolve("idp-parent").resolve("pom.xml"))) {
- return;
- }
- final Path distRoot = root.
- resolve("target").
- resolve("shibboleth-identity-provider-"+ context.getParentPom().getOurInfo().getVersion());
- final List<Path> roots = List.of(distRoot.resolve("bin").resolve("lib"),
- distRoot.resolve("webapp").resolve("WEB-INF").resolve("lib"));
-
- File out = new File("target/dependencyReport.txt");
- try (final PrintWriter report = new PrintWriter(new BufferedOutputStream(new FileOutputStream(out)))) {
- report.format("POM based Testing started at %s\n\n", Instant.now().toString());
-
- final DependencyChecker checker = new DependencyChecker(context, report);
- checker.checkDependencies(roots, false);
- report.format("Completed at %s\n\n", Instant.now().toString());
- }
-
- out = new File("target/signatureReport.txt");
- try (final PrintWriter report = new PrintWriter(new BufferedOutputStream(new FileOutputStream(out)))) {
- report.format("POM based Testing started at %s\n\n", Instant.now().toString());
- final SigChecker sigChecker = new SigChecker(loader, context, report);
- sigChecker.testSignatures(roots);
- }
- }
- }
-}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list