Search in sources :

Example 11 with AbstractFileFilter

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

the class TslPreCompiler method addScriptDependency.

private void addScriptDependency(String scriptFile, String scriptTenant, List<Dependency> deps, String navajoScript, String scriptFolder, int linenr, int type) {
    boolean isExpression = false;
    if (navajoScript.startsWith("[/")) {
        isExpression = true;
    }
    String cleanScript = navajoScript.replace("'", "");
    if (type == Dependency.ENTITY_DEPENDENCY) {
        cleanScript = "entity/" + cleanScript;
    }
    if (scriptTenant != null) {
        // trying tenant-specific variant first
        String navajoScriptFile = fetchScriptFileName(scriptFolder + File.separator + cleanScript + "_" + scriptTenant);
        // Check if exists
        if (navajoScriptFile != null) {
            deps.add(new Dependency(scriptFile, navajoScriptFile, type, linenr));
            // Thus return
            return;
        }
    }
    String navajoScriptFilePartial = scriptFolder + File.separator + cleanScript;
    // Check if exists
    boolean isBroken = true;
    String navajoScriptFile = fetchScriptFileName(navajoScriptFilePartial);
    if (navajoScriptFile != null || isExpression) {
        isBroken = false;
    }
    if (isBroken) {
        // Try scala
        navajoScriptFile = navajoScriptFilePartial + ".scala";
        if (new File(navajoScriptFile).exists()) {
            isBroken = false;
        } else {
            navajoScriptFile = navajoScriptFilePartial + ".unknown";
        }
    }
    deps.add(new Dependency(scriptFile, navajoScriptFile, type, linenr, isBroken));
    // Going to check for tenant-specific include-variants
    if (scriptTenant == null && !isExpression) {
        File scriptFolderFile = new File(scriptFolder, cleanScript).getParentFile();
        if (scriptFolderFile.exists() && scriptFolderFile.isDirectory()) {
            AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(cleanScript) + "_*.xml");
            Collection<File> files = FileUtils.listFiles(scriptFolderFile, fileFilter, null);
            for (File f : files) {
                deps.add(new Dependency(scriptFile, f.getAbsolutePath(), type, linenr));
            }
            // NS3
            AbstractFileFilter fileFilterNS3 = new WildcardFileFilter(FilenameUtils.getName(cleanScript) + "_*.xml");
            Collection<File> filesNS3 = FileUtils.listFiles(scriptFolderFile, fileFilterNS3, null);
            for (File f : filesNS3) {
                deps.add(new Dependency(scriptFile, f.getAbsolutePath(), type, linenr));
            }
        }
    }
}
Also used : File(java.io.File) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) AbstractFileFilter(org.apache.commons.io.filefilter.AbstractFileFilter)

Example 12 with AbstractFileFilter

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

the class BundleCreatorComponent method createBundleNoLocking.

private void createBundleNoLocking(String rpcName, List<String> failures, List<String> success, List<String> skipped, boolean force, boolean keepIntermediate) throws CompilationException {
    boolean matchedScript = false;
    removeOldCompiledScriptFiles(rpcName);
    for (ScriptCompiler compiler : compilers.values()) {
        System.err.println("Checking compiler " + compiler + " to compile service " + rpcName);
        File scriptFolder = new File(navajoIOConfig.getRootPath(), compiler.getRelativeScriptPath());
        File f = new File(scriptFolder, rpcName + compiler.getScriptExtension());
        // Look for other tenant-specific files
        AbstractFileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getBaseName(rpcName) + "_*" + compiler.getScriptExtension());
        File dir = new File(scriptFolder, FilenameUtils.getPath(rpcName));
        Collection<File> files = Collections.<File>emptySet();
        if (dir.exists()) {
            files = FileUtils.listFiles(dir, fileFilter, null);
        }
        Map<String, File> tenantSpecificFiles = new HashMap<>();
        Collection<String> tenantsToIgnore = new ArrayList<>();
        for (File ascript : files) {
            matchedScript = true;
            String pathRelative = getRelative(scriptFolder, ascript);
            String[] splitted = pathRelative.split("\\.");
            String tenantScriptName = splitted[0].replace('\\', '/');
            tenantSpecificFiles.put(tenantScriptName, ascript);
            // Get the tenant out of the name and put it in the tenantsToIgnore collection
            tenantsToIgnore.add(tenantScriptName.split("_")[1]);
        }
        if (f.exists()) {
            matchedScript = true;
            createBundleForScript(rpcName, rpcName, f, tenantsToIgnore, true, failures, success, skipped, keepIntermediate);
        }
        for (Map.Entry<String, File> entry : tenantSpecificFiles.entrySet()) {
            createBundleForScript(entry.getKey(), rpcName, entry.getValue(), tenantsToIgnore, false, failures, success, skipped, keepIntermediate);
        }
        if (matchedScript) {
            break;
        }
    }
    if (!matchedScript) {
        throw new CompilationException("Unable to find script for " + rpcName);
    }
}
Also used : SkipCompilationException(com.dexels.navajo.mapping.compiler.SkipCompilationException) CompilationException(com.dexels.navajo.script.api.CompilationException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WildcardFileFilter(org.apache.commons.io.filefilter.WildcardFileFilter) ScriptCompiler(com.dexels.navajo.compiler.ScriptCompiler) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) 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