incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1143494 - in /sling/trunk/installer: core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java it/pom.xml it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
Date Wed, 06 Jul 2011 16:40:04 GMT
Author: cziegeler
Date: Wed Jul  6 16:40:04 2011
New Revision: 1143494

URL: http://svn.apache.org/viewvc?rev=1143494&view=rev
Log:
SLING-2043 : Upon the installation of a fragment bundle, a refreshPackages call should be
made on the host bundle

Added:
    sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
  (with props)
Modified:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
    sling/trunk/installer/it/pom.xml

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java?rev=1143494&r1=1143493&r2=1143494&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
Wed Jul  6 16:40:04 2011
@@ -84,11 +84,16 @@ public class BundleStartTask extends Abs
 	    if ( b.getState() == Bundle.STARTING && isLazyActivatian(b) ) {
 	        return true;
 	    }
-	    if ( b.getHeaders().get(Constants.FRAGMENT_HOST) != null ) {
-	        return true;
-	    }
-        return false;
+	    return ( getFragmentHostHeader(b) != null );
+	}
+
+	/**
+         * Gets the bundle's Fragment-Host header.
+         */
+	public static String getFragmentHostHeader(final Bundle b) {
+	    return (String) b.getHeaders().get( Constants.FRAGMENT_HOST );
 	}
+
 	/**
 	 * Check if the bundle has the lazy activation policy
 	 */
@@ -126,40 +131,50 @@ public class BundleStartTask extends Abs
 			return;
 		}
 
-        if (isBundleActive(b) ) {
-            this.getLogger().debug("Bundle already started, no action taken: {}/{}", bundleId,
b.getSymbolicName());
-            if ( this.getResource() != null ) {
-                this.setFinishedState(ResourceState.INSTALLED);
+        final String fragmentHostHeader = getFragmentHostHeader(b);
+        if (fragmentHostHeader != null) {
+            this.getLogger().debug("Need to do a refresh of the bundle's host");
+            for (final Bundle bundle : this.creator.getBundleContext().getBundles()) {
+                if (fragmentHostHeader.equals(bundle.getSymbolicName())) {
+                    this.getLogger().debug("Found host bundle to refresh {}", bundle.getBundleId());
+                    this.creator.getPackageAdmin().refreshPackages(new Bundle[] { bundle
});
+                    break;
+                }
             }
-            return;
-        }
-        // Try to start bundle, and if that doesn't work we'll need to retry
-        try {
-            b.start();
-            if ( this.getResource() != null ) {
+
+            this.setFinishedState(ResourceState.INSTALLED);
+        } else {
+            if (isBundleActive(b) ) {
+                this.getLogger().debug("Bundle already started, no action taken: {}/{}",
bundleId, b.getSymbolicName());
                 this.setFinishedState(ResourceState.INSTALLED);
+                return;
             }
-            this.getLogger().info("Bundle started (retry count={}, bundle ID={}) : {}",
-                    new Object[] {retryCount, bundleId, b.getSymbolicName()});
-        } catch (final BundleException e) {
-            this.getLogger().info("Could not start bundle (retry count={}, bundle ID={})
: {}. Reason: {}. Will retry.",
-                    new Object[] {retryCount, bundleId, b.getSymbolicName(), e});
-
-            // Do the first retry immediately (in case "something" happenened right now
-            // that warrants a retry), but for the next ones wait for at least one bundle
-            // event or framework event
-            if (this.retryCount == 0) {
-                this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount();
-            } else {
-                this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount() + 1;
-            }
-            this.retryCount++;
-            if ( this.getResource() == null ) {
-                ctx.addTaskToNextCycle(this);
-            } else {
-                this.getResource().setTemporaryAttribute(ATTR_RC, this.retryCount);
-                this.getResource().setTemporaryAttribute(ATTR_EC, this.eventsCountForRetrying);
+            // Try to start bundle, and if that doesn't work we'll need to retry
+            try {
+                b.start();
+                this.setFinishedState(ResourceState.INSTALLED);
+                this.getLogger().info("Bundle started (retry count={}, bundle ID={}) : {}",
+                        new Object[] {retryCount, bundleId, b.getSymbolicName()});
+            } catch (final BundleException e) {
+                this.getLogger().info("Could not start bundle (retry count={}, bundle ID={})
: {}. Reason: {}. Will retry.",
+                        new Object[] {retryCount, bundleId, b.getSymbolicName(), e});
+
+                // Do the first retry immediately (in case "something" happenened right now
+                // that warrants a retry), but for the next ones wait for at least one bundle
+                // event or framework event
+                if (this.retryCount == 0) {
+                    this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount();
+                } else {
+                    this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount()
+ 1;
+                }
+                this.retryCount++;
+                if ( this.getResource() == null ) {
+                    ctx.addTaskToNextCycle(this);
+                } else {
+                    this.getResource().setTemporaryAttribute(ATTR_RC, this.retryCount);
+                    this.getResource().setTemporaryAttribute(ATTR_EC, this.eventsCountForRetrying);
+                }
             }
-        }
-	}
+    	}
+    }
 }

