Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Agent.java 1.7KB

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