Skip to content

Commit

Permalink
Add official support for Java 20, experimental for Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof committed Dec 19, 2022
1 parent 8a367e3 commit e5b239b
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
JDK_VERSION: 19
JDK 20:
JDK_VERSION: 20
JDK 21:
JDK_VERSION: 21
pool:
vmImage: 'ubuntu-18.04'
steps:
Expand Down
14 changes: 14 additions & 0 deletions org.jacoco.build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,20 @@
</properties>
</profile>

<profile>
<id>java21-bytecode</id>
<activation>
<property>
<name>bytecode.version</name>
<value>21</value>
</property>
</activation>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
</properties>
</profile>

<!-- This profile enables use of ECJ -->
<profile>
<id>ecj</id>
Expand Down
31 changes: 31 additions & 0 deletions org.jacoco.core.test.validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,37 @@
<module>../org.jacoco.core.test.validation.scala</module>
</modules>
</profile>

<profile>
<id>java21-bytecode</id>
<activation>
<property>
<name>bytecode.version</name>
<value>21</value>
</property>
</activation>
<properties>
<!-- Kotlin 1.5.0 doesn't support compilation into 21 -->
<kotlin.compiler.jvmTarget>16</kotlin.compiler.jvmTarget>
<!-- Groovy 3.0.13 does not support compilation into 21 -->
<groovy.targetBytecode>16</groovy.targetBytecode>
<!-- see respective profile in org.jacoco.build about this override -->
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<modules>
<module>../org.jacoco.core.test.validation.kotlin</module>
<module>../org.jacoco.core.test.validation.java7</module>
<module>../org.jacoco.core.test.validation.java8</module>
<module>../org.jacoco.core.test.validation.java14</module>
<module>../org.jacoco.core.test.validation.java16</module>
<!-- Groovy 3.0.13 does not support Java 21
<module>../org.jacoco.core.test.validation.groovy</module>
-->
<module>../org.jacoco.core.test.validation.scala</module>
</modules>
</profile>

