/** * The application base directory. The base directory is the directory * of the script that is executing. So if your script is located at * "/home/joelauer/project/blaze.java" then this baes directory would be * "/home/joelauer/project" * @return The application base directory */ static public Path baseDir() { return ContextHolder.get().baseDir(); }
/** * The application base directory. The base directory is the directory * of the script that is executing. So if your script is located at * "/home/joelauer/project/blaze.java" then this baes directory would be * "/home/joelauer/project" * @return The application base directory */ static public Path baseDir() { return ContextHolder.get().baseDir(); }
static public Path userBlazeEngineScriptClassesDir(Context context, String engineName) throws IOException { // md5 of the canonical path of this application's base directory // should be a consistent hash very usable for generating classes in String key = new StringBuilder() // base directory where script is from .append(context.baseDir().toFile().getCanonicalPath()) // version of blaze .append(Version.getVersion()) .toString(); String md5hash = md5(key); // ~/.blaze/engine/{engineName}/{md5hash} Path userBlazeEngineScriptClassesDir = userBlazeEngineDir(context, engineName) .resolve(md5hash) .resolve("classes"); Files.createDirectories(userBlazeEngineScriptClassesDir); return userBlazeEngineScriptClassesDir; }
static public Path userBlazeEngineScriptClassesDir(Context context, String engineName) throws IOException { // md5 of the canonical path of this application's base directory // should be a consistent hash very usable for generating classes in String key = new StringBuilder() // base directory where script is from .append(context.baseDir().toFile().getCanonicalPath()) // version of blaze .append(Version.getVersion()) .toString(); String md5hash = md5(key); // ~/.blaze/engine/{engineName}/{md5hash} Path userBlazeEngineScriptClassesDir = userBlazeEngineDir(context, engineName) .resolve(md5hash) .resolve("classes"); Files.createDirectories(userBlazeEngineScriptClassesDir); return userBlazeEngineScriptClassesDir; }
@Override public void init(Context initialContext) throws BlazeException { super.init(initialContext); try { // initialize engine with the base directory URL root = initialContext.baseDir().toUri().toURL(); this.groovy = new GroovyScriptEngine(new URL[] { root }); } catch (IOException e) { throw new BlazeException("Unable to create groovy", e); } }