Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9A94E6D42 for ; Wed, 6 Jul 2011 16:40:27 +0000 (UTC) Received: (qmail 266 invoked by uid 500); 6 Jul 2011 16:40:27 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 196 invoked by uid 500); 6 Jul 2011 16:40:26 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 185 invoked by uid 99); 6 Jul 2011 16:40:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jul 2011 16:40:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jul 2011 16:40:25 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E5C3F238890D; Wed, 6 Jul 2011 16:40:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110706164004.E5C3F238890D@eris.apache.org> 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 @@ + fragmentA-1.0 + compile + + run + + + + + + + + + + + + + + + + + + + invalid-version compile @@ -412,6 +435,7 @@ + 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