incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r825307 - in /sling/trunk/installer/osgi/installer/src: main/java/org/apache/sling/osgi/installer/impl/ main/java/org/apache/sling/osgi/installer/impl/tasks/ test/java/org/apache/sling/osgi/installer/impl/
Date Wed, 14 Oct 2009 22:07:19 GMT
Author: bdelacretaz
Date: Wed Oct 14 22:07:19 2009
New Revision: 825307

URL: http://svn.apache.org/viewvc?rev=825307&view=rev
Log:
SLING-1106 - prepare for storing versions of installed bundles

Added:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java
      - copied, changed from r824648, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorage.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfoTest.java
      - copied, changed from r824648, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorageTest.java
Removed:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorage.java
    sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorageTest.java
Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=825307&r1=825306&r2=825307&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
Wed Oct 14 22:07:19 2009
@@ -43,7 +43,7 @@
     private final ServiceTracker logServiceTracker;
     private final OsgiInstallerThread installerThread;
     private long [] counters = new long[COUNTERS_SIZE];
-    private BundleDigestsStorage bundleDigestsStorage;  
+    private PersistentBundleInfo bundleDigestsStorage;  
     
     public OsgiInstallerImpl(final BundleContext bc,
                               final PackageAdmin pa,
@@ -52,7 +52,7 @@
         this.bundleContext = bc;
         this.packageAdmin = pa;
         this.logServiceTracker = logServiceTracker;
-        bundleDigestsStorage = new BundleDigestsStorage(this, bc.getDataFile("bundle-digests.properties"));
+        bundleDigestsStorage = new PersistentBundleInfo(this, bc.getDataFile("bundle-digests.properties"));
         
         installerThread = new OsgiInstallerThread(this);
         installerThread.setDaemon(true);
@@ -180,6 +180,6 @@
     }
 
     public void saveBundleDigest(Bundle b, String digest) throws IOException {
-        bundleDigestsStorage.putDigest(b.getSymbolicName(), digest);
+        bundleDigestsStorage.putInfo(b.getSymbolicName(), digest, "");
     }
  }
\ No newline at end of file

