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
|
@ -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) {
|
public String getElementName(Object obj) {
|
||||||
if (obj instanceof IPathElement) {
|
if (obj instanceof IPathElement) {
|
||||||
|
@ -1699,18 +1699,19 @@ public final class Application implements Runnable {
|
||||||
* ZipRepositories contained in top-level file repositories, for instance.
|
* ZipRepositories contained in top-level file repositories, for instance.
|
||||||
*
|
*
|
||||||
* @param rep the repository to add
|
* @param rep the repository to add
|
||||||
|
* @param current the current/parent repository
|
||||||
* @return if the repository was not yet contained
|
* @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)) {
|
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
|
// This establishes the order of compilation between FileRepositories
|
||||||
// and embedded ZipRepositories.
|
// and embedded ZipRepositories, or repositories added
|
||||||
Repository parent = rep.getParentRepository();
|
// via app.addRepository()
|
||||||
if (parent != null) {
|
if (current != null) {
|
||||||
int idx = repositories.indexOf(parent);
|
int pos = repositories.indexOf(current);
|
||||||
if (idx > -1) {
|
if (pos > -1) {
|
||||||
repositories.add(idx, rep);
|
repositories.add(pos, rep);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1741,6 +1742,28 @@ public final class Application implements Runnable {
|
||||||
return Collections.unmodifiableList(repositories);
|
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
|
* 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.
|
* @param obj the repository, relative or absolute path to the library.
|
||||||
*/
|
*/
|
||||||
public synchronized void addRepository(Object obj) {
|
public synchronized void addRepository(Object obj) {
|
||||||
|
Resource current = app.getCurrentCodeResource();
|
||||||
|
Repository parent = current == null ?
|
||||||
|
null : current.getRepository().getRootRepository();
|
||||||
Repository rep;
|
Repository rep;
|
||||||
if (obj instanceof String) {
|
if (obj instanceof String) {
|
||||||
String path = (String) obj;
|
String path = (String) obj;
|
||||||
|
@ -164,7 +167,7 @@ public class ApplicationBean implements Serializable {
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Invalid argument to addRepository: " + obj);
|
throw new RuntimeException("Invalid argument to addRepository: " + obj);
|
||||||
}
|
}
|
||||||
app.addRepository(rep);
|
app.addRepository(rep, parent);
|
||||||
try {
|
try {
|
||||||
app.typemgr.checkRepository(rep, true);
|
app.typemgr.checkRepository(rep, true);
|
||||||
} catch (IOException iox) {
|
} catch (IOException iox) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ public final class TypeManager {
|
||||||
|
|
||||||
if (list[i].isScriptRoot()) {
|
if (list[i].isScriptRoot()) {
|
||||||
// this is an embedded top-level script repository
|
// 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
|
// repository is new, check it
|
||||||
checkRepository(list[i], update);
|
checkRepository(list[i], update);
|
||||||
}
|
}
|
||||||
|
|
|
@ -799,6 +799,9 @@ public final class RhinoCore implements ScopeProvider {
|
||||||
String sourceName = code.getName();
|
String sourceName = code.getName();
|
||||||
Reader reader = null;
|
Reader reader = null;
|
||||||
|
|
||||||
|
Resource previousCurrentResource = app.getCurrentCodeResource();
|
||||||
|
app.setCurrentCodeResource(code);
|
||||||
|
|
||||||
String encoding = app.getProperty("sourceCharset");
|
String encoding = app.getProperty("sourceCharset");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -834,6 +837,7 @@ public final class RhinoCore implements ScopeProvider {
|
||||||
wrappercache.clear();
|
wrappercache.clear();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
app.setCurrentCodeResource(previousCurrentResource);
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue