geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r152958 - in geronimo/trunk/modules: assembly/ deploy-tool/src/java/org/apache/geronimo/deployment/ deploy-tool/src/java/org/apache/geronimo/deployment/cli/ deployment/src/java/org/apache/geronimo/deployment/ system/src/java/org/apache/geronimo/system/main/ system/src/java/org/apache/geronimo/system/serverinfo/
Date Tue, 08 Feb 2005 23:23:54 GMT
Author: dain
Date: Tue Feb  8 15:23:49 2005
New Revision: 152958

URL: http://svn.apache.org/viewcvs?view=rev&rev=152958
Log:
Added support for java.endorsed.dirs to be set via a manifest entry.  The endorsed dirs property
controls where the jvm looks for new versions of sax, dom and corba classes.
Set endorsed dirs in server.jar and client.jar to <geronimo-install-dir>/lib/endorsed

Added:
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/DirectoryUtils.java
Modified:
    geronimo/trunk/modules/assembly/maven.xml
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/Bootstrap.java
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/CommandLineManifest.java
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
    geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java

Modified: geronimo/trunk/modules/assembly/maven.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/maven.xml?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/assembly/maven.xml (original)
+++ geronimo/trunk/modules/assembly/maven.xml Tue Feb  8 15:23:49 2005
@@ -240,6 +240,8 @@
             <ant:arg value="${server.classpath}"/>
             <ant:arg value="--mainClass"/>
             <ant:arg value="org.apache.geronimo.system.main.Daemon"/>
+            <ant:arg value="--endorsedDirs"/>
+            <ant:arg value="${libDir}/endorsed"/>
             <ant:arg value="--install"/>
             <ant:arg value="target/plan/system-plan.xml"/>
             <ant:arg value="${distDir}/bin/server.jar"/>
@@ -278,6 +280,8 @@
             <ant:arg value="org.apache.geronimo.system.main.ClientCommandLine"/>
             <ant:arg value="--classPath"/>
             <ant:arg value="${client.classpath}"/>
+            <ant:arg value="--endorsedDirs"/>
+            <ant:arg value="${libDir}/endorsed"/>
             <ant:arg value="--install"/>
             <ant:arg value="target/plan/client-system-plan.xml"/>
             <ant:arg value="${distDir}/bin/client.jar"/>

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/Bootstrap.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/Bootstrap.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/Bootstrap.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/Bootstrap.java
Tue Feb  8 15:23:49 2005
@@ -42,6 +42,7 @@
     private String deployerSystemPlan;
     private String j2eeDeployerPlan;
     private String deployerClassPath;
+    private String deployerEndorsedDirs;
     private String deployerGBean;
     private String deploymentFactory;
 
@@ -93,6 +94,14 @@
         this.deployerClassPath = deployerClassPath;
     }
 
+    public String getDeployerEndorsedDirs() {
+        return deployerEndorsedDirs;
+    }
+
+    public void setDeployerEndorsedDirs(String deployerEndorsedDirs) {
+        this.deployerEndorsedDirs = deployerEndorsedDirs;
+    }
+
     public String getDeployerGBean() {
         return deployerGBean;
     }
@@ -133,6 +142,7 @@
             mainAttributes.putValue(CommandLineManifest.MAIN_GBEAN.toString(), deployerGBean);
             mainAttributes.putValue(CommandLineManifest.MAIN_METHOD.toString(), "deploy");
             mainAttributes.putValue(CommandLineManifest.CONFIGURATIONS.toString(), j2eeDeployerConfig.getConfigId());
+            mainAttributes.putValue(CommandLineManifest.ENDORSED_DIRS.toString(), deployerEndorsedDirs);
 
             // attribute that indicates to a JSR-88 tool that we have a Deployment factory
             mainAttributes.putValue("J2EE-DeploymentFactory-Implementation-Class", deploymentFactory);

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/CommandPackage.java
Tue Feb  8 15:23:49 2005
@@ -22,6 +22,9 @@
 import java.io.PrintWriter;
 import java.io.File;
 import java.util.List;
