use of org.apache.tools.ant.types.FileSet 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.types.FileSet 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.types.FileSet in project hudson-2.x by hudson.
the class AbstractItem method renameTo.
/**
* Renames this item.
* Not all the Items need to support this operation, but if you decide to do so,
* you can use this method.
*/
protected void renameTo(String newName) throws IOException {
// always synchronize from bigger objects first
final ItemGroup parent = getParent();
synchronized (parent) {
synchronized (this) {
// sanity check
if (newName == null)
throw new IllegalArgumentException("New name is not given");
// noop?
if (this.name.equals(newName))
return;
Item existing = parent.getItem(newName);
if (existing != null && existing != this)
// see http://www.nabble.com/error-on-renaming-project-tt18061629.html
throw new IllegalArgumentException("Job " + newName + " already exists");
String oldName = this.name;
performBeforeItemRenaming(oldName, newName);
File oldRoot = this.getRootDir();
doSetName(newName);
File newRoot = this.getRootDir();
boolean success = false;
try {
// rename data files
boolean interrupted = false;
boolean renamed = false;
// so retry few times before we fall back to copy.
for (int retry = 0; retry < 5; retry++) {
if (oldRoot.renameTo(newRoot)) {
renamed = true;
// succeeded
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// process the interruption later
interrupted = true;
}
}
if (interrupted)
Thread.currentThread().interrupt();
if (!renamed) {
// failed to rename. it must be that some lengthy
// process is going on
// to prevent a rename operation. So do a copy. Ideally
// we'd like to
// later delete the old copy, but we can't reliably do
// so, as before the VM
// shuts down there might be a new job created under the
// old name.
Copy cp = new Copy();
cp.setProject(new org.apache.tools.ant.Project());
cp.setTodir(newRoot);
FileSet src = new FileSet();
src.setDir(getRootDir());
cp.addFileset(src);
cp.setOverwrite(true);
cp.setPreserveLastModified(true);
// keep going even if
cp.setFailOnError(false);
// there's an error
cp.execute();
// try to delete as much as possible
try {
Util.deleteRecursive(oldRoot);
} catch (IOException e) {
// but ignore the error, since we expect that
e.printStackTrace();
}
}
success = true;
} finally {
// if failed, back out the rename.
if (!success)
doSetName(oldName);
}
callOnRenamed(newName, parent, oldName);
for (ItemListener l : ItemListener.all()) l.onRenamed(this, oldName, newName);
}
}
}
use of org.apache.tools.ant.types.FileSet 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);
}
}
}
use of org.apache.tools.ant.types.FileSet in project quasar by puniverse.
the class SuspendablesScanner method run.
public void run() {
try {
// System.err.println("QQQQQQQQ: " + new SimpleSuspendableClassifier(supersFile).getSuspendableClasses());
final List<URL> us = new ArrayList<>();
if (ant) {
final AntClassLoader acl = (AntClassLoader) getClass().getClassLoader();
classpathToUrls(acl.getClasspath().split(System.getProperty("path.separator")), us);
for (FileSet fs : filesets) us.add(fs.getDir().toURI().toURL());
} else {
// final URLClassLoader ucl = (URLClassLoader) getClass().getClassLoader();
// us.addAll(Arrays.asList(ucl.getURLs()));
}
if (// only in tests
this.urls != null)
us.addAll(Arrays.asList(this.urls));
setURLs(us);
log("Classpath URLs: " + Arrays.toString(this.urls), Project.MSG_INFO);
List<URL> pus = new ArrayList<>();
if (ant) {
for (FileSet fs : filesets) pus.add(fs.getDir().toURI().toURL());
} else
pus.add(projectDir.toUri().toURL());
log("Project URLs: " + pus, Project.MSG_INFO);
final long tStart = System.nanoTime();
scanExternalSuspendables();
final long tScanExternal = System.nanoTime();
if (auto)
log("Scanned external suspendables in " + (tScanExternal - tStart) / 1000000 + " ms", Project.MSG_INFO);
// scan classes in filesets
Function<InputStream, Void> fileVisitor = new Function<InputStream, Void>() {
@Override
public Void apply(InputStream is1) {
try (InputStream is = is1) {
createGraph(is);
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
if (ant)
visitAntProject(fileVisitor);
else
visitProjectDir(fileVisitor);
scanSuspendablesFile(fileVisitor);
final long tBuildGraph = System.nanoTime();
log("Built method graph in " + (tBuildGraph - tScanExternal) / 1000000 + " ms", Project.MSG_INFO);
walkGraph();
final long tWalkGraph = System.nanoTime();
log("Walked method graph in " + (tWalkGraph - tBuildGraph) / 1000000 + " ms", Project.MSG_INFO);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations