From 90ac027afa09353989f9ba1173f49fe2dcd41404 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Wed, 15 Dec 2021 15:30:52 +0100 Subject: [PATCH] Bytecode version of multirelease metadata should be lower or equal to specified version (#158) --- .../invoker.properties | 2 + .../pom.xml | 48 +++++++++++++++++++ .../verify.groovy | 9 ++++ .../enforcer/EnforceBytecodeVersion.java | 10 ++-- 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 src/it/enforce-bytecode-version-multirelease-2/invoker.properties create mode 100644 src/it/enforce-bytecode-version-multirelease-2/pom.xml create mode 100644 src/it/enforce-bytecode-version-multirelease-2/verify.groovy diff --git a/src/it/enforce-bytecode-version-multirelease-2/invoker.properties b/src/it/enforce-bytecode-version-multirelease-2/invoker.properties new file mode 100644 index 00000000..a30e3767 --- /dev/null +++ b/src/it/enforce-bytecode-version-multirelease-2/invoker.properties @@ -0,0 +1,2 @@ +invoker.goals = enforcer:enforce +invoker.buildResult = success diff --git a/src/it/enforce-bytecode-version-multirelease-2/pom.xml b/src/it/enforce-bytecode-version-multirelease-2/pom.xml new file mode 100644 index 00000000..952bb352 --- /dev/null +++ b/src/it/enforce-bytecode-version-multirelease-2/pom.xml @@ -0,0 +1,48 @@ + + 4.0.0 + + pim.pam.poum + smoking + 1.0-SNAPSHOT + + + + + maven-enforcer-plugin + @enforcerPluginVersion@ + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + + + 1.8 + + + + + + compile + + + + + + + UTF-8 + + + + + com.fasterxml.jackson.module + jackson-module-jaxb-annotations + 2.13.0 + runtime + + + diff --git a/src/it/enforce-bytecode-version-multirelease-2/verify.groovy b/src/it/enforce-bytecode-version-multirelease-2/verify.groovy new file mode 100644 index 00000000..7048eeea --- /dev/null +++ b/src/it/enforce-bytecode-version-multirelease-2/verify.groovy @@ -0,0 +1,9 @@ +File file = new File( basedir, "build.log" ); +assert file.exists(); + +String text = file.getText("utf-8"); + +assert text.contains( '[INFO] Adding ignore: module-info' ) +assert !text.contains( '[WARNING] Invalid bytecodeVersion for com.fasterxml.jackson.core:jackson-core:jar:2.13.0:runtime' ) + +return true; diff --git a/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java b/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java index 9fa2756d..2d35a35a 100644 --- a/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java +++ b/src/main/java/org/apache/maven/plugins/enforcer/EnforceBytecodeVersion.java @@ -351,16 +351,16 @@ private String isBadArtifact( Artifact a ) if ( matcher.matches() ) { - Integer expectedMajor = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get( matcher.group( 1 ) ); + Integer maxExpectedMajor = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get( matcher.group( 1 ) ); - if (expectedMajor == null) { + if (maxExpectedMajor == null) { getLog().warn( "Unknown bytecodeVersion for " + a + " : " - + entry.getName() + ": got " + expectedMajor + " class-file-version" ); + + entry.getName() + ": got " + maxExpectedMajor + " class-file-version" ); } - else if ( major != expectedMajor ) + else if ( major > maxExpectedMajor ) { getLog().warn( "Invalid bytecodeVersion for " + a + " : " - + entry.getName() + ": expected " + expectedMajor + ", but was " + major ); + + entry.getName() + ": expected lower or equal to " + maxExpectedMajor + ", but was " + major ); } } else