Search in sources :

Example 26 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project ceylon-compiler by ceylon.

the class CeylonCompileJsAntTask method addToCompileList.

private void addToCompileList(List<File> dirs) {
    for (File srcDir : dirs) {
        if (srcDir.isDirectory()) {
            FileSet fs = (FileSet) this.files.clone();
            fs.setDir(srcDir);
            DirectoryScanner ds = fs.getDirectoryScanner(getProject());
            String[] files = ds.getIncludedFiles();
            for (String fileName : files) compileList.add(new File(srcDir, fileName));
        }
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) File(java.io.File)

Example 27 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project CFLint by cflint.

the class CFLintTask method execute.

@Override
public void execute() {
    FileInputStream fis = null;
    try {
        CFLintConfiguration config = null;
        if (configFile != null) {
            if (configFile.getName().toLowerCase().endsWith(".xml")) {
                config = ConfigUtils.unmarshal(new FileInputStream(configFile), CFLintConfig.class);
            } else {
                config = ConfigUtils.unmarshalJson(new FileInputStream(configFile), CFLintConfig.class);
            }
        }
        CFLintConfiguration cmdLineConfig = null;
        if ((excludeRule != null && excludeRule.trim().length() > 0) || (includeRule != null && includeRule.trim().length() > 0)) {
            cmdLineConfig = new CFLintConfig();
            if (includeRule != null && includeRule.trim().length() > 0) {
                for (final String code : includeRule.trim().split(",")) {
                    cmdLineConfig.addInclude(new PluginMessage(code));
                }
            }
            if (excludeRule != null && excludeRule.trim().length() > 0) {
                for (final String code : excludeRule.trim().split(",")) {
                    cmdLineConfig.addExclude(new PluginMessage(code));
                }
            }
        }
        // TODO combine configs
        final CFLint cflint = new CFLint(config);
        cflint.setVerbose(verbose);
        cflint.setQuiet(quiet);
        if (extensions != null && extensions.trim().length() > 0) {
            cflint.setAllowedExtensions(Arrays.asList(extensions.trim().split(",")));
        }
        CFLintFilter filter = CFLintFilter.createFilter(verbose);
        if (filterFile != null) {
            final File ffile = filterFile;
            if (ffile.exists()) {
                fis = new FileInputStream(ffile);
                final byte[] b = new byte[fis.available()];
                fis.read(b);
                filter = CFLintFilter.createFilter(new String(b), verbose);
            }
        }
        cflint.getBugs().setFilter(filter);
        if (xmlFile == null && htmlFile == null && textFile == null) {
            xmlFile = new File("cflint-result.xml");
        }
        if (xmlFile != null) {
            if (verbose) {
                System.out.println("Style:" + xmlStyle);
            }
            if ("findbugs".equalsIgnoreCase(xmlStyle)) {
                new XMLOutput().outputFindBugs(cflint.getBugs(), createWriter(xmlFile, StandardCharsets.UTF_8), showStats);
            } else {
                new DefaultCFlintResultMarshaller().output(cflint.getBugs(), createWriter(xmlFile, StandardCharsets.UTF_8), showStats);
            }
        }
        if (textFile != null) {
            final Writer textwriter = textFile != null ? new FileWriter(textFile) : new OutputStreamWriter(System.out);
            new TextOutput().output(cflint.getBugs(), textwriter, showStats);
        }
        if (htmlFile != null) {
            try {
                new HTMLOutput(htmlStyle).output(cflint.getBugs(), new FileWriter(htmlFile), showStats);
            } catch (final TransformerException e) {
                throw new IOException(e);
            }
        }
        for (final FileSet fileset : filesets) {
            int progress = 1;
            // 3
            final DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
            final ProgressMonitor progressMonitor = showProgress && !filesets.isEmpty() ? new ProgressMonitor(null, "CFLint", "", 1, ds.getIncludedFilesCount()) : null;
            final String[] includedFiles = ds.getIncludedFiles();
            for (final String includedFile : includedFiles) {
                if (progressMonitor.isCanceled()) {
                    throw new RuntimeException("CFLint scan cancelled");
                }
                final String filename = ds.getBasedir() + File.separator + includedFile;
                progressMonitor.setNote("scanning " + includedFile);
                cflint.scan(filename);
                progressMonitor.setProgress(progress++);
            }
        }
    } catch (final Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (final IOException e) {
        }
    }
}
Also used : TextOutput(com.cflint.TextOutput) CFLintConfiguration(com.cflint.config.CFLintConfiguration) FileWriter(java.io.FileWriter) XMLOutput(com.cflint.XMLOutput) CFLint(com.cflint.CFLint) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) PluginMessage(com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage) DefaultCFlintResultMarshaller(com.cflint.xml.stax.DefaultCFlintResultMarshaller) TransformerException(javax.xml.transform.TransformerException) FileSet(org.apache.tools.ant.types.FileSet) HTMLOutput(com.cflint.HTMLOutput) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) CFLint(com.cflint.CFLint) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) ProgressMonitor(javax.swing.ProgressMonitor) CFLintConfig(com.cflint.config.CFLintConfig) CFLintFilter(com.cflint.tools.CFLintFilter) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer)

Example 28 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class PatchXmlTask method execute.

