Author: gnodet
Date: Tue May  5 15:46:15 2009
New Revision: 771836

URL: http://svn.apache.org/viewvc?rev=771836&view=rev
Log:
FELIX-1111: allow karaf to run on equinox

Added:
    
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Bootstrap.java
    
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/StringMap.java
    felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Utils.java
Modified:
    felix/trunk/karaf/assembly/pom.xml
    felix/trunk/karaf/assembly/src/main/descriptors/unix-bin.xml
    felix/trunk/karaf/assembly/src/main/descriptors/windows-bin.xml
    felix/trunk/karaf/assembly/src/main/distribution/unix-shell/bin/karaf
    felix/trunk/karaf/assembly/src/main/distribution/windows-text/bin/karaf.bat
    felix/trunk/karaf/assembly/src/main/filtered-resources/etc/config.properties
    felix/trunk/karaf/gshell/gshell-core/pom.xml
    felix/trunk/karaf/main/pom.xml
    felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java
    felix/trunk/karaf/pom.xml

Modified: felix/trunk/karaf/assembly/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/pom.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/pom.xml (original)
+++ felix/trunk/karaf/assembly/pom.xml Tue May  5 15:46:15 2009
@@ -230,6 +230,14 @@
             <groupId>com.oracle.osgi</groupId>
             <artifactId>jmx-impl</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.eclipse</groupId>
+            <artifactId>osgi</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+        </dependency>
     </dependencies>
     <build>
         <resources>

Modified: felix/trunk/karaf/assembly/src/main/descriptors/unix-bin.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/descriptors/unix-bin.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/src/main/descriptors/unix-bin.xml (original)
+++ felix/trunk/karaf/assembly/src/main/descriptors/unix-bin.xml Tue May  5 
15:46:15 2009
@@ -124,6 +124,7 @@
                 <include>org.apache.felix:org.osgi.compendium</include>
                 
<include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.prefs</include>
+                <include>org.apache.felix:org.apache.felix.framework</include>
             </includes>
         </dependencySet>
         <dependencySet>
@@ -287,6 +288,15 @@
                 <include>com.oracle.osgi:jmx-impl</include>
             </includes>
         </dependencySet>
+        <dependencySet>
+            <outputDirectory>/system</outputDirectory>
+            <unpack>false</unpack>
+            <useProjectArtifact>false</useProjectArtifact>
+            
<outputFileNameMapping>org/eclipse/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
+            <includes>
+                <include>org.eclipse:osgi</include>
+            </includes>
+        </dependencySet>
 
     </dependencySets>
 

Modified: felix/trunk/karaf/assembly/src/main/descriptors/windows-bin.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/descriptors/windows-bin.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/src/main/descriptors/windows-bin.xml (original)
+++ felix/trunk/karaf/assembly/src/main/descriptors/windows-bin.xml Tue May  5 
15:46:15 2009
@@ -116,6 +116,7 @@
                 <include>org.apache.felix:org.osgi.compendium</include>
                 
<include>org.apache.felix:org.apache.felix.configadmin</include>
                 <include>org.apache.felix:org.apache.felix.prefs</include>
+                <include>org.apache.felix:org.apache.felix.framework</include>
             </includes>
         </dependencySet>
         <dependencySet>
@@ -279,6 +280,15 @@
                 <include>com.oracle.osgi:jmx-impl</include>
             </includes>
         </dependencySet>
