You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2011/07/30 17:00:34 UTC

svn commit: r1152483 - in /geronimo/server/trunk/framework: configs/karaf-framework/pom.xml configs/karaf-framework/src/main/descriptors/geronimo-bin.xml modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java

Author: xuhaihong
Date: Sat Jul 30 15:00:32 2011
New Revision: 1152483

URL: http://svn.apache.org/viewvc?rev=1152483&view=rev
Log:
GERONIMO-5827 Extract the native libraries in the var/native directory, with this, all the native libraries will be loaded from this path

Modified:
    geronimo/server/trunk/framework/configs/karaf-framework/pom.xml
    geronimo/server/trunk/framework/configs/karaf-framework/src/main/descriptors/geronimo-bin.xml
    geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java

Modified: geronimo/server/trunk/framework/configs/karaf-framework/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/pom.xml?rev=1152483&r1=1152482&r2=1152483&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/karaf-framework/pom.xml (original)
+++ geronimo/server/trunk/framework/configs/karaf-framework/pom.xml Sat Jul 30 15:00:32 2011
@@ -548,6 +548,23 @@
                 <artifactId>maven-dependency-plugin</artifactId>
                 <executions>
                     <execution>
+                        <id>unpack</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>unpack</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.apache.karaf.shell</groupId>
+                                    <artifactId>org.apache.karaf.shell.console</artifactId>
+                                    <outputDirectory>target/native</outputDirectory>
+                                    <includes>META-INF/native/**/*</includes>
+                                </artifactItem>
+                            </artifactItems>                                
+                        </configuration>
+                    </execution>                        
+                    <execution>
                         <id>copy</id>
                         <phase>generate-resources</phase>
                         <goals>

Modified: geronimo/server/trunk/framework/configs/karaf-framework/src/main/descriptors/geronimo-bin.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/configs/karaf-framework/src/main/descriptors/geronimo-bin.xml?rev=1152483&r1=1152482&r2=1152483&view=diff
==============================================================================
--- geronimo/server/trunk/framework/configs/karaf-framework/src/main/descriptors/geronimo-bin.xml (original)
+++ geronimo/server/trunk/framework/configs/karaf-framework/src/main/descriptors/geronimo-bin.xml Sat Jul 30 15:00:32 2011
@@ -61,7 +61,10 @@
             <outputDirectory>contents/etc/</outputDirectory>
             <lineEnding>unix</lineEnding>
         </fileSet>
-
+        <fileSet>
+            <directory>target/native/META-INF/native</directory>
+            <outputDirectory>contents/var/native/jansi</outputDirectory>
+        </fileSet>
         <!-- Copy over the examples -->
         <!--<fileSet>-->
             <!--<directory>../demos</directory>-->

