Search in sources :

Example 1 with JavaStubCompilationUnit

use of org.codehaus.groovy.tools.javac.JavaStubCompilationUnit in project groovy by apache.

the class GenerateStubsTask method compile.

@Override
protected void compile() {
    GroovyClassLoader gcl = createClassLoader();
    JavaStubCompilationUnit cu = 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]);
            cu.addSource(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);
        cu.compile();
        log.info("Generated " + cu.getStubCount() + " Java stub(s)");
    } else {
        log.info("No sources found for stub generation");
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) JavaStubCompilationUnit(org.codehaus.groovy.tools.javac.JavaStubCompilationUnit) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 2 with JavaStubCompilationUnit

use of org.codehaus.groovy.tools.javac.JavaStubCompilationUnit in project groovy-core by groovy.

the class GenerateStubsTask method compile.

@Override
protected void compile() {
    GroovyClassLoader gcl = createClassLoader();
    JavaStubCompilationUnit cu = 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]);
            cu.addSource(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);
        cu.compile();
        log.info("Generated " + cu.getStubCount() + " Java stub(s)");
    } else {
        log.info("No sources found for stub generation");
    }
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) JavaStubCompilationUnit(org.codehaus.groovy.tools.javac.JavaStubCompilationUnit) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)2 File (java.io.File)2 BuildException (org.apache.tools.ant.BuildException)2 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)2 JavaStubCompilationUnit (org.codehaus.groovy.tools.javac.JavaStubCompilationUnit)2