+import java.util.LinkedList;
+import java.util.Iterator;
+import java.util.Arrays;
 
 /**
  * The CLI deployer logic to create a configuration package.  Can only be run
@@ -47,56 +50,77 @@
         return true;
     }
 
-    public void execute(PrintWriter out, ServerConnection connection, String[] args) throws
DeploymentException {
+    public void execute(PrintWriter out, ServerConnection connection, String[] argArray)
throws DeploymentException {
         if(connection.isOnline()) {
             throw new DeploymentException("This command cannot be run when the server is
running.  Make sure the server is shut down first.");
         }
+
         String classPath = null;
         String mainClass = null;
-        File module = null;
-        File plan = null;
-        File packageFile;
+        String endorsedDirs = null;
         boolean install = false;
-        int i;
-        for(i = 0; i < args.length; i++) {
-            String arg = args[i];
+
+        // Read off the optional arguments (clasPath, mainClass, endorsedDirs, and install)
+        LinkedList args = new LinkedList(Arrays.asList(argArray));
+        for (Iterator iterator = args.iterator(); iterator.hasNext();) {
+            String arg = (String) iterator.next();
             if(arg.equals("--classPath")) {
-                classPath = args[++i];
+                iterator.remove();
+                classPath = (String) iterator.next();
+                iterator.remove();
             } else if(arg.equals("--mainClass")) {
-                mainClass = args[++i];
+                iterator.remove();
+                mainClass = (String) iterator.next();
+                iterator.remove();
+            } else if(arg.equals("--endorsedDirs")) {
+                iterator.remove();
+                endorsedDirs = (String) iterator.next();
+                iterator.remove();
             } else if(arg.equals("--install")) {
+                iterator.remove();
                 install = true;
             } else if(arg.startsWith("--")) {
-                throw new DeploymentSyntaxException("Invalid argument '"+arg+"'");
+                throw new DeploymentSyntaxException("Invalid option '" + arg + "'");
             } else {
                 break;
             }
         }
-        if(i >= args.length) {
+
+        // if we have any other options on the comman line they are invalid
+        for (Iterator iterator = args.iterator(); iterator.hasNext();) {
+            String arg = (String) iterator.next();
+            if(arg.startsWith("--")) {
+                throw new DeploymentSyntaxException("All command line options must appear
before module, plan or packageFile: " + arg);
+            }
+        }
+
+        if(args.isEmpty()) {
             throw new DeploymentSyntaxException("No fileName specified for package command");
         }
-        packageFile = new File(args[args.length-1]);
+
+        // Read off packageFile which is always the last argument
+        File packageFile;
+        packageFile = new File((String) args.removeLast());
         File parent = packageFile.getAbsoluteFile().getParentFile();
         if(!parent.exists() || !parent.canWrite()) {
             throw new DeploymentSyntaxException("Cannot write to output file "+packageFile.getAbsolutePath());
         }
-        if(i < args.length-1) {
-            File test = new File(args[args.length-2]);
+
+        // Read off the plan and module
+        File module = null;
+        File plan = null;
+        if(!args.isEmpty()) {
+            // if the arg is a directory or jar file, it must be the module; otherwise it
is the plan
+            File test = new File((String) args.removeLast()).getAbsoluteFile();
             if(DeployUtils.isJarFile(test) || test.isDirectory()) {
-                if(module != null) {
-                    throw new DeploymentSyntaxException("Module and plan cannot both be JAR
files or directories!");
-                }
                 module = test;
             } else {
-                if(plan != null) {
-                    throw new DeploymentSyntaxException("Module or plan must be a JAR file
or directory!");
-                }
                 plan = test;
             }
         }
-        if(i < args.length-2) {
-            File test = new File(args[args.length-2]);
-            if(DeployUtils.isJarFile(test)) {
+        if(!args.isEmpty()) {
+            File test = new File((String) args.removeLast()).getAbsoluteFile();
+            if(DeployUtils.isJarFile(test) || test.isDirectory()) {
                 if(module != null) {
                     throw new DeploymentSyntaxException("Module and plan cannot both be JAR
files or directories!");
                 }
@@ -108,17 +132,32 @@
                 plan = test;
             }
         }
-        if(i < args.length - 3) {
-            throw new DeploymentSyntaxException("Too many arguments for deploy command");
-        }
-        if(module != null) {
-            module = module.getAbsoluteFile();
-        }
-        if(plan != null) {
-            plan = plan.getAbsoluteFile();
+
+        // are there extra left over args on the command prompt
+        if(!args.isEmpty()) {
+            throw new DeploymentSyntaxException("Too many arguments for package command");
         }
-        List list = (List)connection.invokeOfflineDeployer(new Object[]{plan, module, packageFile,
install ? Boolean.TRUE : Boolean.FALSE, mainClass, classPath},
-                        new String[]{File.class.getName(), File.class.getName(), File.class.getName(),
boolean.class.getName(), String.class.getName(), String.class.getName()});
+
+        // invoke the deployer
+        List list = (List) connection.invokeOfflineDeployer(
+                new Object[]{
+                    plan,
+                    module,
+                    packageFile,
+                    install ? Boolean.TRUE : Boolean.FALSE,
+                    mainClass,
+                    classPath,
+                    endorsedDirs},
+                new String[]{
+                    File.class.getName(),
+                    File.class.getName(),
+                    File.class.getName(),
+                    boolean.class.getName(),
+                    String.class.getName(),
+                    String.class.getName(),
+                    String.class.getName()});
+
+        // print the configurations created
         for (int j = 0; j < list.size(); j++) {
             out.println("Packaged configuration "+list.get(j)+" to "+packageFile);
         }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
Tue Feb  8 15:23:49 2005
@@ -41,6 +41,7 @@
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.system.main.CommandLineManifest;
 
 /**
  * Command line based deployment utility which combines multiple deployable modules
@@ -77,7 +78,7 @@
         }
 
         try {
-            return deploy(planFile, moduleFile, null, true, null, null);
+            return deploy(planFile, moduleFile, null, true, null, null, null);
         } finally {
             if (tmpDir != null) {
                 DeploymentUtil.recursiveDelete(tmpDir);
@@ -85,46 +86,7 @@
         }
     }
 
-    /*
-     * GBean entry point invoked from an executable CAR.
-     *
-     * @param args command line args
-     *
-    public void deploy(String[] args) throws Exception {
-        Command cmd = parseArgs(args);
-        try {
-            if (cmd == null) {
-                return;
-            }
-
-            File planFile = cmd.planFile;
-            File module = cmd.moduleFile;
-            File carfile = cmd.carFile;
-            boolean install = cmd.install;
-            String mainClass = cmd.mainClass;
-            String classPath = cmd.classPath;
-
-
-            List objectNames = deploy(planFile, module, carfile, install, mainClass, classPath);
-            if (!objectNames.isEmpty()) {
-                Iterator iterator = objectNames.iterator();
-                System.out.println("Server URI: " + iterator.next());
-                while (iterator.hasNext()) {
-                    System.out.println("Client URI: " + iterator.next());
-                }
-            }
-        } finally {
-            if (cmd.isPlanFileTemp) {
-                cmd.planFile.delete();
-            }
-            if (cmd.isModuleFileTemp) {
-                cmd.moduleFile.delete();
-            }
-        }
-    }
-    */
-
-    public List deploy(File planFile, File moduleFile, File targetFile, boolean install,
String mainClass, String classPath) throws DeploymentException {
+    public List deploy(File planFile, File moduleFile, File targetFile, boolean install,
String mainClass, String classPath, String endorsedDirs) throws DeploymentException {
         if (planFile == null && moduleFile == null) {
             throw new DeploymentException("No plan or module specified");
         }
@@ -185,6 +147,9 @@
             if (classPath != null) {
                 mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), classPath);
             }
