Skip to content

Commit f57832d

Browse files
committed
Upgrade to Eclipse 2021-09
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
1 parent 528bfef commit f57832d

File tree

2 files changed

+20
-10
lines changed
  • spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/src/main/java/io/spring/javaformat/formatter/eclipse/rewrite

2 files changed

+20
-10
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
<main.basedir>${basedir}</main.basedir>
3232
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3333
<java.version>1.8</java.version>
34-
<eclipse.repository>https://download.eclipse.org/releases/2021-03/202103171000/</eclipse.repository>
34+
<eclipse.repository>https://download.eclipse.org/releases/2021-09/202109151000/</eclipse.repository>
3535
<eclipse.checkstyle.repository>https://checkstyle.org/eclipse-cs-update-site/</eclipse.checkstyle.repository>
3636
<tycho.disableP2Mirrors>true</tycho.disableP2Mirrors>
3737
<ant.version>1.8.1</ant.version>
3838
<ant-contrib.version>1.0b3</ant-contrib.version>
39-
<asm.version>5.2</asm.version>
39+
<asm.version>7.3.1</asm.version>
4040
<assertj.version>3.8.0</assertj.version>
4141
<checkstyle.version>8.45.1</checkstyle.version>
4242
<gradle.version>3.4</gradle.version>

spring-javaformat/spring-javaformat-formatter-eclipse-rewriter/src/main/java/io/spring/javaformat/formatter/eclipse/rewrite/EclipseRewriter.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* Internal build utility used to rewrite eclipse runtime classes.
4343
*
4444
* @author Phillip Webb
45+
* @author Andy Wilkinson
4546
*/
4647
public final class EclipseRewriter {
4748

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

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

102103
DefaultCodeFormatterManipulator(ClassVisitor visitor) {
103-
super(Opcodes.ASM5, visitor);
104+
super(Opcodes.ASM7, visitor);
104105
}
105106

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

131132
DefaultCodeFormatterMethodManipulator(MethodVisitor mv) {
132-
super(Opcodes.ASM5, mv);
133+
super(Opcodes.ASM7, mv);
133134
}
134135

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

151152
NlsManipulator(ClassVisitor visitor) {
152-
super(Opcodes.ASM5, visitor);
153+
super(Opcodes.ASM7, visitor);
153154
}
154155

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

173174
NslMethodManipulator(MethodVisitor mv) {
174-
super(Opcodes.ASM5, null);
175+
super(Opcodes.ASM7, null);
175176
this.methodVisitor = mv;
176177
}
177178

178179
@Override
179180
public void visitEnd() {
180181
MethodVisitor mv = this.methodVisitor;
181182
mv.visitCode();
183+
mv.visitInsn(Opcodes.ICONST_0);
184+
mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
185+
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "EMPTY_ARGS", "[Ljava/lang/Object;");
182186
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/Boolean", "TRUE", "Ljava/lang/Boolean;");
183-
mv.visitInsn(Opcodes.ARETURN);
184-
mv.visitMaxs(1, 1);
187+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
188+
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "ignoreWarnings", "Z");
189+
mv.visitTypeInsn(Opcodes.NEW, "java/lang/Object");
190+
mv.visitInsn(Opcodes.DUP);
191+
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
192+
mv.visitFieldInsn(Opcodes.PUTSTATIC, "org/eclipse/osgi/util/NLS", "ASSIGNED", "Ljava/lang/Object;");
193+
mv.visitInsn(Opcodes.RETURN);
194+
mv.visitMaxs(2, 0);
185195
mv.visitEnd();
186196
}
187197

0 commit comments

Comments
 (0)