@@ -0,0 +1,12 @@ | |||
Manifest-Version: 1.0 | |||
Automatic-Module-Name: org.aspectj.weaver | |||
Name: org/aspectj/weaver/ | |||
Specification-Title: AspectJ Weaver Classes | |||
Specification-Version: @build.version.short@ | |||
Specification-Vendor: @company.name@ | |||
Implementation-Title: org.aspectj.weaver | |||
Implementation-Version: @build.version.short@ | |||
Implementation-Vendor: @company.name@ | |||
Premain-Class: org.aspectj.weaver.loadtime.Agent | |||
Agent-Class: org.aspectj.weaver.loadtime.Agent | |||
Can-Redefine-Classes: true |
@@ -0,0 +1,67 @@ | |||
/******************************************************************************* | |||
* 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 Alexandre Vasseur | |||
* @author Alexander Kriegisch | |||
*/ | |||
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) { | |||
/* Handle duplicate agents */ | |||
if (s_instrumentation != null) { | |||
return; | |||
} | |||
s_instrumentation = instrumentation; | |||
s_instrumentation.addTransformer(s_transformer); | |||
} | |||
public static void agentmain(String options, Instrumentation instrumentation) { | |||
premain(options, instrumentation); | |||
} | |||
/** | |||
* Returns the Instrumentation system level instance | |||
*/ | |||
public static Instrumentation getInstrumentation() { | |||
if (s_instrumentation == null) { | |||
throw new UnsupportedOperationException( | |||
"AspectJ weaving agent was neither started via '-javaagent' (preMain) " + | |||
"nor attached via 'VirtualMachine.loadAgent' (agentMain)"); | |||
} | |||
return s_instrumentation; | |||
} | |||
} |
@@ -0,0 +1,53 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2005,2018 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 | |||
*******************************************************************************/ | |||
package org.aspectj.weaver.loadtime; | |||
import java.lang.instrument.ClassFileTransformer; | |||
import java.lang.instrument.IllegalClassFormatException; | |||
import java.security.ProtectionDomain; | |||
/** | |||
* Java 1.5 adapter for class pre processor | |||
* | |||
* @author Alexandre Vasseur | |||
* @author Andy Clement | |||
*/ | |||
public class ClassPreProcessorAgentAdapter implements ClassFileTransformer { | |||
private static ClassPreProcessor classPreProcessor; | |||
static { | |||
try { | |||
classPreProcessor = new Aj(); | |||
classPreProcessor.initialize(); | |||
} catch (Exception e) { | |||
throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString()); | |||
} | |||
} | |||
/** | |||
* Invokes the weaver to modify some set of input bytes. | |||
* | |||
* @param loader the defining class loader | |||
* @param className the name of class being loaded | |||
* @param classBeingRedefined is set when hotswap is being attempted | |||
* @param protectionDomain the protection domain for the class being loaded | |||
* @param bytes the incoming bytes (before weaving) | |||
* @return the woven bytes | |||
*/ | |||
@Override | |||
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, | |||
byte[] bytes) throws IllegalClassFormatException { | |||
if (classBeingRedefined != null) { | |||
System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'"); | |||
classPreProcessor.prepareForRedefinition(loader, className); | |||
} | |||
return classPreProcessor.preProcess(className, bytes, loader, protectionDomain); | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
package org.aspectj.loadtime; | |||
/******************************************************************************* | |||
* 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: (See CVS logs) | |||
* | |||
*******************************************************************************/ | |||
import org.aspectj.testing.util.TestUtil; | |||
import junit.framework.Test; | |||
import junit.framework.TestCase; | |||
import junit.framework.TestSuite; | |||
/** | |||
*/ | |||
public class Loadtime5ModuleTests extends TestCase { | |||
public static Test suite() { | |||
TestSuite suite = new TestSuite(Loadtime5ModuleTests.class.getName()); | |||
if (TestUtil.is15VMOrGreater()) { | |||
TestUtil.loadTestsReflectively(suite, "Loadtime515ModuleTests", true); | |||
} else { | |||
suite.addTest(TestUtil.testNamed("all tests require 1.5")); | |||
} | |||
return suite; | |||
} | |||
public static void main(String[] args) { | |||
junit.textui.TestRunner.main(new String[] {Loadtime5ModuleTests.class.getName()}); | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
/* ******************************************************************* | |||
* Copyright (c) 2005-2019 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 | |||
* ******************************************************************/ | |||
package org.aspectj.weaver.loadtime; | |||
import java.lang.instrument.Instrumentation; | |||
import junit.framework.TestCase; | |||
/** | |||
* @author Andy Clement | |||
* @author Wes Isberg | |||
*/ | |||
public class LoadtimeTest extends TestCase { | |||
public void testPremain() throws Exception { | |||
Class<?>[] paramTypes = {String.class, Instrumentation.class }; | |||
assertNotNull(Agent.class.getMethod("premain", paramTypes)); | |||
} | |||
} |