From fdeb5012802008bb57d16dd2ba6e49f943cd722c Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 10 Mar 2024 12:22:09 +0100 Subject: [PATCH] Small cleanup of JDK versions enforcements --- .../dependencies/EnforceBytecodeVersion.java | 19 ++++--------------- src/site/apt/enforceBytecodeVersion.apt.vm | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java b/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java index 8a42c02..90afca3 100644 --- a/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java +++ b/src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java @@ -46,7 +46,6 @@ import org.apache.maven.shared.artifact.filter.AbstractStrictPatternArtifactFilter; import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter; import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter; -import org.codehaus.plexus.util.IOUtil; import org.eclipse.aether.RepositorySystem; /** @@ -154,7 +153,7 @@ static String renderVersion(int major, int minor) { private String message; /** - * JDK version as used for example in the maven-compiler-plugin: 1.5, 1.6 and so on. If in need of more precise + * JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on. If in need of more precise * configuration please see {@link #maxJavaMajorVersionNumber} and {@link #maxJavaMinorVersionNumber} Mandatory if * {@link #maxJavaMajorVersionNumber} not specified. */ @@ -224,14 +223,13 @@ private void computeParameters() throws EnforcerRuleException { } if (maxJdkVersion == null && maxJavaMajorVersionNumber == -1) { throw new IllegalArgumentException( - "Exactly one of maxJdkVersion or " + "maxJavaMajorVersionNumber options should be set."); + "Exactly one of maxJdkVersion or maxJavaMajorVersionNumber options should be set."); } if (maxJdkVersion != null) { Integer needle = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get(maxJdkVersion); if (needle == null) { throw new IllegalArgumentException( - "Unknown JDK version given. Should be something like " - + "\"1.7\", \"8\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\""); + "Unknown JDK version given. Should be something like \"8\", \"11\", \"17\", \"21\" .."); } maxJavaMajorVersionNumber = needle; if (!strict && needle < 53) { @@ -291,25 +289,16 @@ private String isBadArtifact(Artifact a) throws EnforcerRuleException { } } - InputStream is = null; - try { - is = jarFile.getInputStream(entry); + try (InputStream is = jarFile.getInputStream(entry)) { int total = magicAndClassFileVersion.length; while (total > 0) { int read = is.read(magicAndClassFileVersion, magicAndClassFileVersion.length - total, total); - if (read == -1) { throw new EOFException(f.toString()); } - total -= read; } - - is.close(); - is = null; - } finally { - IOUtil.close(is); } int minor = (magicAndClassFileVersion[4] << 8) + magicAndClassFileVersion[5]; diff --git a/src/site/apt/enforceBytecodeVersion.apt.vm b/src/site/apt/enforceBytecodeVersion.apt.vm index b2c08aa..8fb4ec2 100644 --- a/src/site/apt/enforceBytecodeVersion.apt.vm +++ b/src/site/apt/enforceBytecodeVersion.apt.vm @@ -29,7 +29,7 @@ Enforce Bytecode Version The following parameters are supported by this rule: - * <> - the maximum target jdk version in the 1.x form (e.g. 1.6, 1.7, 1.8, 1.9 or 6, 7, 8, 9, 10, 11...) + * <> - the maximum target jdk version (e.g. 8, 11, 17, 21...) * <> - an integer indicating the maximum bytecode major version number (cannot be specified if maxJdkVersion is present)