You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/01/04 22:26:42 UTC

svn commit: r492751 - in /incubator/tuscany/java/sca/runtime/standalone: launcher/src/main/java/org/apache/tuscany/launcher/ server.start/ server.start/src/main/java/org/apache/tuscany/standalone/server/ standalone-api/src/main/java/org/apache/tuscany/...

Author: jboynes
Date: Thu Jan  4 13:26:41 2007
New Revision: 492751

URL: http://svn.apache.org/viewvc?view=rev&rev=492751
Log:
move DirectoryHelper to standalone-api so it can be shared by launcher and server commands

Added:
    incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java   (contents, props changed)
      - copied, changed from r492308, incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/DirectoryHelper.java
Removed:
    incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/DirectoryHelper.java
Modified:
    incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
    incubator/tuscany/java/sca/runtime/standalone/server.start/pom.xml
    incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java

Modified: incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java?view=diff&rev=492751&r1=492750&r2=492751
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java Thu Jan  4 13:26:41 2007
@@ -33,6 +33,7 @@
 
 import org.apache.tuscany.host.runtime.TuscanyRuntime;
 import org.apache.tuscany.host.util.LaunchHelper;
+import org.apache.tuscany.runtime.standalone.DirectoryHelper;
 import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
 import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfoImpl;
 
@@ -53,7 +54,7 @@
         }
         MainLauncherBooter booter = new MainLauncherBooter();
 
-        File installDir = getInstallDirectory();
+        File installDir = DirectoryHelper.getInstallDirectory(MainLauncherBooter.class);
         URL baseUrl = installDir.toURI().toURL();
         File bootDir = getBootDirectory(installDir);
 
@@ -73,7 +74,7 @@
         URL applicationScdl = booter.getApplicationScdl(applicationClassLoader);
 
         String className = System.getProperty("tuscany.launcherClass",
-            "org.apache.tuscany.runtime.standalone.host.StandaloneRuntimeImpl");
+                                              "org.apache.tuscany.runtime.standalone.host.StandaloneRuntimeImpl");
         TuscanyRuntime runtime = (TuscanyRuntime) Beans.instantiate(bootClassLoader, className);
         runtime.setMonitorFactory(runtime.createDefaultMonitorFactory());
         runtime.setSystemScdl(systemScdl);
