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));
}
}
}
}
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);
}
}
Aggregations