</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void should_ignore_synthetic_classes() throws Exception {
@Test
public void should_not_modify_class_bytes_to_support_next_version()
throws Exception {
final byte[] originalBytes = createClass(Opcodes.V19 + 1);
final byte[] originalBytes = createClass(Opcodes.V20 + 1);
final byte[] bytes = new byte[originalBytes.length];
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
final long expectedClassId = CRC64.classId(bytes);
Expand All @@ -132,13 +132,13 @@ private static byte[] createClass(final int version) {
*/
@Test
public void analyzeClass_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V19 + 2);
final byte[] bytes = createClass(Opcodes.V20 + 2);
try {
analyzer.analyzeClass(bytes, "UnsupportedVersion");
fail("exception expected");
} catch (IOException e) {
assertExceptionMessage("UnsupportedVersion", e);
assertEquals("Unsupported class file major version 65",
assertEquals("Unsupported class file major version 66",
e.getCause().getMessage());
}
}
Expand Down Expand Up @@ -218,14 +218,14 @@ public void testAnalyzeClass_BrokenStream() throws IOException {
*/
@Test
public void analyzeAll_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V19 + 2);
final byte[] bytes = createClass(Opcodes.V20 + 2);
try {
analyzer.analyzeAll(new ByteArrayInputStream(bytes),
"UnsupportedVersion");
fail("exception expected");
} catch (IOException e) {
assertExceptionMessage("UnsupportedVersion", e);
assertEquals("Unsupported class file major version 65",
assertEquals("Unsupported class file major version 66",
e.getCause().getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void setup() throws Exception {
@Test
public void should_not_modify_class_bytes_to_support_next_version()
throws Exception {
final byte[] originalBytes = createClass(Opcodes.V19 + 1);
final byte[] originalBytes = createClass(Opcodes.V20 + 1);
final byte[] bytes = new byte[originalBytes.length];
System.arraycopy(originalBytes, 0, bytes, 0, originalBytes.length);
final long expectedClassId = CRC64.classId(bytes);
Expand All @@ -123,13 +123,13 @@ private static byte[] createClass(final int version) {
*/
@Test
public void instrument_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V19 + 2);
final byte[] bytes = createClass(Opcodes.V20 + 2);
try {
instrumenter.instrument(bytes, "UnsupportedVersion");
fail("exception expected");
} catch (final IOException e) {
assertExceptionMessage("UnsupportedVersion", e);
assertEquals("Unsupported class file major version 65",
assertEquals("Unsupported class file major version 66",
e.getCause().getMessage());
}
}
Expand Down Expand Up @@ -221,14 +221,14 @@ public void testSerialization() throws Exception {
*/
@Test
public void instrumentAll_should_throw_exception_for_unsupported_class_file_version() {
final byte[] bytes = createClass(Opcodes.V19 + 2);
final byte[] bytes = createClass(Opcodes.V20 + 2);
try {
instrumenter.instrumentAll(new ByteArrayInputStream(bytes),
new ByteArrayOutputStream(), "UnsupportedVersion");
fail("exception expected");
} catch (final IOException e) {
assertExceptionMessage("UnsupportedVersion", e);
assertEquals("Unsupported class file major version 65",
assertEquals("Unsupported class file major version 66",
e.getCause().getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void setup() {
}

@Test
public void classReaderFor_should_read_java_20_class() {
final byte[] bytes = createJava20Class();
public void classReaderFor_should_read_java_21_class() {
final byte[] bytes = createJava21Class();

final ClassReader classReader = InstrSupport.classReaderFor(bytes);

Expand All @@ -53,16 +53,16 @@ public void classReaderFor_should_read_java_20_class() {
public void visit(final int version, final int access,
final String name, final String signature,
final String superName, final String[] interfaces) {
assertEquals(Opcodes.V19 + 1, version);
assertEquals(Opcodes.V20 + 1, version);
}
}, 0);

assertArrayEquals(createJava20Class(), bytes);
assertArrayEquals(createJava21Class(), bytes);
}

private static byte[] createJava20Class() {
private static byte[] createJava21Class() {
final ClassWriter cw = new ClassWriter(0);
cw.visit(Opcodes.V19 + 1, 0, "Foo", null, "java/lang/Object", null);
cw.visit(Opcodes.V20 + 1, 0, "Foo", null, "java/lang/Object", null);
cw.visitEnd();
return cw.toByteArray();
}
Expand Down Expand Up @@ -131,7 +131,8 @@ public void needFrames_should_return_true_for_versions_greater_than_or_equal_to_
assertTrue(InstrSupport.needsFrames(Opcodes.V17));
assertTrue(InstrSupport.needsFrames(Opcodes.V18));
assertTrue(InstrSupport.needsFrames(Opcodes.V19));
assertTrue(InstrSupport.needsFrames(Opcodes.V19 + 1));
assertTrue(InstrSupport.needsFrames(Opcodes.V20));
assertTrue(InstrSupport.needsFrames(Opcodes.V20 + 1));

assertTrue(InstrSupport.needsFrames(0x0100));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public static void push(final MethodVisitor mv, final int value) {
*/
public static ClassReader classReaderFor(final byte[] b) {
final int originalVersion = getMajorVersion(b);
if (originalVersion == Opcodes.V19 + 1) {
if (originalVersion == Opcodes.V20 + 1) {
// temporarily downgrade version to bypass check in ASM
setMajorVersion(Opcodes.V19, b);
setMajorVersion(Opcodes.V20, b);
}
final ClassReader classReader = new ClassReader(b);
setMajorVersion(originalVersion, b);
Expand Down
8 changes: 8 additions & 0 deletions org.jacoco.doc/docroot/doc/build.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>JDK 17</td>
<td>JDK 18</td>
<td>JDK 19</td>
<td>JDK 20</td>
</tr>
</thead>
<tbody>
Expand All @@ -116,6 +117,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>16</td>
<td>16</td>
<td>16</td>
<td>16</td>
</tr>
<tr>
<td>org.jacoco.core.test.validation.java14</td>
Expand All @@ -134,6 +136,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>14</td>
<td>14</td>
<td>14</td>
<td>14</td>
</tr>
<tr>
<td>org.jacoco.core.test.validation.java8</td>
Expand All @@ -152,6 +155,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>8</td>
<td>8</td>
<td>8</td>
<td>8</td>
</tr>
<tr>
<td>org.jacoco.core.test.validation.java7</td>
Expand All @@ -170,6 +174,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>7</td>
<td>7</td>
<td>7</td>
<td>7</td>
</tr>
<tr>
<td>org.jacoco.core.test.validation.groovy</td>
Expand All @@ -188,6 +193,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>8</td>
<td>8</td>
<td>8</td>
<td>8</td>
</tr>
<tr>
<td>org.jacoco.core.test.validation.kotlin</td>
Expand All @@ -206,6 +212,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>6</td>
<td>6</td>
<td>6</td>
<td>6</td>
</tr>
<tr>
<td>all other modules</td>
Expand All @@ -224,6 +231,7 @@ <h2>Compilation and testing with different JDKs</h2>
<td>7</td>
<td>7</td>
<td>7</td>
<td>7</td>
</tr>
</tbody>
</table>
Expand Down
9 changes: 5 additions & 4 deletions org.jacoco.doc/docroot/doc/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ <h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2>

<h3>New Features</h3>
<ul>
<li>JaCoCo now officially supports Java 19
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1371">#1371</a>).</li>
<li>Experimental support for Java 20 class files
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1335">#1335</a>).</li>
<li>JaCoCo now officially supports Java 19 and 20
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1371">#1371</a>,
<a href="https://github.com/jacoco/jacoco/issues/1386">#1386</a>).</li>
<li>Experimental support for Java 21 class files
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1386">#1386</a>).</li>
<li>Add parameter to include the current project in the <code>report-aggregate</code>
Maven goal
(GitHub <a href="https://github.com/jacoco/jacoco/issues/1007">#1007</a>).</li>
Expand Down
2 changes: 1 addition & 1 deletion org.jacoco.doc/docroot/doc/environment.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h3>JRE/JDK</h3>
The minimum supported JRE version for JaCoCo is Java 5. To guarantee
compatibility JaCoCo release builds should always be executed using JDK 5.
In addition we run builds with 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
18, and 19 JDKs.
18, 19 and 20 JDKs.
</p>

<h3>Build</h3>
Expand Down
2 changes: 1 addition & 1 deletion org.jacoco.doc/docroot/doc/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3>Does JaCoCo have a plug-in for [Eclipse|Netbeans|Whatever...]?</h3>

<h3>What Java versions are supported by JaCoCo?</h3>
<p>
JaCoCo supports Java class files from version 1.0 to 19. However the minimum
JaCoCo supports Java class files from version 1.0 to 20. However the minimum
JRE version required by the JaCoCo runtime (e.g. the agent) and the JaCoCo
tools is 1.5. Also note that class files under test from version 1.6 and above
have to contain valid stackmap frames.
Expand Down

0 comments on commit e5b239b

Please sign in to comment.