r9435 - in helma/helma/trunk/src/helma: framework/core scripting/rhino

[email protected]
Newsgroups gmane.comp.java.helma.cvs
Message-ID <[email protected]>
Author: hannes
Date: 2008-12-15 23:46:29 +0100 (Mon, 15 Dec 2008)
New Revision: 9435

Modified:
   helma/helma/trunk/src/helma/framework/core/Application.java
   helma/helma/trunk/src/helma/framework/core/ApplicationBean.java
   helma/helma/trunk/src/helma/framework/core/TypeManager.java
   helma/helma/trunk/src/helma/scripting/rhino/RhinoCore.java
Log:
Make sure repositories added via app.addRepository are added before the current repository, but don't make the current repository their parent repository. This mostly undoes revision 9305, and fixes bug 654 http://helma.org/bugs/show_bug.cgi?id=654

Details at http://dev.helma.org/trac/helma/changeset/9435

Modified: helma/helma/trunk/src/helma/framework/core/Application.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/Application.java	2008-12-15 15:54:41 UTC (rev 9434)
+++ helma/helma/trunk/src/helma/framework/core/Application.java	2008-12-15 22:46:29 UTC (rev 9435)
@@ -1317,7 +1317,7 @@
     //////////////////////////////////////////////////////////////////////////////////////////////////////////
 
     /**
-     *  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 @@
      * 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;
                 }
             }
@@ -1742,6 +1743,28 @@
     }
 
     /**
+     * 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
      */
     public File getServerDir() {

Modified: helma/helma/trunk/src/helma/framework/core/ApplicationBean.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/ApplicationBean.java	2008-12-15 15:54:41 UTC (rev 9434)
+++ helma/helma/trunk/src/helma/framework/core/ApplicationBean.java	2008-12-15 22:46:29 UTC (rev 9435)
@@ -138,6 +138,9 @@
      * @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 @@
         } 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) {

Modified: helma/helma/trunk/src/helma/framework/core/TypeManager.java
===================================================================
--- helma/helma/trunk/src/helma/framework/core/TypeManager.java	2008-12-15 15:54:41 UTC (rev 9434)
+++ helma/helma/trunk/src/helma/framework/core/TypeManager.java	2008-12-15 22:46:29 UTC (rev 9435)
@@ -141,7 +141,7 @@
 
             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);
                 }

Modified: helma/helma/trunk/src/helma/scripting/rhino/RhinoCore.java
===================================================================
--- helma/helma/trunk/src/helma/scripting/rhino/RhinoCore.java	2008-12-15 15:54:41 UTC (rev 9434)
+++ helma/helma/trunk/src/helma/scripting/rhino/RhinoCore.java	2008-12-15 22:46:29 UTC (rev 9435)
@@ -799,6 +799,9 @@
         String sourceName = code.getName();
         Reader reader = null;
 
+        Resource previousCurrentResource = app.getCurrentCodeResource();
+        app.setCurrentCodeResource(code);
+
         String encoding = app.getProperty("sourceCharset");
 
         try {
@@ -834,6 +837,7 @@
                 wrappercache.clear();
             }
         } finally {
+            app.setCurrentCodeResource(previousCurrentResource);
             if (reader != null) {
                 try {
                     reader.close();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.