/* *******************************************************************
* Copyright (c) 2004 IBM Corporation
- * 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://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Webster, Adrian Colyer,
- * Martin Lippert initial implementation
+ * 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Webster, Adrian Colyer,
+ * Martin Lippert initial implementation
* Andy Clement
* Abraham Nevado
* ******************************************************************/
public WeavingURLClassLoader(URL[] urls, ClassLoader parent) {
super(urls, parent);
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.enter("<init>", this, new Object[] { urls, parent });
+ }
// System.out.println("WeavingURLClassLoader.WeavingURLClassLoader()");
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.exit("<init>");
+ }
}
public WeavingURLClassLoader(URL[] classURLs, URL[] aspectURLs, ClassLoader parent) {
}
private static URL[] getURLs(String path) {
- List urlList = new ArrayList();
+ List<URL> urlList = new ArrayList<>();
for (StringTokenizer t = new StringTokenizer(path, File.pathSeparator); t.hasMoreTokens();) {
File f = new File(t.nextToken().trim());
try {
if (f.exists()) {
URL url = f.toURL();
- if (url != null)
+ if (url != null) {
urlList.add(url);
+ }
}
} catch (MalformedURLException e) {
}
* Override to weave class using WeavingAdaptor
*/
protected Class defineClass(String name, byte[] b, CodeSource cs) throws IOException {
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.enter("defineClass", this, new Object[] { name, b, cs });
+ }
// System.err.println("? WeavingURLClassLoader.defineClass(" + name + ", [" + b.length + "])");
byte orig[] = b;
/* Avoid recursion during adaptor initialization */
}
}
Class clazz;
-
+
// On error, define the original form of the class and log the issue
- try {
+ try {
clazz= super.defineClass(name, b, cs);
} catch (Throwable th) {
trace.error("Weaving class problem. Original class has been returned. The error was caused because of: " + th, th);
clazz= super.defineClass(name, orig, cs);
}
- if (trace.isTraceEnabled())
+ if (trace.isTraceEnabled()) {
trace.exit("defineClass", clazz);
+ }
return clazz;
}
// private interface ClassPreProcessorAdaptor extends ClassPreProcessor {
// public void addURL(URL url);
// }
- //
+ //
// private class WeavingAdaptorPreProcessor implements ClassPreProcessorAdaptor {
- //
+ //
// private WeavingAdaptor adaptor;
- //
+ //
// public WeavingAdaptorPreProcessor (WeavingClassLoader wcl) {
// adaptor = new WeavingAdaptor(wcl);
// }
- //
+ //
// public void initialize() {
// }
//
// }
//
// public void addURL(URL url) {
- //
+ //
// }
// }
/*
* Aspects on ASPECTPATH but missing from CLASSPATH
*/
- public void testIncompletePath() {
+ public void testIncompletePath() throws Exception {
System.out.println("ADVICE_ASPECTS exists? " + new File(ADVICE_ASPECTS).exists());
System.out.println("ASPECTJRT exists? " + new File(ASPECTJRT).exists());
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH, ADVICE_ASPECTS+File.pathSeparator+new File(ASPECTJRT).toString());
- setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH, CLASSES_JAR);
+ setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,
+ CLASSES_JAR + File.pathSeparator + new File(ASPECTJRT).toString());
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader());
-
+ Class<?> loadClass = loader.loadClass("org.aspectj.lang.JoinPoint$StaticPart");
+ System.out.println("JPSP: " + loadClass);
try {
Class<?> clazz = loader.loadClass("LTWHelloWorld");
invokeMain(clazz, new String[] { "LTWAspect" });