+        <dependencySet>
+            <outputDirectory>/system</outputDirectory>
+            <unpack>false</unpack>
+            <useProjectArtifact>false</useProjectArtifact>
+            
<outputFileNameMapping>org/eclipse/${artifact.artifactId}/${artifact.baseVersion}/${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
+            <includes>
+                <include>org.eclipse:osgi</include>
+            </includes>
+        </dependencySet>
 
     </dependencySets>
 

Modified: felix/trunk/karaf/assembly/src/main/distribution/unix-shell/bin/karaf
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/distribution/unix-shell/bin/karaf?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/src/main/distribution/unix-shell/bin/karaf 
(original)
+++ felix/trunk/karaf/assembly/src/main/distribution/unix-shell/bin/karaf Tue 
May  5 15:46:15 2009
@@ -281,7 +281,7 @@
         KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
         KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
     fi
-    exec $JAVA $JAVA_OPTS -Dkaraf.home="$KARAF_HOME" 
-Dkaraf.base="$KARAF_BASE" 
-Djava.util.logging.config.file=$KARAF_BASE/etc/java.util.logging.properties 
$OPTS -classpath "$CLASSPATH" org.apache.felix.karaf.main.Main $*
+    exec $JAVA $JAVA_OPTS -Dkaraf.home="$KARAF_HOME" 
-Dkaraf.base="$KARAF_BASE" 
-Djava.util.logging.config.file=$KARAF_BASE/etc/java.util.logging.properties 
$OPTS -classpath "$CLASSPATH" org.apache.felix.karaf.main.Bootstrap $*
 }
 
 main() {

Modified: 
felix/trunk/karaf/assembly/src/main/distribution/windows-text/bin/karaf.bat
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/distribution/windows-text/bin/karaf.bat?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/assembly/src/main/distribution/windows-text/bin/karaf.bat 
(original)
+++ felix/trunk/karaf/assembly/src/main/distribution/windows-text/bin/karaf.bat 
Tue May  5 15:46:15 2009
@@ -152,7 +152,7 @@
     if "%SHIFT%" == "true" SET ARGS=%2 %3 %4 %5 %6 %7 %8
     if not "%SHIFT%" == "true" SET ARGS=%1 %2 %3 %4 %5 %6 %7 %8    
     rem Execute the Java Virtual Machine
-    "%JAVA%" %JAVA_OPTS% %OPTS% -classpath "%CLASSPATH%" 
-Dkaraf.home="%KARAF_HOME%" -Dkaraf.base="%KARAF_BASE%" 
-Djava.util.logging.config.file=%KARAF_BASE%\etc\java.util.logging.properties 
org.apache.felix.karaf.main.Main %ARGS%
+    "%JAVA%" %JAVA_OPTS% %OPTS% -classpath "%CLASSPATH%" 
-Dkaraf.home="%KARAF_HOME%" -Dkaraf.base="%KARAF_BASE%" 
-Djava.util.logging.config.file=%KARAF_BASE%\etc\java.util.logging.properties 
org.apache.felix.karaf.main.Bootstrap %ARGS%
 
 rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
 

Modified: 
felix/trunk/karaf/assembly/src/main/filtered-resources/etc/config.properties
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/assembly/src/main/filtered-resources/etc/config.properties?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- 
felix/trunk/karaf/assembly/src/main/filtered-resources/etc/config.properties 
(original)
+++ 
felix/trunk/karaf/assembly/src/main/filtered-resources/etc/config.properties 
Tue May  5 15:46:15 2009
@@ -18,6 +18,14 @@
 
################################################################################
 
 #
+# Framework selection properties
+#
+karaf.framework=equinox
+
+karaf.framework.equinox=system/org/eclipse/osgi/${equinox.version}/osgi-${equinox.version}.jar
+karaf.framework.felix=system/org/apache/felix/org.apache.felix.framework/${felix.framework.version}/org.apache.felix.framework-${felix.framework.version}.jar
+
+#
 # Framework config properties.
 #
 org.osgi.framework.system.packages=org.osgi.framework; version=1.4.0, \
@@ -26,7 +34,6 @@
  org.osgi.service.startlevel; version=1.1.0, \
  org.osgi.service.url; version=1.0.0, \
  org.osgi.util.tracker; version=1.3.3, \
- org.apache.felix.karaf.main.spi; version=${karaf.osgi.version}, \
  org.apache.felix.karaf.jaas.boot; version=${karaf.osgi.version}, \
  org.apache.felix.karaf.version; version=${karaf.osgi.version}, \
  ${jre-${java.specification.version}}

Modified: felix/trunk/karaf/gshell/gshell-core/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/gshell/gshell-core/pom.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/gshell/gshell-core/pom.xml (original)
+++ felix/trunk/karaf/gshell/gshell-core/pom.xml Tue May  5 15:46:15 2009
@@ -39,10 +39,6 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix.karaf</groupId>
-            <artifactId>org.apache.felix.karaf.main</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.felix.karaf.jaas</groupId>
             <artifactId>org.apache.felix.karaf.jaas.config</artifactId>
         </dependency>
@@ -167,6 +163,16 @@
             <groupId>org.apache.servicemix.bundles</groupId>
             <artifactId>org.apache.servicemix.bundles.jline</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
 
     <build>

Modified: felix/trunk/karaf/main/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/main/pom.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/main/pom.xml (original)
+++ felix/trunk/karaf/main/pom.xml Tue May  5 15:46:15 2009
@@ -35,12 +35,14 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.framework</artifactId>
+            <groupId>org.eclipse</groupId>
+            <artifactId>osgi</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.felix</groupId>
-            <artifactId>org.osgi.core</artifactId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.servicemix.bundles</groupId>
@@ -61,24 +63,20 @@
                         <Bundle-Description>OSGi R4 
framework.</Bundle-Description>
                         
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         
<Export-Package>org.apache.felix.karaf.main.spi.*;version=${pom.version}</Export-Package>
+                        <!--
                         <Private-Package>
-                            
org.apache.felix.karaf.main;-split-package:=merge-first,
-                            
org.apache.felix.moduleloader.*;-split-package:=merge-first,
-                            
org.apache.felix.framework.*;-split-package:=merge-first,
-                            org.osgi.framework.launch*,
-                            org.osgi.framework.hooks*,
-                            org.osgi.framework;-split-package:=merge-first,
-                            
org.osgi.service.packageadmin;-split-package:=merge-first,
-                            
org.osgi.service.startlevel;-split-package:=merge-first,
-                            org.osgi.service.url;-split-package:=merge-first,
-                            org.osgi.util.tracker;-split-package:=merge-first,
+                            org.apache.felix.*;-split-package:=merge-first,
+                            org.eclipse.*;-split-package:=merge-first,
+                            org.osgi.*;-split-package:=merge-first,
                             META-INF;-split-package:=merge-first
                         </Private-Package>
                         <Import-Package>!*</Import-Package>
+                        -->
                     </instructions>
                     <unpackBundle>true</unpackBundle>
                 </configuration>
             </plugin>
+            <!--
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-shade-plugin</artifactId>
@@ -91,24 +89,25 @@
                         <configuration>
                             <artifactSet>
                                 <includes>
+                                    <include>org.eclipse:osgi</include>
                                     
<include>org.apache.felix:org.apache.felix.framework</include>
-                                    
<include>org.apache.felix:org.osgi.core</include>
                                     
<include>${project.groupId}:${project.artifactId}</include>
                                 </includes>
                             </artifactSet>
                             <filters>
                                 <filter>
-                                    
<artifact>org.apache.felix:org.apache.felix.framework</artifact>
-                                    <excludes>
-                                        <exclude>org/apache/felix/**</exclude>
-                                        <exclude>org/osgi/**</exclude>
-                                    </excludes>
+                                    <artifact>org.eclipse:osgi</artifact>
+                                    <includes>
+                                        <include>org/osgi/**</include>
+                                        <include>org/eclipse/**</include>
+                                        
<include>hookconfigurators.properties</include>
+                                    </includes>
                                 </filter>
                                 <filter>
-                                    
<artifact>org.apache.felix:org.osgi.core</artifact>
-                                    <excludes>
-                                        <exclude>org/osgi/**</exclude>
-                                    </excludes>
+                                    
<artifact>org.apache.felix:org.apache.felix.framework</artifact>
+                                    <includes>
+                                        <include>org/apache/felix/**</include>
+                                    </includes>
                                 </filter>
                             </filters>
                             
<createSourcesJar>${createSourcesJar}</createSourcesJar>
@@ -118,6 +117,7 @@
                     </execution>
                 </executions>
             </plugin>
+        -->
         </plugins>
         <resources>
             <resource>
@@ -148,6 +148,11 @@
                                 <configuration>
                                     <artifactItems>
                                         <artifactItem>
+                                            <groupId>org.eclipse</groupId>
+                                            <artifactId>osgi</artifactId>
+                                            <classifier>sources</classifier>
+                                        </artifactItem>
+                                        <artifactItem>
                                             <groupId>org.apache.felix</groupId>
                                             
<artifactId>org.osgi.core</artifactId>
                                             <classifier>sources</classifier>

Added: 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Bootstrap.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Bootstrap.java?rev=771836&view=auto
==============================================================================
--- 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Bootstrap.java 
(added)
+++ 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Bootstrap.java 
Tue May  5 15:46:15 2009
@@ -0,0 +1,73 @@
+/*
+ * 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.felix.karaf.main;
+
+import java.util.Properties;
+import java.io.File;
+import java.io.InputStream;
+import java.io.FileNotFoundException;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.lang.reflect.Method;
+
+public class Bootstrap {
+
+    public static final String FRAMEWORK_PROPERTIES_FILE_NAME = 
"config.properties";
+
+    public static final String KARAF_FRAMEWORK = "karaf.framework";
+
+    public static void main(String[] args) {
+        try {
+            File home = Utils.getKarafHome();
+            File file = new File(new File(home, "etc"), 
FRAMEWORK_PROPERTIES_FILE_NAME);
+            if (!file.exists()) {
+                throw new FileNotFoundException(file.getAbsolutePath());
+            }
+            Properties props = new Properties();
+            InputStream is = new FileInputStream(file);
+            props.load(is);
+            is.close();
+
+            String framework = props.getProperty(KARAF_FRAMEWORK);
+            if (framework == null) {
+                throw new IllegalArgumentException("Property " + 
KARAF_FRAMEWORK + " must be set in the etc/" + FRAMEWORK_PROPERTIES_FILE_NAME + 
" configuration file");
+            }
+            String bundle = props.getProperty(KARAF_FRAMEWORK + "." + 
framework);
+            if (bundle == null) {
+                throw new IllegalArgumentException("Property " + 
KARAF_FRAMEWORK + "." + framework + " must be set in the etc/" + 
FRAMEWORK_PROPERTIES_FILE_NAME + " configuration file");
+            }
+            File bundleFile = new File(home, bundle);
+            if (!bundleFile.exists()) {
+                throw new FileNotFoundException(bundleFile.getAbsolutePath());
+            }
+
+            URLClassLoader classLoader = (URLClassLoader) 
Bootstrap.class.getClassLoader();
+            Method mth = URLClassLoader.class.getDeclaredMethod("addURL", 
URL.class);
+            mth.setAccessible(true);
+            mth.invoke(classLoader, bundleFile.toURL());
+
+            Main.main(args);
+
+        } catch (Throwable t) {
+            t.printStackTrace();
+            System.exit(-1);
+        }
+    }
+}

Modified: 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java 
(original)
+++ felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Main.java 
Tue May  5 15:46:15 2009
@@ -22,33 +22,29 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.JarURLConnection;
+import java.io.InputStreamReader;
+import java.io.BufferedReader;
 import java.net.MalformedURLException;
-import java.net.URI;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.security.Provider;
 import java.security.Security;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.StringTokenizer;
 import java.util.concurrent.CountDownLatch;
 
-import org.apache.felix.framework.Felix;
-import org.apache.felix.framework.cache.BundleCache;
-import org.apache.felix.framework.util.FelixConstants;
-import org.apache.felix.framework.util.StringMap;
-import org.apache.felix.karaf.main.spi.MainService;
+import org.apache.felix.karaf.main.Utils;
 import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.launch.Framework;
+import org.osgi.framework.launch.FrameworkFactory;
 import org.osgi.service.startlevel.StartLevel;
 
 /**
@@ -62,7 +58,7 @@
  * the framework.
  * </p>
  */
-public class Main implements MainService, BundleActivator {
+public class Main {
     /**
      * The default name used for the system properties file.
      */
@@ -130,17 +126,15 @@
 
     public static final String PROPERTY_LOCK_CLASS_DEFAULT = 
SimpleFileLock.class.getName();
 
-
     private File karafHome;
     private File karafBase;
-    private static Properties m_configProps = null;
-    private static Felix m_felix = null;
+    private Properties configProps = null;
+    private Framework framework = null;
     private final String[] args;
     private int exitCode;
     private Lock lock;
-    private CountDownLatch shutdown = new CountDownLatch(1);
     private int defaultStartLevel = 100;
-    private int lockStartLevel = 0;
+    private int lockStartLevel = 1;
     private int lockDelay = 1000;
     private boolean exiting = false;
 
@@ -149,8 +143,8 @@
     }
 
     public void launch() throws Exception {
-        karafHome = getServiceMixHome();
-        karafBase = getServiceMixBase(karafHome);
+        karafHome = Utils.getKarafHome();
+        karafBase = getKarafBase(karafHome);
 
         //System.out.println("Karaf Home: "+main.servicemixHome.getPath());
         //System.out.println("Karaf Base: "+main.servicemixBase.getPath());
@@ -162,47 +156,34 @@
         loadSystemProperties();
 
         // Read configuration properties.
-        m_configProps = loadConfigProperties();
+        configProps = loadConfigProperties();
 
         // Copy framework properties from the system properties.
-        Main.copySystemProperties(m_configProps);
-
-        processSecurityProperties(m_configProps);
-
-        m_configProps.setProperty(BundleCache.CACHE_ROOTDIR_PROP, 
karafBase.getPath() + "/data");
-        m_configProps.setProperty(Constants.FRAMEWORK_STORAGE, "cache");
-
-        // Register the Main class so that other bundles can inspect the 
command line args.
-        BundleActivator activator = new BundleActivator() {
-            private ServiceRegistration registration;
+        Main.copySystemProperties(configProps);
 
-            public void start(BundleContext context) {
-                registration = 
context.registerService(MainService.class.getName(), Main.this, null);
-            }
-
-            public void stop(BundleContext context) {
-                registration.unregister();
-                shutdown.countDown();
-            }
-        };
-        List<BundleActivator> activations = new ArrayList<BundleActivator>();
-        activations.add(this);
-        activations.add(activator);
+        processSecurityProperties(configProps);
 
-        m_configProps.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, 
activations);
+        File storage = new File(karafBase.getPath(), "data/cache");
+        storage.mkdirs();
+        configProps.setProperty(Constants.FRAMEWORK_STORAGE, 
storage.getAbsolutePath());
 
         try {
-            defaultStartLevel = 
Integer.parseInt(m_configProps.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
-            lockStartLevel = 
Integer.parseInt(m_configProps.getProperty(PROPERTY_LOCK_LEVEL, 
Integer.toString(lockStartLevel)));
-            lockDelay = 
Integer.parseInt(m_configProps.getProperty(PROPERTY_LOCK_DELAY, 
Integer.toString(lockDelay)));
-            
m_configProps.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, 
Integer.toString(lockStartLevel));
+            defaultStartLevel = 
Integer.parseInt(configProps.getProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL));
+            lockStartLevel = 
Integer.parseInt(configProps.getProperty(PROPERTY_LOCK_LEVEL, 
Integer.toString(lockStartLevel)));
+            lockDelay = 
Integer.parseInt(configProps.getProperty(PROPERTY_LOCK_DELAY, 
Integer.toString(lockDelay)));
+            configProps.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, 
Integer.toString(lockStartLevel));
             // Start up the OSGI framework
-            m_felix = new Felix(new StringMap(m_configProps, false));
-            m_felix.start();
+
+            InputStream is = 
getClass().getResourceAsStream("/META-INF/services/" + 
FrameworkFactory.class.getName());
+            String factoryClass = new BufferedReader(new InputStreamReader(is, 
"UTF-8")).readLine();
+            FrameworkFactory factory = (FrameworkFactory) 
getClass().getClassLoader().loadClass(factoryClass).newInstance();
+            framework = factory.newFramework(new StringMap(configProps, 
false));
+            framework.start();
+            processAutoProperties(framework.getBundleContext());
             // Start lock monitor
             new Thread() {
                 public void run() {
-                    lock(m_configProps);
+                    lock(configProps);
                 }
             }.start();
         }
