public class GenerateStubsTask
extends CompileTaskSupport
{
protected void compile() {
GroovyClassLoader gcl = createClassLoader();
JavaStubCompilationUnit compilation = new JavaStubCompilationUnit(config, gcl, destdir);
int count = 0;
String[] list = src.list();
for (int i = 0; i < list.length; i++) {
File basedir = getProject().resolveFile(list[i]);
if (!basedir.exists()) {
throw new BuildException("Source directory does not exist: " + basedir, getLocation());
}
DirectoryScanner scanner = getDirectoryScanner(basedir);
String[] includes = scanner.getIncludedFiles();
log.debug("Including files from: " + basedir);
for (int j=0; j < includes.length; j++) {
log.debug(" " + includes[j]);
File file = new File(basedir, includes[j]);
compilation.addSourceFile(file);
// Increment the count for each non/java src we found
if (!includes[j].endsWith(".java")) {
count++;
}
}
}
if (count > 0) {
log.info("Generating " + count + " Java stub" + (count > 1 ? "s" : "") + " to " + destdir);
// Generate the stubs
compilation.compile(Phases.CONVERSION);
}
else {
log.info("No sources found for stub generation");
}
}