Search in sources :

Example 6 with GlobPatternMapper

use of org.apache.tools.ant.util.GlobPatternMapper in project groovy by apache.

the class Groovyc method scanDir.

/**
 * Scans the directory looking for source files to be compiled.
 * The results are returned in the class variable compileList
 *
 * @param srcDir  The source directory
 * @param destDir The destination directory
 * @param files   An array of filenames
 */
protected void scanDir(File srcDir, File destDir, String[] files) {
    GlobPatternMapper m = new GlobPatternMapper();
    SourceFileScanner sfs = new SourceFileScanner(this);
    File[] newFiles;
    for (String extension : getScriptExtensions()) {
        m.setFrom("*." + extension);
        m.setTo("*.class");
        newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
        addToCompileList(newFiles);
    }
    if (jointCompilation) {
        m.setFrom("*.java");
        m.setTo("*.class");
        newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
        addToCompileList(newFiles);
    }
}
Also used : GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 7 with GlobPatternMapper

use of org.apache.tools.ant.util.GlobPatternMapper in project groovy by apache.

the class GroovycTask method compile.

@Override
protected void compile() {
    Path path = getClasspath();
    if (path != null) {
        config.setClasspath(path.toString());
    }
    config.setTargetDirectory(destdir);
    GroovyClassLoader gcl = createClassLoader();
    CompilationUnit compilation = new CompilationUnit(config, null, gcl);
    GlobPatternMapper mapper = new GlobPatternMapper();
    mapper.setFrom("*.groovy");
    mapper.setTo("*.class");
    int count = 0;
    String[] list = src.list();
    for (String s : list) {
        File basedir = getProject().resolveFile(s);
        if (!basedir.exists()) {
            throw new BuildException("Source directory does not exist: " + basedir, getLocation());
        }
        DirectoryScanner scanner = getDirectoryScanner(basedir);
        String[] includes = scanner.getIncludedFiles();
        if (force) {
            log.debug("Forcefully including all files from: " + basedir);
            for (String include : includes) {
                File file = new File(basedir, include);
                log.debug("    " + file);
                compilation.addSource(file);
                count++;
            }
        } else {
            log.debug("Including changed files from: " + basedir);
            SourceFileScanner sourceScanner = new SourceFileScanner(this);
            File[] files = sourceScanner.restrictAsFiles(includes, basedir, destdir, mapper);
            for (File file : files) {
                log.debug("    " + file);
                compilation.addSource(file);
                count++;
            }
        }
    }
    if (count > 0) {
        log.info("Compiling " + count + " source file" + (count > 1 ? "s" : "") + " to " + destdir);
        compilation.compile();
    } else {
        log.info("No sources found to compile");
    }
}
Also used : Path(org.apache.tools.ant.types.Path) GroovyClassLoader(groovy.lang.GroovyClassLoader) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 8 with GlobPatternMapper

use of org.apache.tools.ant.util.GlobPatternMapper in project jangaroo-tools by CoreMedia.

the class ExmlcTask method scanDir.

/**
 * Scans the directory looking for source files to be compiled.
 * The results are returned in the class variable compileList
 *
 * @param srcDir  the source directory
 * @param destDir the destination directory
 * @param files   the files to scan
 */
protected void scanDir(File srcDir, File destDir, String[] files) {
    GlobPatternMapper m = new GlobPatternMapper();
    m.setFrom("*.exml");
    m.setTo("*.as");
    SourceFileScanner sfs = new SourceFileScanner(this);
    File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
    if (newFiles.length > 0) {
        File[] newCompileList = new File[compileList.length + newFiles.length];
        System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
        System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
        compileList = newCompileList;
    }
}
Also used : GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 9 with GlobPatternMapper

use of org.apache.tools.ant.util.GlobPatternMapper in project jangaroo-tools by CoreMedia.

the class JoocTask method scanDir.

/**
 * Scans the directory looking for source files to be compiled.
 * The results are returned in the class variable compileList
 *
 * @param srcDir  the source directory
 * @param destDir the destination directory
 * @param files   the files to scan
 */
protected void scanDir(File srcDir, File destDir, String[] files) {
    GlobPatternMapper m = new GlobPatternMapper();
    m.setFrom("*" + Jooc.INPUT_FILE_SUFFIX);
    m.setTo("*.js");
    SourceFileScanner sfs = new SourceFileScanner(this);
    File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
    if (newFiles.length > 0) {
        File[] newCompileList = new File[compileList.length + newFiles.length];
        System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
        System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
        compileList = newCompileList;
    }
}
Also used : GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Example 10 with GlobPatternMapper

use of org.apache.tools.ant.util.GlobPatternMapper in project groovy-core by groovy.

the class GroovycTask method compile.

protected void compile() {
    Path path = getClasspath();
    if (path != null) {
        config.setClasspath(path.toString());
    }
    config.setTargetDirectory(destdir);
    GroovyClassLoader gcl = createClassLoader();
    CompilationUnit compilation = new CompilationUnit(config, null, gcl);
    GlobPatternMapper mapper = new GlobPatternMapper();
    mapper.setFrom("*.groovy");
    mapper.setTo("*.class");
    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();
        if (force) {
            log.debug("Forcefully including all files from: " + basedir);
            for (int j = 0; j < includes.length; j++) {
                File file = new File(basedir, includes[j]);
                log.debug("    " + file);
                compilation.addSource(file);
                count++;
            }
        } else {
            log.debug("Including changed files from: " + basedir);
            SourceFileScanner sourceScanner = new SourceFileScanner(this);
            File[] files = sourceScanner.restrictAsFiles(includes, basedir, destdir, mapper);
            for (int j = 0; j < files.length; j++) {
                log.debug("    " + files[j]);
                compilation.addSource(files[j]);
                count++;
            }
        }
    }
    if (count > 0) {
        log.info("Compiling " + count + " source file" + (count > 1 ? "s" : "") + " to " + destdir);
        compilation.compile();
    } else {
        log.info("No sources found to compile");
    }
}
Also used : Path(org.apache.tools.ant.types.Path) GroovyClassLoader(groovy.lang.GroovyClassLoader) CompilationUnit(org.codehaus.groovy.control.CompilationUnit) GlobPatternMapper(org.apache.tools.ant.util.GlobPatternMapper) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) File(java.io.File)

Aggregations

GlobPatternMapper (org.apache.tools.ant.util.GlobPatternMapper)11 File (java.io.File)9 SourceFileScanner (org.apache.tools.ant.util.SourceFileScanner)8 BuildException (org.apache.tools.ant.BuildException)4 FileNameMapper (org.apache.tools.ant.util.FileNameMapper)3 MergingMapper (org.apache.tools.ant.util.MergingMapper)3 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)2 Path (org.apache.tools.ant.types.Path)2 ChainedMapper (org.apache.tools.ant.util.ChainedMapper)2 FlatFileNameMapper (org.apache.tools.ant.util.FlatFileNameMapper)2 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)2 Test (org.junit.Test)2 List (java.util.List)1 Resource (org.apache.tools.ant.types.Resource)1 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)1 ArchiveResource (org.apache.tools.ant.types.resources.ArchiveResource)1 FileResource (org.apache.tools.ant.types.resources.FileResource)1 ZipResource (org.apache.tools.ant.types.resources.ZipResource)1 IdentityMapper (org.apache.tools.ant.util.IdentityMapper)1