Permalink
Browse files

modified the aspectj example to use build-time weaving

  • Loading branch information...
1 parent 30de4fa commit 40cbe75cd41e7c8b9f1d69fcea84893ecdbdabde Jakub Holy committed Apr 13, 2011
Showing with 79 additions and 7 deletions.
  1. +3 −1 README
  2. +44 −0 aspectj-inject-build.xml
  3. +32 −6 pom.xml
View
@@ -27,7 +27,9 @@ I've been using Maven 2.2.1.
*## java -classpath /path/to/javassist-3.14.0-GA.jar:/path/to/classes iterate.jz2011.codeinjection.javassist.JavassistInstrumenter
*## java -classpath target/javassist:/path/to/classes iterate.jz2011.codeinjection.javassist.Main
*# AspectJ:
-*## java "-javaagent:/path/to/aspectjweaver.jar" -classpath "/path/to/classes:/path/to/aspectjrt-1.6.10.jar" iterate.jz2011.codeinjection.aspectj.Main
+*## In aspectj-inject-build.xml define maven.plugin.classpath as described
+*## ant -f aspectj-inject-build.xml
+*## java -classpath "/path/to/classes:/path/to/aspectjrt-1.6.10.jar" iterate.jz2011.codeinjection.aspectj.Main
Dependencies for the Java Proxy example:
+- net.jakubholy.testing:dbunit-embeddedderby-parenttest:jar:1.2.0:compile
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="aspectj_code_injection" default="inject_binaries">
+ <description>
+ Inject the AspectJ aspect into the compiled target .class via AspectJ Ant task
+ </description>
+
+ <!-- =================================
+ target: inject_binaries
+ ================================= -->
+ <target name="inject_binaries">
+
+ <!--
+ This build must be run from Maven to have the maven classpath references defined!
+ Otherwise you'd need to define them yourselfm similarly to:
+
+ <path id="maven.plugin.classpath">
+ <pathelement location="${user.home}/.m2/repository/org/aspectj/aspectjtools/1.6.10/aspectjtools-1.6.10.jar"/>
+ </path>
+ <path id="maven.compile.classpath">
+ <pathelement location="${user.home}/.m2/repository/org/aspectj/aspectjrt/1.6.10/aspectjrt-1.6.10.jar"/>
+ <pathelement location="target/classes"/>
+ </path>
+ -->
+
+ <taskdef
+ resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"
+ classpathref="maven.plugin.classpath" />
+
+ <iajc
+ inpath="target/classes"
+ destDir="target/classes"
+ verbose="false"
+ showWeaveInfo="true"
+ source="1.6"
+ classpathRef="maven.compile.classpath"
+ Xlint="ignore">
+
+ <exclude name="iterate/jz2011/codeinjection/aspectj/LoggingAspect.java" />
+ </iajc>
+
+ <echo id="inject_binaries" level="info">ANT has finished injecting AspectJ aspects into classes in target/classes/</echo>
+ </target>
+
+</project>
View
@@ -108,6 +108,33 @@
</plugin>
<plugin>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>1.6</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjtools</artifactId> <!-- contains the AspectJ Ant plugin -->
+ <version>1.6.10</version>
+ </dependency>
+ </dependencies>
+
+ <executions>
+ <execution>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <target>
+ <!-- inheritRefs=true to pass in the maven classpath refs -->
+ <ant antfile="aspectj-inject-build.xml" inheritRefs="true" />
+ </target>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
@@ -122,7 +149,10 @@
<configuration>
<executable>java</executable>
<arguments>
+
+ <!-- Aspect woven staticaly by Maven => no need for the load-time weaving agentlib:
<argument>-javaagent:${project.build.directory}/aspectj/aspectjweaver.jar</argument>
+ -->
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
@@ -181,12 +211,8 @@
</goals>
<configuration>
<mainClass>iterate.jz2011.codeinjection.javassist.JavassistInstrumenter</mainClass>
- <!-- Optional: run the other method
- <arguments>
- <argument>iterate.jz2011.codeinjection.javassist.TargetClass</argument>
- <argument>myMethodSlower</argument>
- </arguments>
- -->
+ <!-- Optional: run the other method <arguments> <argument>iterate.jz2011.codeinjection.javassist.TargetClass</argument>
+ <argument>myMethodSlower</argument> </arguments> -->
</configuration>
</execution>
<execution>

0 comments on commit 40cbe75

Please sign in to comment.