Modified: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java?rev=1152483&r1=1152482&r2=1152483&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java Sat Jul 30 15:00:32 2011
@@ -48,22 +48,22 @@ import org.osgi.service.packageadmin.Pac
 import org.osgi.service.startlevel.StartLevel;
 
 public class FrameworkLauncher {
-    
+
     /**
      * The default name used for the system properties file.
      */
     public static final String SYSTEM_PROPERTIES_FILE_NAME = "system.properties";
-    
+
     /**
      * The default name used for the configuration properties file.
      */
     public static final String CONFIG_PROPERTIES_FILE_NAME = "config.properties";
-    
+
     /**
      * The default name used for the startup properties file.
      */
     public static final String STARTUP_PROPERTIES_FILE_NAME = "startup.properties";
-    
+
     /**
      * The system property for specifying the Karaf home directory.  The home directory
      * hold the binary install of Karaf.
@@ -75,11 +75,11 @@ public class FrameworkLauncher {
      * holds the configuration and data for a Karaf instance.
      */
     private static final String PROP_KARAF_BASE = "karaf.base";
-        
+
     private static final String DEFAULT_REPO = "karaf.default.repository";
-    
+
     private static final String KARAF_FRAMEWORK = "karaf.framework";
-       
+
     private static final Logger LOG = Logger.getLogger(FrameworkLauncher.class.getName());
 
     private boolean uniqueInstance = false;
@@ -88,59 +88,59 @@ public class FrameworkLauncher {
     private String configFile = CONFIG_PROPERTIES_FILE_NAME;
     private String additionalConfigFile = null;
     private boolean cleanStorage = false;
-    
-    private ServerInfo serverInfo;    
+
+    private ServerInfo serverInfo;
     private File geronimoHome;
     private File geronimoBase;
     private File cacheDirectory;
-    
+
     private Properties configProps = null;
-        
+
     private Framework framework = null;
-    
+
     public void setLog4jConfigFile(String log4jFile) {
         this.log4jFile = log4jFile;
     }
-    
+
     public void setConfigFile(String configFile) {
         this.configFile = configFile;
     }
-    
+
     public void setAdditionalConfigFile(String additionalConfigFile) {
         this.additionalConfigFile = additionalConfigFile;
     }
-    
+
     public void setStartupFile(String startupFile) {
         this.startupFile = startupFile;
     }
-    
+
     public void setUniqueInstance(boolean uniqueInstance) {
         this.uniqueInstance = uniqueInstance;
     }
-    
+
     public void setCleanStorage(boolean cleanStorage) {
         this.cleanStorage = cleanStorage;
     }
-        
+
     public void launch() throws Exception {
         geronimoHome = Utils.getGeronimoHome();
         geronimoBase = Utils.getGeronimoBase(geronimoHome);
-        
-        Utils.setTempDirectory(geronimoBase);        
+
+        Utils.setTempDirectory(geronimoBase);
         Utils.setLog4jConfigurationFile(geronimoBase, log4jFile);
-        
-        System.setProperty(Utils.HOME_DIR_SYS_PROP, geronimoHome.getAbsolutePath());        
+
+        System.setProperty(Utils.HOME_DIR_SYS_PROP, geronimoHome.getAbsolutePath());
         System.setProperty(Utils.SERVER_DIR_SYS_PROP, geronimoBase.getAbsolutePath());
-                
+
         System.setProperty(PROP_KARAF_HOME, geronimoHome.getPath());
         System.setProperty(PROP_KARAF_BASE, geronimoBase.getPath());
-        
+
         // Load system properties.
         loadSystemProperties(geronimoBase);
 
         // Read configuration properties.
         configProps = loadConfigProperties(geronimoBase);
-        
+
         // Copy framework properties from the system properties.
         copySystemProperties(configProps);
 
@@ -148,10 +148,12 @@ public class FrameworkLauncher {
 
         processSecurityProperties(configProps);
 
+        configJansiPath();
+
         setFrameworkStorage(configProps);
-        
+
         if (cleanStorage) {
-            configProps.setProperty(Constants.FRAMEWORK_STORAGE_CLEAN, 
+            configProps.setProperty(Constants.FRAMEWORK_STORAGE_CLEAN,
                                     Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
         }
 
@@ -160,22 +162,22 @@ public class FrameworkLauncher {
                 FrameworkLauncher.this.destroy(false);
             }
         });
-        
+
         // Start up the OSGI framework
         ServiceLoader<FrameworkFactory> loader = ServiceLoader.load(FrameworkFactory.class);
         FrameworkFactory factory = loader.iterator().next();
         framework = factory.newFramework(new StringMap(configProps, false));
-        
+
         framework.init();
-        
+
         BundleContext bundleContext = framework.getBundleContext();
-        
-        serverInfo = new ServerInfo(geronimoHome, geronimoBase);      
+
+        serverInfo = new ServerInfo(geronimoHome, geronimoBase);
         bundleContext.registerService(ServerInfo.class.getName(), serverInfo, null);
-        
+
         List<BundleInfo> startList = loadStartupProperties();
         startBundles(bundleContext, startList);
-        
+
         framework.start();
 
     }
@@ -191,12 +193,31 @@ public class FrameworkLauncher {
             Utils.recursiveDelete(cacheDirectory);
         }
     }
-    
+
+    private void configJansiPath() {
+        String osName = "";
+        String name = System.getProperty("os.name").toLowerCase().trim();
+        if (name.startsWith("linux")) {
+            osName = "linux";
+        } else if (name.startsWith("mac os x")) {
+            osName = "osx";
+        } else if (name.startsWith("win")) {
+            osName = "windows";
+        } else {
+            osName = name.replaceAll("\\W+", "_");
+        }
+        String bitMode = System.getProperty("sun.arch.data.model");
+        if (bitMode == null) {
+            bitMode = System.getProperty("com.ibm.vm.bitmode");
+        }
+        System.setProperty("library.jansi.path", new File(geronimoBase, "var/native/jansi/" + osName + bitMode).getAbsolutePath());
+    }
+
     private void destroyFramework(boolean await) throws BundleException, InterruptedException {
         if (framework == null) {
             return;
         }
-        
+
         if (await) {
             while (true) {
                 FrameworkEvent event = framework.waitForStop(0);
@@ -210,16 +231,16 @@ public class FrameworkLauncher {
             framework.waitForStop(0);
         }
     }
-        
+
     public Framework getFramework() {
         return framework;
     }
-        
+
     private void setFrameworkStorage(Properties configProps) throws IOException {
         if (configProps.getProperty(Constants.FRAMEWORK_STORAGE) != null) {
             return;
         }
-        
+
         if (uniqueInstance) {
             File var = new File(geronimoBase, "var");
             File tmpFile = File.createTempFile("instance-", "", var);
@@ -228,11 +249,11 @@ public class FrameworkLauncher {
         } else {
             cacheDirectory = new File(geronimoBase, "var/cache");
         }
-                
+
         cacheDirectory.mkdirs();
         configProps.setProperty(Constants.FRAMEWORK_STORAGE, cacheDirectory.getAbsolutePath());
     }
-    
+
     private static void processSecurityProperties(Properties m_configProps) {
         String prop = m_configProps.getProperty("org.apache.karaf.security.providers");
         if (prop != null) {
@@ -264,7 +285,7 @@ public class FrameworkLauncher {
     protected static void loadSystemProperties(File baseDir) throws IOException {
         File file = new File(new File(baseDir, "etc"), SYSTEM_PROPERTIES_FILE_NAME);
         Properties props = Utils.loadPropertiesFile(file, false);
-        
+
         // Perform variable substitution on specified properties.
         for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
             String name = (String) e.nextElement();
@@ -273,10 +294,10 @@ public class FrameworkLauncher {
         }
     }
 
-    private Properties loadConfigProperties(File baseDir) throws Exception {        
+    private Properties loadConfigProperties(File baseDir) throws Exception {
         File config = new File(new File(baseDir, "etc"), configFile);
         Properties configProps = Utils.loadPropertiesFile(config, false);
-        
+
         // Perform config props override
         if (additionalConfigFile != null){
             File additionalConfig = new File(new File(baseDir, "etc"), additionalConfigFile);
@@ -285,7 +306,7 @@ public class FrameworkLauncher {
                 configProps.setProperty((String)entry.getKey(), (String)entry.getValue());
             }
         }
-        
+
         // Perform variable substitution for system properties.
         for (Enumeration e = configProps.propertyNames(); e.hasMoreElements();) {
             String name = (String) e.nextElement();
@@ -305,7 +326,7 @@ public class FrameworkLauncher {
             }
         }
     }
-    
+
     private void updateClassLoader(Properties configProps) throws Exception {
     	String framework = configProps.getProperty(KARAF_FRAMEWORK);
         if (framework == null) {
@@ -330,15 +351,15 @@ public class FrameworkLauncher {
     }
 
     private void startBundles(BundleContext context, List<BundleInfo> startList) throws Exception {
-        
+
         // Retrieve the Start Level service, since it will be needed
         // to set the start level of the installed bundles.
         StartLevel sl = (StartLevel) context.getService(context.getServiceReference(StartLevel.class.getName()));
-        
+
         // Set the default bundle start level
         int ibsl = Integer.parseInt(configProps.getProperty("karaf.startlevel.bundle", "60"));
         sl.setInitialBundleStartLevel(ibsl);
-        
+
         for (BundleInfo info : startList) {
             InputStream in = new FileInputStream(info.location);
             Bundle bundle = null;
@@ -350,30 +371,30 @@ public class FrameworkLauncher {
             if (info.startLevel > 0) {
                 sl.setBundleStartLevel(bundle, info.startLevel);
             }
-            
+
             info.bundle = bundle;
         }
-        
+
 
         // Retrieve the PackageAdmin service
         PackageAdmin pa = (PackageAdmin) context.getService(context.getServiceReference(PackageAdmin.class.getName()));
-                
+
         for (BundleInfo info : startList) {
             if (pa.getBundleType(info.bundle) != PackageAdmin.BUNDLE_TYPE_FRAGMENT) { //Fragment bundle can not start
                  info.bundle.start();
-            } 
+            }
         }
-        
+
     }
-    
-    private List<BundleInfo> loadStartupProperties() throws Exception {        
+
+    private List<BundleInfo> loadStartupProperties() throws Exception {
         File etc = new File(geronimoBase, "etc");
-                
+
         File file = new File(etc, startupFile);
         Properties startupProps = Utils.loadPropertiesFile(file, true);
-        
+
         ArrayList<File> bundleDirs = new ArrayList<File>();
-        
+
         String defaultRepo = System.getProperty(DEFAULT_REPO, "repository");
 
         if (geronimoBase.equals(geronimoHome)) {
@@ -382,23 +403,23 @@ public class FrameworkLauncher {
             bundleDirs.add(new File(geronimoBase, defaultRepo));
             bundleDirs.add(new File(geronimoHome, defaultRepo));
         }
-        
+
         return loadStartupProperties(startupProps, bundleDirs);
     }
-    
+
     protected List<BundleInfo> loadStartupProperties(Properties startupProps, List<File> bundleDirs) {
         List<BundleInfo> startList = new ArrayList<BundleInfo>();
 
         for (Iterator iterator = startupProps.keySet().iterator(); iterator.hasNext();) {
             String location = (String) iterator.next();
-            
+
             File file = findFile(bundleDirs, location);
-            
+
             if (file == null) {
                 System.err.println("Artifact " + location + " not found");
                 continue;
             }
-            
+
             int level;
             try {
                 level = Integer.parseInt(startupProps.getProperty(location).trim());
@@ -406,20 +427,20 @@ public class FrameworkLauncher {
                 System.err.print("Ignoring " + location + " (run level must be an integer)");
                 continue;
             }
-                        
+
             String mvnLocation = toMvnUrl(location);
-            
+
             BundleInfo info = new BundleInfo();
             info.location = file;
             info.mvnLocation = mvnLocation;
             info.startLevel = level;
-            
+
             startList.add(info);
         }
-        
+
         return startList;
     }
-          
+
     private static File findFile(List<File> bundleDirs, String name) {
         for (File bundleDir : bundleDirs) {
             File file = findFile(bundleDir, name);
@@ -445,7 +466,7 @@ public class FrameworkLauncher {
 
         return null;
     }
-    
+
     private static String toMvnUrl(String location) {
         String[] p = location.split("/");
         if (p.length >= 4 && p[p.length-1].startsWith(p[p.length-3] + "-" + p[p.length-2])) {
@@ -484,8 +505,8 @@ public class FrameworkLauncher {
             return location;
         }
     }
-    
-    static class BundleInfo {        
+
+    static class BundleInfo {
         File location;
         String mvnLocation;
         int startLevel;