if (cp == null) {
cp = "";
}
//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
String classdir = outdir + "/classes";
File outputLocationFile = new File(classdir);
outputLocationFile.mkdir();
Path classPath = new Path(codeGenProject, classdir);
classPath.add(new Path(codeGenProject, TEST_CLASSES_DIR));
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));
}
classPath.add(new Path(codeGenProject, cp));
javaCompiler.setClasspath(classPath);
//set sourcePath - The generated output directories also become part of the sourcepath
Path sourcePath = new Path(codeGenProject, outdir);
sourcePath.setLocation(outputLocationFile);
javaCompiler.setSrcdir(sourcePath);
//output the classes into the output dir as well
javaCompiler.setDestdir(outputLocationFile);
javaCompiler.setDebug(true);
javaCompiler.setVerbose(true);
javaCompiler.execute();
// codeGenProject.executeTarget(COMPILE_TARGET_NAME);
}