aboutsummaryrefslogtreecommitdiffstats
path: root/loadtime5
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-05-04 14:39:14 +0000
committeravasseur <avasseur>2005-05-04 14:39:14 +0000
commitd5d800b24cd16c1bb8b99e3216b30b6b3fbb56a4 (patch)
tree49191b075675450e5e01a75b047de4935c3253cd /loadtime5
parent70b9ffd2ceb86d00443d68931e8265ee9a8f8fa7 (diff)
downloadaspectj-d5d800b24cd16c1bb8b99e3216b30b6b3fbb56a4.tar.gz
aspectj-d5d800b24cd16c1bb8b99e3216b30b6b3fbb56a4.zip
loadtime5 java5 module
Diffstat (limited to 'loadtime5')
-rw-r--r--loadtime5/build.xml48
-rw-r--r--loadtime5/loadtime5.mf.txt2
-rw-r--r--loadtime5/src/org/aspectj/weaver/loadtime/Agent.java56
-rw-r--r--loadtime5/src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java63
4 files changed, 169 insertions, 0 deletions
diff --git a/loadtime5/build.xml b/loadtime5/build.xml
new file mode 100644
index 000000000..97a1e2d99
--- /dev/null
+++ b/loadtime5/build.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<project name="loadtime5" default="all" basedir=".">
+
+ <import file="../build/build-common.xml"/>
+ <import file="../asm/build.xml"/>
+ <import file="../bridge/build.xml"/>
+ <import file="../loadtime/build.xml"/>
+ <import file="../weaver/build.xml"/>
+ <import file="../util/build.xml"/>
+ <import file="../runtime/build.xml/"/>
+ <import file="../aspectj5rt/build.xml"/>
+
+ <path id="loadtime5.src.path">
+ <pathelement path="../asm/bin"/>
+ <pathelement path="../bridge/bin"/>
+ <pathelement path="../loadtime/bin"/>
+ <pathelement path="../weaver/bin"/>
+ <fileset dir="${basedir}/../lib">
+ <include name="bcel/*.jar"/>
+ </fileset>
+ </path>
+
+ <target name="compile" depends="init,
+ asm.compile,
+ bridge.compile,
+ loadtime.compile,
+ weaver.compile" if="jdk15">
+ <!-- FIXME: we override compile due to use of 1.5 -->
+ <mkdir dir="${basedir}/bin"/>
+ <javac debug="on" destdir="${basedir}/bin" source="1.5" target="1.5">
+ <src path="${basedir}/src"/>
+ <classpath refid="loadtime5.src.path"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="compile">
+ <delete file="${build.ajdir}/jars/loadtime5.jar"/>
+ <copy file="loadtime5.mf.txt" todir="${build.ajdir}/temp" filtering="yes"/>
+ <jar destfile="${build.ajdir}/jars/loadtime5.jar" manifest="${build.ajdir}/temp/loadtime5.mf.txt">
+ <fileset dir="bin">
+ <include name="**/*"/>
+ </fileset>
+ </jar>
+ <!-- FIXME AV we can push it to lib/test as well for the AntSpec need -->
+ </target>
+
+</project>
+
diff --git a/loadtime5/loadtime5.mf.txt b/loadtime5/loadtime5.mf.txt
new file mode 100644
index 000000000..fa19c87cc
--- /dev/null
+++ b/loadtime5/loadtime5.mf.txt
@@ -0,0 +1,2 @@
+Premain-Class: org.aspectj.weaver.loadtime.Agent
+Can-Redefine-Classes: true
diff --git a/loadtime5/src/org/aspectj/weaver/loadtime/Agent.java b/loadtime5/src/org/aspectj/weaver/loadtime/Agent.java
new file mode 100644
index 000000000..bb3489841
--- /dev/null
+++ b/loadtime5/src/org/aspectj/weaver/loadtime/Agent.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver.loadtime;
+
+import java.lang.instrument.Instrumentation;
+import java.lang.instrument.ClassFileTransformer;
+
+/**
+ * Java 1.5 preMain agent to hook in the class pre processor
+ * Can be used with -javaagent:aspectjweaver.jar
+ *
+ * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
+ */
+public class Agent {
+
+ /**
+ * The instrumentation instance
+ */
+ private static Instrumentation s_instrumentation;
+
+ /**
+ * The ClassFileTransformer wrapping the weaver
+ */
+ private static ClassFileTransformer s_transformer = new ClassPreProcessorAgentAdapter();
+
+ /**
+ * JSR-163 preMain Agent entry method
+ *
+ * @param options
+ * @param instrumentation
+ */
+ public static void premain(String options, Instrumentation instrumentation) {
+ s_instrumentation = instrumentation;
+ s_instrumentation.addTransformer(s_transformer);
+ }
+
+ /**
+ * Returns the Instrumentation system level instance
+ */
+ public static Instrumentation getInstrumentation() {
+ if (s_instrumentation == null) {
+ throw new UnsupportedOperationException("Java 5 was not started with preMain -javaagent for AspectJ");
+ }
+ return s_instrumentation;
+ }
+
+}
diff --git a/loadtime5/src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java b/loadtime5/src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java
new file mode 100644
index 000000000..9e81bd13d
--- /dev/null
+++ b/loadtime5/src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Alexandre Vasseur initial implementation
+ *******************************************************************************/
+package org.aspectj.weaver.loadtime;
+
+import org.aspectj.weaver.loadtime.Aj;
+import org.aspectj.weaver.loadtime.ClassPreProcessor;
+
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.security.ProtectionDomain;
+
+/**
+ * Java 1.5 adapter for class pre processor
+ *
+ * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
+ */
+public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
+
+ /**
+ * Concrete preprocessor.
+ */
+ private static ClassPreProcessor s_preProcessor;
+
+ static {
+ try {
+ s_preProcessor = new Aj();
+ s_preProcessor.initialize();
+ } catch (Exception e) {
+ throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
+ }
+ }
+
+ /**
+ * Weaving delegation
+ *
+ * @param loader the defining class loader
+ * @param className the name of class beeing loaded
+ * @param classBeingRedefined when hotswap is called
+ * @param protectionDomain
+ * @param bytes the bytecode before weaving
+ * @return the weaved bytecode
+ */
+ public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
+ ProtectionDomain protectionDomain, byte[] bytes) throws IllegalClassFormatException {
+ if (classBeingRedefined == null) {
+ return s_preProcessor.preProcess(className, bytes, loader);
+ } else {
+ //FIXME av for now we skip hotswap. We should think more about that
+ new Exception("AspectJ5 does not weave hotswapped class (" + className + ")").printStackTrace();
+ return bytes;
+ }
+ }
+
+}