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
This commit is contained in:
parent
b20ef3074a
commit
2ea2823a35
4 changed files with 41 additions and 11 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue