1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package net.sf.infrared.tools.weaving; |
23 |
|
|
24 |
|
import java.io.File; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.Set; |
27 |
|
import org.apache.tools.ant.BuildException; |
28 |
|
import org.codehaus.aspectwerkz.compiler.AspectWerkzC; |
29 |
|
import org.codehaus.aspectwerkz.compiler.CompileException; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
public class Aw2System extends AbstractAspectSystem { |
36 |
|
private AspectWerkzC compiler; |
37 |
|
|
38 |
0 |
private boolean loggedOnce = false; |
39 |
|
|
40 |
0 |
public Aw2System() { |
41 |
0 |
compiler = new AspectWerkzC(); |
42 |
|
try { |
43 |
0 |
compiler.setPreprocessor("org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor"); |
44 |
0 |
} catch (CompileException ex) { |
45 |
0 |
throw new BuildException("Failed to set AW preprocessor", ex); |
46 |
0 |
} |
47 |
0 |
compiler.setHaltOnError(true); |
48 |
0 |
compiler.setVerbose(false); |
49 |
0 |
compiler.setVerify(false); |
50 |
|
|
51 |
|
|
52 |
0 |
} |
53 |
|
|
54 |
|
public void instrumentJars(File[] jars) { |
55 |
0 |
if (! loggedOnce) { |
56 |
0 |
getLogger().verbose("[Aw2] Setup: " + |
57 |
|
"\n\t AspectPath = " + getAspectPathAsString() + |
58 |
|
"\n\t ClassPath = " + getClassPathAsString()); |
59 |
0 |
loggedOnce = true; |
60 |
|
} |
61 |
|
|
62 |
0 |
Set cp = new HashSet(); |
63 |
0 |
cp.addAll(getClassPath()); |
64 |
0 |
cp.addAll(getAspectPath()); |
65 |
|
|
66 |
0 |
compiler.setCompilationPath((File[]) cp.toArray(new File[0]), getClass().getClassLoader()); |
67 |
|
|
68 |
0 |
for (int i = 0; i < jars.length; i++) { |
69 |
|
try { |
70 |
0 |
compiler.compileJar(jars[i]); |
71 |
0 |
getLogger().verbose("[Aw2] Instrumented jar " + jars[i].getAbsolutePath()); |
72 |
0 |
} catch (CompileException ex) { |
73 |
0 |
throw new BuildException("Error in compiling jars", ex); |
74 |
0 |
} |
75 |
|
} |
76 |
0 |
} |
77 |
|
|
78 |
|
public void instrumentClasses(File[] classes, String[] packaging) { |
79 |
0 |
if (! loggedOnce) { |
80 |
0 |
getLogger().verbose("[Aw2] Setup: " + |
81 |
|
"\n\t AspectPath = " + getAspectPathAsString() + |
82 |
|
"\n\t ClassPath = " + getClassPathAsString()); |
83 |
0 |
loggedOnce = true; |
84 |
|
} |
85 |
|
|
86 |
0 |
for (int i = 0; i < classes.length; i++) { |
87 |
|
try { |
88 |
0 |
compiler.compileClass(classes[i], packaging[i]); |
89 |
0 |
} catch (CompileException ex) { |
90 |
0 |
throw new BuildException("Error in compiling class " + |
91 |
|
packaging[i] + "." + classes[i].getName() + "; " + |
92 |
|
"the most common cause is due to all extra classes referenced from the " + |
93 |
|
"application not being added to 'extraclasspath' of the infrared task", ex); |
94 |
0 |
} |
95 |
|
} |
96 |
0 |
getLogger().verbose("[Aw2] Instrumented jar " + classes.length + " classes"); |
97 |
0 |
} |
98 |
|
} |