Search in sources :

Example 56 with DirectoryScanner

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);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) BuildException(org.apache.tools.ant.BuildException) ProcessEngineInfo(org.camunda.bpm.engine.ProcessEngineInfo) ZipInputStream(java.util.zip.ZipInputStream) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 57 with DirectoryScanner

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

Example 58 with DirectoryScanner

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

Example 59 with DirectoryScanner

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

Example 60 with DirectoryScanner

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

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