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;
}
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;
}
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;
}
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);
}
}
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");
}
}
Aggregations