-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental support for Java 9 class files
- Loading branch information
Showing
12 changed files
with
243 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.java.version = 1.9+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Evgeny Mandrikov - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>jacoco</groupId> | ||
<artifactId>setup-parent</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../setup-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>it-java9</artifactId> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<target>1.9</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>check</id> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
<configuration> | ||
<rules> | ||
<!-- implementation is needed only for Maven 2 --> | ||
<rule implementation="org.jacoco.maven.RuleConfiguration"> | ||
<limits> | ||
<!-- implementation is needed only for Maven 2 --> | ||
<limit implementation="org.jacoco.report.check.Limit"> | ||
<counter>INSTRUCTION</counter> | ||
<value>COVEREDCOUNT</value> | ||
<minimum>8</minimum> | ||
<maximum>8</maximum> | ||
</limit> | ||
</limits> | ||
</rule> | ||
</rules> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
19 changes: 19 additions & 0 deletions
19
jacoco-maven-plugin.test/it/it-java9/src/main/java/Example.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
public class Example { | ||
|
||
public void sayHello(String name) { | ||
// http://openjdk.java.net/jeps/280 | ||
System.out.println("Hello, " + name); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
jacoco-maven-plugin.test/it/it-java9/src/test/java/ExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
import org.junit.Test; | ||
|
||
public class ExampleTest { | ||
|
||
@Test | ||
public void test() { | ||
new Example().sayHello("test"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
org.jacoco.core/src/org/jacoco/core/internal/Java9Support.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2009, 2016 Mountainminds GmbH & Co. KG and Contributors | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Evgeny Mandrikov - initial API and implementation | ||
* | ||
*******************************************************************************/ | ||
package org.jacoco.core.internal; | ||
|
||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.Opcodes; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Patching for Java 9 classes, so that ASM can read them. | ||
*/ | ||
public final class Java9Support { | ||
|
||
public static final int V1_9 = Opcodes.V1_8 + 1; | ||
|
||
private Java9Support() { | ||
} | ||
|
||
/** | ||
* Copy of {@link ClassReader#readClass(InputStream, boolean)}. | ||
*/ | ||
public static byte[] readClass(final InputStream is, boolean close) | ||
throws IOException { | ||
if (is == null) { | ||
throw new IOException("Class not found"); | ||
} | ||
try { | ||
byte[] b = new byte[is.available()]; | ||
int len = 0; | ||
while (true) { | ||
int n = is.read(b, len, b.length - len); | ||
if (n == -1) { | ||
if (len < b.length) { | ||
byte[] c = new byte[len]; | ||
System.arraycopy(b, 0, c, 0, len); | ||
b = c; | ||
} | ||
return b; | ||
} | ||
len += n; | ||
if (len == b.length) { | ||
int last = is.read(); | ||
if (last < 0) { | ||
return b; | ||
} | ||
byte[] c = new byte[b.length + 1000]; | ||
System.arraycopy(b, 0, c, 0, len); | ||
c[len++] = (byte) last; | ||
b = c; | ||
} | ||
} | ||
} finally { | ||
if (close) { | ||
is.close(); | ||
} | ||
} | ||
} | ||
|
||
private static void putShort(byte[] b, int index, int s) { | ||
b[index] = (byte) (s >>> 8); | ||
b[index + 1] = (byte) s; | ||
} | ||
|
||
private static short readShort(byte[] b, int index) { | ||
return (short) (((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF)); | ||
} | ||
|
||
public static boolean isPatchRequired(byte[] buffer) { | ||
return readShort(buffer, 6) == V1_9; | ||
} | ||
|
||
public static byte[] downgradeIfRequired(byte[] buffer) { | ||
return isPatchRequired(buffer) ? downgrade(buffer) : buffer; | ||
} | ||
|
||
public static byte[] downgrade(byte[] b) { | ||
byte[] result = Arrays.copyOf(b, b.length); | ||
putShort(result, 6, Opcodes.V1_8); | ||
return result; | ||
} | ||
|
||
public static void upgrade(byte[] b) { | ||
putShort(b, 6, V1_9); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters