Search in sources :

Example 66 with FileSet

use of org.apache.tools.ant.types.FileSet in project datanucleus-core by datanucleus.

the class EnhancerTask method getDirectoryScanner.

private DirectoryScanner getDirectoryScanner(File dir) {
    FileSet fileset = new FileSet();
    fileset.setDir(dir);
    return fileset.getDirectoryScanner(getProject());
}
Also used : FileSet(org.apache.tools.ant.types.FileSet)

Example 67 with FileSet

use of org.apache.tools.ant.types.FileSet in project datanucleus-core by datanucleus.

the class SchemaToolTask method getFiles.

protected File[] getFiles() {
    List<File> v = new ArrayList<File>();
    Iterator<FileSet> filesetIter = filesets.iterator();
    while (filesetIter.hasNext()) {
        FileSet fs = filesetIter.next();
        DirectoryScanner ds = fs.getDirectoryScanner(getProject());
        ds.scan();
        String[] f = ds.getIncludedFiles();
        for (int j = 0; j < f.length; j++) {
            String pathname = f[j];
            File file = new File(ds.getBasedir(), pathname);
            file = getProject().resolveFile(file.getPath());
            v.add(file);
        }
    }
    return v.toArray(new File[v.size()]);
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) ArrayList(java.util.ArrayList) File(java.io.File)

Example 68 with FileSet

use of org.apache.tools.ant.types.FileSet 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 69 with FileSet

use of org.apache.tools.ant.types.FileSet 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 70 with FileSet

use of org.apache.tools.ant.types.FileSet 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)

Aggregations

FileSet (org.apache.tools.ant.types.FileSet)165 File (java.io.File)124 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)83 BuildException (org.apache.tools.ant.BuildException)49 Test (org.junit.Test)41 IOException (java.io.IOException)36 ArrayList (java.util.ArrayList)29 Project (org.apache.tools.ant.Project)22 Resource (org.apache.tools.ant.types.Resource)12 FileResource (org.apache.tools.ant.types.resources.FileResource)10 URL (java.net.URL)6 Hashtable (java.util.Hashtable)6 ArchiveFileSet (org.apache.tools.ant.types.ArchiveFileSet)6 Path (org.apache.tools.ant.types.Path)6 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)6 PrintStream (java.io.PrintStream)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 ZipFileSet (org.apache.tools.ant.types.ZipFileSet)5