Search in sources :

Example 1 with AbstractFileFilter

use of org.apache.commons.io.filefilter.AbstractFileFilter in project fabric8 by jboss-fuse.

the class PatchTestSupport method preparePatchZip.

protected void preparePatchZip(String directoryToZip, String zipFile, final boolean includeParentDirectory) throws IOException {
    File zip = new File(zipFile);
    zip.getParentFile().mkdirs();
    final ZipArchiveOutputStream zos1 = new ZipArchiveOutputStream(new FileOutputStream(zip));
    final File patchDirectory = new File(directoryToZip);
    FileUtils.iterateFilesAndDirs(patchDirectory, new AbstractFileFilter() {

        @Override
        public boolean accept(File file) {
            if (file.isDirectory()) {
                return false;
            }
            String path = Utils.relative(includeParentDirectory ? patchDirectory.getParentFile() : patchDirectory, file);
            ZipArchiveEntry entry = new ZipArchiveEntry(path);
            try {
                try {
                    Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(file.toPath());
                    entry.setUnixMode(Utils.getUnixModeFromPermissions(file, permissions));
                } catch (UnsupportedOperationException ignoredOnWindows) {
                }
                byte[] bytes = FileUtils.readFileToByteArray(file);
                zos1.putArchiveEntry(entry);
                zos1.write(bytes, 0, bytes.length);
                zos1.closeArchiveEntry();
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
            return true;
        }
    }, DirectoryFileFilter.DIRECTORY);
    zos1.close();
}
Also used : Set(java.util.Set) FileOutputStream(java.io.FileOutputStream) ZipArchiveOutputStream(org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IOException(java.io.IOException) File(java.io.File) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Example 2 with AbstractFileFilter

use of org.apache.commons.io.filefilter.AbstractFileFilter in project dcos-commons by mesosphere.

the class ExampleMultiServiceResource method listYamls.

/**
 * Returns a list of all available YAML examples, suitable for launching an example service against.
 */
@Path("yaml")
@GET
public Response listYamls() {
    JSONArray yamls = new JSONArray();
    // Sort names alphabetically:
    Collection<File> files = new TreeSet<>(FileUtils.listFiles(new File(YAML_DIR), new AbstractFileFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(YAML_EXT);
        }
    }, null));
    for (File f : files) {
        String name = f.getName();
        // Remove .yml extension in response:
        yamls.put(name.substring(0, name.length() - YAML_EXT.length()));
    }
    return ResponseUtils.jsonOkResponse(yamls);
}
Also used : TreeSet(java.util.TreeSet) JSONArray(org.json.JSONArray) File(java.io.File) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with AbstractFileFilter

use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.

the class BundleCreatorComponent method doInstall.

private Bundle doInstall(String scriptPath, boolean force) throws BundleException, FileNotFoundException, MalformedURLException {
    String rpcName = rpcNameFromScriptPath(scriptPath);
    Bundle b = null;
    // Non-tenant specific jar file
    File compiledPath = new File(navajoIOConfig.getCompiledScriptPath(), FilenameUtils.getPath(rpcName));
    File jarFile = new File(compiledPath, FilenameUtils.getBaseName(rpcName) + ".jar");
    // Look for other tenant-specific jar files
    AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getBaseName(rpcName) + "_*.jar");
    if (!compiledPath.exists() || !compiledPath.isDirectory()) {
        logger.warn("CompiledPath is not a directory? {} This is going to crash...", compiledPath);
    }
    Collection<File> files = FileUtils.listFiles(compiledPath, fileFilter, null);
    if (jarFile.exists()) {
        files.add(jarFile);
    }
    for (File bundleFile : files) {
        final String uri = bundleFile.toURI().toURL().toString();
        Bundle previous = bundleContext.getBundle(uri);
        if (previous != null) {
            if (force) {
                logger.debug("uninstalling bundle with URI {} with file: {}: ", uri, bundleFile);
                previous.uninstall();
            } else {
                logger.debug("Skipping bundle at: " + uri + " as it is already installed. Lastmod: " + new Date(previous.getLastModified()) + " status: " + previous.getState());
                continue;
            }
        }
        logger.debug("Installing script: {}", bundleFile.getName());
        FileInputStream fis = new FileInputStream(bundleFile);
        b = this.bundleContext.installBundle(uri, fis);
        b.start();
    }
    scriptsMap.remove(rpcName);
    return b;
}
Also used : Bundle(org.osgi.framework.Bundle) File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) Date(java.util.Date) FileInputStream(java.io.FileInputStream) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Example 4 with AbstractFileFilter

