geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r835091 - in /geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main: ServerInfo.java Utils.java
Date Wed, 11 Nov 2009 21:58:30 GMT
Author: gawor
Date: Wed Nov 11 21:58:30 2009
New Revision: 835091

URL: http://svn.apache.org/viewvc?rev=835091&view=rev
Log:
missed some files

Added:
    geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
  (with props)
    geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
  (with props)

Added: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java?rev=835091&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
Wed Nov 11 21:58:30 2009
@@ -0,0 +1,77 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.main;
+
+import java.io.File;
+import java.net.URI;
+
+public class ServerInfo {
+    
+    private File base;
+    private URI baseURI;
+    private File baseServer;
+    private URI baseServerURI;
+    
+    public ServerInfo(File geronimoHome, File geronimoBase) {
+        this.base = geronimoHome;
+        this.baseURI = base.toURI();
+        this.baseServer = geronimoBase;
+        this.baseServerURI = baseServer.toURI();
+    }
+    
+    public String resolvePath(String filename) {
+        return resolve(filename).getAbsolutePath();
+    }
+
+    public String resolveServerPath(String filename) {
+        return resolveServer(filename).getAbsolutePath();
+    }
+    
+    public File resolve(String filename) {
+        return resolveWithBase(base, filename);
+    }
+
+    public File resolveServer(String filename) {
+        return resolveWithBase(baseServer, filename);
+    }
+
+    public URI resolve(URI uri) {
+        return baseURI.resolve(uri);
+    }
+
+    public URI resolveServer(URI uri) {
+        return baseServerURI.resolve(uri);
+    }
+    
+    private File resolveWithBase(File baseDir, String filename) {
+        File file = new File(filename);
+        if (file.isAbsolute()) {
+            return file;
+        }
+        return new File(baseDir, filename);
+    }
+
+    public File getBase() {
+        return base;
+    }
+    
+    public File getBaseServer() {
+        return baseServer;
+    }
+    
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ServerInfo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java?rev=835091&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
Wed Nov 11 21:58:30 2009
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.JarURLConnection;
+import java.net.URI;
+
+public class Utils {
+
+    public static final String SERVER_NAME_SYS_PROP = "org.apache.geronimo.server.name";
+    public static final String SERVER_DIR_SYS_PROP = "org.apache.geronimo.server.dir";
+    public static final String HOME_DIR_SYS_PROP = "org.apache.geronimo.home.dir";
+    
+    public static File getGeronimoHome() throws IOException {
+        File rc = null;
+
+        // Use the system property if specified.
+        String path = System.getProperty(HOME_DIR_SYS_PROP);
+        if (path != null) {
+            rc = validateDirectoryExists(path, "Invalid " + HOME_DIR_SYS_PROP + " system
property");
+        }
+
+        // Try to figure it out using the jar file this class was loaded from.
+        if (rc == null) {
+            // guess the home from the location of the jar
+            URL url = Main.class.getClassLoader().getResource(Main.class.getName().replace(".",
"/") + ".class");
+            if (url != null) {
+                try {
+                    JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
+                    url = jarConnection.getJarFileURL();
+                    rc = new File(new URI(url.toString())).getCanonicalFile().getParentFile().getParentFile();
+                } catch (Exception ignored) {
+                }
+            }
+        }
+
+        if (rc == null) {
+            throw new IOException("The Geronimo install directory could not be determined.
 Please set the " + HOME_DIR_SYS_PROP + " system property");
+        }
+
+        return rc;
+    }
+
+    public static File getGeronimoBase(File base) {
+        File baseServerDir;
+        
+        // first check if the base server directory has been provided via
+        // system property override.
+        String baseServerDirPath = System.getProperty(SERVER_DIR_SYS_PROP);
+        if (baseServerDirPath == null) {
+            // then check if a server name has been provided
+            String serverName = System.getProperty(SERVER_NAME_SYS_PROP);
+            if (serverName == null) {
+                // default base server directory.
+                baseServerDir = base;
+            } else {
+                baseServerDir = new File(base, serverName);
+            }
+        } else {
+            baseServerDir = new File(baseServerDirPath);
+            if (!baseServerDir.isAbsolute()) {
+                baseServerDir = new File(base, baseServerDirPath);
+            }
+        }
+
+        validateDirectoryExists(baseServerDir, "The Geronimo server directory could not be
determined");
+        
+        return baseServerDir;
+    }
+    
+    public static File getTempDirectory(File base) {
+        String tmpDirPath = System.getProperty("java.io.tmpdir", "temp");
+        File tmpDir = new File(tmpDirPath);
+        if (!tmpDir.isAbsolute()) {
+            tmpDir = new File(base, tmpDirPath);
+        }
+        
+        validateDirectoryExists(tmpDir, "The temporary directory could not be determined");
+        
+        return tmpDir;
+    }
+    
+    public static File getLog4jConfigurationFile(File base, String defaultFile) {
+        File log4jFile = null;
+        
+        String log4jFilePath = System.getProperty("org.apache.geronimo.log4jservice.configuration",
defaultFile);       
+        if (log4jFilePath != null) {                   
+            log4jFile = new File(log4jFilePath);
+            if (!log4jFile.isAbsolute()) {
+                log4jFile = new File(base, log4jFilePath);
+            }
+        }
+        
+        return log4jFile;
+    }
+    
+    public static File validateDirectoryExists(String path, String errPrefix) {
+        return validateDirectoryExists(new File(path), errPrefix);
+    }
+    
+    public static File validateDirectoryExists(File path, String errPrefix) {
+        File rc;
+        try {
+            rc = path.getCanonicalFile();
+        } catch (IOException e) {
+            throw new IllegalArgumentException(errPrefix + " '" + path + "' : " + e.getMessage());
+        }
+        if (!rc.exists()) {
+            throw new IllegalArgumentException(errPrefix + " '" + path + "' : does not exist");
+        }
+        if (!rc.isDirectory()) {
+            throw new IllegalArgumentException(errPrefix + " '" + path + "' : is not a directory");
+        }
+        return rc;
+    }
+  
+}

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Utils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message