Search in sources :

Example 61 with DirectoryScanner

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);
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 62 with DirectoryScanner

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;
}
Also used : Project(org.apache.tools.ant.Project) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 63 with DirectoryScanner

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());
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 64 with DirectoryScanner

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");
            }
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) NotImplementedException(org.apache.commons.lang.NotImplementedException) URI(java.net.URI) File(java.io.File) URL(java.net.URL)

Example 65 with DirectoryScanner

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;
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)150 File (java.io.File)122 FileSet (org.apache.tools.ant.types.FileSet)84 BuildException (org.apache.tools.ant.BuildException)73 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)32 Project (org.apache.tools.ant.Project)14 Resource (org.apache.tools.ant.types.Resource)11 Test (org.junit.Test)11 FileResource (org.apache.tools.ant.types.resources.FileResource)8 HashMap (java.util.HashMap)7 Path (org.apache.tools.ant.types.Path)7 Hashtable (java.util.Hashtable)6 PatternSet (org.apache.tools.ant.types.PatternSet)6 FileWriter (java.io.FileWriter)5 LinkedList (java.util.LinkedList)5 List (java.util.List)5 StringTokenizer (java.util.StringTokenizer)5 Vector (java.util.Vector)5 DirSet (org.apache.tools.ant.types.DirSet)5