+            if (endorsedDirs != null) {
+                mainAttributes.putValue(CommandLineManifest.ENDORSED_DIRS.toString(), endorsedDirs);
+            }
 
             // Write the manifest
             FileOutputStream out = null;
@@ -243,115 +208,7 @@
             DeploymentUtil.close(module);
         }
     }
-    /*
-    private static Command parseArgs(String[] args) throws ParseException, DeploymentException
{
-        Options options = new Options();
-        options.addOption("h", "help", false, "print this message");
-        options.addOption("I", "install", false, "install configuration in store");
-        options.addOption("o", "outfile", true, "output file to generate");
-        options.addOption("m", "module", true, "module to deploy");
-        options.addOption("p", "plan", true, "deployment plan");
-        options.addOption(null, "mainClass", true, "deployment plan");
-        options.addOption(null, "classPath", true, "deployment plan");
-
-        CommandLine cmd = new PosixParser().parse(options, args);
-        if (cmd.hasOption("h")) {
-            new HelpFormatter().printHelp("deploy.jar [OPTIONS] <module>...", options);
-            return null;
-        }
 
-        Command command = new Command();
-        try {
-            command.install = cmd.hasOption('I');
-            if (cmd.hasOption('o')) {
-                command.carFile = new File(cmd.getOptionValue('o'));
-            }
-            if (cmd.hasOption('p')) {
-                URI uri = getURI(cmd.getOptionValue('p'));
-                if ("file".equals(uri.getScheme())) {
-                    command.planFile = new File(uri);
-                    command.isPlanFileTemp = false;
-                } else {
-                    try {
-                        command.planFile = DeploymentUtil.toTempFile(uri.toURL());
-                    } catch (IOException e) {
-                        throw new DeploymentException("Invalid plan file location: " + uri,
e);
-                    }
-                    command.isPlanFileTemp = true;
-                }
-            }
-            if (cmd.hasOption('m')) {
-                URI uri = getURI(cmd.getOptionValue('m'));
-                if ("file".equals(uri.getScheme())) {
-                    command.moduleFile = new File(uri);
-                    command.isModuleFileTemp = false;
-                } else {
-                    try {
-                        command.moduleFile = DeploymentUtil.toTempFile(uri.toURL());
-                    } catch (IOException e) {
-                        throw new DeploymentException("Invalid module file location: " +
uri, e);
-                    }
-                    command.isModuleFileTemp = true;
-                }
-            }
-
-            if (command.moduleFile == null && command.planFile == null) {
-                System.err.println("No plan or module specified");
-                return null;
-            }
-            if (cmd.hasOption("mainClass")) {
-                command.mainClass = cmd.getOptionValue("mainClass");
-            }
-            if (cmd.hasOption("classPath")) {
-                command.classPath = cmd.getOptionValue("classPath");
-            }
-            return command;
-        } catch (Throwable e) {
-            if (command.isPlanFileTemp) {
-                command.planFile.delete();
-            }
-            if (command.isModuleFileTemp) {
-                command.moduleFile.delete();
-            }
-
-            if (e instanceof DeploymentException) {
-                throw (DeploymentException) e;
-            } else if (e instanceof RuntimeException) {
-                throw (RuntimeException) e;
-            } else if (e instanceof Error) {
-                throw (Error) e;
-            }
-            throw new DeploymentException(e);
-        }
-    }
-
-    private static URI getURI(String location) throws DeploymentException {
-		// on windows the location may be an absolute path including a drive letter
-		// this will cause uri.resolve to fail because of the presence of a ':' character
-		// to stop this we first try locating the uri using a File object
-		File file = new File(location);
-		if (file.exists() && file.canRead()) {
-			return file.toURI();
-		}
-
-        URI uri = new File(".").toURI().resolve(location);
-        if (!"file".equals(uri.getScheme()) && uri.getPath().endsWith("/")) {
-            throw new DeploymentException("Unpacked modules can only be loaded from the local
file system");
-        }
-        return uri;
-    }
-
-    private static class Command {
-        private boolean install;
-        private File carFile;
-        private File moduleFile;
-        private boolean isModuleFileTemp = false;
-        private File planFile;
-        private boolean isPlanFileTemp = false;
-        private String mainClass;
-        private String classPath;
-    }
-*/
     public static final GBeanInfo GBEAN_INFO;
 
     private static final String DEPLOYER = "Deployer";
