Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for maven.compiler.release/testRelease #167

Merged
merged 1 commit into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant
@Parameter(required = false, defaultValue = "${maven.compiler.target}")
private String targetVersion;

/**
* The default compiler release version used to expand references to bundled JDK signatures.
* E.g., if you use "jdk-deprecated", it will expand to this version.
* This setting should be identical to the release version used in the compiler plugin starting with Java 9.
*/
@Parameter(required = false, defaultValue = "${maven.compiler.release}")
private String releaseVersion;

/**
* List of patterns matching all class files to be parsed from the classesDirectory.
* Can be changed to e.g. exclude several files (using excludes).
Expand Down Expand Up @@ -248,7 +256,7 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant

/** gets overridden for test, because it uses testTargetVersion as optional name to override */
protected String getTargetVersion() {
return targetVersion;
return (releaseVersion != null) ? releaseVersion : targetVersion;
}

private File resolveSignaturesArtifact(SignaturesArtifact signaturesArtifact) throws ArtifactResolutionException, ArtifactNotFoundException {
Expand Down Expand Up @@ -385,7 +393,8 @@ public void info(String msg) {
String targetVersion = getTargetVersion();
if ("".equals(targetVersion)) targetVersion = null;
if (targetVersion == null) {
log.warn("The 'targetVersion' parameter or '${maven.compiler.target}' property is missing. " +
log.warn("The 'targetVersion' and 'targetRelease' parameters or " +
"'${maven.compiler.target}' and '${maven.compiler.release}' properties are missing. " +
"Trying to read bundled JDK signatures without compiler target. " +
"You have to explicitly specify the version in the resource name.");
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/de/thetaphi/forbiddenapis/maven/TestCheckMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public final class TestCheckMojo extends AbstractCheckMojo {
@Parameter(required = false, defaultValue = "${maven.compiler.testTarget}")
private String testTargetVersion;

/**
* The default compiler release version used to expand references to bundled JDK signatures.
* This setting falls back to "targetVersion" if undefined. This can be used to override
* the release version solely used for tests.
* E.g., if you use "jdk-deprecated", it will expand to this version.
* This setting should be identical to the release version used in the compiler plugin.
*/
@Parameter(required = false, defaultValue = "${maven.compiler.testRelease}")
private String testReleaseVersion;

@Override
protected List<String> getClassPathElements() {
return this.classpathElements;
Expand All @@ -71,7 +81,8 @@ protected File getClassesDirectory() {

@Override
protected String getTargetVersion() {
return (testTargetVersion != null) ? testTargetVersion : super.getTargetVersion();
return (testReleaseVersion != null) ?
testReleaseVersion : (testTargetVersion != null) ? testTargetVersion : super.getTargetVersion();
}

}