use of com.laytonsmith.core.exceptions.CRE.CREIncludeException in project CommandHelper by EngineHub.
the class IncludeCache method get.
public static ParseTree get(File file, Target t) {
CHLog.GetLogger().Log(TAG, LogLevel.DEBUG, "Loading " + file, t);
if (cache.containsKey(file)) {
CHLog.GetLogger().Log(TAG, LogLevel.INFO, "Returning " + file + " from cache", t);
return cache.get(file);
}
CHLog.GetLogger().Log(TAG, LogLevel.VERBOSE, "Cache does not already contain file. Compiling and caching.", t);
// We have to pull the file from the FS, and compile it.
if (!Security.CheckSecurity(file)) {
throw new CRESecurityException("The script cannot access " + file + " due to restrictions imposed by the base-dir setting.", t);
}
CHLog.GetLogger().Log(TAG, LogLevel.VERBOSE, "Security check passed", t);
try {
String s = new ZipReader(file).getFileContents();
ParseTree tree = MethodScriptCompiler.compile(MethodScriptCompiler.lex(s, file, true));
CHLog.GetLogger().Log(TAG, LogLevel.VERBOSE, "Compilation succeeded, adding to cache.", t);
IncludeCache.add(file, tree);
return tree;
} catch (ConfigCompileException ex) {
throw new CREIncludeException("There was a compile error when trying to include the script at " + file + "\n" + ex.getMessage() + " :: " + file.getName() + ":" + ex.getLineNum(), t);
} catch (ConfigCompileGroupException ex) {
StringBuilder b = new StringBuilder();
b.append("There were compile errors when trying to include the script at ").append(file).append("\n");
for (ConfigCompileException e : ex.getList()) {
b.append(e.getMessage()).append(" :: ").append(e.getFile().getName()).append(":").append(e.getLineNum());
}
throw new CREIncludeException(b.toString(), t);
} catch (IOException ex) {
throw new CREIOException("The script at " + file + " could not be found or read in.", t);
}
}
Aggregations