Skip to content

Commit fdeb501

Browse files
slachiewiczslawekjaranowski
authored andcommitted
Small cleanup of JDK versions enforcements
1 parent 461f15d commit fdeb501

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/main/java/org/codehaus/mojo/extraenforcer/dependencies/EnforceBytecodeVersion.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.maven.shared.artifact.filter.AbstractStrictPatternArtifactFilter;
4747
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
4848
import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter;
49-
import org.codehaus.plexus.util.IOUtil;
5049
import org.eclipse.aether.RepositorySystem;
5150

5251
/**
@@ -154,7 +153,7 @@ static String renderVersion(int major, int minor) {
154153
private String message;
155154

156155
/**
157-
* JDK version as used for example in the maven-compiler-plugin: 1.5, 1.6 and so on. If in need of more precise
156+
* JDK version as used for example in the maven-compiler-plugin: 8, 11 and so on. If in need of more precise
158157
* configuration please see {@link #maxJavaMajorVersionNumber} and {@link #maxJavaMinorVersionNumber} Mandatory if
159158
* {@link #maxJavaMajorVersionNumber} not specified.
160159
*/
@@ -224,14 +223,13 @@ private void computeParameters() throws EnforcerRuleException {
224223
}
225224
if (maxJdkVersion == null && maxJavaMajorVersionNumber == -1) {
226225
throw new IllegalArgumentException(
227-
"Exactly one of maxJdkVersion or " + "maxJavaMajorVersionNumber options should be set.");
226+
"Exactly one of maxJdkVersion or maxJavaMajorVersionNumber options should be set.");
228227
}
229228
if (maxJdkVersion != null) {
230229
Integer needle = JDK_TO_MAJOR_VERSION_NUMBER_MAPPING.get(maxJdkVersion);
231230
if (needle == null) {
232231
throw new IllegalArgumentException(
233-
"Unknown JDK version given. Should be something like "
234-
+ "\"1.7\", \"8\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\"");
232+
"Unknown JDK version given. Should be something like \"8\", \"11\", \"17\", \"21\" ..");
235233
}
236234
maxJavaMajorVersionNumber = needle;
237235
if (!strict && needle < 53) {
@@ -291,25 +289,16 @@ private String isBadArtifact(Artifact a) throws EnforcerRuleException {
291289
}
292290
}
293291

294-
InputStream is = null;
295-
try {
296-
is = jarFile.getInputStream(entry);
292+
try (InputStream is = jarFile.getInputStream(entry)) {
297293
int total = magicAndClassFileVersion.length;
298294
while (total > 0) {
299295
int read =
300296
is.read(magicAndClassFileVersion, magicAndClassFileVersion.length - total, total);
301-
302297
if (read == -1) {
303298
throw new EOFException(f.toString());
304299
}
305-
306300
total -= read;
307301
}
308-
309-
is.close();
310-
is = null;
311-
} finally {
312-
IOUtil.close(is);
313302
}
314303

315304
int minor = (magicAndClassFileVersion[4] << 8) + magicAndClassFileVersion[5];

src/site/apt/enforceBytecodeVersion.apt.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Enforce Bytecode Version
2929

3030
The following parameters are supported by this rule:
3131

32-
* <<maxJdkVersion>> - 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...)
32+
* <<maxJdkVersion>> - the maximum target jdk version (e.g. 8, 11, 17, 21...)
3333

3434
* <<maxJavaMajorVersionNumber>> - an integer indicating the maximum bytecode major version number (cannot be specified if maxJdkVersion is present)
3535

0 commit comments

Comments
 (0)