Search in sources :

Example 36 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project jetty.project by eclipse.

the class FileMatchingConfiguration method isIncluded.

/**
     * Checks if passed file is scanned by any of the directory scanners.
     * 
     * @param pathToFile a fully qualified path to tested file.
     * @return true if so, false otherwise.
     */
public boolean isIncluded(String pathToFile) {
    Iterator scanners = directoryScanners.iterator();
    while (scanners.hasNext()) {
        DirectoryScanner scanner = (DirectoryScanner) scanners.next();
        scanner.scan();
        String[] includedFiles = scanner.getIncludedFiles();
        for (int i = 0; i < includedFiles.length; i++) {
            File includedFile = new File(scanner.getBasedir(), includedFiles[i]);
            if (pathToFile.equalsIgnoreCase(includedFile.getAbsolutePath())) {
                return true;
            }
        }
    }
    return false;
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Iterator(java.util.Iterator) File(java.io.File)

Example 37 with DirectoryScanner

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

the class AbstractProcessTask method getFiles.

protected Collection getFiles() {
    Map fileMap = new HashMap();
    Project p = getProject();
    for (int i = 0; i < filesets.size(); i++) {
        FileSet fs = (FileSet) filesets.elementAt(i);
        DirectoryScanner ds = fs.getDirectoryScanner(p);
        String[] srcFiles = ds.getIncludedFiles();
        File dir = fs.getDir(p);
        for (int j = 0; j < srcFiles.length; j++) {
            File src = new File(dir, srcFiles[j]);
            fileMap.put(src.getAbsolutePath(), src);
        }
    }
    return fileMap.values();
}
Also used : Project(org.apache.tools.ant.Project) FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 38 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project quasar by puniverse.

the class InstrumentationTask method execute.

@Override
public void execute() throws BuildException {
    try {
        final List<URL> urls = new ArrayList<>();
        for (FileSet fs : filesets) urls.add(fs.getDir().toURI().toURL());
        final ClassLoader cl = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
        final QuasarInstrumentor instrumentor = new QuasarInstrumentor(true);
        instrumentor.setCheck(check);
        instrumentor.setVerbose(verbose);
        instrumentor.setDebug(debug);
        instrumentor.setAllowMonitors(allowMonitors);
        instrumentor.setAllowBlocking(allowBlocking);
        instrumentor.setLog(new Log() {

            @Override
            public void log(LogLevel level, String msg, Object... args) {
                final int msgLevel;
                switch(level) {
                    case DEBUG:
                        msgLevel = Project.MSG_DEBUG;
                        break;
                    case INFO:
                        msgLevel = Project.MSG_INFO;
                        break;
                    case WARNING:
                        msgLevel = Project.MSG_WARN;
                        break;
                    default:
                        throw new AssertionError("Unhandled log level: " + level);
                }
                InstrumentationTask.this.log(level + ": " + String.format(msg, args), msgLevel);
            }

            @Override
            public void error(String msg, Throwable ex) {
                InstrumentationTask.this.log("ERROR: " + msg, ex, Project.MSG_ERR);
            }
        });
        for (FileSet fs : filesets) {
            final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
            final String[] includedFiles = ds.getIncludedFiles();
            for (String filename : includedFiles) {
                if (filename.endsWith(".class")) {
                    File file = new File(fs.getDir(), filename);
                    if (file.isFile()) {
                        final String className = instrumentor.checkClass(cl, file);
                        workList.add(new WorkListEntry(className, file));
                    } else
                        log("File not found: " + filename);
                }
            }
        }
        instrumentor.log(LogLevel.INFO, "Instrumenting " + workList.size() + " classes");
        for (WorkListEntry f : workList) instrumentClass(cl, instrumentor, f);
    } catch (Exception ex) {
        log(ex.getMessage());
        throw new BuildException(ex.getMessage(), ex);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArrayList(java.util.ArrayList) URL(java.net.URL) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) URLClassLoader(java.net.URLClassLoader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) URLClassLoader(java.net.URLClassLoader) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 39 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project quasar by puniverse.

the class OldSuspendablesScanner method execute.

@Override
public void execute() throws BuildException {
    readSuspandables();
    if (USE_REFLECTION)
        log("Using reflection", Project.MSG_INFO);
    try {
        List<URL> urls = new ArrayList<>();
        for (FileSet fs : filesets) urls.add(fs.getDir().toURI().toURL());
        cl = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
        log("URLs: " + Arrays.toString(cl.getURLs()), Project.MSG_INFO);
        // scan classes in filesets
        for (FileSet fs : filesets) {
            try {
                final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
                final String[] includedFiles = ds.getIncludedFiles();
                for (String filename : includedFiles) {
                    if (filename.endsWith(CLASSFILE_SUFFIX)) {
                        File file = new File(fs.getDir(), filename);
                        if (file.isFile())
                            scanClass(file);
                        else
                            log("File not found: " + filename);
                    }
                }
            } catch (BuildException ex) {
                log(ex.getMessage(), ex, Project.MSG_WARN);
            }
        }
        scanSuspendablesFile();
        log("OUTPUT: " + supersFile, Project.MSG_INFO);
        outputResults(supersFile, append, results);
    } catch (Exception e) {
        log(e, Project.MSG_ERR);
        throw new BuildException(e);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) URLClassLoader(java.net.URLClassLoader) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 40 with DirectoryScanner

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

the class AppBundlerTask method copyClassPathEntries.

private void copyClassPathEntries(File javaDirectory) throws IOException {
    for (FileSet fileSet : classPath) {
        File classPathDirectory = fileSet.getDir();
        DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
        String[] includedFiles = directoryScanner.getIncludedFiles();
        for (String includedFile : includedFiles) {
            File source = new File(classPathDirectory, includedFile);
            File destination = new File(javaDirectory, new File(includedFile).getName());
            copy(source, destination);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) 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