Search in sources :

Example 41 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project groovy by apache.

the class Groovyc method execute.

/**
     * Executes the task.
     *
     * @throws BuildException if an error occurs
     */
public void execute() throws BuildException {
    checkParameters();
    resetFileLists();
    loadRegisteredScriptExtensions();
    if (javac != null)
        jointCompilation = true;
    // scan source directories and dest directory to build up
    // compile lists
    String[] list = src.list();
    for (String filename : list) {
        File file = getProject().resolveFile(filename);
        if (!file.exists()) {
            throw new BuildException("srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
        }
        DirectoryScanner ds = this.getDirectoryScanner(file);
        String[] files = ds.getIncludedFiles();
        scanDir(file, destDir != null ? destDir : file, files);
    }
    compile();
    if (updatedProperty != null && taskSuccess && compileList.length != 0) {
        getProject().setNewProperty(updatedProperty, "true");
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 42 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project groovy by apache.

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)

Example 43 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project yui-compressor-ant-task by n0ha.

the class YuiCompressorTask method execute.

@Override
public void execute() {
    validateDirs();
    final DirectoryScanner ds = getDirectoryScanner(fromDir);
    final String[] files = ds.getIncludedFiles();
    for (final String file : files) {
        final File inFile = new File(fromDir.getAbsolutePath(), file);
        final String fileType = FileType.getFileType(file);
        if (fileType == null) {
            continue;
        }
        final File outFile = new File(toDir.getAbsolutePath(), file.replaceFirst(fileType + "$", newFileSuffix(fileType)));
        if (isEnabled()) {
            compressFile(inFile, outFile, fileType);
        } else {
            try {
                copyFile(inFile, outFile);
            } catch (final IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (verbose) {
        log(stats.getXmlStats());
        log(stats.getHtmlStats());
        log(stats.getXhtmlStats());
        log(stats.getJsStats());
        log(stats.getCssStats());
        log(stats.getTotalStats());
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException) File(java.io.File)

Example 44 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.

the class OperatorDiscoveryTest method getClassFileInClasspath.

public static String[] getClassFileInClasspath() {
    String classpath = System.getProperty("java.class.path");
    String[] paths = classpath.split(":");
    List<String> fnames = new LinkedList<>();
    for (String cp : paths) {
        File f = new File(cp);
        if (!f.isDirectory()) {
            continue;
        }
        DirectoryScanner ds = new DirectoryScanner();
        ds.setBasedir(f);
        ds.setIncludes(new String[] { "**\\*.class" });
        ds.scan();
        for (String name : ds.getIncludedFiles()) {
            fnames.add(new File(f, name).getAbsolutePath());
        }
    }
    return fnames.toArray(new String[] {});
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File) LinkedList(java.util.LinkedList)

Example 45 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.

the class ApexCli method expandFileNames.

private static String[] expandFileNames(String fileName) throws IOException {
    // TODO: need to work with other users
    if (fileName.matches("^[a-zA-Z]+:.*")) {
        // it's a URL
        return new String[] { fileName };
    }
    if (fileName.startsWith("~" + File.separator)) {
        fileName = System.getProperty("user.home") + fileName.substring(1);
    }
    fileName = new File(fileName).getCanonicalPath();
    LOG.debug("Canonical path: {}", fileName);
    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setIncludes(new String[] { fileName });
    scanner.scan();
    return scanner.getIncludedFiles();
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)57 File (java.io.File)52 BuildException (org.apache.tools.ant.BuildException)26 FileSet (org.apache.tools.ant.types.FileSet)26 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)12 GroovyClassLoader (groovy.lang.GroovyClassLoader)4 FileInputStream (java.io.FileInputStream)4 FilenameFilter (java.io.FilenameFilter)4 Project (org.apache.tools.ant.Project)4 DirSet (org.apache.tools.ant.types.DirSet)4 PatternSet (org.apache.tools.ant.types.PatternSet)4 LinkedList (java.util.LinkedList)3 Path (org.apache.tools.ant.types.Path)3 AbstractProject (hudson.model.AbstractProject)2 VirtualChannel (hudson.remoting.VirtualChannel)2 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2