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.

ClassPreProcessorAgentAdapter.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*******************************************************************************
  2. * Copyright (c) 2005,2018 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *******************************************************************************/
  9. package org.aspectj.weaver.loadtime;
  10. import java.lang.instrument.ClassFileTransformer;
  11. import java.lang.instrument.IllegalClassFormatException;
  12. import java.security.ProtectionDomain;
  13. /**
  14. * Java 1.5 adapter for class pre processor
  15. *
  16. * @author Alexandre Vasseur
  17. * @author Andy Clement
  18. */
  19. public class ClassPreProcessorAgentAdapter implements ClassFileTransformer {
  20. private static ClassPreProcessor classPreProcessor;
  21. static {
  22. try {
  23. classPreProcessor = new Aj();
  24. classPreProcessor.initialize();
  25. } catch (Exception e) {
  26. throw new ExceptionInInitializerError("could not initialize JSR163 preprocessor due to: " + e.toString());
  27. }
  28. }
  29. /**
  30. * Invokes the weaver to modify some set of input bytes.
  31. *
  32. * @param loader the defining class loader
  33. * @param className the name of class being loaded
  34. * @param classBeingRedefined is set when hotswap is being attempted
  35. * @param protectionDomain the protection domain for the class being loaded
  36. * @param bytes the incoming bytes (before weaving)
  37. * @return the woven bytes
  38. */
  39. @Override
  40. public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain,
  41. final byte[] bytes) throws IllegalClassFormatException {
  42. if (classBeingRedefined != null) {
  43. System.err.println("INFO: (Enh120375): AspectJ attempting reweave of '" + className + "'");
  44. classPreProcessor.prepareForRedefinition(loader, className);
  45. }
  46. return classPreProcessor.preProcess(className, bytes, loader, protectionDomain);
  47. }
  48. }