Skip to content

Commit

Permalink
Update to ASM 6.0:
Browse files Browse the repository at this point in the history
- change Jarjar Bings classpath to still use ASM 5.2 (until it's updated)
- remove Java 9 class file patching
- upgrade all visitors to use Opcodes.ASM6
  • Loading branch information
uschindler authored and centic9 committed Jan 16, 2018
1 parent 81075b0 commit b8f5cf1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
8 changes: 6 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
<ivy:cachepath pathid="path.main-build" conf="build" log="${ivy.logging}"/>
<ivy:cachepath pathid="path.main-bundle" conf="bundle" log="${ivy.logging}"/>
<ivy:cachepath pathid="path.test" conf="test" log="${ivy.logging}"/>
<ivy:cachepath pathid="path.jarjar" conf="jarjar" log="${ivy.logging}"/>
<path id="path.main-run">
<path refid="path.main-bundle"/>
<pathelement path="build/main"/>
Expand Down Expand Up @@ -205,7 +206,7 @@

<target name="-install-tasks" depends="-init" unless="installed.tasks">
<ivy:cachepath pathid="path.tasks" conf="buildtools" log="${ivy.logging}"/>
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpathref="path.tasks"/>
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpathref="path.jarjar"/>
<taskdef uri="antlib:org.apache.maven.artifact.ant" classpathref="path.tasks"/>
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="path.tasks"/>
<typedef uri="antlib:org.apache.rat.anttasks" classpathref="path.tasks"/>
Expand Down Expand Up @@ -366,6 +367,9 @@
<zipfileset dir="build/main"/>
<restrict>
<name name="**/*.class" handledirsep="true"/>
<not>
<name name="module-info.class" handledirsep="true"/>
</not>
<archives>
<zips><fileset refid="fileset.bundle"/></zips>
</archives>
Expand Down Expand Up @@ -620,7 +624,7 @@
<groovy classpathref="path.tools-run" src="${groovy-tools.dir}/generate-deprecated.groovy"/>
</target>

<target name="generate-internal" depends="compile-tools" description="Generates deprecated API signature lists for current JDK">
<target name="generate-internal" depends="compile-tools" description="Generates internal API signature lists for current JDK">
<mkdir dir="${signatures.dir}"/>
<property name="internal.output.file" location="${signatures.dir}/jdk-internal-${build.java.runtime}.txt"/>
<java classpathref="path.tools-run" classname="de.thetaphi.forbiddenapis.InternalApiGen" fork="false">
Expand Down
19 changes: 13 additions & 6 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
<!DOCTYPE ivy-module [
<!ENTITY maven.version "2.0">
<!ENTITY gradle.version "2.3">
<!ENTITY asm.version "5.2">
<!ENTITY asm.version "6.0">
<!ENTITY jarjar.asm.version "5.2">
]>
<ivy-module version="2.0">
<info organisation="de.thetaphi" module="forbiddenapis"/>
<configurations defaultconfmapping="build-&gt;*;bundle-&gt;*;test-&gt;*;buildtools-&gt;*">
<configurations defaultconfmapping="build-&gt;*;bundle-&gt;*;test-&gt;*;buildtools-&gt;*;jarjar-&gt;*">
<conf name="build" transitive="false" visibility="private" />
<conf name="bundle" transitive="false" visibility="private" />
<conf name="test" transitive="false" visibility="private" />
<conf name="buildtools" transitive="false" visibility="private" />
<conf name="jarjar" transitive="false" visibility="private" />
</configurations>
<dependencies>
<!-- we compile against the minimum ANT / Maven / Gradle versions: -->
Expand All @@ -39,7 +41,7 @@
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="build"/>
<!-- Gradle also needs Groovy, but we need it as build tool, too: -->
<dependency org="org.codehaus.groovy" name="groovy-all" rev="2.4.12" conf="build,buildtools"/>
<!-- ASM minimal required: -->
<!-- ASM minimal (latest version) required: -->
<dependency org="org.ow2.asm" name="asm" rev="&asm.version;" conf="build,bundle,buildtools"/>
<dependency org="org.ow2.asm" name="asm-commons" rev="&asm.version;" conf="build,bundle,buildtools"/>
<!--
Expand All @@ -49,13 +51,18 @@
-->
<dependency org="org.codehaus.plexus" name="plexus-utils" rev="1.1" conf="build,bundle"/>
<dependency org="commons-cli" name="commons-cli" rev="1.3.1" conf="build,bundle"/>
<dependency org="org.sonatype.plugins" name="jarjar-maven-plugin" rev="1.9" conf="buildtools"/>
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.3" conf="buildtools"/>
<dependency org="org.apache.rat" name="apache-rat" rev="0.11" conf="buildtools"/>
<dependency org="org.apache.ant" name="ant-antunit" rev="1.3" conf="test"/>
<dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="test"/>
<dependency org="junit" name="junit" rev="4.12" conf="test"/>
<dependency org="org.hamcrest" name="hamcrest-core" rev="1.3" conf="test"/>
<!-- deps only needed for build tools and tasks: -->
<dependency org="org.apache.maven" name="maven-ant-tasks" rev="2.1.3" conf="buildtools"/>
<dependency org="org.apache.rat" name="apache-rat" rev="0.11" conf="buildtools"/>
<!-- JarJar needs older ASM version until it gets updated - add separate config: -->
<dependency org="org.ow2.asm" name="asm" rev="&jarjar.asm.version;" conf="jarjar"/>
<dependency org="org.ow2.asm" name="asm-commons" rev="&jarjar.asm.version;" conf="jarjar"/>
<dependency org="org.sonatype.plugins" name="jarjar-maven-plugin" rev="1.9" conf="jarjar"/>
<!-- exclude sources and javadocs in Maven/Ivy downloads: -->
<exclude org="*" ext="*" matcher="regexp" type="source|javadoc"/>
</dependencies>
</ivy-module>
8 changes: 6 additions & 2 deletions src/main/java/de/thetaphi/forbiddenapis/AsmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,17 @@ public static String getModuleName(URL jrtUrl) {
}
}

