* Actually add embedded top-level repositories to the app's repositories

* Simplify last-top-level-repository check in TypeManager
* Fix Application.getAppDir()
This commit is contained in:
hns 2005-03-23 16:42:38 +00:00
parent 92da97550c
commit 908424d18a
2 changed files with 77 additions and 26 deletions

View file

@ -46,17 +46,20 @@ public final class Application implements IPathElement, Runnable {
// the name of this application // the name of this application
private String name; private String name;
// application sources
ArrayList repositories;
// properties and db-properties // properties and db-properties
ResourceProperties props; ResourceProperties props;
// properties and db-properties // properties and db-properties
ResourceProperties dbProps; ResourceProperties dbProps;
// Helma server home directory // This application's main directory
File home; File appDir;
// application sources // Helma server hopHome directory
ArrayList repositories; File hopHome;
// embedded db directory // embedded db directory
File dbDir; File dbDir;
@ -138,7 +141,7 @@ public final class Application implements IPathElement, Runnable {
private CryptResource pwfile; private CryptResource pwfile;
// Map of java class names to object prototypes // Map of java class names to object prototypes
ResourceProperties classMapping; ResourceProperties classMapping;
// Map of extensions allowed for public skins // Map of extensions allowed for public skins
Properties skinExtensions; Properties skinExtensions;
@ -211,10 +214,10 @@ public final class Application implements IPathElement, Runnable {
ResourceProperties sysDbProps; ResourceProperties sysDbProps;
sysProps = sysDbProps = null; sysProps = sysDbProps = null;
home = null; hopHome = null;
if (server != null) { if (server != null) {
home = server.getHopHome(); hopHome = server.getHopHome();
if (dbDir == null) { if (dbDir == null) {
dbDir = new File(server.getDbHome(), name); dbDir = new File(server.getDbHome(), name);
@ -229,6 +232,13 @@ public final class Application implements IPathElement, Runnable {
dbDir.mkdirs(); dbDir.mkdirs();
} }
for (int i=0; i<repositories.length; i++) {
if (repositories[i] instanceof FileRepository) {
appDir = new File(repositories[i].getName());
break;
}
}
// give the Helma Thread group a name so the threads can be recognized // give the Helma Thread group a name so the threads can be recognized
threadgroup = new ThreadGroup("TX-" + name); threadgroup = new ThreadGroup("TX-" + name);
@ -245,8 +255,8 @@ public final class Application implements IPathElement, Runnable {
// the passwd file, to be used with the authenticate() function // the passwd file, to be used with the authenticate() function
CryptResource parentpwfile = null; CryptResource parentpwfile = null;
if (home != null) { if (hopHome != null) {
parentpwfile = new CryptResource(new FileResource(new File(home, "passwd")), null); parentpwfile = new CryptResource(new FileResource(new File(hopHome, "passwd")), null);
} }
pwfile = new CryptResource(repositories[0].getResource("passwd"), parentpwfile); pwfile = new CryptResource(repositories[0].getResource("passwd"), parentpwfile);
@ -435,18 +445,30 @@ public final class Application implements IPathElement, Runnable {
sessionMgr.shutdown(); sessionMgr.shutdown();
} }
/**
* Returns true if this app is currently running
*
* @return
*/
public synchronized boolean isRunning() { public synchronized boolean isRunning() {
return running; return running;
} }
/**
* Get the application directory.
*
* @return
*/
public File getAppDir() { public File getAppDir() {
try { return appDir;
return new File(((FileRepository) getRepositories().next()).getName());
} catch (ClassCastException ex) {
return null;
}
} }
/**
* Get a comparator for comparing Resources according to the order of
* repositories they're contained in.
*
* @return
*/
public ResourceComparator getResourceComparator() { public ResourceComparator getResourceComparator() {
return resourceComparator; return resourceComparator;
} }
@ -1569,6 +1591,33 @@ public final class Application implements IPathElement, Runnable {
return name; return name;
} }
/**
* Add a repository to this app's repository list. This is used for
* ZipRepositories contained in top-level file repositories, for instance.
*
* @param rep
* @return if the repository was not yet contained
*/
public boolean addRepository(Repository rep) {
if (rep != null && !repositories.contains(rep)) {
// Add the new repository before its parent 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);
return true;
}
}
// no parent or parent not in app's repositories.
repositories.add(rep);
return true;
}
return false;
}
/** /**
* Searches for the index of the given repository for this app. * Searches for the index of the given repository for this app.
* The arguement must be a root argument, or -1 will be returned. * The arguement must be a root argument, or -1 will be returned.
@ -1586,14 +1635,14 @@ public final class Application implements IPathElement, Runnable {
* @return iterator through application repositories * @return iterator through application repositories
*/ */
public Iterator getRepositories() { public Iterator getRepositories() {
return repositories.iterator(); return ((List) repositories.clone()).iterator();
} }
/** /**
* Return the directory of the Helma server * Return the directory of the Helma server
*/ */
public File getServerDir() { public File getServerDir() {
return home; return hopHome;
} }
/** /**

View file

@ -39,8 +39,6 @@ public final class TypeManager {
final static String skinExtension = ".skin"; final static String skinExtension = ".skin";
private Application app; private Application app;
Repository[] repositories;
long[] modified;
// map of prototypes // map of prototypes
private HashMap prototypes; private HashMap prototypes;
@ -49,6 +47,7 @@ public final class TypeManager {
private long lastCheck = 0; private long lastCheck = 0;
private long lastCodeUpdate; private long lastCodeUpdate;
private long lastRepositoryScan;
// app specific class loader, includes jar files in the app directory // app specific class loader, includes jar files in the app directory
private AppClassLoader loader; private AppClassLoader loader;
@ -62,9 +61,6 @@ public final class TypeManager {
*/ */
public TypeManager(Application app) { public TypeManager(Application app) {
this.app = app; this.app = app;
repositories = new Repository[app.repositories.size()];
app.repositories.toArray(repositories);
modified = new long[repositories.length];
prototypes = new HashMap(); prototypes = new HashMap();
jarfiles = new HashSet(); jarfiles = new HashSet();
@ -124,7 +120,10 @@ public final class TypeManager {
for (int i = 0; i < list.length; i++) { for (int i = 0; i < list.length; i++) {
if (list[i].isScriptRoot()) { if (list[i].isScriptRoot()) {
// this is an embedded top-level script repository // this is an embedded top-level script repository
checkRepository(list[i]); if (app.addRepository(list[i])) {
// repository is new, check it
checkRepository(list[i]);
}
} else { } else {
// its an prototype // its an prototype
String name = null; String name = null;
@ -162,11 +161,14 @@ public final class TypeManager {
*/ */
private void checkRepositories() throws IOException { private void checkRepositories() throws IOException {
// check if any files have been created/removed since last time we checked... // check if any files have been created/removed since last time we checked...
for (int i = 0; i < repositories.length; i++) { Iterator it = app.getRepositories();
if (repositories[i].lastModified() > modified[i]) { while (it.hasNext()) {
modified[i] = repositories[i].lastModified(); Repository repository = (Repository) it.next();
if (repository.lastModified() > lastRepositoryScan) {
lastRepositoryScan = Math.max(System.currentTimeMillis(),
repository.lastModified());
checkRepository(repositories[i]); checkRepository(repository);
} }
} }