@@ -215,11 +196,11 @@
     public void destroy(boolean await) throws Exception {
         try {
             if (await) {
-                shutdown.await();
+                framework.waitForStop(0);
             }
             exiting = true;
-            if (m_felix.getState() == Bundle.ACTIVE) {
-                m_felix.stop();
+            if (framework.getState() == Bundle.ACTIVE) {
+                framework.stop();
             }
         } finally {
             unlock();
@@ -227,26 +208,6 @@
     }
 
     /**
-     * Used to instigate auto-install and auto-start configuration
-     * property processing via a custom framework activator during
-     * framework startup.
-     *
-     * @param context The system bundle context.
-     */
-    public void start(BundleContext context) {
-        Main.processAutoProperties(context);
-    }
-
-    /**
-     * Currently does nothing as part of framework shutdown.
-     *
-     * @param context The system bundle context.
-     */
-    public void stop(BundleContext context) {
-        // Do nothing.
-    }
-
-    /**
      * <p>
      * This method performs the main task of constructing an framework instance
      * and starting its execution. The following functions are performed
@@ -337,81 +298,18 @@
         }
     }
 
-    private static File getServiceMixHome() throws IOException {
-        File rc = null;
-
-        // Use the system property if specified.
-        String path = System.getProperty(PROP_KARAF_HOME);
-        if (path != null) {
-            rc = validateDirectoryExists(path, "Invalid " + PROP_KARAF_HOME + 
" system property");
-        }
-
-        if (rc == null) {
-            path = System.getenv(ENV_KARAF_HOME);
-            if (path != null) {
-                rc = validateDirectoryExists(path, "Invalid " + ENV_KARAF_HOME 
+ " environment variable");
-            }
-        }
-
-        // 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) {
-            // Dig into the classpath to guess the location of the jar
-            String classpath = System.getProperty("java.class.path");
-            int index = classpath.toLowerCase().indexOf("karaf.jar");
-            int start = classpath.lastIndexOf(File.pathSeparator, index) + 1;
-            if (index >= start) {
-                String jarLocation = classpath.substring(start, index);
-                rc = new File(jarLocation).getCanonicalFile().getParentFile();
-            }
-        }
-        if (rc == null) {
-            throw new IOException("The Karaf install directory could not be 
determined.  Please set the " + PROP_KARAF_HOME + " system property or the " + 
ENV_KARAF_HOME + " environment variable.");
-        }
-
-        return rc;
-    }
-
-    private static File validateDirectoryExists(String path, String errPrefix) 
{
-        File rc;
-        try {
-            rc = new File(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;
-    }
-
-    private static File getServiceMixBase(File defaultValue) {
+    private static File getKarafBase(File defaultValue) {
         File rc = null;
 
         String path = System.getProperty(PROP_KARAF_BASE);
         if (path != null) {
-            rc = validateDirectoryExists(path, "Invalid " + PROP_KARAF_BASE + 
" system property");
+            rc = Utils.validateDirectoryExists(path, "Invalid " + 
PROP_KARAF_BASE + " system property");
         }
 
         if (rc == null) {
             path = System.getenv(ENV_KARAF_BASE);
             if (path != null) {
-                rc = validateDirectoryExists(path, "Invalid " + ENV_KARAF_BASE 
+ " environment variable");
+                rc = Utils.validateDirectoryExists(path, "Invalid " + 
ENV_KARAF_BASE + " environment variable");
             }
         }
 
@@ -440,9 +338,9 @@
      * Processes the auto-install and auto-start properties from the
      * specified configuration properties.
      */
-    private static void processAutoProperties(BundleContext context) {
+    private void processAutoProperties(BundleContext context) {
         // Check if we want to convert URLs to maven style
-        boolean convertToMavenUrls = 
Boolean.parseBoolean(m_configProps.getProperty(PROPERTY_CONVERT_TO_MAVEN_URL, 
"true"));
+        boolean convertToMavenUrls = 
Boolean.parseBoolean(configProps.getProperty(PROPERTY_CONVERT_TO_MAVEN_URL, 
"true"));
 
         // Retrieve the Start Level service, since it will be needed
         // to set the start level of the installed bundles.
@@ -454,7 +352,7 @@
         // the start level to which the bundles are assigned is specified by
         // appending a ".n" to the auto-install property name, where "n" is
         // the desired start level for the list of bundles.
-        for (Iterator i = m_configProps.keySet().iterator(); i.hasNext();) {
+        for (Iterator i = configProps.keySet().iterator(); i.hasNext();) {
             String key = (String) i.next();
 
             // Ignore all keys that are not the auto-install property.
@@ -475,7 +373,7 @@
                 }
             }
 
-            StringTokenizer st = new 
StringTokenizer(m_configProps.getProperty(key), "\" ", true);
+            StringTokenizer st = new 
StringTokenizer(configProps.getProperty(key), "\" ", true);
             if (st.countTokens() > 0) {
                 String location = null;
                 do {
@@ -502,7 +400,7 @@
         // where "n" is the desired start level for the list of bundles.
         // The following code starts bundles in two passes, first it installs
         // them, then it starts them.
-        for (Iterator i = m_configProps.keySet().iterator(); i.hasNext();) {
+        for (Iterator i = configProps.keySet().iterator(); i.hasNext();) {
             String key = (String) i.next();
 
             // Ignore all keys that are not the auto-start property.
@@ -523,7 +421,7 @@
                 }
             }
 
-            StringTokenizer st = new 
StringTokenizer(m_configProps.getProperty(key), "\" ", true);
+            StringTokenizer st = new 
StringTokenizer(configProps.getProperty(key), "\" ", true);
             if (st.countTokens() > 0) {
                 String location = null;
                 do {
@@ -544,10 +442,10 @@
         }
 
         // Now loop through and start the installed bundles.
-        for (Iterator i = m_configProps.keySet().iterator(); i.hasNext();) {
+        for (Iterator i = configProps.keySet().iterator(); i.hasNext();) {
             String key = (String) i.next();
             if (key.startsWith(PROPERTY_AUTO_START)) {
-                StringTokenizer st = new 
StringTokenizer(m_configProps.getProperty(key), "\" ", true);
+                StringTokenizer st = new 
StringTokenizer(configProps.getProperty(key), "\" ", true);
                 if (st.countTokens() > 0) {
                     String location = null;
                     do {
@@ -1091,14 +989,6 @@
         this.exitCode = exitCode;
     }
 
-    public File getKarafHome() {
-        return karafHome;
-    }
-
-    public File getKarafBase() {
-        return karafBase;
-    }
-
     public void lock(Properties props) {
         try {
             if (Boolean.parseBoolean(props.getProperty(PROPERTY_USE_LOCK, 
"true"))) {
@@ -1117,7 +1007,7 @@
                             }
                             Thread.sleep(lockDelay);
                         }
-                        if (m_felix.getState() == Bundle.ACTIVE && !exiting) {
+                        if (framework.getState() == Bundle.ACTIVE && !exiting) 
{
                             System.out.println("Lost the lock, stopping this 
instance ...");
                             setStartLevel(lockStartLevel);
                         }
@@ -1141,7 +1031,7 @@
     }
 
     protected void setStartLevel(int level) throws Exception {
-        BundleContext ctx = m_felix.getBundleContext();
+        BundleContext ctx = framework.getBundleContext();
         ServiceReference[] refs = 
ctx.getServiceReferences(StartLevel.class.getName(), null);
         StartLevel sl = (StartLevel) ctx.getService(refs[0]);
         sl.setStartLevel(level);

Added: 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/StringMap.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/StringMap.java?rev=771836&view=auto
==============================================================================
--- 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/StringMap.java 
(added)
+++ 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/StringMap.java 
Tue May  5 15:46:15 2009
@@ -0,0 +1,95 @@
+/*
+ * 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.felix.karaf.main;
+
+import java.util.*;
+
+/**
+ * Simple utility class that creates a map for string-based keys by
+ * extending <tt>TreeMap</tt>. This map can be set to use case-sensitive
+ * or case-insensitive comparison when searching for the key.
+ * Any keys put into this map will be converted to
+ * a <tt>String</tt> using the <tt>toString()</tt> method,
+ * since it is only intended to compare strings.
+**/
+public class StringMap extends TreeMap
+{
+    public StringMap()
+    {
+        this(true);
+    }
+
+    public StringMap(boolean caseSensitive)
+    {
+        super(new StringComparator(caseSensitive));
+    }
+
+    public StringMap(Map map, boolean caseSensitive)
+    {
+        this(caseSensitive);
+        putAll(map);
+    }
+
+    public Object put(Object key, Object value)
+    {
+        return super.put(key.toString(), value);
+    }
+
+    public boolean isCaseSensitive()
+    {
+        return ((StringComparator) comparator()).isCaseSensitive();
+    }
+
+    public void setCaseSensitive(boolean b)
+    {
+        ((StringComparator) comparator()).setCaseSensitive(b);
+    }
+
+    private static class StringComparator implements Comparator
+    {
+        private boolean m_isCaseSensitive = true;
+
+        public StringComparator(boolean b)
+        {
+            m_isCaseSensitive = b;
+        }
+
+        public int compare(Object o1, Object o2)
+        {
+            if (m_isCaseSensitive)
+            {
+                return o1.toString().compareTo(o2.toString());
+            }
+            else
+            {
+                return o1.toString().compareToIgnoreCase(o2.toString());
+            }
+        }
+
+        public boolean isCaseSensitive()
+        {
+            return m_isCaseSensitive;
+        }
+
+        public void setCaseSensitive(boolean b)
+        {
+            m_isCaseSensitive = b;
+        }
+    }
+}
\ No newline at end of file

Added: 
felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Utils.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Utils.java?rev=771836&view=auto
==============================================================================
--- felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Utils.java 
(added)
+++ felix/trunk/karaf/main/src/main/java/org/apache/felix/karaf/main/Utils.java 
Tue May  5 15:46:15 2009
@@ -0,0 +1,93 @@
+/*
+ * 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.felix.karaf.main;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.JarURLConnection;
+import java.net.URI;
+
+import org.apache.felix.karaf.main.Main;
+
+public class Utils {
+
+    public static File getKarafHome() throws IOException {
+        File rc = null;
+
+        // Use the system property if specified.
+        String path = System.getProperty(Main.PROP_KARAF_HOME);
+        if (path != null) {
+            rc = validateDirectoryExists(path, "Invalid " + 
Main.PROP_KARAF_HOME + " system property");
+        }
+
+        if (rc == null) {
+            path = System.getenv(Main.ENV_KARAF_HOME);
+            if (path != null) {
+                rc = validateDirectoryExists(path, "Invalid " + 
Main.ENV_KARAF_HOME + " environment variable");
+            }
+        }
+
+        // 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) {
+            // Dig into the classpath to guess the location of the jar
+            String classpath = System.getProperty("java.class.path");
+            int index = classpath.toLowerCase().indexOf("karaf.jar");
+            int start = classpath.lastIndexOf(File.pathSeparator, index) + 1;
+            if (index >= start) {
+                String jarLocation = classpath.substring(start, index);
+                rc = new File(jarLocation).getCanonicalFile().getParentFile();
+            }
+        }
+        if (rc == null) {
+            throw new IOException("The Karaf install directory could not be 
determined.  Please set the " + Main.PROP_KARAF_HOME + " system property or the 
" + Main.ENV_KARAF_HOME + " environment variable.");
+        }
+
+        return rc;
+    }
+
+    public static File validateDirectoryExists(String path, String errPrefix) {
+        File rc;
+        try {
+            rc = new File(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;
+    }
+}

Modified: felix/trunk/karaf/pom.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/karaf/pom.xml?rev=771836&r1=771835&r2=771836&view=diff
==============================================================================
--- felix/trunk/karaf/pom.xml (original)
+++ felix/trunk/karaf/pom.xml Tue May  5 15:46:15 2009
@@ -75,6 +75,7 @@
         <commons.vfs.version>1.0_1</commons.vfs.version>
         <depends.maven.plugin.version>1.0</depends.maven.plugin.version>
         <easymock.version>2.4</easymock.version>
+        <equinox.version> 3.5.0.v20090429-1630</equinox.version>
         <felix.configadmin.version>1.0.4</felix.configadmin.version>
         <felix.plugin.version>2.0.0</felix.plugin.version>
         <felix.framework.version>1.6.0</felix.framework.version>
@@ -85,7 +86,7 @@
         <geronimo.annotation.version>1.1.1</geronimo.annotation.version>
         <geronimo.servlet.version>1.1.2</geronimo.servlet.version>
         <gshell.version>1.0-alpha-2</gshell.version>
-        <jaxp.ri.version>1.4.2_1</jaxp.ri.version>
+        <jaxp.ri.version>1.4.2_2</jaxp.ri.version>
         <junit.version>3.8.2_1</junit.version>
         <jline.version>0.9.94_1</jline.version>
         <log4j.version>1.2.14</log4j.version>
@@ -817,6 +818,11 @@
                 <artifactId>pax-exam-junit-extender-impl</artifactId>
                 <version>${pax.exam.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.eclipse</groupId>
+                <artifactId>osgi</artifactId>
+                <version>${equinox.version}</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 


Reply via email to