@@ -359,9 +216,8 @@
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(Deployer.class, DEPLOYER);
 
-//        infoFactory.addOperation("deploy", new Class[]{String[].class});
         infoFactory.addOperation("deploy", new Class[]{File.class, File.class});
-        infoFactory.addOperation("deploy", new Class[]{File.class, File.class, File.class,
boolean.class, String.class, String.class});
+        infoFactory.addOperation("deploy", new Class[]{File.class, File.class, File.class,
boolean.class, String.class, String.class, String.class});
 
         infoFactory.addReference("Builders", ConfigurationBuilder.class);
         infoFactory.addReference("Store", ConfigurationStore.class);

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/CommandLineManifest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/CommandLineManifest.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/CommandLineManifest.java
(original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/CommandLineManifest.java
Tue Feb  8 15:23:49 2005
@@ -39,6 +39,7 @@
     public static final Attributes.Name MAIN_GBEAN = new Attributes.Name("Main-GBean");
     public static final Attributes.Name MAIN_METHOD = new Attributes.Name("Main-Method");
     public static final Attributes.Name CONFIGURATIONS = new Attributes.Name("Configurations");
+    public static final Attributes.Name ENDORSED_DIRS = new Attributes.Name("Endorsed-Dirs");
 
     public static CommandLineManifest getManifestEntries() {
         // find the startup jar
@@ -92,18 +93,31 @@
                 }
             }
         }