@SuppressWarnings("unused")
private static void patchClassMajorVersion(byte[] header, int versionFrom, int versionTo) {
final ByteBuffer buf = ByteBuffer.wrap(header).order(ByteOrder.BIG_ENDIAN);
if (buf.getShort(6) == versionFrom) {
buf.putShort(6, (short) versionTo);
}
}

/** Utility method to load class files of Java 9 by patching them, so ASM can read them. */
/** Utility method to load class files of later Java versions by patching them, so ASM can read them. Does nothing at the moment. */
public static ClassReader readAndPatchClass(InputStream in) throws IOException {
/*
final byte[] b = new byte[8];
final PushbackInputStream pbin = new PushbackInputStream(in, b.length);
for (int upto = 0; upto < b.length;) {
Expand All @@ -173,9 +175,11 @@ public static ClassReader readAndPatchClass(InputStream in) throws IOException {
throw new EOFException("Not enough bytes available to read header of class file.");
upto += read;
}
patchClassMajorVersion(b, Opcodes.V1_8 + 1, Opcodes.V1_8);
patchClassMajorVersion(b, Opcodes.V9 + 1, Opcodes.V9);
pbin.unread(b);
return new ClassReader(pbin);
*/
return new ClassReader(in);
}

}
6 changes: 3 additions & 3 deletions src/main/java/de/thetaphi/forbiddenapis/ClassScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ClassScanner(RelatedClassLookup lookup,
final Map<String,String> forbiddenMethods, final Map<String,String> forbiddenFields,
final Pattern suppressAnnotations,
final boolean forbidNonPortableRuntime) {
super(Opcodes.ASM5);
super(Opcodes.ASM6);
this.lookup = lookup;
this.forbiddenClasses = forbiddenClasses;
this.forbiddenClassPatterns = forbiddenClassPatterns;
Expand Down Expand Up @@ -268,7 +268,7 @@ public FieldVisitor visitField(final int access, final String name, final String
if (classSuppressed) {
return null;
}
return new FieldVisitor(Opcodes.ASM5) {
return new FieldVisitor(Opcodes.ASM6) {
final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0;
{
// only check signature, if field is not synthetic
Expand Down Expand Up @@ -313,7 +313,7 @@ public MethodVisitor visitMethod(final int access, final String name, final Stri
if (classSuppressed) {
return null;
}
return new MethodVisitor(Opcodes.ASM5) {
return new MethodVisitor(Opcodes.ASM6) {
private final Method myself = new Method(name, desc);
private final boolean isDeprecated = (access & Opcodes.ACC_DEPRECATED) != 0;
private int lineNo = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ClassSignature(final ClassReader classReader, boolean isRuntimeClass, boo
final Set<Method> methods = new HashSet<Method>();
final Set<String> fields = new HashSet<String>();
final Set<String> signaturePolymorphicMethods = new HashSet<String>();
classReader.accept(new ClassVisitor(Opcodes.ASM5) {
classReader.accept(new ClassVisitor(Opcodes.ASM6) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
final Method m = new Method(name, desc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void parseClass(InputStream in) throws IOException {
if ((reader.getAccess() & ACC_PUBLIC) == 0 || !AsmUtils.isPortableRuntimeClass(className)) {
return;
}
reader.accept(new ClassVisitor(ASM5) {
reader.accept(new ClassVisitor(ASM6) {
boolean classDeprecated = false;

@Override
Expand Down

0 comments on commit b8f5cf1

Please sign in to comment.