Skip to content

Commit

Permalink
Small cleanup of JDK versions enforcements
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Mar 10, 2024
1 parent ddfdae9 commit 4620280
Showing 1 changed file with 4 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.apache.maven.shared.artifact.filter.StrictPatternExcludesArtifactFilter;
import org.apache.maven.shared.artifact.filter.StrictPatternIncludesArtifactFilter;
import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
import org.codehaus.plexus.util.IOUtil;
import org.eclipse.aether.RepositorySystem;

/**
Expand Down Expand Up @@ -157,7 +156,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.
*/
Expand Down Expand Up @@ -246,14 +245,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) {
Expand Down Expand Up @@ -313,25 +311,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];
Expand Down

0 comments on commit 4620280

Please sign in to comment.