incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r788311 - in /sling/trunk/contrib/extensions/jcrinstall/osgi/src: main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
Date Thu, 25 Jun 2009 10:26:40 GMT
Author: bdelacretaz
Date: Thu Jun 25 10:26:40 2009
New Revision: 788311

URL: http://svn.apache.org/viewvc?rev=788311&view=rev
Log:
SLING-1001 - take the Maven SNAPSHOT convention into account when comparing bundle versions

Added:
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java?rev=788311&r1=788310&r2=788311&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessor.java
Thu Jun 25 10:26:40 2009
@@ -53,6 +53,8 @@
 
     /** {@link Storage} key for the bundle ID */
     public static final String KEY_BUNDLE_ID = "bundle.id";
+    
+    public static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT";
 
     /** Max time allowed to refresh packages (TODO configurable??) */
     public static final int MAX_REFRESH_PACKAGES_WAIT_SECONDS = 30;
@@ -175,12 +177,9 @@
 			if (b != null && retryCount == 1) {
 				final Version installedVersion = new Version((String)(b.getHeaders().get(Constants.BUNDLE_VERSION)));
 				final Version newBundleVersion = new Version(m.getMainAttributes().getValue(Constants.BUNDLE_VERSION));
-				if (newBundleVersion.compareTo(installedVersion) <= 0) {
-		            log.debug(
-		                "Ignore update of bundle {} from {} as the installed version is equal or
higher.",
-		                b.getSymbolicName(), uri);
+				if(ignoreNewBundle(b.getSymbolicName(), uri, installedVersion, newBundleVersion)) {
 		            return InstallResultCode.IGNORED;
-			    }
+				}
 			}
 
 			if (b != null) {
@@ -225,9 +224,39 @@
         synchronized (activeBundles) {
             installedBundles.add(b.getBundleId());
         }
+        
+        // Successful - reset retry count
+        retryCount = 0;
+        attributes.put("RETRY_COUNT", retryCount);
 
         return updated ? InstallResultCode.UPDATED : InstallResultCode.INSTALLED;
     }
+    
+    /** Decide if new bundle musg be ignored, based on the supplied Versions */
+    boolean ignoreNewBundle(String symbolicName, String uri, Version installedVersion, Version
newBundleVersion) {
+    	
+    	boolean ignore = false;
+    	final int comparison = newBundleVersion.compareTo(installedVersion);
+    	
+    	// Same version but snapshots - do not ignore
+    	if(comparison == 0  && installedVersion.toString().contains(MAVEN_SNAPSHOT_MARKER))
{
+    		if(log.isDebugEnabled()) {
+        		log.debug("Bundle " + symbolicName + " (" + uri + ") "
+        				+ " has same version (" + installedVersion + ") than installed bundle, but version
contains "
+        				+ MAVEN_SNAPSHOT_MARKER + ", will be updated");
+    		}
+    		
+    	} else if (comparison <= 0) {
+			ignore = true;
+			if(log.isDebugEnabled()) {
+				log.debug("Ignoring update of bundle " + symbolicName + " (" + uri
+						+ ") as installed version (" + installedVersion + ") is equal or higher than " + newBundleVersion
+						);
+			}
+	    }
+		
+		return ignore;
+    }
 
     /**
      * @see org.apache.sling.osgi.installer.OsgiResourceProcessor#uninstall(java.lang.String,
java.util.Map)

Added: sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java?rev=788311&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
(added)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
Thu Jun 25 10:26:40 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.sling.osgi.installer.impl;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+/** Test ignoring bundle updates based on Versions (SLING-1001) */
+public class BundleResourceProcessorIgnoreBundlesTest {
+
+	private final String symbolicName = "testbundle";
+	private final String uri = "testuri";
+	private BundleResourceProcessor brp;
+	private Mockery mockery;
+	
+    @org.junit.Before public void setup() {
+        mockery = new Mockery();
+        final BundleContext bc = mockery.mock(BundleContext.class);
+        final PackageAdmin pa = mockery.mock(PackageAdmin.class);
+        final StartLevel s = new MockStartLevel();
+        
+        mockery.checking(new Expectations() {{
+            allowing(bc).addFrameworkListener(with(any(FrameworkListener.class)));
+        }});
+        
+        brp = new BundleResourceProcessor(bc, pa, s);
+    }
+
+	@org.junit.Test public void testLowerVersion() {
+		final Version installedVersion = new Version("1.1");
+		final Version newVersion = new Version("1.0");
+		assertTrue("Lower version must be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+
+	@org.junit.Test public void testHigherVersion() {
+		final Version installedVersion = new Version("1.1");
+		final Version newVersion = new Version("1.2");
+		assertFalse("Higher version must not be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+
+	@org.junit.Test public void testSameVersion() {
+		final Version installedVersion = new Version("1.1");
+		final Version newVersion = new Version("1.1");
+		assertTrue("Same version must be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+
+	@org.junit.Test public void testSameVersionSnapshot() {
+		final Version installedVersion = new Version("2.0.5.incubator-SNAPSHOT");
+		final Version newVersion = new Version("2.0.5.incubator-SNAPSHOT");
+		assertFalse("Same version snapshot must not be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+
+	@org.junit.Test public void testLowerVersionSnapshot() {
+		final Version installedVersion = new Version("2.0.5.incubator-SNAPSHOT");
+		final Version newVersion = new Version("2.0.4.incubator-SNAPSHOT");
+		assertTrue("Lower version snapshot must be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+
+	@org.junit.Test public void testHigherVersionSnapshot() {
+		final Version installedVersion = new Version("2.0.5.incubator-SNAPSHOT");
+		final Version newVersion = new Version("2.0.6.incubator-SNAPSHOT");
+		assertFalse("Higher version snapshot must not be ignored",
+				brp.ignoreNewBundle(symbolicName, uri, installedVersion, newVersion));
+	}
+}

Propchange: sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/BundleResourceProcessorIgnoreBundlesTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message