Change appDir handling:

* If appDir is not defined in apps.properties, use the last file repository as appdir
   (used to be the first one)
* If appDir is defined, add it to the end of the repository list if it isn't explicitly
   listed as repository.
* If appDir is defined in apps.properties, use it for the app.dir JS variable.
* Never automatically create an app's file repositories.
This commit is contained in:
hns 2005-12-12 17:54:26 +00:00
parent fa3ddd8a68
commit 326f30a88b
2 changed files with 27 additions and 31 deletions

View file

@ -180,7 +180,7 @@ public final class Application implements IPathElement, Runnable {
*/
public Application(String name, Repository[] repositories, File dbDir)
throws RemoteException, IllegalArgumentException {
this(name, null, repositories, dbDir);
this(name, null, repositories, null, dbDir);
}
/**
@ -189,14 +189,15 @@ public final class Application implements IPathElement, Runnable {
*/
public Application(String name, Server server)
throws RemoteException, IllegalArgumentException {
this(name, server, new Repository[0], null);
this(name, server, new Repository[0], null, null);
}
/**
* Build an application with the given name, server instance, sources and
* db directory.
*/
public Application(String name, Server server, Repository[] repositories, File customDbDir)
public Application(String name, Server server, Repository[] repositories,
File customAppDir, File customDbDir)
throws RemoteException, IllegalArgumentException {
if ((name == null) || (name.trim().length() == 0)) {
throw new IllegalArgumentException("Invalid application name: " + name);
@ -212,6 +213,7 @@ public final class Application implements IPathElement, Runnable {
this.repositories.addAll(Arrays.asList(repositories));
resourceComparator = new ResourceComparator(this);
appDir = customAppDir;
dbDir = customDbDir;
// system-wide properties, default to null
@ -239,10 +241,12 @@ public final class Application implements IPathElement, Runnable {
dbDir.mkdirs();
}
for (int i=0; i<repositories.length; i++) {
if (repositories[i] instanceof FileRepository) {
appDir = new File(repositories[i].getName());
break;
if (appDir == null) {
for (int i=repositories.length-1; i>=0; i--) {
if (repositories[i] instanceof FileRepository) {
appDir = new File(repositories[i].getName());
break;
}
}
}

View file

@ -333,18 +333,17 @@ public class ApplicationManager implements XmlRpcHandler {
// read and configure app repositories
ArrayList repositoryList = new ArrayList();
Class[] parameters = { String.class };
for (int i = 0; true; i++) {
Class[] parameters = { String.class };
String repositoryArgs = props.getProperty(name + ".repository." + i);
String[] repositoryArgs = { props.getProperty(name + ".repository." + i) };
if (repositoryArgs[0] != null) {
if (repositoryArgs != null) {
// lookup repository implementation
String repositoryImpl = props.getProperty(name + ".repository." + i +
".implementation");
if (repositoryImpl == null) {
// implementation not set manually, have to guess it
if (repositoryArgs[0].endsWith(".zip")) {
if (repositoryArgs.endsWith(".zip")) {
repositoryImpl = "helma.framework.repository.ZipRepository";
} else {
repositoryImpl = "helma.framework.repository.FileRepository";
@ -355,10 +354,10 @@ public class ApplicationManager implements XmlRpcHandler {
try {
newRepository = (Repository) Class.forName(repositoryImpl)
.getConstructor(parameters)
.newInstance((Object[]) repositoryArgs);
.newInstance(new Object[] { repositoryArgs });
repositoryList.add(newRepository);
} catch (Exception ex) {
System.out.println("Adding repository " + repositoryArgs[0] + " failed. " +
System.out.println("Adding repository " + repositoryArgs + " failed. " +
"Will not use that repository. Check your initArgs!");
}
} else {
@ -369,24 +368,17 @@ public class ApplicationManager implements XmlRpcHandler {
}
}
if (repositoryList.size() > 0) {
repositories = new Repository[repositoryList.size()];
repositoryList.toArray(repositories);
} else {
repositories = new Repository[1];
if (appDir != null) {
repositories[0] = new FileRepository(appDir);
} else {
repositories[0] = new FileRepository(new File(server.getAppsHome(), appName));
}
try {
if (!repositories[0].exists()) {
repositories[0].create();
}
} catch (Exception swallow) {
// couldn't create repository
if (appDir != null) {
FileRepository appRep = new FileRepository(appDir);
if (!repositoryList.contains(appRep)) {
repositoryList.add(appRep);
}
} else if (repositoryList.isEmpty()) {
repositoryList.add(new FileRepository(
new File(server.getAppsHome(), appName)));
}
repositories = new Repository[repositoryList.size()];
repositoryList.toArray(repositories);
}
@ -395,7 +387,7 @@ public class ApplicationManager implements XmlRpcHandler {
try {
// create the application instance
app = new Application(appName, server, repositories, dbDir);
app = new Application(appName, server, repositories, appDir, dbDir);
// register ourselves
descriptors.put(appName, this);