use of org.apache.tools.ant.DirectoryScanner in project groovy by apache.
the class Groovyc method execute.
/**
* Executes the task.
*
* @throws BuildException if an error occurs
*/
public void execute() throws BuildException {
checkParameters();
resetFileLists();
loadRegisteredScriptExtensions();
if (javac != null)
jointCompilation = true;
// scan source directories and dest directory to build up
// compile lists
String[] list = src.list();
for (String filename : list) {
File file = getProject().resolveFile(filename);
if (!file.exists()) {
throw new BuildException("srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
}
DirectoryScanner ds = this.getDirectoryScanner(file);
String[] files = ds.getIncludedFiles();
scanDir(file, destDir != null ? destDir : file, files);
}
compile();
if (updatedProperty != null && taskSuccess && compileList.length != 0) {
getProject().setNewProperty(updatedProperty, "true");
}
}
use of org.apache.tools.ant.DirectoryScanner in project groovy by apache.
the class GroovycTask method compile.
protected void compile() {
Path path = getClasspath();
if (path != null) {
config.setClasspath(path.toString());
}
config.setTargetDirectory(destdir);
GroovyClassLoader gcl = createClassLoader();
CompilationUnit compilation = new CompilationUnit(config, null, gcl);
GlobPatternMapper mapper = new GlobPatternMapper();
mapper.setFrom("*.groovy");
mapper.setTo("*.class");
int count = 0;
String[] list = src.list();
for (int i = 0; i < list.length; i++) {
File basedir = getProject().resolveFile(list[i]);
if (!basedir.exists()) {
throw new BuildException("Source directory does not exist: " + basedir, getLocation());
}
DirectoryScanner scanner = getDirectoryScanner(basedir);
String[] includes = scanner.getIncludedFiles();
if (force) {
log.debug("Forcefully including all files from: " + basedir);
for (int j = 0; j < includes.length; j++) {
File file = new File(basedir, includes[j]);
log.debug(" " + file);
compilation.addSource(file);
count++;
}
} else {
log.debug("Including changed files from: " + basedir);
SourceFileScanner sourceScanner = new SourceFileScanner(this);
File[] files = sourceScanner.restrictAsFiles(includes, basedir, destdir, mapper);
for (int j = 0; j < files.length; j++) {
log.debug(" " + files[j]);
compilation.addSource(files[j]);
count++;
}
}
}
if (count > 0) {
log.info("Compiling " + count + " source file" + (count > 1 ? "s" : "") + " to " + destdir);
compilation.compile();
} else {
log.info("No sources found to compile");
}
}
use of org.apache.tools.ant.DirectoryScanner in project yui-compressor-ant-task by n0ha.
the class YuiCompressorTask method execute.
@Override
public void execute() {
validateDirs();
final DirectoryScanner ds = getDirectoryScanner(fromDir);
final String[] files = ds.getIncludedFiles();
for (final String file : files) {
final File inFile = new File(fromDir.getAbsolutePath(), file);
final String fileType = FileType.getFileType(file);
if (fileType == null) {
continue;
}
final File outFile = new File(toDir.getAbsolutePath(), file.replaceFirst(fileType + "$", newFileSuffix(fileType)));
if (isEnabled()) {
compressFile(inFile, outFile, fileType);
} else {
try {
copyFile(inFile, outFile);
} catch (final IOException e) {
e.printStackTrace();
}
}
}
if (verbose) {
log(stats.getXmlStats());
log(stats.getHtmlStats());
log(stats.getXhtmlStats());
log(stats.getJsStats());
log(stats.getCssStats());
log(stats.getTotalStats());
}
}
use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.
the class OperatorDiscoveryTest method getClassFileInClasspath.
public static String[] getClassFileInClasspath() {
String classpath = System.getProperty("java.class.path");
String[] paths = classpath.split(":");
List<String> fnames = new LinkedList<>();
for (String cp : paths) {
File f = new File(cp);
if (!f.isDirectory()) {
continue;
}
DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(f);
ds.setIncludes(new String[] { "**\\*.class" });
ds.scan();
for (String name : ds.getIncludedFiles()) {
fnames.add(new File(f, name).getAbsolutePath());
}
}
return fnames.toArray(new String[] {});
}
use of org.apache.tools.ant.DirectoryScanner in project apex-core by apache.
the class ApexCli method expandFileNames.
private static String[] expandFileNames(String fileName) throws IOException {
// TODO: need to work with other users
if (fileName.matches("^[a-zA-Z]+:.*")) {
// it's a URL
return new String[] { fileName };
}
if (fileName.startsWith("~" + File.separator)) {
fileName = System.getProperty("user.home") + fileName.substring(1);
}
fileName = new File(fileName).getCanonicalPath();
LOG.debug("Canonical path: {}", fileName);
DirectoryScanner scanner = new DirectoryScanner();
scanner.setIncludes(new String[] { fileName });
scanner.scan();
return scanner.getIncludedFiles();
}
Aggregations