[java-mvn-enforcer] branch main updated: JPAR-190 Investigate an enforcer to check all jars and poms ~/.m2/.... towards the end of a build
Rod Widdowson
rdw at steadingsoftware.com
Sun Oct 9 13:13:34 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=a93e00d4816f102b6e9c713fdf37f15ff7426466
The following commit(s) were added to refs/heads/main by this push:
new a93e00d JPAR-190 Investigate an enforcer to check all jars and poms ~/.m2/.... towards the end of a build
a93e00d is described below
commit a93e00d4816f102b6e9c713fdf37f15ff7426466
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sun Oct 9 14:12:59 2022 +0100
JPAR-190 Investigate an enforcer to check all jars and poms ~/.m2/.... towards the end of a build
https://shibboleth.atlassian.net/browse/JPAR-190
Better reporting of where the various reports are written to
---
.../shibboleth/mvn/enforcer/impl/JarEnforcer.java | 94 +++++++++++++---------
1 file changed, 57 insertions(+), 37 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 5cba2eb..98ca12f 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -105,7 +105,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
/** Duplicate jars (same name, different versions. */
private boolean multipleJarVersionsFatal = true;
-
/** The list of things which get added to real versions. */
private String versionExtensions = "-SNAPSHOT -GA -jre -empty-to-avoid-conflict-with-guava";
@@ -124,6 +123,45 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
/** The {@link RepositorySystem} we will use. */
private RepositorySystem repositorySystem;
+ /** {@literal ${basedir}\target} */
+ private Path targetDir;
+
+ /**
+ * Get the path for the m2 Sig check - as configured or the default
+ * @return the path
+ */
+ private Path getM2ReportPath() {
+ if (m2ReportPath == null) {
+ return targetDir.resolve("m2SignatureReport.txt");
+ }
+ return Path.of(m2ReportPath);
+ }
+
+ /**
+ * Get the path for the signature check - as configured or the default
+ * @return the path
+ */
+ private Path getSigCheckReportPath() {
+ if (sigCheckReportPath == null) {
+ return targetDir.resolve("signatureReport.txt");
+ }
+ return Path.of(sigCheckReportPath);
+ }
+
+ /**
+ * Get the path for the dependency check - as configured or the default
+ * @return the path
+ */
+ private Path getDepCheckReportPath() {
+ if (depCheckReportPath == null) {
+ return targetDir.resolve("dependencyReport.txt");
+ }
+ return Path.of(depCheckReportPath);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
EnforcerLogger.setMavenLogger(helper.getLog());
@@ -155,7 +193,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
artifactResolver = helper.getComponent(ArtifactResolver.class);
session = (MavenSession) helper.evaluate( "${session}" );
project = (MavenProject) helper.evaluate( "${project}" );
- final Path target = Path.of(helper.evaluate( "${basedir}" ).toString()).resolve("target");
+ targetDir = Path.of(helper.evaluate( "${basedir}" ).toString()).resolve("target");
if (repositorySystem == null || artifactResolver == null || session == null || project == null) {
throw new EnforcerRuleException("Could not set up artifact environment");
}
@@ -175,20 +213,20 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
pomContext.initialize(pom);
- final boolean m2Result = performM2Check(pomContext, target);
- final boolean depdendencyResult = performDependencyCheck(pomContext, target, tgzPaths, zipPaths);
- final boolean signatureResult = performSignatureCheck(pomContext, target, tgzPaths, zipPaths);
+ final boolean m2Result = performM2Check(pomContext);
+ final boolean depdendencyResult = performDependencyCheck(pomContext, tgzPaths, zipPaths);
+ final boolean signatureResult = performSignatureCheck(pomContext, tgzPaths, zipPaths);
if (!depdendencyResult) {
throw new EnforcerRuleException(
- "Dependency check failed, check the file ./target/dependencyReport.txt");
+ "Dependency check failed, check the file " + getDepCheckReportPath());
}
if (!signatureResult) {
throw new EnforcerRuleException(
- "Signature check over distribution failed, check the file ./target/signatureReport.txt");
+ "Signature check over distribution failed, check the file " + getSigCheckReportPath());
}
if (!m2Result) {
throw new EnforcerRuleException(
- "Signature check over ~m2 failed, check the file ./target/m2SignatureReport.txt");
+ "Signature check over ~m2 failed, check the file " + getM2ReportPath());
}
}
@@ -243,11 +281,10 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
/** Do the m2 signature checks
* @param pomContext Context for the work
- * @param target Target Directory of this project
* @return if this worked (or was suppressed)
* @throws Exception is resolution fails
*/
- private boolean performM2Check(final ProjectPomContext pomContext, final Path target) throws Exception {
+ private boolean performM2Check(final ProjectPomContext pomContext) throws Exception {
boolean m2Result = true;
if (checkM2) {
final Path resolvedPom = downloadArtifact(dataGroupId, dataArtifactId, dataVersion, "", "jar").toPath();
@@ -261,47 +298,37 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
}
root = root.getParent();
log.info("Inferred M2 Root at {}", root);
- final Path reportPath;
- if (m2ReportPath == null) {
- reportPath = target.resolve("m2SignatureReport.txt");
- } else {
- reportPath = Path.of(m2ReportPath);
- }
try (final PrintWriter report =
- new PrintWriter(new BufferedOutputStream(new FileOutputStream(reportPath.toFile())))) {
+ new PrintWriter(new BufferedOutputStream(new FileOutputStream(getM2ReportPath().toFile())))) {
report.format("M2 Signature Testing started at %s\n\n", Instant.now().toString());
final M2SigChecker chk = new M2SigChecker(pomContext, report);
m2Result = chk.testSignatures(root);
report.format("Completed at %s\n\n", Instant.now().toString());
}
+ if (!m2Result) {
+ log.error("Signature check over ~m2 failed, check the file {}", getM2ReportPath());
+ }
}
return m2Result;
}
/** Do the signature check
* @param pomContext Context for the work
- * @param target Target Directory of this project
* @param tgzPaths the tgzFiles to look at.
* @param zipPaths the zipFiles to look at.
* @return if this worked (or was suppressed)
* @throws IOException if a file was not found or archive handling failed
* @throws EnforcerRuleException if we were doing an invalid SNAPSHOT/nonSNAPSHOT test
*/
- private boolean performSignatureCheck(final ProjectPomContext pomContext, final Path target,
+ private boolean performSignatureCheck(final ProjectPomContext pomContext,
final List<Path> tgzPaths, final List<Path> zipPaths) throws IOException, EnforcerRuleException {
boolean signatureResult = true;
if (checkSignatures) {
if (isGPGDataASnapshot() && !pomContext.isSnapShot()) {
throw new EnforcerRuleException("Running a signature check of a non SNAPSHOT build against a SNAPSHOT of GPGData");
}
- final Path reportPath;
- if (sigCheckReportPath == null) {
- reportPath = target.resolve("signatureReport.txt");
- } else {
- reportPath = Path.of(sigCheckReportPath);
- }
try (final PrintWriter report =
- new PrintWriter(new BufferedOutputStream(new FileOutputStream(reportPath.toFile())))) {
+ new PrintWriter(new BufferedOutputStream(new FileOutputStream(getSigCheckReportPath().toFile())))) {
report.format("Signature Testing started at %s\n\n", Instant.now().toString());
final SigChecker sigChecker = new SigChecker(pomContext, report);
@@ -320,7 +347,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
}
report.format("Completed at %s\n\n", Instant.now().toString());
if (!signatureResult) {
- log.error("Signature check failed, check the file ./target/signatureReport.txt");
+ log.error("Signature check failed, check the file {}", getSigCheckReportPath());
}
}
}
@@ -329,24 +356,17 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
/** Do the dependency check
* @param pomContext Context for the work
- * @param target Target Directory of this project
* @param tgzPaths the tgzFiles to look at.
* @param zipPaths the zipFiles to look at.
* @return if this worked (or was suppressed)
* @throws IOException if a file was not found or archive handling failed
*/
- private boolean performDependencyCheck(final ProjectPomContext pomContext, final Path target,
+ private boolean performDependencyCheck(final ProjectPomContext pomContext,
final List<Path> tgzPaths, final List<Path> zipPaths) throws IOException {
boolean depdendencyResult = true;
if (checkDependencies) {
- final Path reportPath;
- if (depCheckReportPath == null) {
- reportPath = target.resolve("dependencyReport.txt");
- } else {
- reportPath = Path.of(depCheckReportPath);
- }
try (final PrintWriter report =
- new PrintWriter(new BufferedOutputStream(new FileOutputStream(reportPath.toFile())))) {
+ new PrintWriter(new BufferedOutputStream(new FileOutputStream(getDepCheckReportPath().toFile())))) {
report.format("POM based Dependency Testing started at %s\n", Instant.now().toString());
@@ -368,7 +388,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
}
report.format("Completed at %s\n\n", Instant.now().toString());
if (!depdendencyResult) {
- log.error( "Dependency check failed, check the file ./target/dependencyReport.txt");
+ log.error( "Dependency check failed, check the file {}", getDepCheckReportPath());
}
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list