diff options
author | wisberg <wisberg> | 2005-05-11 09:33:34 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2005-05-11 09:33:34 +0000 |
commit | 21dda4b6e9e0111c53881bcfedc9833d63fee5a6 (patch) | |
tree | 439dce528aba878a8605c92540466d2feb37f496 /loadtime5/java5-src | |
parent | 7679c0851b89ffba34b5ec9d3b05511dcdc85d9c (diff) | |
download | aspectj-21dda4b6e9e0111c53881bcfedc9833d63fee5a6.tar.gz aspectj-21dda4b6e9e0111c53881bcfedc9833d63fee5a6.zip |
src -> java5-src; note test target runs AsmModuleTests, not Loadtime5ModuleTests - prior bug. See newbuild.xml.
Diffstat (limited to 'loadtime5/java5-src')
-rw-r--r-- | loadtime5/java5-src/org/aspectj/weaver/loadtime/Agent.java | 56 | ||||
-rw-r--r-- | loadtime5/java5-src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java | 63 |
2 files changed, 119 insertions, 0 deletions
diff --git a/loadtime5/java5-src/org/aspectj/weaver/loadtime/Agent.java b/loadtime5/java5-src/org/aspectj/weaver/loadtime/Agent.java new file mode 100644 index 000000000..bb3489841 --- /dev/null +++ b/loadtime5/java5-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/java5-src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java b/loadtime5/java5-src/org/aspectj/weaver/loadtime/ClassPreProcessorAgentAdapter.java new file mode 100644 index 000000000..9e81bd13d --- /dev/null +++ b/loadtime5/java5-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; + } + } + +} |