-        CommandLineManifest commandLineManifest = new CommandLineManifest(mainGBean, mainMethod,
configurations);
+
+        // get the list of endorsed directories
+        List endorsedDirs = new ArrayList();
+        String endorsedDirsString = mainAttributes.getValue(ENDORSED_DIRS);
+        if (endorsedDirsString != null) {
+            for (StringTokenizer tokenizer = new StringTokenizer(endorsedDirsString, " ");
tokenizer.hasMoreTokens();) {
+                String configuration = tokenizer.nextToken();
+                endorsedDirs.add(configuration);
+            }
+        }
+
+        CommandLineManifest commandLineManifest = new CommandLineManifest(mainGBean, mainMethod,
configurations, endorsedDirs);
         return commandLineManifest;
     }
 
     private final ObjectName mainGBean;
     private final String mainMethod;
     private final List configurations;
+    private final List endorsedDirs;
 
-    public CommandLineManifest(ObjectName mainGBean, String mainMethod, List configurations)
{
+    public CommandLineManifest(ObjectName mainGBean, String mainMethod, List configurations,
List endorsedDirs) {
         this.mainGBean = mainGBean;
         this.mainMethod = mainMethod;
         this.configurations = Collections.unmodifiableList(configurations);
+        this.endorsedDirs = endorsedDirs;
     }
 
     public ObjectName getMainGBean() {
@@ -116,5 +130,9 @@
 
     public List getConfigurations() {
         return configurations;
+    }
+
+    public List getEndorsedDirs() {
+        return endorsedDirs;
     }
 }

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java (original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/main/Daemon.java Tue
Feb  8 15:23:49 2005
@@ -19,6 +19,7 @@
 
 import java.io.IOException;
 import java.io.ObjectInputStream;
+import java.io.File;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
@@ -38,6 +39,7 @@
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.log.GeronimoLogging;
 import org.apache.geronimo.system.url.GeronimoURLFactory;
+import org.apache.geronimo.system.serverinfo.DirectoryUtils;
 
 /**
  * @version $Rev$ $Date$
@@ -78,6 +80,34 @@
         log.info("Server startup begun");
 
         try {
+            // Determine the geronimo installation directory
+            File geronimoInstallDirectory = DirectoryUtils.getGeronimoInstallDirectory();
+            if (geronimoInstallDirectory == null) {
+                System.err.println("Could not determine geronimo installation directory");
+                System.exit(1);
+                throw new AssertionError();
+            }
+
+            // setup the endorsed dir entry
+            CommandLineManifest manifestEntries = CommandLineManifest.getManifestEntries();
+            String endorsedDirs = System.getProperty("java.endorsed.dirs", "");
+            for (Iterator iterator = manifestEntries.getEndorsedDirs().iterator(); iterator.hasNext();)
{
+                String directoryName = (String) iterator.next();
+                File directory = new File(directoryName);
+                if (!directory.isAbsolute()) {
+                    directory = new File(geronimoInstallDirectory, directoryName);
+                }
+
+                if (endorsedDirs.length() > 0) {
+                    endorsedDirs += File.pathSeparatorChar;
+                }
+                endorsedDirs += directory.getAbsolutePath();
+            }
+            if (endorsedDirs.length() > 0) {
+                System.setProperty("java.endorsed.dirs", endorsedDirs);
+            }
+            log.info("java.endorsed.dirs=" + System.getProperty("java.endorsed.dirs"));
+
             // get a list of the configuration uris from the command line
             List configs = new ArrayList();
             for (int i = 0; i < args.length; i++) {

Added: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/DirectoryUtils.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/DirectoryUtils.java?view=auto&rev=152958
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/DirectoryUtils.java
(added)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/DirectoryUtils.java
Tue Feb  8 15:23:49 2005
@@ -0,0 +1,58 @@
+/**
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.system.serverinfo;
+
+import java.io.File;
+import java.net.JarURLConnection;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public final class DirectoryUtils {
+    private static final Log log = LogFactory.getLog(DirectoryUtils.class);
+    private static final File geronimoInstallDirectory;
+
+    static {
+        // guess from the location of the jar
+        URL url = DirectoryUtils.class.getClassLoader().getResource("META-INF/startup-jar");
+
+        File directory = null;
+        if (url != null) {
+            try {
+                JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
+                url = jarConnection.getJarFileURL();
+
+                URI baseURI = new URI(url.toString()).resolve("..");
+                directory = new File(baseURI);
+            } catch (Exception ignored) {
+                log.error("Error while determining the geronimo installation directory",
ignored);
+            }
+        } else {
+            log.error("Cound not determin the geronimo installation directory, because the
startup jar could not be found in the current class loader.");
+        }
+        geronimoInstallDirectory = directory;
+    }
+
+    public static File getGeronimoInstallDirectory() {
+        return geronimoInstallDirectory;
+    }
+}

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java?view=diff&r1=152957&r2=152958
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
(original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/serverinfo/ServerInfo.java
Tue Feb  8 15:23:49 2005
@@ -18,10 +18,7 @@
 package org.apache.geronimo.system.serverinfo;
 
 import java.io.File;
-import java.io.IOException;
-import java.net.JarURLConnection;
 import java.net.URI;
-import java.net.URL;
 
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
@@ -54,26 +51,19 @@
         // on the command line.
         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");
+            base = DirectoryUtils.getGeronimoInstallDirectory();
+            if (base == null) {
+                throw new IllegalArgumentException("Could not determine geronimo installation
directory");
             }
-            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 {
             base = new File(baseDirectory);
-            baseURI = base.toURI();
         }
+
         if (!base.isDirectory()) {
             throw new IllegalArgumentException("Base directory is not a directory: " + baseDirectory);
         }
+
+        baseURI = base.toURI();
         System.setProperty("geronimo.base.dir", base.getAbsolutePath());
     }
 
@@ -86,9 +76,7 @@
      * fully-qualified it will be resolved to an absolute pathname
      * using system-dependent rules (@link java.io.File). If it's relative
      * it will be resolved relative to the base directory.
-     *
      * @return an absolute pathname
-     *
      * @see java.io.File#File(String pathname)
      * @see java.io.File#getAbsolutePath()
      */
@@ -101,7 +89,7 @@
      *
      * @param filename a <code>String</code> containing a pathname,
      * which will be resolved by {@link #resolvePath(String
-     * filename)}.
+            * filename)}.
      * @return a <code>File</code> value
      */
     public File resolve(final String filename) {



Mime
View raw message