]> source.dussan.org Git - aspectj.git/commitdiff
Replace use of ASM-renamed by original ASM
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 16 May 2021 03:17:12 +0000 (10:17 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Sun, 16 May 2021 03:17:12 +0000 (10:17 +0700)
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 <Alexander@Kriegisch.name>
20 files changed:
ajde.core/pom.xml
ajde/pom.xml
ajdoc/pom.xml
aspectjtools/aspectjtools-assembly.xml
aspectjtools/pom.xml
aspectjweaver/aspectjweaver-assembly.xml
aspectjweaver/pom.xml
loadtime/pom.xml
org.aspectj.ajdt.core/pom.xml
org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java
run-all-junit-tests/pom.xml
taskdefs/pom.xml
testing-drivers/pom.xml
testing/pom.xml
tests/java5/ataspectj/ataspectj/UnweavableTest.java
tests/pom.xml
weaver/pom.xml
weaver/src/main/java/org/aspectj/weaver/bcel/LazyClassGen.java
weaver/src/main/java/org/aspectj/weaver/bcel/asm/AsmDetector.java
weaver/src/main/java/org/aspectj/weaver/bcel/asm/StackMapAdder.java

index 3121c4f49d14cb9ae6ccb5759858352e5c78494d..9cb66316f64c3786f284b8649b1972adada31534 100644 (file)
@@ -42,8 +42,8 @@
       <artifactId>org.eclipse.jdt.core</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
     <dependency>
       <groupId>org.aspectj</groupId>
index e48254e59775b9288e658bd7e01e9ae2b8aa1a05..79d22931816bd1fcb41702b1921159e2d6b7c09b 100644 (file)
@@ -33,8 +33,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
     <dependency>
       <groupId>org.aspectj</groupId>
index e071e10c38cc477c8509171b4e1fb5b76fbb4f52..60b39e6cb86af5438bc0656ac88f8abed889fd79 100644 (file)
@@ -55,8 +55,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
     <dependency>
       <groupId>org.aspectj</groupId>
index 9a6777509949bca150081c5a3ebecc83e5279e66..004e1048ec4cb67f22c63f39877b734baab43a97 100644 (file)
@@ -17,7 +17,7 @@
                        <useProjectArtifact>false</useProjectArtifact>
                        <includes>
                                <include>org.aspectj:org.eclipse.jdt.core</include>
-                               <include>org.aspectj:asm-renamed</include>
+                               <include>org.ow2.asm:asm</include>
                        </includes>
                </dependencySet>
        </dependencySets>
index edd60f711de83f898b62046be5330cb683d1bd1f..0d5eb7913732516b91f6ece7d45db3d454b98936 100644 (file)
@@ -50,7 +50,8 @@
                                                <configuration>
                                                        <classifier>sources</classifier>
                                                        <!--<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>-->
-                                                       <includeArtifactIds>org.eclipse.jdt.core,asm-renamed</includeArtifactIds>
+                                                       <includeGroupIds>org.aspectj,org.ow2.asm</includeGroupIds>
+                                                       <includeArtifactIds>org.eclipse.jdt.core,asm</includeArtifactIds>
                                                        <outputDirectory>${project.build.directory}/unzipped-sources</outputDirectory>
                                                        <!-- Avoid accidentally shading test-scoped dependencies like JUnit -->
                                                        <includeScope>runtime</includeScope>
                                </executions>
                        </plugin>
 
+                       <!--
+                               Relocate ASM from 'org.objectweb.asm' to 'aj.org.objectweb.asm'
+
+                               TODO: Using Maven Shade after Maven Assembly instead of creating uber JAR and relocating package names at the
+                                 same time is suboptimal and maybe slower than doing both at the same time. Migrating from Assembly to Shade
+                                 requires all dependencies to produce source JARs, though, which currently is not the case. Because we also
+                                 want to create a complete source JAR, for now we keep Assembly around, because it manually copies project
+                                 sources from their respective directories before zipping them up.
+                       -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-shade-plugin</artifactId>
+                               <configuration>
+                                       <createSourcesJar>true</createSourcesJar>
+                                       <createDependencyReducedPom>false</createDependencyReducedPom>
+                                       <shadedArtifactAttached>false</shadedArtifactAttached>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>asm-relocate</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>shade</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <minimizeJar>false</minimizeJar>
+                                                       <shadeSourcesContent>true</shadeSourcesContent>
+                                                       <artifactSet>
+                                                               <includes>
+                                                                       <include>${project.groupId}:${project.artifactId}</include>
+                                                               </includes>
+                                                       </artifactSet>
+                                                       <relocations>
+                                                               <relocation>
+                                                                       <pattern>org.objectweb.asm</pattern>
+                                                                       <shadedPattern>aj.org.objectweb.asm</shadedPattern>
+                                                               </relocation>
+                                                       </relocations>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+
                        <!-- Caveat: Attaching the flattened POM needs packaging=jar, so do not use packaging=pom for this module -->
                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                        <artifactId>org.eclipse.jdt.core</artifactId>
                </dependency>
                <dependency>
-                       <groupId>org.aspectj</groupId>
-                       <artifactId>asm-renamed</artifactId>
+                       <groupId>org.ow2.asm</groupId>
+                       <artifactId>asm</artifactId>
                </dependency>
        </dependencies>
 
index 3325043167124898531502c81e99134f186691b5..3433f65556747b948ddfc0de25ae7ee6ee9852c6 100644 (file)
@@ -16,7 +16,7 @@
                        <!-- Avoid warning when trying to add non-existing main artifact JAR -->
                        <useProjectArtifact>false</useProjectArtifact>
                        <includes>
-                               <include>org.aspectj:asm-renamed</include>
+                               <include>org.ow2.asm:asm</include>
                        </includes>
                </dependencySet>
        </dependencySets>
index a9147dd143cb3d4dc2e87b44b663b978a40f3dbc..6689fbb6e90407a2e3eda540664adf0e08b2c3f8 100644 (file)
@@ -50,7 +50,8 @@
                                                <configuration>
                                                        <classifier>sources</classifier>
                                                        <!--<failOnMissingClassifierArtifact>false</failOnMissingClassifierArtifact>-->
-                                                       <includeArtifactIds>asm-renamed</includeArtifactIds>
+                                                       <includeGroupIds>org.ow2.asm</includeGroupIds>
+                                                       <includeArtifactIds>asm</includeArtifactIds>
                                                        <outputDirectory>${project.build.directory}/unzipped-sources</outputDirectory>
                                                        <!-- Avoid accidentally shading test-scoped dependencies like JUnit -->
                                                        <includeScope>runtime</includeScope>
                                </executions>
                        </plugin>
 
+                       <!--
+                               Relocate ASM from 'org.objectweb.asm' to 'aj.org.objectweb.asm'
+
+                               TODO: Using Maven Shade after Maven Assembly instead of creating uber JAR and relocating package names at the
+                                 same time is suboptimal and maybe slower than doing both at the same time. Migrating from Assembly to Shade
+                                 requires all dependencies to produce source JARs, though, which currently is not the case. Because we also
+                                 want to create a complete source JAR, for now we keep Assembly around, because it manually copies project
+                                 sources from their respective directories before zipping them up.
+                       -->
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-shade-plugin</artifactId>
+                               <configuration>
+                                       <createSourcesJar>true</createSourcesJar>
+                                       <createDependencyReducedPom>false</createDependencyReducedPom>
+                                       <shadedArtifactAttached>false</shadedArtifactAttached>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>asm-relocate</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>shade</goal>
+                                               </goals>
+                                               <configuration>
+                                                       <minimizeJar>false</minimizeJar>
+                                                       <shadeSourcesContent>true</shadeSourcesContent>
+                                                       <artifactSet>
+                                                               <includes>
+                                                                       <include>${project.groupId}:${project.artifactId}</include>
+                                                               </includes>
+                                                       </artifactSet>
+                                                       <relocations>
+                                                               <relocation>
+                                                                       <pattern>org.objectweb.asm</pattern>
+                                                                       <shadedPattern>aj.org.objectweb.asm</shadedPattern>
+                                                               </relocation>
+                                                       </relocations>
+                                               </configuration>
+                                       </execution>
+                               </executions>
+                       </plugin>
+
                        <!-- Caveat: Attaching the flattened POM needs packaging=jar, so do not use packaging=pom for this module -->
                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                        <version>${project.version}</version>
                </dependency>
                <dependency>
-                       <groupId>org.aspectj</groupId>
-                       <artifactId>asm-renamed</artifactId>
+                       <groupId>org.ow2.asm</groupId>
+                       <artifactId>asm</artifactId>
                </dependency>
        </dependencies>
 
index ae0645a92a44aac3d6147a79b36e40279d096659..7bc38c2fc18e64c732c86d8c5f97ad816c496ed9 100644 (file)
@@ -38,8 +38,8 @@
                        <version>${project.version}</version>
                </dependency>
                <dependency>
-                       <groupId>org.aspectj</groupId>
-                       <artifactId>asm-renamed</artifactId>
+                       <groupId>org.ow2.asm</groupId>
+                       <artifactId>asm</artifactId>
                </dependency>
                <dependency>
                        <groupId>org.aspectj</groupId>
index 747fce918d413ee9f987f3711ad05e9f569c2592..6117b1580a8f4acc207cea1fa1504d847c399d5c 100644 (file)
@@ -64,8 +64,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
   </dependencies>
 
index 6a93731a58fba4f2db5117dc3cddf68287a69df6..22db23d17be3dedc90fbeddbbb87793085cb7929 100644 (file)
@@ -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"
index c1d3a1fe4a5ec4bbb0bf3874cbf09fa907558bce..7a3f8abe973201756843c662ec79c5f03da2de24 100644 (file)
                        <scope>test</scope>
                </dependency>
                <dependency>
-                       <groupId>org.aspectj</groupId>
-                       <artifactId>asm-renamed</artifactId>
+                       <groupId>org.ow2.asm</groupId>
+                       <artifactId>asm</artifactId>
                        <scope>test</scope>
                </dependency>
                <dependency>
                                        <usedDependencies>
                                                <!-- The tests need these during runtime, even though no direct usage is in our classes -->
                                                <usedDependency>ant:ant-launcher</usedDependency>
-                                               <usedDependency>org.aspectj:asm-renamed</usedDependency>
+                                               <usedDependency>org.ow2.asm:asm</usedDependency>
                                                <usedDependency>org.aspectj:ajde</usedDependency>
                                                <usedDependency>org.aspectj:build</usedDependency>
                                                <usedDependency>org.aspectj:tests</usedDependency>
index d44faf2ca3719255c0c32bc6d5983c5170451c53..39e120e213113aed6b17e653e3c3f5cdc81cea28 100644 (file)
@@ -39,8 +39,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
     <dependency>
       <!-- Identical to lib/ant/lib/ant.jar, a former system-scoped dependency -->
index d15888cefc915d428cbce48ae12b8c1f71ea46ee..b252d276ab258431912ca17f80a617a2c52f9d11 100644 (file)
@@ -35,8 +35,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
   </dependencies>
 
index dfd9758381cb058e1fa6200df538fcfd142bbc03..335da941de7b213a9cfb0144b017f90bf905aeab 100644 (file)
@@ -49,8 +49,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
     <dependency>
       <groupId>org.aspectj</groupId>
index 95f9e2712854f9838f94e495038e599b3b32b0d2..066b30b053b291121edda7971c80203a9ed57997 100644 (file)
@@ -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 <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
index 95f91d838c3caa0f4bf73e0878bc59aeb2254a5d..99d1809ec7b1be16242ba891b9407f6c15c57e41 100644 (file)
@@ -40,8 +40,8 @@
                        <version>${project.version}</version>
                </dependency>
                <dependency>
-                       <groupId>org.aspectj</groupId>
-                       <artifactId>asm-renamed</artifactId>
+                       <groupId>org.ow2.asm</groupId>
+                       <artifactId>asm</artifactId>
                </dependency>
                <dependency>
                        <groupId>org.aspectj</groupId>
index b812ffba1b886ca799e5fc404aa010c04e7ab7c6..f47c1ddc50f3694c6dab3b086ed8edccc29f28ff 100644 (file)
@@ -62,8 +62,8 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
-      <groupId>org.aspectj</groupId>
-      <artifactId>asm-renamed</artifactId>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm</artifactId>
     </dependency>
   </dependencies>
 </project>
index 5e72d84ce8ceed70eb709b281e74f6d9e5d03921..22c7945f0c189b949fe1a04d7db0f37a53182153 100644 (file)
@@ -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);
                }
index 5d5bb6990c67a29acff54eb82fc37e2b55a0be4b..5fa7bd006c0266ccea8bacf090a7ac7d1c05282a 100644 (file)
  * ******************************************************************/
 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");
        }
 }
index 1de90f8888175b946ecf962671b3823fda29f44a..07f3435aeb49310f5e37a4f5436e1a6a3a069ca0 100644 (file)
@@ -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