use of org.apache.tools.ant.DirectoryScanner in project freemarker by apache.
the class FreemarkerXmlTask method execute.
@Override
public void execute() throws BuildException {
DirectoryScanner scanner;
String[] list;
if (baseDir == null) {
baseDir = getProject().getBaseDir();
}
if (destDir == null) {
String msg = "destdir attribute must be set!";
throw new BuildException(msg, getLocation());
}
File templateFile = null;
if (templateDir == null) {
if (templateName != null) {
templateFile = new File(templateName);
if (!templateFile.isAbsolute()) {
templateFile = new File(getProject().getBaseDir(), templateName);
}
templateDir = templateFile.getParentFile();
templateName = templateFile.getName();
} else {
templateDir = baseDir;
}
setTemplateDir(templateDir);
} else if (templateName != null) {
if (new File(templateName).isAbsolute()) {
throw new BuildException("Do not specify an absolute location for the template as well as a templateDir");
}
templateFile = new File(templateDir, templateName);
}
if (templateFile != null) {
templateFileLastModified = templateFile.lastModified();
}
try {
if (templateName != null) {
parsedTemplate = cfg.getTemplate(templateName, templateEncoding);
}
} catch (IOException ioe) {
throw new BuildException(ioe.toString());
}
// get the last modification of the template
log("Transforming into: " + destDir.getAbsolutePath(), Project.MSG_INFO);
// projectFile relative to baseDir
if (projectAttribute != null && projectAttribute.length() > 0) {
projectFile = new File(baseDir, projectAttribute);
if (projectFile.isFile())
projectFileLastModified = projectFile.lastModified();
else {
log("Project file is defined, but could not be located: " + projectFile.getAbsolutePath(), Project.MSG_INFO);
projectFile = null;
}
}
generateModels();
// find the files/directories
scanner = getDirectoryScanner(baseDir);
propertiesTemplate = wrapMap(project.getProperties());
userPropertiesTemplate = wrapMap(project.getUserProperties());
builderFactory.setValidating(validation);
try {
builder = builderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new BuildException("Could not create document builder", e, getLocation());
}
// get a list of files to work on
list = scanner.getIncludedFiles();
for (int i = 0; i < list.length; ++i) {
process(baseDir, list[i], destDir);
}
}
use of org.apache.tools.ant.DirectoryScanner in project revapi by revapi.
the class FileArchive method scanFileSet.
private static File[] scanFileSet(FileSet fs) {
Project prj = fs.getProject();
DirectoryScanner scanner = fs.getDirectoryScanner(prj);
scanner.scan();
File basedir = scanner.getBasedir();
String[] fileNames = scanner.getIncludedFiles();
File[] ret = new File[fileNames.length];
for (int i = 0; i < fileNames.length; i++) {
String fileName = fileNames[i];
ret[i] = new File(basedir, fileName);
}
return ret;
}
use of org.apache.tools.ant.DirectoryScanner in project tomcat70 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.
Iterator<FileSet> iter = filesets.iterator();
while (iter.hasNext()) {
FileSet fs = iter.next();
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
File basedir = ds.getBasedir();
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
File from = new File(basedir, files[i]);
File to = new File(todir, files[i] + ".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());
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.
the class StramAppLauncher method processLibJars.
private void processLibJars(String libjars, Set<URL> clUrls) throws Exception {
for (String libjar : libjars.split(",")) {
// if hadoop file system, copy from hadoop file system to local
URI uri = new URI(libjar);
String scheme = uri.getScheme();
if (scheme == null) {
// expand wildcards
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[] { libjar });
scanner.scan();
String[] files = scanner.getIncludedFiles();
for (String file : files) {
clUrls.add(new URL("file:" + file));
}
} else if (scheme.equals("file")) {
clUrls.add(new URL(libjar));
} else {
if (fs != null) {
Path path = new Path(libjar);
File dependencyJarsDir = new File(StramClientUtils.getUserDTDirectory(), "dependencyJars");
dependencyJarsDir.mkdirs();
File localJarFile = new File(dependencyJarsDir, path.getName());
fs.copyToLocalFile(path, new Path(localJarFile.getAbsolutePath()));
clUrls.add(new URL("file:" + localJarFile.getAbsolutePath()));
} else {
throw new NotImplementedException("Jar file needs to be from Hadoop File System also in order for the dependency jars to be in Hadoop File System");
}
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.
the class ApexCli method expandFileName.
private static String expandFileName(String fileName, boolean expandWildCard) throws IOException {
if (fileName.matches("^[a-zA-Z]+:.*")) {
// it's a URL
return fileName;
}
// TODO: need to work with other users' home directory
if (fileName.startsWith("~" + File.separator)) {
fileName = System.getProperty("user.home") + fileName.substring(1);
}
fileName = new File(fileName).getCanonicalPath();
// LOG.debug("Canonical path: {}", fileName);
if (expandWildCard) {
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[] { fileName });
scanner.scan();
String[] files = scanner.getIncludedFiles();
if (files.length == 0) {
throw new CliException(fileName + " does not match any file");
} else if (files.length > 1) {
throw new CliException(fileName + " matches more than one file");
}
return files[0];
} else {
return fileName;
}
}
Aggregations