*
* @param outputLocation
*/
private void compile(String outputLocation){
//using the ant javac task for compilation
Javac javaCompiler = new Javac();
Project codeGenProject = new Project();
Target compileTarget = new Target();
compileTarget.setName(COMPILE_TARGET_NAME);
compileTarget.addTask(javaCompiler);
codeGenProject.addTarget(compileTarget);
codeGenProject.setSystemProperties();
javaCompiler.setProject(codeGenProject);
javaCompiler.setIncludejavaruntime(true);
javaCompiler.setIncludeantruntime(true);
/*
This harmless looking setFork is actually very important. unless the compiler is
forked it wont work!
*/
javaCompiler.setFork(true);
//Create classpath - The generated output directories also become part of the classpath
//reason for this is that some codegenerators(XMLBeans) produce compiled classes as part of
//generated artifacts
File outputLocationFile = new File(outputLocation);
Path classPath = new Path(codeGenProject,outputLocation) ;
classPath.addExisting(classPath.concatSystemClasspath(),false);
for (int i = 0; i < moduleNames.length; i++) {
classPath.add(new Path(codeGenProject,MODULE_PATH_PREFIX +moduleNames[i]+CLASSES_DIR));
}
javaCompiler.setClasspath(classPath);
//set sourcePath - The generated output directories also become part of the sourcepath
Path sourcePath = new Path(codeGenProject,outputLocation) ;
sourcePath.setLocation(outputLocationFile);
javaCompiler.setSrcdir(sourcePath);
//output the classes into the output dir as well
javaCompiler.setDestdir(outputLocationFile);
javaCompiler.setVerbose(true);
try {
codeGenProject.executeTarget(COMPILE_TARGET_NAME);
} catch (BuildException e) {
fail();
}