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;
}
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());
}
}
use of org.apache.tools.ant.DirectoryScanner in project ceylon-compiler by ceylon.
the class SourceModules method getModules.
// TODO filters by module name, supported backends (transitive)
public Set<Module> getModules() {
if (this.dir == null) {
this.dir = getProject().resolveFile(Constants.DEFAULT_SOURCE_DIR);
}
FileSet fs = new FileSet();
fs.setDir(this.dir);
// TODO Handle default module
fs.setIncludes("**/" + Constants.MODULE_DESCRIPTOR);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] files = ds.getIncludedFiles();
log("<sourcemodules> found files " + Arrays.toString(files), Project.MSG_VERBOSE);
URI base = dir.toURI();
LinkedHashSet<Module> result = new LinkedHashSet<Module>();
try {
CeylonClassLoader loader = Util.getCeylonClassLoaderCachedInProject(getProject());
for (String file : files) {
URI uri = new File(this.dir, file).getParentFile().toURI();
log("<sourcemodules> file " + file + "=> uri " + uri, Project.MSG_VERBOSE);
String moduleName = base.relativize(uri).getPath().replace('/', '.');
if (moduleName.endsWith(".")) {
moduleName = moduleName.substring(0, moduleName.length() - 1);
}
log("<sourcemodules> file " + file + "=> moduleName " + moduleName, Project.MSG_VERBOSE);
Module mav = new Module();
mav.setName(moduleName);
String version;
try {
version = new ModuleDescriptorReader(loader, mav.getName(), dir).getModuleVersion();
} catch (NoSuchModuleException e) {
log("<sourcemodules> file " + file + "=> module cannot be read: " + moduleName, Project.MSG_VERBOSE);
// skip it
continue;
}
log("<sourcemodules> file " + file + "=> module " + moduleName + "/" + version, Project.MSG_VERBOSE);
mav.setVersion(version);
result.add(mav);
}
} catch (ClassLoaderSetupException x) {
log("failed to set up Ceylon classloader: could not load module set", Project.MSG_VERBOSE);
}
return result;
}
use of org.apache.tools.ant.DirectoryScanner in project ceylon-compiler by ceylon.
the class CeylonCompileJsAntTask method addToCompileList.
private void addToCompileList(List<File> dirs) {
for (File srcDir : dirs) {
if (srcDir.isDirectory()) {
FileSet fs = (FileSet) this.files.clone();
fs.setDir(srcDir);
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] files = ds.getIncludedFiles();
for (String fileName : files) compileList.add(new File(srcDir, fileName));
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project tomcat by apache.
the class Txt2Html method execute.
/**
* Perform the conversion
*
* @throws BuildException if an error occurs during execution of
* this task.
*/
@Override
public void execute() throws BuildException {
int count = 0;
// Step through each file and convert.
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File basedir = ds.getBasedir();
String[] files = ds.getIncludedFiles();
for (String file : files) {
File from = new File(basedir, file);
File to = new File(todir, file + ".html");
if (!to.exists() || (from.lastModified() > to.lastModified())) {
log("Converting file '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath(), Project.MSG_VERBOSE);
try {
convert(from, to);
} catch (IOException e) {
throw new BuildException("Could not convert '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'", e);
}
count++;
}
}
if (count > 0) {
log("Converted " + count + " file" + (count > 1 ? "s" : "") + " to " + todir.getAbsolutePath());
}
}
}
Aggregations