FELIX-5209 get the system bundle by location not id

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1734365 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/fileinstall/pom.xml b/fileinstall/pom.xml
index 73f23d8..8c8e827 100644
--- a/fileinstall/pom.xml
+++ b/fileinstall/pom.xml
@@ -20,7 +20,7 @@
   <parent>
     <groupId>org.apache.felix</groupId>
     <artifactId>felix-parent</artifactId>
-    <version>2.1</version>
+    <version>3</version>
     <relativePath>../pom/pom.xml</relativePath>
   </parent>
 	
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
index 74630b6..5b51ffb 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
@@ -127,6 +127,7 @@
     boolean useStartActivationPolicy;
     String filter;
     BundleContext context;
+    private Bundle systemBundle;
     String originatingFileName;
     boolean noInitialDelay;
     int startLevel;
@@ -161,6 +162,7 @@
         this.fileInstall = fileInstall;
         this.properties = properties;
         this.context = context;
+        systemBundle = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION);
         poll = getLong(properties, POLL, 2000);
         logLevel = getInt(properties, LOG_LEVEL, Util.getGlobalLogLevel(context));
         originatingFileName = properties.get(FILENAME);
@@ -295,10 +297,10 @@
 
         while (!interrupted()) {
             try {
-                FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
+                FrameworkStartLevel startLevelSvc = systemBundle.adapt(FrameworkStartLevel.class);
                 // Don't access the disk when the framework is still in a startup phase.
                 if (startLevelSvc.getStartLevel() >= activeLevel
-                        && context.getBundle(0).getState() == Bundle.ACTIVE) {
+                        && systemBundle.getState() == Bundle.ACTIVE) {
                     Set<File> files = scanner.scan(false);
                     // Check that there is a result.  If not, this means that the directory can not be listed,
                     // so it's presumably not a valid directory (it may have been deleted by someone).
@@ -311,6 +313,7 @@
                     wait(poll);
                 }
             } catch (InterruptedException e) {
+                interrupt();
                 return;
             } catch (Throwable e) {
                 try {
@@ -669,7 +672,7 @@
      */
     void refresh(Collection<Bundle> bundles) throws InterruptedException
     {
-        FileInstall.refresh(context, bundles);
+        FileInstall.refresh(systemBundle, bundles);
     }
 
     /**
@@ -1188,7 +1191,7 @@
      */
     private void startAllBundles()
     {
-        FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
+        FrameworkStartLevel startLevelSvc = systemBundle.adapt(FrameworkStartLevel.class);
         List<Bundle> bundles = new ArrayList<Bundle>();
         for (Artifact artifact : getArtifacts()) {
             if (artifact.getBundleId() > 0) {
@@ -1226,7 +1229,7 @@
       */
     private boolean startBundle(Bundle bundle)
     {
-        FrameworkStartLevel startLevelSvc = context.getBundle(0).adapt(FrameworkStartLevel.class);
+        FrameworkStartLevel startLevelSvc = systemBundle.adapt(FrameworkStartLevel.class);
         // Fragments can never be started.
         // Bundles can only be started transient when the start level of the framework is high
         // enough. Persistent (i.e. non-transient) starts will simply make the framework start the
diff --git a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
index 468cfb6..f5b1eae 100644
--- a/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
+++ b/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
@@ -317,10 +317,10 @@
     /**
      * Convenience to refresh the packages
      */
-    static void refresh(BundleContext context, Collection<Bundle> bundles) throws InterruptedException
+    static void refresh(Bundle systemBundle, Collection<Bundle> bundles) throws InterruptedException
     {
         final CountDownLatch latch = new CountDownLatch(1);
-        FrameworkWiring wiring = context.getBundle(0).adapt(FrameworkWiring.class);
+        FrameworkWiring wiring = systemBundle.adapt(FrameworkWiring.class);
         wiring.refreshBundles(bundles, new FrameworkListener() {
             public void frameworkEvent(FrameworkEvent event) {
                 latch.countDown();
diff --git a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
index 0d579c4..6769c4d 100644
--- a/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
+++ b/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/DirectoryWatcherTest.java
@@ -34,6 +34,7 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.startlevel.FrameworkStartLevel;
 import org.osgi.framework.wiring.BundleRevision;
@@ -74,7 +75,7 @@
         EasyMock.expect(mockBundleContext.getServiceReference(LogService.class.getName()))
                         .andStubReturn(null);
         EasyMock.expect(mockBundleContext.getBundle()).andReturn(mockBundle).anyTimes();
-        EasyMock.expect(mockBundleContext.getBundle(0)).andReturn(mockSysBundle).anyTimes();
+        EasyMock.expect(mockBundleContext.getBundle(Constants.SYSTEM_BUNDLE_LOCATION)).andReturn(mockSysBundle).anyTimes();
         EasyMock.expect(mockSysBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes();
         EasyMock.expect(mockSysBundle.adapt(FrameworkStartLevel.class)).andReturn(mockStartLevel).anyTimes();
         EasyMock.expect(mockStartLevel.getStartLevel()).andReturn(50).anyTimes();