11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2016 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .context .weaving ;
1818
19-
2019import java .lang .instrument .ClassFileTransformer ;
2120import java .lang .instrument .IllegalClassFormatException ;
2221import java .security .ProtectionDomain ;
4443public class AspectJWeavingEnabler
4544 implements BeanFactoryPostProcessor , BeanClassLoaderAware , LoadTimeWeaverAware , Ordered {
4645
46+ public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml" ;
47+
48+
4749 private ClassLoader beanClassLoader ;
4850
4951 private LoadTimeWeaver loadTimeWeaver ;
5052
51- public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml" ;
52-
5353
5454 @ Override
5555 public void setBeanClassLoader (ClassLoader classLoader ) {
@@ -71,6 +71,12 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
7171 enableAspectJWeaving (this .loadTimeWeaver , this .beanClassLoader );
7272 }
7373
74+
75+ /**
76+ * Enable AspectJ weaving with the given {@link LoadTimeWeaver}.
77+ * @param weaverToUse the LoadTimeWeaver to apply to (or {@code null} for a default weaver)
78+ * @param beanClassLoader the class loader to create a default weaver for (if necessary)
79+ */
7480 public static void enableAspectJWeaving (LoadTimeWeaver weaverToUse , ClassLoader beanClassLoader ) {
7581 if (weaverToUse == null ) {
7682 if (InstrumentationLoadTimeWeaver .isInstrumentationAvailable ()) {
@@ -80,8 +86,8 @@ public static void enableAspectJWeaving(LoadTimeWeaver weaverToUse, ClassLoader
8086 throw new IllegalStateException ("No LoadTimeWeaver available" );
8187 }
8288 }
83- weaverToUse .addTransformer (new AspectJClassBypassingClassFileTransformer (
84- new ClassPreProcessorAgentAdapter ()));
89+ weaverToUse .addTransformer (
90+ new AspectJClassBypassingClassFileTransformer ( new ClassPreProcessorAgentAdapter ()));
8591 }
8692
8793
@@ -108,4 +114,5 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
108114 return this .delegate .transform (loader , className , classBeingRedefined , protectionDomain , classfileBuffer );
109115 }
110116 }
117+
111118}
0 commit comments