use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.

the class BundleCreatorComponent method removeOldCompiledScriptFiles.

private void removeOldCompiledScriptFiles(String rpcName) {
    AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getBaseName(rpcName) + "_*.jar");
    File compiledPath = new File(navajoIOConfig.getCompiledScriptPath(), FilenameUtils.getPath(rpcName));
    if (compiledPath.isDirectory()) {
        // Removing jar itself
        File jarFile = new File(compiledPath, FilenameUtils.getBaseName(rpcName) + ".jar");
        if (jarFile.exists()) {
            jarFile.delete();
        }
        Collection<File> files = FileUtils.listFiles(compiledPath, fileFilter, null);
        for (File bundleFile : files) {
            if (bundleFile.isFile() && bundleFile.exists()) {
                bundleFile.delete();
            }
        }
    }
}
Also used : WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) File(java.io.File) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Example 5 with AbstractFileFilter

use of org.apache.commons.io.filefilter.AbstractFileFilter in project navajo by Dexels.

the class TslPreCompiler method addSuperEntityDependency.

private void addSuperEntityDependency(String scriptFile, String scriptTenant, String scriptFolder, List<Dependency> deps, Document tslDoc, Element n, String superEntity) {
    String version = "0";
    if (superEntity.indexOf(".") != -1) {
        version = superEntity.substring(superEntity.indexOf(".") + 1, superEntity.indexOf("?") == -1 ? superEntity.length() : superEntity.indexOf("?"));
    }
    String replace = "." + version;
    superEntity = superEntity.replace(replace, "");
    if (superEntity.indexOf('?') > 0) {
        superEntity = superEntity.split("\\?")[0];
    }
    if (scriptTenant != null) {
        // trying tenant-specific variant first
        String operationScriptFile = fetchScriptFileName(scriptFolder + File.separator + superEntity + "_" + scriptTenant);
        // Check if exists
        if (operationScriptFile != null) {
            deps.add(new Dependency(scriptFile, operationScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
            // Thus continue with next entity
            return;
        }
    }
    String superScriptFile = fetchScriptFileName(scriptFolder + File.separator + "entity" + File.separator + superEntity);
    // Check if exists
    boolean isBroken = false;
    if (superScriptFile == null) {
        isBroken = true;
        superScriptFile = scriptFolder + File.separator + "entity" + File.separator + superEntity + ".broken";
    }
    deps.add(new Dependency(scriptFile, superScriptFile, Dependency.ENTITY_DEPENDENCY, getLineNr(n), isBroken));
    // Going to check for tenant-specific include-variants
    if (scriptTenant == null) {
        File scriptFolderFile = new File(superScriptFile).getParentFile();
        if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
            AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(superEntity) + "_*.xml");
            Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
            for (File f : files) {
                deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
            }
            // NS3
            AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(superEntity) + "_*.ns");
            Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
            for (File f : filesNS3) {
                deps.add(new Dependency(scriptFile, f.getAbsolutePath(), Dependency.ENTITY_DEPENDENCY, getLineNr(n)));
            }
        }
    }
}
Also used : File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Aggregations

File (java.io.File)12 AbstractFileFilter (org.apache.commons.io.filefilter.AbstractFileFilter)12 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)8 IOException (java.io.IOException)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 FileOutputStream (java.io.FileOutputStream)2 Set (java.util.Set)2 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)2 ZipArchiveOutputStream (org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream)2 ScriptCompiler (com.dexels.navajo.compiler.ScriptCompiler)1 SkipCompilationException (com.dexels.navajo.mapping.compiler.SkipCompilationException)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 UserException (com.dexels.navajo.script.api.UserException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1