You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Agent.java 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*******************************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Common Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * http://www.eclipse.org/legal/cpl-v10.html
  7. *
  8. * Contributors:
  9. * Alexandre Vasseur initial implementation
  10. *******************************************************************************/
  11. package org.aspectj.weaver.loadtime;
  12. import java.lang.instrument.Instrumentation;
  13. import java.lang.instrument.ClassFileTransformer;
  14. /**
  15. * Java 1.5 preMain agent to hook in the class pre processor
  16. * Can be used with -javaagent:aspectjweaver.jar
  17. *
  18. * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur</a>
  19. */
  20. public class Agent {
  21. /**
  22. * The instrumentation instance
  23. */
  24. private static Instrumentation s_instrumentation;
  25. /**
  26. * The ClassFileTransformer wrapping the weaver
  27. */
  28. private static ClassFileTransformer s_transformer = new ClassPreProcessorAgentAdapter();
  29. /**
  30. * JSR-163 preMain Agent entry method
  31. *
  32. * @param options
  33. * @param instrumentation
  34. */
  35. public static void premain(String options, Instrumentation instrumentation) {
  36. s_instrumentation = instrumentation;
  37. s_instrumentation.addTransformer(s_transformer);
  38. }
  39. /**
  40. * Returns the Instrumentation system level instance
  41. */
  42. public static Instrumentation getInstrumentation() {
  43. if (s_instrumentation == null) {
  44. throw new UnsupportedOperationException("Java 5 was not started with preMain -javaagent for AspectJ");
  45. }
  46. return s_instrumentation;
  47. }
  48. }