1 package attrib4j.ant;
2
3 import org.apache.tools.ant.BuildException;
4 import org.apache.tools.ant.taskdefs.Javac;
5 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
6 import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
7
8 /***
9 * A first shot at implementing a compiler adapter so that compiling with
10 * attributes very easy to invoke from within Ant. This might also be
11 * implemented using an an build listener when the javac task finishes.
12 *
13 * @author <a href="mailto:mark.pollack@codestreet.com">Mark Pollack</a>
14 *
15 */
16 public class Attrib4jCompilerAdapter implements CompilerAdapter {
17
18 /***
19 * A reference to the Javac task set by the Ant runtime.
20 */
21 private Javac _javac;
22
23 /***
24 * Set the Javac task.
25 * @see org.apache.tools.ant.taskdefs.compilers.CompilerAdapter#setJavac(org.apache.tools.ant.taskdefs.Javac)
26 */
27 public void setJavac(Javac javac) {
28 _javac = javac;
29
30 }
31
32 /***
33 * Run the normal javac task, then extract parameters from the javac task and run
34 * the attrib4j task.
35 * @see org.apache.tools.ant.taskdefs.compilers.CompilerAdapter#execute()
36 */
37 public boolean execute() throws BuildException {
38
39 //TODO mimic the decision logic to determine which 'original' compiler adapter to run....
40 //if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4) {
41 String compilerFactorySwitch = "javac1.4";
42
43 //Need to pass in javac just so it can have access to logging facility.
44 CompilerAdapter originalAdapter =
45 CompilerAdapterFactory.getCompiler(compilerFactorySwitch, _javac);
46 originalAdapter.setJavac(_javac);
47 boolean javacOK = originalAdapter.execute();
48
49 if (javacOK = false) {
50 return false;
51 } else {
52
53 //At this point, javac has been called....
54
55 Attrib4jTask aTask = new Attrib4jTask();
56 String err = aTask.setupAttrib4j(_javac);
57 if (null != err) {
58 throw new BuildException(err, _javac.getLocation());
59 }
60 aTask.execute();
61
62 return true;
63 }
64
65 }
66
67 }
This page was automatically generated by Maven