@Override
public void execute() throws BuildException {
    if (patchFile == null)
        throw new BuildException("You must specify a patch file");
    if (!patchFile.isFile())
        throw new BuildException("The file '" + patchFile + "' does not exist");
    if (!destDir.isDirectory())
        throw new BuildException("The destDir '" + destDir + "' is not a directory");
    DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
    String[] srcFilenames = ds.getIncludedFiles();
    if (srcFilenames.length == 0)
        throw new BuildException("You must designate at least one input file.");
    long patchFileDate = patchFile.lastModified();
    Element patches;
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(patchFile));
        patches = XMLUtils.parse(in).getDocumentElement();
    } catch (Exception e) {
        throw new BuildException("Could not read '" + patchFile + "'", e);
    }
    if (patchId != null) {
        patches = findElementById(patches, patchId);
        if (patches == null)
            throw new BuildException("The patch file '" + patchFile + "' does not contain a patch with the id '" + patchId + "'");
    }
    for (int j = 0; j < srcFilenames.length; j++) {
        File inputFile = new File(ds.getBasedir(), srcFilenames[j]);
        String baseFilename = inputFile.getName();
        File outputFile = new File(destDir, baseFilename);
        long inputDate = Math.max(inputFile.lastModified(), patchFileDate);
        if (outputFile.lastModified() > inputDate) {
            // file is already up-to-date
            log("File '" + outputFile + "' is up-to-date", Project.MSG_VERBOSE);
            continue;
        }
        Document document;
        try {
            document = JAXPUtils.getDocumentBuilder().parse(inputFile);
        } catch (Exception e) {
            throw new BuildException("Could not parse input file '" + inputFile + "'", e);
        }
        XmlPatch.apply(document, patches);
        try {
            // convert the modified document back into text
            String docText = XMLUtils.getAsText(document);
            // the top of the file
            if (docText.indexOf("<html") != -1 && docText.startsWith("<?")) {
                int dirEnd = docText.indexOf("?>");
                docText = docText.substring(dirEnd + 2);
            }
            // write the file
            OutputStream out = new BufferedOutputStream(new CleanupNewlines(new FileOutputStream(outputFile)));
            out.write(docText.getBytes("UTF-8"));
            out.close();
        } catch (Exception e) {
            throw new BuildException("Could not write to output file '" + outputFile + "'", e);
        }
        log("Wrote '" + outputFile + "'");
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FilterOutputStream(java.io.FilterOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) BufferedInputStream(java.io.BufferedInputStream) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) FileOutputStream(java.io.FileOutputStream) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 29 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class JLexBatch method execute.

public void execute() throws BuildException {
    DirectoryScanner ds = fileset.getDirectoryScanner(getProject());
    String[] srcFilenames = ds.getIncludedFiles();
    if (srcFilenames.length == 0)
        throw new BuildException("You must designate at least one input lexer file.");
    for (int j = 0; j < srcFilenames.length; j++) {
        String inputFilename = srcFilenames[j];
        File inputFile = new File(ds.getBasedir(), inputFilename);
        String outputFilename = getOutputFilename(inputFilename);
        File outputFile = new File(ds.getBasedir(), outputFilename);
        if (outputFile.lastModified() > inputFile.lastModified())
            // file is already up-to-date
            continue;
        try {
            JLex.Main.main(new String[] { inputFile.getAbsolutePath(), outputFile.getAbsolutePath() });
        } catch (IOException ioe) {
            throw new BuildException("Cannot create file '" + outputFile + "'");
        }
    }
}
Also used : DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) IOException(java.io.IOException) File(java.io.File)

Example 30 with DirectoryScanner

use of org.apache.tools.ant.DirectoryScanner in project processdash by dtuma.

the class OrphanedResources method execute.

public void execute() throws BuildException {
    DirectoryScanner ds = getDirectoryScanner(dir);
    String[] srcFiles = ds.getIncludedFiles();
    HashMap props = new HashMap();
    for (int j = 0; j < srcFiles.length; j++) {
        String key = getFileKey(srcFiles[j]);
        if (key != null)
            props.put(key, loadProps(srcFiles[j]));
    }
    numOrphans = 0;
    Iterator i = props.keySet().iterator();
    while (i.hasNext()) {
        String key = (String) i.next();
        checkForOrphans(key, props);
    }
    if (numOrphans > 0)
        throw new BuildException(numOrphans + " orphaned resources found.");
}
Also used : HashMap(java.util.HashMap) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Iterator(java.util.Iterator) BuildException(org.apache.tools.ant.BuildException)

Aggregations

DirectoryScanner (org.apache.tools.ant.DirectoryScanner)57 File (java.io.File)52 BuildException (org.apache.tools.ant.BuildException)26 FileSet (org.apache.tools.ant.types.FileSet)26 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)12 GroovyClassLoader (groovy.lang.GroovyClassLoader)4 FileInputStream (java.io.FileInputStream)4 FilenameFilter (java.io.FilenameFilter)4 Project (org.apache.tools.ant.Project)4 DirSet (org.apache.tools.ant.types.DirSet)4 PatternSet (org.apache.tools.ant.types.PatternSet)4 LinkedList (java.util.LinkedList)3 Path (org.apache.tools.ant.types.Path)3 AbstractProject (hudson.model.AbstractProject)2 VirtualChannel (hudson.remoting.VirtualChannel)2 OutputStream (java.io.OutputStream)2 URI (java.net.URI)2 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2