@@ -166,29 +167,6 @@
     protected URL getApplicationScdl(ClassLoader applicationClassLoader) {
         String resource = System.getProperty("tuscany.applicationScdlPath", "META-INF/sca/default.scdl");
         return applicationClassLoader.getResource(resource);
-    }
-
-    public static File getInstallDirectory() {
-        // use system property if defined
-        String property = System.getProperty("tuscany.installDir");
-        if (property != null) {
-            return new File(property);
-        }
-
-        // use the parent of directory containing this command
-        URL url = MainLauncherBooter.class.getResource("MainLauncherBooter.class");
-        if (!"jar".equals(url.getProtocol())) {
-            throw new IllegalStateException("Must be run from a jar: " + url);
-        }
-
-        String jarLocation = url.toString();
-        jarLocation = jarLocation.substring(4, jarLocation.lastIndexOf("!/"));
-        if (!jarLocation.startsWith("file:")) {
-            throw new IllegalStateException("Must be run from a local filesystem: " + jarLocation);
-        }
-
-        File jarFile = new File(URI.create(jarLocation));
-        return jarFile.getParentFile().getParentFile();
     }
 
     public static File getBootDirectory(File installDirectory) {

Modified: incubator/tuscany/java/sca/runtime/standalone/server.start/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/server.start/pom.xml?view=diff&rev=492751&r1=492750&r2=492751
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/server.start/pom.xml (original)
+++ incubator/tuscany/java/sca/runtime/standalone/server.start/pom.xml Thu Jan  4 13:26:41 2007
@@ -38,6 +38,12 @@
             <artifactId>sca-api-r0.95</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.tuscany.sca.runtime.standalone</groupId>
+            <artifactId>standalone-api</artifactId>
+            <version>${sca.version}</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.tuscany.sca.kernel</groupId>
             <artifactId>core</artifactId>
             <version>${sca.version}</version>

Modified: incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java?view=diff&rev=492751&r1=492750&r2=492751
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/TuscanyServer.java Thu Jan  4 13:26:41 2007
@@ -38,6 +38,7 @@
 import org.apache.tuscany.standalone.server.management.jmx.RmiAgent;
 
 import org.apache.tuscany.core.services.management.jmx.runtime.JmxRuntimeInfoImpl;
+import org.apache.tuscany.runtime.standalone.DirectoryHelper;
 
 /**
  * This class provides the commandline interface for starting the 
@@ -96,14 +97,11 @@
      *
      */
     private TuscanyServer() throws MalformedURLException {
-        installDirectory = DirectoryHelper.getInstallDirectory();
+        installDirectory = DirectoryHelper.getInstallDirectory(TuscanyServer.class);
         baseUrl = installDirectory.toURI().toURL();
         agent = RmiAgent.getInstance();
     }
 
-    /**
-     * @see org.apache.tuscany.standalone.server.TuscanyServerMBean#startRuntime(java.lang.String, boolean)
-     */
     public final void startRuntime(final String bootPath, final boolean online, final String managementDomain) {
 
         try {

Copied: incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java (from r492308, incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/DirectoryHelper.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java?view=diff&rev=492751&p1=incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/DirectoryHelper.java&r1=492308&p2=incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java&r2=492751
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/server.start/src/main/java/org/apache/tuscany/standalone/server/DirectoryHelper.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java Thu Jan  4 13:26:41 2007
@@ -16,84 +16,98 @@
  * specific language governing permissions and limitations
  * under the License.    
  */
-package org.apache.tuscany.standalone.server;
+package org.apache.tuscany.runtime.standalone;
 
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
 
 /**
- * Utility class for directory related operations.
- * 
- * @version $Revision$ $Date$
+ * Utility class for installation directory related operations.
  *
+ * @version $Revision$ $Date$
  */
-public abstract class DirectoryHelper {
-    
-    /** Installation directory system property. */
-    private static final String INSTALL_DIRECTORY_PROPERTY = "tuscany.installDir";
-    
+public final class DirectoryHelper {
+
     /**
-     * Utility class constructor.
-     *
+     * Installation directory system property name.
      */
+    private static final String INSTALL_DIRECTORY_PROPERTY = "tuscany.installDir";
+
     private DirectoryHelper() {
     }
-    
+
     /**
-     * Gets the installation directory.
-     * @return Directory where tuscany standalone server is installed.
+     * Gets the installation directory based on the location of a class file.
+     * If the system property <code>tuscany.installDir</code> is set then its value is used as the
+     * location of the installation directory. Otherwise, we assume we are running from an
+     * executable jar containing the supplied class and the installation directory is assumed to
+     * be the parent of the directory containing that jar.
+     *
+     * @param clazz the class to use as a way to find the executable jar
+     * @return directory where tuscany standalone server is installed.
+     * @throws IllegalArgumentException if the property is set but its value is not an existing directory
+     * @throws IllegalStateException    if the location could not be determined from the location of the class file
      */
-    static final File getInstallDirectory() {
-        
-        File installDirectory = null;
+    public static File getInstallDirectory(Class clazz) throws IllegalStateException, IllegalArgumentException {
+
         String installDirectoryPath = System.getProperty(INSTALL_DIRECTORY_PROPERTY);
-        
-        if (installDirectoryPath != null) {
-            installDirectory = new File(installDirectoryPath);
-        } else {
 
-            // use the parent of directory containing this command
-            URL url = TuscanyServer.class.getResource("TuscanyServer.class");
-            if (!"jar".equals(url.getProtocol())) {
-                throw new IllegalStateException("Must be run from a jar: " + url);
-            }
-    
-            String jarLocation = url.toString();
-            jarLocation = jarLocation.substring(4, jarLocation.lastIndexOf("!/"));
-            if (!jarLocation.startsWith("file:")) {
-                throw new IllegalStateException("Must be run from a local filesystem: " + jarLocation);
+        if (installDirectoryPath != null) {
+            File installDirectory = new File(installDirectoryPath);
+            if (!installDirectory.exists()) {
+                throw new IllegalArgumentException(INSTALL_DIRECTORY_PROPERTY
+                    + " property does not refer to an existing directory: " + installDirectory);
             }
-    
-            File jarFile = new File(URI.create(jarLocation));
-            installDirectory = jarFile.getParentFile().getParentFile();    
+            return installDirectory;
+        }
+
+        // get the name of the Class's bytecode
+        String name = clazz.getName();
+        int last = name.lastIndexOf('.');
+        if (last != -1) {
+            name = name.substring(last);
+        }
+        name = name + ".class";
+
+        // get location of the bytecode - should be a jar: URL
+        URL url = clazz.getResource(name);
+        if (url == null) {
+            throw new IllegalStateException("Unable to get location of bytecode resource " + name);
+        }
+
+        String jarLocation = url.toString();
+        if (!jarLocation.startsWith("jar:")) {
+            throw new IllegalStateException("Must be run from a jar: " + url);
         }
 
-        if(!installDirectory.exists()) {
-            throw new IllegalStateException("Install directory doesn't exist: " + installDirectory);
+        // extract the location of thr jar from the resource URL 
+        jarLocation = jarLocation.substring(4, jarLocation.lastIndexOf("!/"));
+        if (!jarLocation.startsWith("file:")) {
+            throw new IllegalStateException("Must be run from a local filesystem: " + jarLocation);
         }
-        
-        return installDirectory;
-        
+
+        File jarFile = new File(URI.create(jarLocation));
+        return jarFile.getParentFile().getParentFile();
     }
-    
+
     /**
-     * Gets the boot directory where all the boot libraries are stored. This 
-     * is expected to be a directory named <code>boot</code> under the install 
+     * Gets the boot directory where all the boot libraries are stored. This
+     * is expected to be a directory named <code>boot</code> under the install
      * directory.
-     * 
+     *
      * @param installDirectory Tuscany install directory.
-     * @param bootPath Boot path for the runtime.
+     * @param bootPath         Boot path for the runtime.
      * @return Tuscany boot directory.
      */
-    static final File getBootDirectory(File installDirectory, String bootPath) {
-        
-        File bootDirectory =  new File(installDirectory, bootPath);  
-        if(!bootDirectory.exists()) {
+    public static File getBootDirectory(File installDirectory, String bootPath) {
+
+        File bootDirectory = new File(installDirectory, bootPath);
+        if (!bootDirectory.exists()) {
             throw new IllegalStateException("Boot directory doesn't exist: " + bootDirectory.getAbsolutePath());
         }
         return bootDirectory;
-        
+
     }
 
 }

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/runtime/standalone/standalone-api/src/main/java/org/apache/tuscany/runtime/standalone/DirectoryHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org