Implemeting both require and include.

This commit is contained in:
Eric van der Vlist 2021-05-02 10:50:48 +02:00
parent b62623370a
commit 5203bbf0e9
1 changed files with 15 additions and 6 deletions

View File

@ -11,12 +11,25 @@
out = Packages.java.lang.System.out;
CommonsOperationsUtil = Packages.ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil;
/*
* Function include
*
*/
include = function (filepath) {
out.println('include("' + filepath + '")');
filepath = CommonsOperationsUtil.expandAndResolvePath(authorAccess, filepath);
var text = new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths. get (java.net.URI(filepath))));
text = String(text);
eval(text);
}
/*
* Function require
*
*/
require = function (filepath) {
out.println('require("' + filepath + '")');
// Check if the object has been initialized
if (Object.keys(require).length == 0) {
@ -34,11 +47,7 @@ require = function (filepath) {
if (require.urisSet[filepath] == undefined) {
require.urisStack.push(filepath);
require.urisSet[filepath] = true;
var uri = new java.net.URI(filepath);
out.println('Including ' + uri.toString());
var text = new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths. get (targetURI)));
text = String(text);
eval(text);
include(filepath);
require.urisStack.pop();
}
}
}