Search in sources :

Example 6 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class Tar method archiveIsUpToDate.

/**
 * Is the archive up to date in relationship to a list of files.
 * @param files the files to check
 * @param dir   the base directory for the files.
 * @return true if the archive is up to date.
 * @since Ant 1.5.2
 */
protected boolean archiveIsUpToDate(final String[] files, final File dir) {
    final SourceFileScanner sfs = new SourceFileScanner(this);
    final MergingMapper mm = new MergingMapper();
    mm.setTo(tarFile.getAbsolutePath());
    return sfs.restrict(files, dir, null, mm).length == 0;
}
Also used : SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) MergingMapper(org.apache.tools.ant.util.MergingMapper)

Example 7 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class UpToDate method scanDir.

/**
 * Scan a directory for files to check for "up to date"ness
 * @param srcDir the directory
 * @param files the files to scan for
 * @return true if the files are up to date
 */
protected boolean scanDir(File srcDir, String[] files) {
    SourceFileScanner sfs = new SourceFileScanner(this);
    FileNameMapper mapper = getMapper();
    File dir = srcDir;
    if (mapperElement == null) {
        dir = null;
    }
    return sfs.restrict(files, srcDir, dir, mapper).length == 0;
}
Also used : SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) File(java.io.File)

Example 8 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.

the class UpToDate method eval.

/**
 * Evaluate (all) target and source file(s) to
 * see if the target(s) is/are up-to-date.
 * @return true if the target(s) is/are up-to-date
 */
@Override
public boolean eval() {
    if (sourceFileSets.isEmpty() && sourceResources.isEmpty() && sourceFile == null) {
        throw new BuildException("At least one srcfile or a nested <srcfiles> or <srcresources> element must be set.");
    }
    if ((!sourceFileSets.isEmpty() || !sourceResources.isEmpty()) && sourceFile != null) {
        throw new BuildException("Cannot specify both the srcfile attribute and a nested <srcfiles> or <srcresources> element.");
    }
    if (targetFile == null && mapperElement == null) {
        throw new BuildException("The targetfile attribute or a nested mapper element must be set.");
    }
    // if the target file is not there, then it can't be up-to-date
    if (targetFile != null && !targetFile.exists()) {
        log("The targetfile \"" + targetFile.getAbsolutePath() + "\" does not exist.", Project.MSG_VERBOSE);
        return false;
    }
    // if the source file isn't there, throw an exception
    if (sourceFile != null && !sourceFile.exists()) {
        throw new BuildException("%s not found.", sourceFile.getAbsolutePath());
    }
    boolean upToDate = true;
    if (sourceFile != null) {
        if (mapperElement == null) {
            upToDate = targetFile.lastModified() >= sourceFile.lastModified();
        } else {
            SourceFileScanner sfs = new SourceFileScanner(this);
            upToDate = sfs.restrict(new String[] { sourceFile.getAbsolutePath() }, null, null, mapperElement.getImplementation()).length == 0;
        }
        if (!upToDate) {
            log(sourceFile.getAbsolutePath() + " is newer than (one of) its target(s).", Project.MSG_VERBOSE);
        }
    }
    // filesets are separate from the rest for performance
    // reasons.  If we use the code for union below, we'll always
    // scan all filesets, even if we know the target is out of
    // date after the first test.
    Iterator<FileSet> iter = sourceFileSets.iterator();
    while (upToDate && iter.hasNext()) {
        FileSet fs = iter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        upToDate = scanDir(fs.getDir(getProject()), ds.getIncludedFiles());
    }
    if (upToDate) {
        Resource[] r = sourceResources.listResources();
        if (r.length > 0) {
            upToDate = ResourceUtils.selectOutOfDateSources(this, r, getMapper(), getProject()).length == 0;
        }
    }
    return upToDate;
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Resource(org.apache.tools.ant.types.Resource) BuildException(org.apache.tools.ant.BuildException) SourceFileScanner(org.apache.tools.ant.util.SourceFileScanner)

Example 9 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner 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 10 with SourceFileScanner

use of org.apache.tools.ant.util.SourceFileScanner 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)

Aggregations

SourceFileScanner (org.apache.tools.ant.util.SourceFileScanner)14 File (java.io.File)11 GlobPatternMapper (org.apache.tools.ant.util.GlobPatternMapper)8 BuildException (org.apache.tools.ant.BuildException)5 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)5 Path (org.apache.tools.ant.types.Path)3 FileNameMapper (org.apache.tools.ant.util.FileNameMapper)3 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 Vector (java.util.Vector)2 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)2 IOException (java.io.IOException)1 Remote (java.rmi.Remote)1 Stream (java.util.stream.Stream)1 AntClassLoader (org.apache.tools.ant.AntClassLoader)1 Project (org.apache.tools.ant.Project)1 RmicAdapter (org.apache.tools.ant.taskdefs.rmic.RmicAdapter)1 RmicAdapterFactory (org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory)1 FileSet (org.apache.tools.ant.types.FileSet)1 FilterSetCollection (org.apache.tools.ant.types.FilterSetCollection)1 Reference (org.apache.tools.ant.types.Reference)1