use of org.apache.tools.ant.DirectoryScanner in project camunda-bpm-platform by camunda.
the class DeployBarTask method execute.
public void execute() throws BuildException {
List<File> files = new ArrayList<File>();
if (file != null) {
files.add(file);
}
if (fileSets != null) {
for (FileSet fileSet : fileSets) {
DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
File baseDir = directoryScanner.getBasedir();
String[] includedFiles = directoryScanner.getIncludedFiles();
String[] excludedFiles = directoryScanner.getExcludedFiles();
List<String> excludedFilesList = Arrays.asList(excludedFiles);
for (String includedFile : includedFiles) {
if (!excludedFilesList.contains(includedFile)) {
files.add(new File(baseDir, includedFile));
}
}
}
}
Thread currentThread = Thread.currentThread();
ClassLoader originalClassLoader = currentThread.getContextClassLoader();
currentThread.setContextClassLoader(DeployBarTask.class.getClassLoader());
LogUtil.readJavaUtilLoggingConfigFromClasspath();
try {
log("Initializing process engine " + processEngineName);
ProcessEngines.init();
ProcessEngine processEngine = ProcessEngines.getProcessEngine(processEngineName);
if (processEngine == null) {
List<ProcessEngineInfo> processEngineInfos = ProcessEngines.getProcessEngineInfos();
if (processEngineInfos != null && processEngineInfos.size() > 0) {
// Since no engine with the given name is found, we can't be 100% sure which ProcessEngineInfo
// is causing the error. We should show ALL errors and process engine names / resource URL's.
String message = getErrorMessage(processEngineInfos, processEngineName);
throw new ProcessEngineException(message);
} else
throw new ProcessEngineException("Could not find a process engine with name '" + processEngineName + "', no engines found. " + "Make sure an engine configuration is present on the classpath");
}
RepositoryService repositoryService = processEngine.getRepositoryService();
log("Starting to deploy " + files.size() + " files");
for (File file : files) {
String path = file.getAbsolutePath();
log("Handling file " + path);
try {
FileInputStream inputStream = new FileInputStream(file);
try {
log("deploying bar " + path);
repositoryService.createDeployment().name(file.getName()).addZipInputStream(new ZipInputStream(inputStream)).deploy();
} finally {
IoUtil.closeSilently(inputStream);
}
} catch (Exception e) {
throw new BuildException("couldn't deploy bar " + path + ": " + e.getMessage(), e);
}
}
} finally {
currentThread.setContextClassLoader(originalClassLoader);
}
}
use of org.apache.tools.ant.DirectoryScanner in project pmd by pmd.
the class CPDTask method tokenizeFiles.
private void tokenizeFiles(CPD cpd) throws IOException {
for (FileSet fileSet : filesets) {
DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
String[] includedFiles = directoryScanner.getIncludedFiles();
for (int i = 0; i < includedFiles.length; i++) {
File file = new File(directoryScanner.getBasedir() + System.getProperty("file.separator") + includedFiles[i]);
log("Tokenizing " + file.getAbsolutePath(), Project.MSG_VERBOSE);
cpd.add(file);
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project openj9 by eclipse.
the class JUnitResultsSummary method execute.
@Override
public void execute() throws BuildException {
StringBuilder out = new StringBuilder();
if (fileSets.size() == 0) {
throw new BuildException("No filesets supplied.");
}
if ((property == null) && (null == file)) {
throw new BuildException("property or output file not specified");
}
int count = 0;
for (FileSet thisFileSet : fileSets) {
DirectoryScanner scanner = thisFileSet.getDirectoryScanner(getProject());
String[] files = scanner.getIncludedFiles();
if (files.length == 0) {
log("Empty fileset supplied");
}
for (String fileName : files) {
File thisFile = new File(scanner.getBasedir(), fileName);
try {
if (!thisFile.exists()) {
log("Ignoring " + thisFile.getCanonicalPath() + ", because it doesn't exist");
continue;
}
if (verbose) {
log("Processing file " + thisFile.getCanonicalPath());
}
process(thisFile, out);
count++;
} catch (Exception ex) {
throw new BuildException(ex);
}
}
}
log("Processed " + count + " test cases");
if (out.length() == 0) {
out.append("No failures detected");
}
if (property != null) {
getProject().setNewProperty(property, out.toString());
}
if (file != null) {
writeOutputFile(out);
}
}
use of org.apache.tools.ant.DirectoryScanner in project openj9 by eclipse.
the class ExecOverFiles method execute.
public void execute() throws BuildException {
if (exec == null) {
throw new BuildException("No <exec> nested element supplied.");
}
if (command == null || command.length() == 0) {
throw new BuildException("No non-empty command attribute supplied.");
}
for (FileSet fs : fileSets) {
DirectoryScanner scanner = fs.getDirectoryScanner(getProject());
String[] files = scanner.getIncludedFiles();
exec.setDir(scanner.getBasedir());
for (String filename : files) {
Commandline cmd = new Commandline(command.replace(FILENAME_REPLACE, filename));
exec.setCommand(cmd);
// overwrites file with output
exec.setOutput(new File(scanner.getBasedir() + "/" + filename));
exec.execute();
}
}
}
use of org.apache.tools.ant.DirectoryScanner in project openj9 by eclipse.
the class ClassList method createList.
private void createList() {
File path = new File((String) attribs.get(ATTRIB_OUTPUT));
if (!path.exists()) {
boolean pathCreated = path.mkdirs();
if (!pathCreated) {
throw new BuildException("The output path for the file list [" + path.getPath() + "] could not be found");
}
}
File dir = (File) attribs.get(ATTRIB_DIR);
if (!dir.exists()) {
throw new BuildException("The output path for the file list [" + dir.getPath() + "] could not be found");
}
File outputFile = new File(path, (String) attribs.get(ATTRIB_FILE));
if (outputFile.exists()) {
outputFile.delete();
}
FileWriter out = null;
try {
out = new FileWriter(outputFile);
log("Created output file " + outputFile.getPath());
DirectoryScanner ds = getDirectoryScanner(dir);
String[] files = ds.getIncludedFiles();
for (int i = 0; i < files.length; i++) {
int pos = files[i].lastIndexOf(File.separatorChar);
if (pos != -1) {
String classname = files[i].substring(pos + 1);
pos = classname.lastIndexOf('.');
if (pos != -1) {
String data = classname.substring(0, pos);
pos = data.indexOf("Pointer");
if (pos != -1) {
String shortname = data.substring(0, pos);
out.write(shortname.toLowerCase() + "=" + shortname + "\n");
} else {
out.write(data.toLowerCase() + "=" + data + "\n");
}
log("adding file: " + files[i]);
}
}
}
out.close();
} catch (IOException e) {
throw new BuildException(e);
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) {
log("Could not close output file " + e.getMessage(), Project.MSG_ERR);
}
}
}
}
Aggregations