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));
}
}
}
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) {
}
}
}
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 + "'");
}
}
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 + "'");
}
}
}
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.");
}
Aggregations