use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.
the class Copy method buildMap.
/**
* Add to a map of files/directories to copy.
*
* @param fromDir the source directory.
* @param toDir the destination directory.
* @param names a list of filenames.
* @param mapper a <code>FileNameMapper</code> value.
* @param map a map of source file to array of destination files.
*/
protected void buildMap(final File fromDir, final File toDir, final String[] names, final FileNameMapper mapper, final Hashtable<String, String[]> map) {
String[] toCopy = null;
if (forceOverwrite) {
final Vector<String> v = new Vector<String>();
for (String name : names) {
if (mapper.mapFileName(name) != null) {
v.addElement(name);
}
}
toCopy = new String[v.size()];
v.copyInto(toCopy);
} else {
final SourceFileScanner ds = new SourceFileScanner(this);
toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
}
for (String name : toCopy) {
final File src = new File(fromDir, name);
final String[] mappedFiles = mapper.mapFileName(name);
if (mappedFiles == null || mappedFiles.length == 0) {
continue;
}
if (!enableMultipleMappings) {
map.put(src.getAbsolutePath(), new String[] { new File(toDir, mappedFiles[0]).getAbsolutePath() });
} else {
// reuse the array created by the mapper
for (int k = 0; k < mappedFiles.length; k++) {
mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
}
map.put(src.getAbsolutePath(), mappedFiles);
}
}
}
use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.
the class Native2Ascii method execute.
/**
* Execute the task
*
* @throws BuildException is there is a problem in the task execution.
*/
@Override
public void execute() throws BuildException {
// Scanner to find our inputs
DirectoryScanner scanner = null;
// list of files to process
String[] files;
// default srcDir to basedir
if (srcDir == null) {
srcDir = getProject().resolveFile(".");
}
// Require destDir
if (destDir == null) {
throw new BuildException("The dest attribute must be set.");
}
// include a file with the same extension, but ....
if (srcDir.equals(destDir) && extension == null && mapper == null) {
throw new BuildException("The ext attribute or a mapper must be set if src and dest dirs are the same.");
}
FileNameMapper m;
if (mapper == null) {
if (extension == null) {
m = new IdentityMapper();
} else {
m = new ExtMapper();
}
} else {
m = mapper.getImplementation();
}
scanner = getDirectoryScanner(srcDir);
files = scanner.getIncludedFiles();
SourceFileScanner sfs = new SourceFileScanner(this);
files = sfs.restrict(files, srcDir, destDir, m);
int count = files.length;
if (count == 0) {
return;
}
String message = "Converting " + count + " file" + (count != 1 ? "s" : "") + " from ";
log(message + srcDir + " to " + destDir);
for (String file : files) {
String[] dest = m.mapFileName(file);
if (dest != null && dest.length > 0) {
convert(file, dest[0]);
}
}
}
use of org.apache.tools.ant.util.SourceFileScanner in project jangaroo-tools by CoreMedia.
the class PropcTask 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 the files to scan
*/
protected void scanDir(File srcDir, File destDir, String[] files) {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("*.properties");
m.setTo("*.as");
SourceFileScanner sfs = new SourceFileScanner(this);
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
if (newFiles.length > 0) {
File[] newCompileList = new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
compileList = newCompileList;
}
}
use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.
the class Javac 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(final File srcDir, final File destDir, final String[] files) {
final GlobPatternMapper m = new GlobPatternMapper();
for (String extension : findSupportedFileExtensions()) {
m.setFrom(extension);
m.setTo("*.class");
final SourceFileScanner sfs = new SourceFileScanner(this);
final File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
if (newFiles.length > 0) {
lookForPackageInfos(srcDir, newFiles);
final File[] newCompileList = new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0, compileList.length);
System.arraycopy(newFiles, 0, newCompileList, compileList.length, newFiles.length);
compileList = newCompileList;
}
}
}
use of org.apache.tools.ant.util.SourceFileScanner in project ant by apache.
the class Rmic method scanDir.
/**
* Scans the directory looking for class files to be compiled.
* The result is returned in the class variable compileList.
* @param baseDir the base direction
* @param files the list of files to scan
* @param mapper the mapper of files to target files
*/
protected void scanDir(File baseDir, String[] files, FileNameMapper mapper) {
String[] newFiles = files;
if (idl) {
log("will leave uptodate test to rmic implementation in idl mode.", Project.MSG_VERBOSE);
} else if (iiop && iiopOpts != null && iiopOpts.contains("-always")) {
log("no uptodate test as -always option has been specified", Project.MSG_VERBOSE);
} else {
SourceFileScanner sfs = new SourceFileScanner(this);
newFiles = sfs.restrict(files, baseDir, getOutputDir(), mapper);
}
Stream.of(newFiles).map(s -> s.replace(File.separatorChar, '.')).map(s -> s.substring(0, s.lastIndexOf(".class"))).forEach(compileList::add);
}
Aggregations