Search in sources :

Example 6 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project hudson-2.x by hudson.

the class FilePath method glob.

/**
     * Runs Ant glob expansion.
     *
     * @return
     *      A set of relative file names from the base directory.
     */
private static String[] glob(File dir, String includes) throws IOException {
    if (isAbsolute(includes))
        throw new IOException("Expecting Ant GLOB pattern, but saw '" + includes + "'. See http://ant.apache.org/manual/Types/fileset.html for syntax");
    FileSet fs = Util.createFileSet(dir, includes);
    DirectoryScanner ds = fs.getDirectoryScanner(new Project());
    String[] files = ds.getIncludedFiles();
    return files;
}
Also used : Project(org.apache.tools.ant.Project) AbstractProject(hudson.model.AbstractProject) FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException)

Example 7 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project hudson-2.x by hudson.

the class Fingerprinter method record.

private void record(AbstractBuild<?, ?> build, BuildListener listener, Map<String, String> record, final String targets) throws IOException, InterruptedException {
    final class Record implements Serializable {

        final boolean produced;

        final String relativePath;

        final String fileName;

        final String md5sum;

        public Record(boolean produced, String relativePath, String fileName, String md5sum) {
            this.produced = produced;
            this.relativePath = relativePath;
            this.fileName = fileName;
            this.md5sum = md5sum;
        }

        Fingerprint addRecord(AbstractBuild build) throws IOException {
            FingerprintMap map = Hudson.getInstance().getFingerprintMap();
            return map.getOrCreate(produced ? build : null, fileName, md5sum);
        }

        private static final long serialVersionUID = 1L;
    }
    final long buildTimestamp = build.getTimeInMillis();
    FilePath ws = build.getWorkspace();
    if (ws == null) {
        listener.error(Messages.Fingerprinter_NoWorkspace());
        build.setResult(Result.FAILURE);
        return;
    }
    List<Record> records = ws.act(new FileCallable<List<Record>>() {

        public List<Record> invoke(File baseDir, VirtualChannel channel) throws IOException {
            List<Record> results = new ArrayList<Record>();
            FileSet src = Util.createFileSet(baseDir, targets);
            DirectoryScanner ds = src.getDirectoryScanner();
            for (String f : ds.getIncludedFiles()) {
                File file = new File(baseDir, f);
                // consider the file to be produced by this build only if the timestamp
                // is newer than when the build has started.
                // 2000ms is an error margin since since VFAT only retains timestamp at 2sec precision
                boolean produced = buildTimestamp <= file.lastModified() + 2000;
                try {
                    results.add(new Record(produced, f, file.getName(), new FilePath(file).digest()));
                } catch (IOException e) {
                    throw new IOException2(Messages.Fingerprinter_DigestFailed(file), e);
                } catch (InterruptedException e) {
                    throw new IOException2(Messages.Fingerprinter_Aborted(), e);
                }
            }
            return results;
        }
    });
    for (Record r : records) {
        Fingerprint fp = r.addRecord(build);
        if (fp == null) {
            listener.error(Messages.Fingerprinter_FailedFor(r.relativePath));
            continue;
        }
        fp.add(build);
        record.put(r.relativePath, fp.getHashString());
    }
}
Also used : FilePath(hudson.FilePath) Serializable(java.io.Serializable) Fingerprint(hudson.model.Fingerprint) AbstractBuild(hudson.model.AbstractBuild) FileSet(org.apache.tools.ant.types.FileSet) VirtualChannel(hudson.remoting.VirtualChannel) IOException(java.io.IOException) FingerprintMap(hudson.model.FingerprintMap) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) IOException2(hudson.util.IOException2)

Example 8 with DirectoryScanner

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

the class AppBundlerTask method copyLibraryPathEntries.

private void copyLibraryPathEntries(File macOSDirectory) throws IOException {
    for (FileSet fileSet : libraryPath) {
        File libraryPathDirectory = fileSet.getDir();
        DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
        String[] includedFiles = directoryScanner.getIncludedFiles();
        for (String includedFile : includedFiles) {
            File source = new File(libraryPathDirectory, includedFile);
            File destination = new File(macOSDirectory, 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)

Example 9 with DirectoryScanner

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

the class AppBundlerTask method copyRuntime.

private void copyRuntime(File plugInsDirectory) throws IOException {
    if (runtime != null) {
        File runtimeHomeDirectory = runtime.getDir();
        File runtimeContentsDirectory = runtimeHomeDirectory.getParentFile();
        File runtimeDirectory = runtimeContentsDirectory.getParentFile();
        // Create root plug-in directory
        File pluginDirectory = new File(plugInsDirectory, runtimeDirectory.getName());
        pluginDirectory.mkdir();
        // Create Contents directory
        File pluginContentsDirectory = new File(pluginDirectory, runtimeContentsDirectory.getName());
        pluginContentsDirectory.mkdir();
        // Copy MacOS directory
        File runtimeMacOSDirectory = new File(runtimeContentsDirectory, "MacOS");
        copy(runtimeMacOSDirectory, new File(pluginContentsDirectory, runtimeMacOSDirectory.getName()));
        // Copy Info.plist file
        File runtimeInfoPlistFile = new File(runtimeContentsDirectory, "Info.plist");
        copy(runtimeInfoPlistFile, new File(pluginContentsDirectory, runtimeInfoPlistFile.getName()));
        // Copy included contents of Home directory
        File pluginHomeDirectory = new File(pluginContentsDirectory, runtimeHomeDirectory.getName());
        DirectoryScanner directoryScanner = runtime.getDirectoryScanner(getProject());
        String[] includedFiles = directoryScanner.getIncludedFiles();
        for (String includedFile : includedFiles) {
            //for (int i = 0; i < includedFiles.length; i++) {
            //String includedFile = includedFiles[i];
            File source = new File(runtimeHomeDirectory, includedFile);
            File destination = new File(pluginHomeDirectory, includedFile);
            copy(source, destination);
        }
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 10 with DirectoryScanner

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

the class SuspendablesScanner method visitAntProject.

private void visitAntProject(Function<InputStream, Void> classFileVisitor) throws IOException {
    for (FileSet fs : filesets) {
        try {
            final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
            final String[] includedFiles = ds.getIncludedFiles();
            for (String filename : includedFiles) {
                if (isClassFile(filename)) {
                    try {
                        File file = new File(fs.getDir(), filename);
                        if (file.isFile())
                            classFileVisitor.apply(new FileInputStream(file));
                        else
                            log("File not found: " + filename);
                    } catch (Exception e) {
                        throw new RuntimeException("Exception while processing " + filename, e);
                    }
                }
            }
        } catch (BuildException ex) {
            log(ex.getMessage(), ex, Project.MSG_WARN);
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) ClassLoaderUtil.isClassFile(co.paralleluniverse.common.reflection.ClassLoaderUtil.isClassFile) File(java.io.File) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

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