use of org.apache.tools.ant.types.FileSet in project ant by apache.
the class Tar method check.
/**
* Checks whether the archive is out-of-date with respect to the resources
* of the given collection.
*
* <p>Also checks that either all collections only contain file
* resources or this class supports non-file collections.</p>
*
* <p>And - in case of file-collections - ensures that the archive won't
* contain itself.</p>
*
* @param rc the resource collection to check
* @return whether the archive is up-to-date
* @since Ant 1.7
*/
protected boolean check(final ResourceCollection rc) {
boolean upToDate = true;
if (isFileFileSet(rc)) {
final FileSet fs = (FileSet) rc;
upToDate = check(fs.getDir(getProject()), getFileNames(fs));
} else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) {
throw new BuildException("only filesystem resources are supported");
} else if (rc.isFilesystemOnly()) {
final Set<File> basedirs = new HashSet<>();
final Map<File, List<String>> basedirToFilesMap = new HashMap<>();
for (final Resource res : rc) {
final FileResource r = ResourceUtils.asFileResource(res.as(FileProvider.class));
File base = r.getBaseDir();
if (base == null) {
base = Copy.NULL_FILE_PLACEHOLDER;
}
basedirs.add(base);
List<String> files = basedirToFilesMap.get(base);
if (files == null) {
files = new Vector<>();
basedirToFilesMap.put(base, files);
}
if (base == Copy.NULL_FILE_PLACEHOLDER) {
files.add(r.getFile().getAbsolutePath());
} else {
files.add(r.getName());
}
}
for (final File base : basedirs) {
final File tmpBase = base == Copy.NULL_FILE_PLACEHOLDER ? null : base;
final List<String> files = basedirToFilesMap.get(base);
upToDate &= check(tmpBase, files);
}
} else {
// non-file resources
for (Resource r : rc) {
upToDate = archiveIsUpToDate(r);
}
}
return upToDate;
}
use of org.apache.tools.ant.types.FileSet in project ant by apache.
the class CCMCheck method execute.
/**
* Executes the task.
* <p>
* Builds a command line to execute ccm and then calls Exec's run method
* to execute the command line.
* </p>
* @throws BuildException on error
*/
@Override
public void execute() throws BuildException {
if (file == null && filesets.isEmpty()) {
throw new BuildException("Specify at least one source - a file or a fileset.");
}
if (file != null && file.exists() && file.isDirectory()) {
throw new BuildException("CCMCheck cannot be generated for directories");
}
if (file != null && !filesets.isEmpty()) {
throw new BuildException("Choose between file and fileset !");
}
if (getFile() != null) {
doit();
return;
}
for (FileSet fs : filesets) {
final File basedir = fs.getDir(getProject());
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
for (String srcFile : ds.getIncludedFiles()) {
setFile(new File(basedir, srcFile));
doit();
}
}
}
use of org.apache.tools.ant.types.FileSet in project ant by apache.
the class ChangeLogTask method execute.
/**
* Execute task
*
* @exception BuildException if something goes wrong executing the
* cvs command
*/
@Override
public void execute() throws BuildException {
// may be altered in validate
File savedDir = inputDir;
try {
validate();
final Properties userList = new Properties();
loadUserlist(userList);
for (CvsUser user : cvsUsers) {
user.validate();
userList.put(user.getUserID(), user.getDisplayname());
}
if (!remote) {
setCommand("log");
if (getTag() != null) {
CvsVersion myCvsVersion = new CvsVersion();
myCvsVersion.setProject(getProject());
myCvsVersion.setTaskName("cvsversion");
myCvsVersion.setCvsRoot(getCvsRoot());
myCvsVersion.setCvsRsh(getCvsRsh());
myCvsVersion.setPassfile(getPassFile());
myCvsVersion.setDest(inputDir);
myCvsVersion.execute();
if (myCvsVersion.supportsCvsLogWithSOption()) {
addCommandArgument("-S");
}
}
} else {
// supply 'rlog' as argument instead of command
setCommand("");
addCommandArgument("rlog");
// Do not print name/header if no revisions
// selected. This is quicker: less output to parse.
addCommandArgument("-S");
// Do not list tags. This is quicker: less output to
// parse.
addCommandArgument("-N");
}
if (null != startTag || null != endTag) {
// man, do I get spoiled by C#'s ?? operator
String startValue = startTag == null ? "" : startTag;
String endValue = endTag == null ? "" : endTag;
addCommandArgument("-r" + startValue + "::" + endValue);
} else if (null != startDate) {
final SimpleDateFormat outputDate = new SimpleDateFormat("yyyy-MM-dd");
// We want something of the form: -d ">=YYYY-MM-dd"
final String dateRange = ">=" + outputDate.format(startDate);
// Supply '-d' as a separate argument - Bug# 14397
addCommandArgument("-d");
addCommandArgument(dateRange);
}
// Check if list of files to check has been specified
for (FileSet fileSet : filesets) {
final DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
for (String file : scanner.getIncludedFiles()) {
addCommandArgument(file);
}
}
final ChangeLogParser parser = new ChangeLogParser(remote, getPackage(), getModules());
final RedirectingStreamHandler handler = new RedirectingStreamHandler(parser);
log(getCommand(), Project.MSG_VERBOSE);
setDest(inputDir);
setExecuteStreamHandler(handler);
try {
super.execute();
} finally {
final String errors = handler.getErrors();
if (null != errors) {
log(errors, Project.MSG_ERR);
}
}
final CVSEntry[] entrySet = parser.getEntrySetAsArray();
final CVSEntry[] filteredEntrySet = filterEntrySet(entrySet);
replaceAuthorIdWithName(userList, filteredEntrySet);
writeChangeLog(filteredEntrySet);
} finally {
inputDir = savedDir;
}
}
use of org.apache.tools.ant.types.FileSet in project ant by apache.
the class Find method execute2.
public void execute2() {
validate();
String foundLocation = null;
for (FileSet fs : filesets) {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] includedFiles = ds.getIncludedFiles();
for (String includedFile : includedFiles) {
String filename = includedFile.replace('\\', '/');
filename = filename.substring(filename.lastIndexOf("/") + 1);
if (foundLocation == null && file.equals(filename)) {
File base = ds.getBasedir();
File found = new File(base, includedFile);
foundLocation = found.getAbsolutePath();
}
}
}
if (foundLocation != null)
getProject().setNewProperty(location, foundLocation);
}
use of org.apache.tools.ant.types.FileSet in project ci.ant by WASdev.
the class CompileJSPs method copyClassFiles.
private void copyClassFiles(File jspCompileDir) {
Copy copy = new Copy();
copy.setProject(getProject());
copy.setTaskName(getTaskName());
destdir.mkdirs();
copy.setTodir(destdir);
FileSet files = new FileSet();
files.setDir(jspCompileDir);
files.setIncludes("**/*.class");
copy.addFileset(files);
copy.execute();
}
Aggregations