diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index d02b3da4..0622c1ad 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -1317,7 +1317,7 @@ public final class Application implements Runnable { ////////////////////////////////////////////////////////////////////////////////////////////////////////// /** - * Return the name to be used to get this element from its parent + * Return the name to be used to get this element from its parent */ public String getElementName(Object obj) { if (obj instanceof IPathElement) { @@ -1699,18 +1699,19 @@ public final class Application implements Runnable { * ZipRepositories contained in top-level file repositories, for instance. * * @param rep the repository to add + * @param current the current/parent repository * @return if the repository was not yet contained */ - public boolean addRepository(Repository rep) { + public boolean addRepository(Repository rep, Repository current) { if (rep != null && !repositories.contains(rep)) { - // Add the new repository before its parent repository. + // Add the new repository before its parent/current repository. // This establishes the order of compilation between FileRepositories - // and embedded ZipRepositories. - Repository parent = rep.getParentRepository(); - if (parent != null) { - int idx = repositories.indexOf(parent); - if (idx > -1) { - repositories.add(idx, rep); + // and embedded ZipRepositories, or repositories added + // via app.addRepository() + if (current != null) { + int pos = repositories.indexOf(current); + if (pos > -1) { + repositories.add(pos, rep); return true; } } @@ -1741,6 +1742,28 @@ public final class Application implements Runnable { return Collections.unmodifiableList(repositories); } + /** + * Set the code resource currently being evaluated/compiled. This is used + * to set the proper parent repository when a new repository is added + * via app.addRepository(). + * + * @param resource the resource being currently evaluated/compiled + */ + public void setCurrentCodeResource(Resource resource) { + currentCodeResource = resource; + } + + /** + * Set the code resource currently being evaluated/compiled. This is used + * to set the proper parent repository when a new repository is added + * via app.addRepository(). + + * @return the resource being currently evaluated/compiled + */ + public Resource getCurrentCodeResource() { + return currentCodeResource; + } + /** * Return the directory of the Helma server */ diff --git a/src/helma/framework/core/ApplicationBean.java b/src/helma/framework/core/ApplicationBean.java index d23c2c4c..13b2bb26 100644 --- a/src/helma/framework/core/ApplicationBean.java +++ b/src/helma/framework/core/ApplicationBean.java @@ -138,6 +138,9 @@ public class ApplicationBean implements Serializable { * @param obj the repository, relative or absolute path to the library. */ public synchronized void addRepository(Object obj) { + Resource current = app.getCurrentCodeResource(); + Repository parent = current == null ? + null : current.getRepository().getRootRepository(); Repository rep; if (obj instanceof String) { String path = (String) obj; @@ -164,7 +167,7 @@ public class ApplicationBean implements Serializable { } else { throw new RuntimeException("Invalid argument to addRepository: " + obj); } - app.addRepository(rep); + app.addRepository(rep, parent); try { app.typemgr.checkRepository(rep, true); } catch (IOException iox) { diff --git a/src/helma/framework/core/TypeManager.java b/src/helma/framework/core/TypeManager.java index 818a250b..d6696c28 100644 --- a/src/helma/framework/core/TypeManager.java +++ b/src/helma/framework/core/TypeManager.java @@ -141,7 +141,7 @@ public final class TypeManager { if (list[i].isScriptRoot()) { // this is an embedded top-level script repository - if (app.addRepository(list[i])) { + if (app.addRepository(list[i], list[i].getParentRepository())) { // repository is new, check it checkRepository(list[i], update); } diff --git a/src/helma/scripting/rhino/RhinoCore.java b/src/helma/scripting/rhino/RhinoCore.java index 41ecb8ab..e9d85262 100644 --- a/src/helma/scripting/rhino/RhinoCore.java +++ b/src/helma/scripting/rhino/RhinoCore.java @@ -799,6 +799,9 @@ public final class RhinoCore implements ScopeProvider { String sourceName = code.getName(); Reader reader = null; + Resource previousCurrentResource = app.getCurrentCodeResource(); + app.setCurrentCodeResource(code); + String encoding = app.getProperty("sourceCharset"); try { @@ -834,6 +837,7 @@ public final class RhinoCore implements ScopeProvider { wrappercache.clear(); } } finally { + app.setCurrentCodeResource(previousCurrentResource); if (reader != null) { try { reader.close();