Search in sources :

Example 1 with ScriptCompiler

use of com.dexels.navajo.compiler.ScriptCompiler in project navajo by Dexels.

the class BundleCreatorComponent method getApplicableScriptFile.

private File getApplicableScriptFile(String rpcName, String tenant) {
    for (ScriptCompiler compiler : compilers.values()) {
        File scriptFolder = new File(navajoIOConfig.getRootPath(), compiler.getRelativeScriptPath());
        if (tenant != null) {
            String tenantFilename = rpcName + "_" + tenant + compiler.getScriptExtension();
            File f = new File(scriptFolder, tenantFilename);
            if (f.exists()) {
                return f;
            }
        }
        String filename = rpcName + compiler.getScriptExtension();
        File f = new File(scriptFolder, filename);
        if (f.exists()) {
            return f;
        }
    }
    return null;
}
Also used : ScriptCompiler(com.dexels.navajo.compiler.ScriptCompiler) File(java.io.File)

Example 2 with ScriptCompiler

use of com.dexels.navajo.compiler.ScriptCompiler 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

ScriptCompiler (com.dexels.navajo.compiler.ScriptCompiler)2 File (java.io.File)2 SkipCompilationException (com.dexels.navajo.mapping.compiler.SkipCompilationException)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractFileFilter (org.apache.commons.io.filefilter.AbstractFileFilter)1 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)1