Skip to content

Commit

Permalink
Upgrade to Eclipse 2021-09
Browse files Browse the repository at this point in the history
2021-09 requires Java 11 so the version of ASM has been upgraded to
one that supports Java 11 bytecode and EclipseRewriter has been
updated to use the matching ASM API version.

2021-09 also contains an updated version of the NLS class that we
rewrite to remove a call to System.getProperty. Previously, this
call was done in an isolated fashion in the run method of an
anonmyous inner-class. It's now been updated [1] to use a lamdba
which results in the call to System.getProperty now being part of
the class's static initializer. This commit rewrites this <clinit>
to retain the existing initialization of EMPTY_ARGS and ASSIGNED
fields while updating the initialization of ignoreWarnings to
replace the System.getProperty call with a hardcoded true value.

Closes gh-277

[1] https://git.eclipse.org/c/equinox/rt.equinox.framework.git/commit/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/util/NLS.java?id=ba6205dab1f857fe87cf5985f03c1b5e88797064
  • Loading branch information
wilkinsona committed Sep 23, 2021
1 parent 528bfef commit f57832d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
<main.basedir>${basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<eclipse.repository>https://download.eclipse.org/releases/2021-03/202103171000/</eclipse.repository>
<eclipse.repository>https://download.eclipse.org/releases/2021-09/202109151000/</eclipse.repository>
<eclipse.checkstyle.repository>https://checkstyle.org/eclipse-cs-update-site/</eclipse.checkstyle.repository>
<tycho.disableP2Mirrors>true</tycho.disableP2Mirrors>
<ant.version>1.8.1</ant.version>
<ant-contrib.version>1.0b3</ant-contrib.version>
<asm.version>5.2</asm.version>
<asm.version>7.3.1</asm.version>
<assertj.version>3.8.0</assertj.version>
<checkstyle.version>8.45.1</checkstyle.version>
<gradle.version>3.4</gradle.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Internal build utility used to rewrite eclipse runtime classes.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public final class EclipseRewriter {

Expand Down Expand Up @@ -75,7 +76,7 @@ public void rewrite(String file) throws IOException {
private void rewrite(FileSystem zip) throws IOException {
rewrite(zip, "org/eclipse/jdt/internal/formatter/DefaultCodeFormatter.class",
DefaultCodeFormatterManipulator::new);
rewrite(zip, "org/eclipse/osgi/util/NLS$1.class", NlsManipulator::new);
rewrite(zip, "org/eclipse/osgi/util/NLS.class", NlsManipulator::new);
}

private void rewrite(FileSystem zip, String name, Function<ClassWriter, ClassVisitor> manipulator)
Expand All @@ -100,7 +101,7 @@ public static void main(String[] args) throws Exception {
private static class DefaultCodeFormatterManipulator extends ClassVisitor {

DefaultCodeFormatterManipulator(ClassVisitor visitor) {
super(Opcodes.ASM5, visitor);
super(Opcodes.ASM7, visitor);
}

@Override
Expand Down Expand Up @@ -129,7 +130,7 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si
private static class DefaultCodeFormatterMethodManipulator extends MethodVisitor {

DefaultCodeFormatterMethodManipulator(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
super(Opcodes.ASM7, mv);
}

@Override
Expand All @@ -149,12 +150,12 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
private static class NlsManipulator extends ClassVisitor {

NlsManipulator(ClassVisitor visitor) {
super(Opcodes.ASM5, visitor);
super(Opcodes.ASM7, visitor);
}

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if ("run".equals(name) && desc.contains("Boolean")) {
if ("<clinit>".equals(name)) {
return new NslMethodManipulator(super.visitMethod(access, name, desc, signature, exceptions));
}
return super.visitMethod(access, name, desc, signature, exceptions);
Expand All @@ -171,17 +172,26 @@ private static class NslMethodManipulator extends MethodVisitor {
private final MethodVisitor methodVisitor;

NslMethodManipulator(MethodVisitor mv) {
super(Opcodes.ASM5, null);
super(Opcodes.ASM7, null);
this.methodVisitor = mv;
}

@Override
public void visitEnd() {
MethodVisitor mv = this.methodVisitor;
mv.visitCode();
mv.visitInsn(Opcodes.ICONST_0);
mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "EMPTY_ARGS", "[Ljava/lang/Object;");
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TRUE", "Ljava/lang/Boolean;");
mv.visitInsn(Opcodes.ARETURN);
mv.visitMaxs(1, 1);
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "ignoreWarnings", "Z");
mv.visitTypeInsn(Opcodes.NEW, "java/lang/Object");
mv.visitInsn(Opcodes.DUP);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "ASSIGNED", "Ljava/lang/Object;");
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(2, 0);
mv.visitEnd();
}

Expand Down

0 comments on commit f57832d

Please sign in to comment.