jboynes 2004/02/18 10:02:57
Modified:
modules/system/src/java/org/apache/geronimo/system/logging/log4j/appender
FileAppenderService.java
modules/system/src/java/org/apache/geronimo/system/serverinfo
ServerInfo.java
Log:
Support directories with spaces in them
Bit of tidy up too
Revision Changes Path
1.2 +4 -1
incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/logging/log4j/appender/FileAppenderService.java
Index: FileAppenderService.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/logging/log4j/appender/FileAppenderService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FileAppenderService.java 12 Feb 2004 18:12:52 -0000 1.1
+++ FileAppenderService.java 18 Feb 2004 18:02:57 -0000 1.2
@@ -56,6 +56,8 @@
package org.apache.geronimo.system.logging.log4j.appender;
+import java.io.File;
+
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
@@ -117,6 +119,7 @@
private void setAppenderFile(String file) {
file = serverInfo.resolvePath(file);
+ new File(file).getParentFile().mkdirs();
((FileAppender) appender).setFile(file);
}
1.3 +23 -63
incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
Index: ServerInfo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServerInfo.java 13 Feb 2004 23:21:39 -0000 1.2
+++ ServerInfo.java 18 Feb 2004 18:02:57 -0000 1.3
@@ -56,9 +56,9 @@
package org.apache.geronimo.system.serverinfo;
import java.io.File;
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.io.IOException;
import java.net.JarURLConnection;
+import java.net.URI;
import java.net.URL;
import org.apache.geronimo.gbean.GAttributeInfo;
@@ -71,7 +71,6 @@
* @version $Revision$ $Date$
*/
public class ServerInfo {
- private String baseDirectory;
private final File base;
private final URI baseURI;
@@ -87,71 +86,32 @@
// Before we try the persistent value, we always check the
// system properties first. This lets an admin override this
// on the command line.
- String systemProperty = System.getProperty("geronimo.base.dir");
- if (systemProperty != null && systemProperty.length() > 0) {
- this.baseDirectory = systemProperty;
- } else {
- // next try the persistent value
- if (baseDirectory != null && baseDirectory.length() > 0) {
- this.baseDirectory = baseDirectory;
- } else {
- // last chance - guess where the base directory shoul be
- URL url =
getClass().getClassLoader().getResource("META-INF/startup-jar");
- if(url != null) {
- try {
- JarURLConnection jarConnection = (JarURLConnection)
url.openConnection();
- URI uri = new
URI(jarConnection.getJarFileURL().toString()).resolve("..");
- this.baseDirectory = uri.getPath();
- } catch (Exception e) {
- // ignore exception is thrown below
- }
- }
+ baseDirectory = System.getProperty("geronimo.base.dir",
baseDirectory);
+ if (baseDirectory == null || baseDirectory.length() == 0) {
+ // guess from the location of the jar
+ URL url =
getClass().getClassLoader().getResource("META-INF/startup-jar");
+ if (url == null) {
+ throw new IllegalArgumentException("Unable to determine
location of startup jar");
}
- }
-
- if(this.baseDirectory == null) {
- throw new IllegalArgumentException("Could not find base
directory. Please use the -Dgeronimo.base.dir=<your-directory> command line
option.");
- }
-
- // now that we have the base directory, check that it is a valid
directory
- base = new File(this.baseDirectory);
- if (base.exists()) {
- if (!base.isDirectory()) {
- throw new IllegalArgumentException("Base directory is not a
directory: " + this.baseDirectory);
+ try {
+ JarURLConnection jarConnection = (JarURLConnection)
url.openConnection();
+ url = jarConnection.getJarFileURL();
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Unable to extract base
URL from location");
}
+ baseURI = new URI(url.toString()).resolve("..");
+ base = new File(baseURI);
} else {
- if (!base.mkdirs()) {
- throw new IllegalArgumentException("Could not create base
directory: " + this.baseDirectory);
- }
+ base = new File(baseDirectory);
+ baseURI = base.toURI();
+ }
+ if (!base.isDirectory()) {
+ throw new IllegalArgumentException("Base directory is not a
directory: "+baseDirectory);
}
- baseURI = base.toURI();
}
public String resolvePath(final String filename) {
- File dir;
- File file;
- try {
- // uri supplied from the user
- URI logURI = new URI(filename);
-
- // if the log uri is relative, resolve it based on the
baseDirectory
- logURI = new URI(baseDirectory.trim() + "/.").resolve(logURI);
-
- // the base directory may be relative to the server start
directory
- logURI = new File(".").toURI().resolve(logURI);
-
- file = new File(logURI);
- dir = file.getParentFile();
- } catch (URISyntaxException e) {
- throw (IllegalArgumentException) new
IllegalArgumentException().initCause(e);
- }
-
- if (!dir.exists()) {
- boolean success = dir.mkdirs();
- if (!success) {
- throw new IllegalArgumentException("Failed to create
directory structure: " + dir);
- }
- }
+ File file = new File(base, filename);
return file.getAbsolutePath();
}
@@ -160,7 +120,7 @@
}
public String getBaseDirectory() {
- return baseDirectory;
+ return base.getAbsolutePath();
}
public String getVersion() {