AptCompilerAdapterpublic class AptCompilerAdapter extends DefaultCompilerAdapter The implementation of the apt compiler for JDK 1.5
As usual, the low level entry points for Java tools are neither documented or
stable; this entry point may change from that of 1.5.0_01-b08 without any
warning at all. The IDE decompile of the tool entry points is as follows:
public class Main {
public Main() ;
public static transient void main(String... strings) ;
public static transient int process(String... strings);
public static transient int process(PrintWriter printWriter,
String... strings) ;
public static transient int process(
AnnotationProcessorFactory annotationProcessorFactory,
String... strings) ;
public static transient int process(
AnnotationProcessorFactory annotationProcessorFactory,
PrintWriter printWriter,
String... strings);
private static transient int processing(
AnnotationProcessorFactory annotationProcessorFactory,
PrintWriter printWriter,
String... strings) ;
}
This Adapter is designed to run Apt in-JVM, an option that is not actually
exposed to end-users, because it was too brittle during beta testing; classpath
problems being the core issue. |
Fields Summary |
---|
private static final int | APT_COMPILER_SUCCESSInteger returned by the Apt compiler to indicate success. | public static final String | APT_ENTRY_POINTclass in tools.jar that implements APT | public static final String | APT_METHOD_NAMEmethod used to compile. |
Methods Summary |
---|
public boolean | execute()Run the compilation.
attributes.log("Using apt compiler", Project.MSG_VERBOSE);
//set up the javac options
Commandline cmd = setupModernJavacCommand();
//then add the Apt options
setAptCommandlineSwitches(cmd);
//finally invoke APT
// Use reflection to be able to build on all JDKs:
try {
Class c = Class.forName(APT_ENTRY_POINT);
Object compiler = c.newInstance();
Method compile = c.getMethod(APT_METHOD_NAME,
new Class[]{(new String[]{}).getClass()});
int result = ((Integer) compile.invoke
(compiler, new Object[]{cmd.getArguments()}))
.intValue();
return (result == APT_COMPILER_SUCCESS);
} catch (BuildException be) {
//rethrow build exceptions
throw be;
} catch (Exception ex) {
//cast everything else to a build exception
throw new BuildException("Error starting apt compiler",
ex, location);
}
| protected org.apache.tools.ant.taskdefs.Apt | getApt()Get the facade task that fronts this adapter
return (Apt) getJavac();
| static void | setAptCommandlineSwitches(org.apache.tools.ant.taskdefs.Apt apt, org.apache.tools.ant.types.Commandline cmd)Using the front end arguments, set up the command line to run Apt
if (!apt.isCompile()) {
cmd.createArgument().setValue("-nocompile");
}
// Process the factory class
String factory = apt.getFactory();
if (factory != null) {
cmd.createArgument().setValue("-factory");
cmd.createArgument().setValue(factory);
}
// Process the factory path
Path factoryPath = apt.getFactoryPath();
if (factoryPath != null) {
cmd.createArgument().setValue("-factorypath");
cmd.createArgument().setPath(factoryPath);
}
File preprocessDir = apt.getPreprocessDir();
if (preprocessDir != null) {
cmd.createArgument().setValue("-s");
cmd.createArgument().setFile(preprocessDir);
}
// Process the processor options
Vector options = apt.getOptions();
Enumeration elements = options.elements();
Apt.Option opt;
StringBuffer arg = null;
while (elements.hasMoreElements()) {
opt = (Apt.Option) elements.nextElement();
arg = new StringBuffer();
arg.append("-A").append(opt.getName());
if (opt.getValue() != null) {
arg.append("=").append(opt.getValue());
}
cmd.createArgument().setValue(arg.toString());
}
| protected void | setAptCommandlineSwitches(org.apache.tools.ant.types.Commandline cmd)using our front end task, set up the command line switches
Apt apt = getApt();
setAptCommandlineSwitches(apt, cmd);
|
|