From 45254f588150c944dfde84821308d27cc9d34a37 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 16 May 2021 10:17:12 +0700 Subject: [PATCH] Replace use of ASM-renamed by original ASM This involves replacing references in weaver application code as well as a few tests. In order to make AspectJ weaver + tools contain a relocated ASM version, I added a Maven Shade relocation step after Maven Assembly created the uber JARs. Relocation works for both binaries and sources and also encompasses Class::forName calls like in class AsmDetector. Signed-off-by: Alexander Kriegisch --- ajde.core/pom.xml | 4 +- ajde/pom.xml | 4 +- ajdoc/pom.xml | 4 +- aspectjtools/aspectjtools-assembly.xml | 2 +- aspectjtools/pom.xml | 50 +++++++++++++++++-- aspectjweaver/aspectjweaver-assembly.xml | 2 +- aspectjweaver/pom.xml | 50 +++++++++++++++++-- loadtime/pom.xml | 4 +- org.aspectj.ajdt.core/pom.xml | 4 +- .../org/aspectj/tools/ajc/AjcTestCase.java | 8 +-- run-all-junit-tests/pom.xml | 6 +-- taskdefs/pom.xml | 4 +- testing-drivers/pom.xml | 4 +- testing/pom.xml | 4 +- .../ataspectj/ataspectj/UnweavableTest.java | 8 +-- tests/pom.xml | 4 +- weaver/pom.xml | 4 +- .../org/aspectj/weaver/bcel/LazyClassGen.java | 6 ++- .../aspectj/weaver/bcel/asm/AsmDetector.java | 17 +++---- .../weaver/bcel/asm/StackMapAdder.java | 10 ++-- 20 files changed, 145 insertions(+), 54 deletions(-) diff --git a/ajde.core/pom.xml b/ajde.core/pom.xml index 3121c4f49..9cb66316f 100644 --- a/ajde.core/pom.xml +++ b/ajde.core/pom.xml @@ -42,8 +42,8 @@ org.eclipse.jdt.core - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/ajde/pom.xml b/ajde/pom.xml index e48254e59..79d229318 100644 --- a/ajde/pom.xml +++ b/ajde/pom.xml @@ -33,8 +33,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/ajdoc/pom.xml b/ajdoc/pom.xml index e071e10c3..60b39e6cb 100644 --- a/ajdoc/pom.xml +++ b/ajdoc/pom.xml @@ -55,8 +55,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/aspectjtools/aspectjtools-assembly.xml b/aspectjtools/aspectjtools-assembly.xml index 9a6777509..004e1048e 100644 --- a/aspectjtools/aspectjtools-assembly.xml +++ b/aspectjtools/aspectjtools-assembly.xml @@ -17,7 +17,7 @@ false org.aspectj:org.eclipse.jdt.core - org.aspectj:asm-renamed + org.ow2.asm:asm diff --git a/aspectjtools/pom.xml b/aspectjtools/pom.xml index edd60f711..0d5eb7913 100644 --- a/aspectjtools/pom.xml +++ b/aspectjtools/pom.xml @@ -50,7 +50,8 @@ sources - org.eclipse.jdt.core,asm-renamed + org.aspectj,org.ow2.asm + org.eclipse.jdt.core,asm ${project.build.directory}/unzipped-sources runtime @@ -140,6 +141,49 @@ + + + org.apache.maven.plugins + maven-shade-plugin + + true + false + false + + + + asm-relocate + package + + shade + + + false + true + + + ${project.groupId}:${project.artifactId} + + + + + org.objectweb.asm + aj.org.objectweb.asm + + + + + + + org.codehaus.mojo @@ -179,8 +223,8 @@ org.eclipse.jdt.core - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/aspectjweaver/aspectjweaver-assembly.xml b/aspectjweaver/aspectjweaver-assembly.xml index 332504316..3433f6555 100644 --- a/aspectjweaver/aspectjweaver-assembly.xml +++ b/aspectjweaver/aspectjweaver-assembly.xml @@ -16,7 +16,7 @@ false - org.aspectj:asm-renamed + org.ow2.asm:asm diff --git a/aspectjweaver/pom.xml b/aspectjweaver/pom.xml index a9147dd14..6689fbb6e 100644 --- a/aspectjweaver/pom.xml +++ b/aspectjweaver/pom.xml @@ -50,7 +50,8 @@ sources - asm-renamed + org.ow2.asm + asm ${project.build.directory}/unzipped-sources runtime @@ -143,6 +144,49 @@ + + + org.apache.maven.plugins + maven-shade-plugin + + true + false + false + + + + asm-relocate + package + + shade + + + false + true + + + ${project.groupId}:${project.artifactId} + + + + + org.objectweb.asm + aj.org.objectweb.asm + + + + + + + org.codehaus.mojo @@ -178,8 +222,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/loadtime/pom.xml b/loadtime/pom.xml index ae0645a92..7bc38c2fc 100644 --- a/loadtime/pom.xml +++ b/loadtime/pom.xml @@ -38,8 +38,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/org.aspectj.ajdt.core/pom.xml b/org.aspectj.ajdt.core/pom.xml index 747fce918..6117b1580 100644 --- a/org.aspectj.ajdt.core/pom.xml +++ b/org.aspectj.ajdt.core/pom.xml @@ -64,8 +64,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java index 6a93731a5..22db23d17 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java @@ -63,12 +63,12 @@ public abstract class AjcTestCase extends TestCase { */ protected Ajc ajc; - public static final String CLASSPATH_ASM_RENAMED = + public static final String CLASSPATH_ASM = Arrays.stream(System.getProperty("java.class.path") .split(File.pathSeparator)) - .filter(path -> path.contains("asm-renamed")) + .filter(path -> path.replace('\\', '/').contains("org/ow2/asm/")) .findFirst() - .orElseThrow(() -> new RuntimeException("library 'asm-renamed' not found on classpath")); + .orElseThrow(() -> new RuntimeException("ASM library not found on classpath")); // see Ajc and AntSpec public static final String DEFAULT_CLASSPATH_ENTRIES = @@ -76,7 +76,7 @@ public abstract class AjcTestCase extends TestCase { + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "junit" + File.separator + "junit.jar" + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel.jar" + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "bcel" + File.separator + "bcel-verifier.jar" - + File.pathSeparator + CLASSPATH_ASM_RENAMED + + File.pathSeparator + CLASSPATH_ASM + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "testing-client.jar" // hmmm, this next one should perhaps point to an aj-build jar... + File.pathSeparator + ".." + File.separator + "lib" + File.separator + "test" + File.separator + "aspectjrt.jar" diff --git a/run-all-junit-tests/pom.xml b/run-all-junit-tests/pom.xml index c1d3a1fe4..7a3f8abe9 100644 --- a/run-all-junit-tests/pom.xml +++ b/run-all-junit-tests/pom.xml @@ -157,8 +157,8 @@ test - org.aspectj - asm-renamed + org.ow2.asm + asm test @@ -245,7 +245,7 @@ ant:ant-launcher - org.aspectj:asm-renamed + org.ow2.asm:asm org.aspectj:ajde org.aspectj:build org.aspectj:tests diff --git a/taskdefs/pom.xml b/taskdefs/pom.xml index d44faf2ca..39e120e21 100644 --- a/taskdefs/pom.xml +++ b/taskdefs/pom.xml @@ -39,8 +39,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/testing-drivers/pom.xml b/testing-drivers/pom.xml index d15888cef..b252d276a 100644 --- a/testing-drivers/pom.xml +++ b/testing-drivers/pom.xml @@ -35,8 +35,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/testing/pom.xml b/testing/pom.xml index dfd975838..335da941d 100644 --- a/testing/pom.xml +++ b/testing/pom.xml @@ -49,8 +49,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/tests/java5/ataspectj/ataspectj/UnweavableTest.java b/tests/java5/ataspectj/ataspectj/UnweavableTest.java index 95f9e2712..066b30b05 100644 --- a/tests/java5/ataspectj/ataspectj/UnweavableTest.java +++ b/tests/java5/ataspectj/ataspectj/UnweavableTest.java @@ -22,10 +22,10 @@ import java.io.Serializable; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; -import aj.org.objectweb.asm.ClassWriter; -import aj.org.objectweb.asm.Opcodes; -import aj.org.objectweb.asm.MethodVisitor; -import aj.org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.AnnotationVisitor; /** * @author Alexandre Vasseur diff --git a/tests/pom.xml b/tests/pom.xml index 95f91d838..99d1809ec 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -40,8 +40,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm org.aspectj diff --git a/weaver/pom.xml b/weaver/pom.xml index b812ffba1..f47c1ddc5 100644 --- a/weaver/pom.xml +++ b/weaver/pom.xml @@ -62,8 +62,8 @@ ${project.version} - org.aspectj - asm-renamed + org.ow2.asm + asm diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java index 5e72d84ce..22c7945f0 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java @@ -754,7 +754,11 @@ public final class LazyClassGen { // are required (unless turning off the verifier) if ((myGen.getMajor() == Constants.MAJOR_1_6 && world.shouldGenerateStackMaps()) || myGen.getMajor() > Constants.MAJOR_1_6) { if (!AsmDetector.isAsmAround) { - throw new BCException("Unable to find Asm for stackmap generation (Looking for 'aj.org.objectweb.asm.ClassReader'). Stackmap generation for woven code is required to avoid verify errors on a Java 1.7 or higher runtime"); + throw new BCException( + "Unable to find ASM classes (" + AsmDetector.CLASS_READER + ", " + AsmDetector.CLASS_VISITOR + ") " + + "for stackmap generation. Stackmap generation for woven code is required to avoid verify errors " + + "on a Java 1.7 or higher runtime." + ); } wovenClassFileData = StackMapAdder.addStackMaps(world, wovenClassFileData); } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java index 5d5bb6990..5fa7bd006 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java @@ -11,26 +11,25 @@ * ******************************************************************/ package org.aspectj.weaver.bcel.asm; -import java.lang.reflect.Method; - /** * Determines if a version of asm is around that will enable us to add stack map attributes to classes that we produce. - * + * * @author Andy Clement */ public class AsmDetector { - + public static final String CLASS_READER = "org.objectweb.asm.ClassReader"; + public static final String CLASS_VISITOR = "org.objectweb.asm.ClassVisitor"; public static boolean isAsmAround; static { try { - Class reader = Class.forName("aj.org.objectweb.asm.ClassReader"); - Class visitor = Class.forName("aj.org.objectweb.asm.ClassVisitor"); - Method m = reader.getMethod("accept", new Class[] { visitor, Integer.TYPE }); - isAsmAround = m != null; + Class reader = Class.forName(CLASS_READER); + Class visitor = Class.forName(CLASS_VISITOR); + reader.getMethod("accept", visitor, Integer.TYPE); + isAsmAround = true; } catch (Exception e) { isAsmAround = false; } - // System.out.println(isAsmAround?"ASM detected":"No ASM found"); + //System.out.println(isAsmAround ? "ASM detected" : "No ASM found"); } } diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java index 1de90f888..07f3435ae 100644 --- a/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java +++ b/weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java @@ -15,11 +15,11 @@ import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; -import aj.org.objectweb.asm.ClassReader; -import aj.org.objectweb.asm.ClassVisitor; -import aj.org.objectweb.asm.ClassWriter; -import aj.org.objectweb.asm.MethodVisitor; -import aj.org.objectweb.asm.Opcodes; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassVisitor; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; /** * Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data and then a reader/writer -- 2.39.5