Copied: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java
(from r824648, sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorage.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java?p2=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java&p1=sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorage.java&r1=824648&r2=825307&rev=825307&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorage.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java
Wed Oct 14 22:07:19 2009
@@ -31,18 +31,19 @@
 
 import org.osgi.service.log.LogService;
 
-/** Store bundle digests in a file, to avoid re-installing
- *  snapshots needlessly when restarting.
+/** Store the digests and version numbers of installed bundles
+ *  in a file, to keep track of what we installed.
  */
-class BundleDigestsStorage {
+class PersistentBundleInfo {
     private Properties digests = new Properties();
     private final File dataFile;
     private final OsgiInstallerContext ctx;
+    private static final String VERSION_PREFIX = "V:";
     
     /** Load the list from supplied file, which is also
      *  used by purgeAndSave to save our data
      */
-    BundleDigestsStorage(OsgiInstallerContext ctx, File dataFile) throws IOException {
+    PersistentBundleInfo(OsgiInstallerContext ctx, File dataFile) throws IOException {
         this.ctx = ctx;
         this.dataFile = dataFile;
         InputStream is = null;
@@ -64,14 +65,15 @@
         }
     }
     
-    /** Remove digests which do not belong to installed bundles,
+    /** Remove data which do not belongs to installed bundles,
      *  and save our data
      */
     void purgeAndSave(TreeSet<String> installedBundlesSymbolicNames) throws IOException
{
         final List<String> toRemove = new ArrayList<String>();
         for(Object o : digests.keySet()) {
             final String key = (String)o;
-            if(!installedBundlesSymbolicNames.contains(key)) {
+            if(!installedBundlesSymbolicNames.contains(key) 
+                    && !installedBundlesSymbolicNames.contains(key.substring(VERSION_PREFIX.length())))
{
                 toRemove.add(key);
             }
         }
@@ -96,12 +98,18 @@
     }
     
     /** Store a bundle digest - not persisted until purgeAndSave is called */
-    void putDigest(String bundleSymbolicName, String digest) {
+    void putInfo(String bundleSymbolicName, String digest, String installedVersion) {
         digests.setProperty(bundleSymbolicName, digest);
+        digests.setProperty(VERSION_PREFIX + bundleSymbolicName, installedVersion);
     }
     
     /** Retrieve digest, null if not found */
     String getDigest(String bundleSymbolicName) {
         return digests.getProperty(bundleSymbolicName);
     }
+    
+    /** Retrieve installed version, null if not found */
+    String getInstalledVersion(String bundleSymbolicName) {
+        return digests.getProperty(VERSION_PREFIX + bundleSymbolicName);
+    }
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=825307&r1=825306&r2=825307&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
Wed Oct 14 22:07:19 2009
@@ -60,6 +60,13 @@
 		final LogService log = ctx.getLogService();
 		boolean needToRetry = false;
 		
+        if(bundleId == 0) {
+            if(log != null) {
+                log.log(LogService.LOG_DEBUG, "Bundle 0 is the framework bundle, ignoring
request to start it");
+            }
+            return;
+        }
+        
 		if(b == null) {
 			if(log != null) {
 				log.log(LogService.LOG_INFO, "Cannot start bundle, id not found:" + bundleId);

Copied: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfoTest.java
(from r824648, sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorageTest.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfoTest.java?p2=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfoTest.java&p1=sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorageTest.java&r1=824648&r2=825307&rev=825307&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/BundleDigestsStorageTest.java
(original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfoTest.java
Wed Oct 14 22:07:19 2009
@@ -20,6 +20,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
 
 import java.io.File;
 import java.io.IOException;
@@ -28,59 +29,83 @@
 import org.junit.Before;
 import org.junit.Test;
 
-public class BundleDigestsStorageTest {
-    private BundleDigestsStorage storage;
+public class PersistentBundleInfoTest {
+    private PersistentBundleInfo storage;
     private File testFile;
     private TreeSet<String> installedBundles;
+    private static final String NO_VERSION = "";
     
     @Before
     public void setUp() throws Exception {
         testFile = File.createTempFile(getClass().getSimpleName(), "properties");
         testFile.deleteOnExit();
-        storage = new BundleDigestsStorage(new MockOsgiInstallerContext(), testFile);
+        storage = new PersistentBundleInfo(new MockOsgiInstallerContext(), testFile);
         installedBundles = new TreeSet<String>();
     }
     
     @Test
     public void testCloseAndReopen() throws IOException {
-        storage.putDigest("foo", "bar");
+        storage.putInfo("foo", "bar", NO_VERSION);
         assertEquals("Before save, expecting bar digest", "bar", storage.getDigest("foo"));
         installedBundles.add("foo");
         storage.purgeAndSave(installedBundles);
         assertEquals("After save, expecting bar digest", "bar", storage.getDigest("foo"));
-        storage.putDigest("foo", "wii");
+        storage.putInfo("foo", "wii", NO_VERSION);
         assertEquals("After change, expecting wii digest", "wii", storage.getDigest("foo"));
         storage = null;
-        final BundleDigestsStorage copy = new BundleDigestsStorage(new MockOsgiInstallerContext(),
testFile);
+        final PersistentBundleInfo copy = new PersistentBundleInfo(new MockOsgiInstallerContext(),
testFile);
         assertEquals("In copy saved before change, expecting bar digest", "bar", copy.getDigest("foo"));
     }
     
     @Test
     public void testPurge() throws IOException {
         for(int i=0; i < 50; i++) {
-            storage.putDigest("foo" + i, "bar" + i);
+            storage.putInfo("foo" + i, "bar" + i, "1." + i);
             if(i % 2 == 0) {
                 installedBundles.add("foo" + i);
             }
         }
         for(int i=0; i < 50; i++) {
-            assertEquals("Before save, expecting digest to match at step " + i, "bar" + i,
storage.getDigest("foo" + i));
+            assertEquals("Before save, expecting digest to match at step " + i, "bar" + i,

+                    storage.getDigest("foo" + i));
+            assertEquals("Before save, expecting version to match at step " + i, "1." + i,

+                    storage.getInstalledVersion("foo" + i));
         }
         storage.purgeAndSave(installedBundles);
         for(int i=0; i < 50; i++) {
             if(i % 2 != 0) {
-                assertNull("After purge, expecting null digest at step " + i, storage.getDigest("foo"
+ i));
+                assertNull("After purge, expecting null digest at step " + i, 
+                        storage.getDigest("foo" + i));
+                assertNull("After purge, expecting null version at step " + i, 
+                        storage.getInstalledVersion("foo" + i));
             } else {
-                assertEquals("After purge, expecting digest to match at step " + i, "bar"
+ i, storage.getDigest("foo" + i));
+                assertNotNull("After purge, expecting non-null digest at step " + i, 
+                        storage.getDigest("foo" + i));
+                assertEquals("After purge, expecting digest to match at step " + i, "bar"
+ i, 
+                        storage.getDigest("foo" + i));
+                assertNotNull("After purge, expecting non-null version at step " + i, 
+                        storage.getInstalledVersion("foo" + i));
+                assertEquals("After purge, expecting version to match at step " + i, "1."
+ i, 
+                        storage.getInstalledVersion("foo" + i));
             }
         }
         storage = null;
-        final BundleDigestsStorage copy = new BundleDigestsStorage(new MockOsgiInstallerContext(),
testFile);
+        final PersistentBundleInfo copy = new PersistentBundleInfo(new MockOsgiInstallerContext(),
testFile);
         for(int i=0; i < 50; i++) {
             if(i % 2 != 0) {
-                assertNull("In copy, expecting null digest at step " + i, copy.getDigest("foo"
+ i));
+                assertNull("In copy, expecting null digest at step " + i, 
+                        copy.getDigest("foo" + i));
+                assertNull("In copy, expecting null version at step " + i, 
+                        copy.getInstalledVersion("foo" + i));
             } else {
-                assertEquals("In copy, expecting digest to match at step " + i, "bar" + i,
copy.getDigest("foo" + i));
+                assertNotNull("In copy, expecting non-null digest at step " + i, 
+                        copy.getDigest("foo" + i));
+                assertEquals("In copy, expecting digest to match at step " + i, "bar" + i,

+                        copy.getDigest("foo" + i));
+                assertNotNull("In copy, expecting non-null version at step " + i, 
+                        copy.getInstalledVersion("foo" + i));
+                assertEquals("In copy, expecting version to match at step " + i, "1." + i,

+                        copy.getInstalledVersion("foo" + i));
             }
         }
     }



Mime
View raw message