Modified: sling/trunk/installer/it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/pom.xml?rev=1143494&r1=1143493&r2=1143494&view=diff
==============================================================================
--- sling/trunk/installer/it/pom.xml (original)
+++ sling/trunk/installer/it/pom.xml Wed Jul  6 16:40:04 2011
@@ -373,6 +373,29 @@
                         </configuration>
                     </execution>
                     <execution>
+                        <id>fragmentA-1.0</id>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>run</goal>
+                        </goals>
+                        <configuration>
+                            <tasks name="Create fragment bundle 1.0">
+                                <jar destfile="${project.build.directory}/${project.artifactId}-${project.version}-testfragment-1.0.jar">
+                                    <fileset dir="${project.build.directory}/classes">
+                                        <include name="META-INF/**" />
+                                    </fileset>
+                                    <manifest>
+                                        <attribute name="Manifest-Version" value="2" />
+                                        <attribute name="Bundle-Name" value="OSGi controller
test fragment bundle" />
+                                        <attribute name="Fragment-Host" value="osgi-installer-testbundle"
/>
+                                        <attribute name="Bundle-Version" value="1.0" />
+                                        <attribute name="Bundle-SymbolicName" value="osgi-installer-testfragment"
/>
+                                    </manifest>
+                                </jar>
+                            </tasks>
+                        </configuration>
+                    </execution>
+                    <execution>
                         <id>invalid-version</id>
                         <phase>compile</phase>
                         <goals>
@@ -412,6 +435,7 @@
                                         <include name="*testB-1.0.jar" />
                                         <include name="*testA-1.0.jar" />
                                         <include name="*needsB.jar" />
+                                        <include name="*testfragment-1.0.jar" />
                                     </fileset>
                                 </copy>
                             </tasks>

Added: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java?rev=1143494&view=auto
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
(added)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
Wed Jul  6 16:40:04 2011
@@ -0,0 +1,90 @@
+/*
+ * 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.installer.it;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+@RunWith(JUnit4TestRunner.class)
+public class FragmentInstallTest extends OsgiInstallerTestBase {
+
+    @org.ops4j.pax.exam.junit.Configuration
+    public static Option[] configuration() {
+        Option[] options = defaultConfiguration();
+        options[0] = equinox();
+        return options;
+    }
+
+    @Before
+    public void setUp() {
+        setupInstaller();
+    }
+
+    @After
+    public void tearDown() {
+        super.tearDown();
+    }
+
+
+    @Test
+    public void testInstallFragment() throws Exception {
+        final String hostSymbolicName = "osgi-installer-testbundle";
+        assertNull("Test host bundle must be absent before installing", findBundle(hostSymbolicName));
+        final String fragmentSymbolicName = "osgi-installer-testfragment";
+        assertNull("Test fragment bundle must be absent before installing", findBundle(fragmentSymbolicName));
+
+        Object listener = this.startObservingBundleEvents();
+        installer.updateResources(URL_SCHEME, getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testbundle-1.2.jar"), "digest1"), null);
+        // wait for two tasks: install and start
+        this.waitForBundleEvents("Test bundle 1.2 must be found after waitForInstallerAction",
listener,
+                new BundleEvent(hostSymbolicName, "1.2", org.osgi.framework.BundleEvent.INSTALLED),
+                new BundleEvent(hostSymbolicName, "1.2", org.osgi.framework.BundleEvent.STARTED));
+        this.assertBundle("Bundle version 1.2 must be installed.", hostSymbolicName, "1.2",
Bundle.ACTIVE);
+
+        listener = this.startObservingBundleEvents();
+        installer.updateResources(URL_SCHEME, getInstallableResource(
+                getTestBundle(BUNDLE_BASE_NAME + "-testfragment-1.0.jar"), "digest1"), null);
+        this.waitForBundleEvents("Fragment bundle 1.0 must be found after waitForInstallerAction",
listener,
+                new BundleEvent(fragmentSymbolicName, "1.0", org.osgi.framework.BundleEvent.INSTALLED),
+                new BundleEvent(hostSymbolicName, "1.2", org.osgi.framework.BundleEvent.STARTED));
+        this.assertBundle("Bundle version 1.2 must be still be active.", hostSymbolicName,
"1.2", Bundle.ACTIVE);
+
+        Bundle host = findBundle(hostSymbolicName);
+        Bundle[] fragments = getService(PackageAdmin.class).getFragments(host);
+        assertNotNull("Bundle should have attached fragments", fragments);
+        boolean hadFragment = false;
+        for (Bundle fragment : fragments) {
+            if (fragmentSymbolicName.equals(fragment.getSymbolicName())) {
+                hadFragment = true;
+            }
+        }
+        assertTrue("Bundle should have fragment bundle attached", hadFragment);
+    }
+
+}

Propchange: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/FragmentInstallTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message