Skip to content

Commit

Permalink
Consolidate place to check current JDK version
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof committed Jun 9, 2020
1 parent 5719310 commit b141ae0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.jacoco.core.test.validation.java5;

import org.jacoco.core.test.validation.JavaVersion;
import org.jacoco.core.test.validation.Source.Line;
import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.java5.targets.EnumSwitchTarget;
Expand All @@ -27,7 +28,7 @@ public EnumSwitchTest() {
}

public void assertSwitch(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.6")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.6")) {
// class that holds "switch map" is not marked as synthetic when
// compiling with javac 1.5
assertPartlyCovered(line, 0, 2);
Expand Down
Expand Up @@ -24,6 +24,7 @@

import org.jacoco.core.internal.instr.InstrSupport;
import org.jacoco.core.test.TargetLoader;
import org.jacoco.core.test.validation.JavaVersion;
import org.jacoco.core.test.validation.Source.Line;
import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.java5.targets.FinallyTarget;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void assertFinally(final Line line) {
}

public void assertTwoRegions1(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
// https://bugs.openjdk.java.net/browse/JDK-7008643
assertPartlyCovered(line);
} else {
Expand All @@ -71,7 +72,7 @@ public void assertTwoRegions1(final Line line) {
}

public void assertTwoRegionsReturn1(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
// https://bugs.openjdk.java.net/browse/JDK-7008643
assertEmpty(line);
} else {
Expand All @@ -80,7 +81,7 @@ public void assertTwoRegionsReturn1(final Line line) {
}

public void assertTwoRegionsReturn2(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
// https://bugs.openjdk.java.net/browse/JDK-7008643
assertEmpty(line);
} else {
Expand All @@ -89,7 +90,7 @@ public void assertTwoRegionsReturn2(final Line line) {
}

public void assertEmptyTry1(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
// compiler bug fixed in javac >= 1.8:
assertPartlyCovered(line);
} else {
Expand All @@ -98,7 +99,7 @@ public void assertEmptyTry1(final Line line) {
}

public void assertEmptyTry2(final Line line) {
if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
// compiler bug fixed in javac >= 1.8:
assertFullyCovered(line);
} else {
Expand Down Expand Up @@ -146,7 +147,7 @@ private void gotos() throws IOException {

expected.add("breakStatement.for");
if (isJDKCompiler) {
if (JAVA_VERSION.isBefore("10")) {
if (JavaVersion.current().isBefore("10")) {
// https://bugs.openjdk.java.net/browse/JDK-8180141
expected.add("breakStatement.1");
} else {
Expand Down Expand Up @@ -179,7 +180,7 @@ private void gotos() throws IOException {
expected.add("nested.3");
}

if (isJDKCompiler && JAVA_VERSION.isBefore("1.8")) {
if (isJDKCompiler && JavaVersion.current().isBefore("1.8")) {
expected.add("emptyTry.2");
}

Expand Down
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.jacoco.core.test.validation.java7;

import org.jacoco.core.test.validation.JavaVersion;
import org.jacoco.core.test.validation.Source.Line;
import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.java7.targets.TryWithResourcesTarget;
Expand All @@ -28,7 +29,7 @@ public TryWithResourcesTest() {

public void assertTry(final Line line) {
// without filter this line is covered partly:
if (!isJDKCompiler || JAVA_VERSION.isBefore("11")) {
if (!isJDKCompiler || JavaVersion.current().isBefore("11")) {
assertFullyCovered(line);
} else {
assertEmpty(line);
Expand All @@ -40,7 +41,7 @@ public void assertReturnInBodyClose(final Line line) {
if (isJDKCompiler) {
// https://bugs.openjdk.java.net/browse/JDK-8134759
// javac 7 and 8 up to 8u92 are affected
if (JAVA_VERSION.isBefore("1.8.0_92")) {
if (JavaVersion.current().isBefore("1.8.0_92")) {
assertFullyCovered(line);
} else {
assertEmpty(line);
Expand All @@ -61,9 +62,9 @@ public void assertHandwritten(final Line line) {
public void assertEmptyClose(final Line line) {
if (!isJDKCompiler) {
assertPartlyCovered(line, 7, 1);
} else if (JAVA_VERSION.isBefore("8")) {
} else if (JavaVersion.current().isBefore("8")) {
assertPartlyCovered(line, 6, 2);
} else if (JAVA_VERSION.isBefore("9")) {
} else if (JavaVersion.current().isBefore("9")) {
assertPartlyCovered(line, 2, 2);
} else {
assertFullyCovered(line);
Expand All @@ -74,9 +75,9 @@ public void assertThrowInBodyClose(final Line line) {
// not filtered
if (!isJDKCompiler) {
assertNotCovered(line, 6, 0);
} else if (JAVA_VERSION.isBefore("9")) {
} else if (JavaVersion.current().isBefore("9")) {
assertNotCovered(line, 4, 0);
} else if (JAVA_VERSION.isBefore("11")) {
} else if (JavaVersion.current().isBefore("11")) {
assertNotCovered(line);
} else {
assertEmpty(line);
Expand Down
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.jacoco.core.test.validation.java8;

import org.jacoco.core.test.validation.JavaVersion;
import org.jacoco.core.test.validation.Source.Line;
import org.jacoco.core.test.validation.ValidationTestBase;
import org.jacoco.core.test.validation.java8.targets.BadCycleInterfaceTarget;
Expand All @@ -28,7 +29,7 @@ public BadCycleInterfaceTest() throws Exception {

@Test
public void method_execution_sequence() throws Exception {
if (JAVA_VERSION.isBefore("1.8.0_152")) {
if (JavaVersion.current().isBefore("1.8.0_152")) {
assertLogEvents("baseclinit", "childdefaultmethod", "childclinit",
"childstaticmethod");
} else {
Expand All @@ -37,7 +38,7 @@ public void method_execution_sequence() throws Exception {
}

public void assertBaseClInit(final Line line) {
if (JAVA_VERSION.isBefore("1.8.0_152")) {
if (JavaVersion.current().isBefore("1.8.0_152")) {
// Incorrect interpetation of JVMS 5.5 in JDK 8 causes a default
// method to be called before the static initializer of an interface
// (see JDK-8098557 and JDK-8164302):
Expand All @@ -51,7 +52,7 @@ public void assertBaseClInit(final Line line) {
}

public void assertChildDefault(final Line line) throws Exception {
if (JAVA_VERSION.isBefore("1.8.0_152")) {
if (JavaVersion.current().isBefore("1.8.0_152")) {
// Incorrect interpetation of JVMS 5.5 in JDK 8 causes a default
// method to be called before the static initializer of an interface
// (see JDK-8098557 and JDK-8164302):
Expand Down
Expand Up @@ -41,9 +41,6 @@ public abstract class ValidationTestBase {

protected static final boolean isJDKCompiler = Compiler.DETECT.isJDK();

protected static final JavaVersion JAVA_VERSION = new JavaVersion(
System.getProperty("java.version"));

private static final String[] STATUS_NAME = new String[4];

{
Expand Down

0 comments on commit b141ae0

Please sign in to comment.