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
Support Java 9 class file format #406
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
115 changes: 115 additions & 0 deletions
115
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,115 @@ | ||
/******************************************************************************* | ||
* 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 java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
|
||
/** | ||
* Patching for Java 9 classes, so that ASM can read them. | ||
*/ | ||
public final class Java9Support { | ||
|
||
/** | ||
* Version of the Java 9 class file format. | ||
*/ | ||
public static final int V1_9 = Opcodes.V1_8 + 1; | ||
|
||
private Java9Support() { | ||
} | ||
|
||
/** | ||
* Reads all bytes from an input stream into a byte array. | ||
* | ||
* @param is | ||
* the input stream to read from | ||
* @return a byte array containing all the bytes from the stream | ||
* @throws IOException | ||
* if an I/O error occurs | ||
*/ | ||
public static byte[] readFully(final InputStream is) | ||
throws IOException { | ||
if (is == null) { | ||
throw new IllegalArgumentException(); | ||
} | ||
final byte[] buf = new byte[1024]; | ||
final ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
while (true) { | ||
int r = is.read(buf); | ||
if (r == -1) { | ||
break; | ||
} | ||
out.write(buf, 0, r); | ||
} | ||
return out.toByteArray(); | ||
} | ||
|
||
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)); | ||
} | ||
|
||
/** | ||
* Determines whether class definition contains {@link #V1_9} version. | ||
* | ||
* @param buffer | ||
* definition of the class | ||
* @return <code>true</code> if class definition contains Java 9 version | ||
*/ | ||
public static boolean isPatchRequired(byte[] buffer) { | ||
return readShort(buffer, 6) == V1_9; | ||
} | ||
|
||
/** | ||
* Returns new definition of class with version {@link Opcodes#V1_8}, | ||
* if it has version {@link #V1_9}. | ||
* | ||
* @param buffer | ||
* definition of the class | ||
* @return new definition of the class | ||
*/ | ||
public static byte[] downgradeIfRequired(byte[] buffer) { | ||
return isPatchRequired(buffer) ? downgrade(buffer) : buffer; | ||
} | ||
|
||
/** | ||
* Replaces version in the definition of class on {@link Opcodes#V1_8}. | ||
* | ||
* @param b | ||
* definition of the class | ||
* @return new definition of the class | ||
*/ | ||
public static byte[] downgrade(byte[] b) { | ||
byte[] result = new byte[b.length]; | ||
System.arraycopy(b, 0, result, 0, b.length); | ||
putShort(result, 6, Opcodes.V1_8); | ||
return result; | ||
} | ||
|
||
/** | ||
* Replaces version in the definition of class on {@link #V1_9}. | ||
* | ||
* @param b | ||
* definition of the class | ||
*/ | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see several JavaDoc warnings on this class. Even if the code is temporary I would prefer if our code comes without warnings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marchof I suppose that those warnings are generated by Eclipse? I don't see warnings in IntelliJ , even when explicitly executing all built-in inspections for Javadocs. So could you please elaborate what needs to be fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we require to have JavaDoc on all public Java classes and members.