Return-Path: Delivered-To: apmail-incubator-aries-commits-archive@minotaur.apache.org Received: (qmail 81103 invoked from network); 3 Sep 2010 10:48:44 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 3 Sep 2010 10:48:44 -0000 Received: (qmail 79242 invoked by uid 500); 3 Sep 2010 10:48:44 -0000 Delivered-To: apmail-incubator-aries-commits-archive@incubator.apache.org Received: (qmail 79141 invoked by uid 500); 3 Sep 2010 10:48:41 -0000 Mailing-List: contact aries-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: aries-dev@incubator.apache.org Delivered-To: mailing list aries-commits@incubator.apache.org Received: (qmail 79133 invoked by uid 99); 3 Sep 2010 10:48:40 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Sep 2010 10:48:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Fri, 03 Sep 2010 10:48:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E969923888E7; Fri, 3 Sep 2010 10:48:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r992259 - in /incubator/aries/trunk/application: application-itests/src/test/java/org/apache/aries/application/runtime/itests/ application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/ Date: Fri, 03 Sep 2010 10:48:00 -0000 To: aries-commits@incubator.apache.org From: mahrwald@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100903104800.E969923888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mahrwald Date: Fri Sep 3 10:48:00 2010 New Revision: 992259 URL: http://svn.apache.org/viewvc?rev=992259&view=rev Log: Support application uninstall with subsequent reinstall Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java?rev=992259&r1=992258&r2=992259&view=diff ============================================================================== --- incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java (original) +++ incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java Fri Sep 3 10:48:00 2010 @@ -97,118 +97,111 @@ public class IsolatedRuntimeTest extends try { ctx.start(); - - BundleContext appContext = null; - for (Bundle sharedBundle : bundleContext.getBundles()) - { - if (sharedBundle.getSymbolicName().equals("shared.bundle.framework")) - { - BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext(); - for (Bundle appBundle : sharedContext.getBundles()) - { - if (appBundle.getSymbolicName().equals("test.eba")) - { - appContext = ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext(); - break; - } - } - break; - } - } - - if (appContext != null) { - // Dive into the context and pull out the composite bundle for the app - Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" + HelloWorld.class.getName() + ")"); - ServiceTracker tracker = new ServiceTracker(appContext, - osgiFilter, - null); - tracker.open(); - - Object hw = tracker.waitForService(DEFAULT_TIMEOUT); - - tracker.close(); + assertHelloWorldService("test.eba"); + } finally { + ctx.stop(); + manager.uninstall(ctx); + } + } + + @Test + public void testAppWithApplicationManifest() throws Exception { - // We can cast to our version of HelloWorld as it is in a different classloader - // so reflect into it to get the single method - Class returnClass = hw.getClass(); - Method method = returnClass.getDeclaredMethod("getMessage",null); - result = (String)method.invoke(hw); - - } - else - fail("No service found inside application framework"); - - } catch (Exception e) + AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class); + AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba"))); + AriesApplicationContext ctx = manager.install(app); + + try { - System.out.println("MOOP"); + ctx.start(); - e.printStackTrace(); + assertHelloWorldService("org.apache.aries.sample2"); } finally { ctx.stop(); manager.uninstall(ctx); } - - assertEquals (result, "hello world"); } - + @Test - public void testAppWithApplicationManifest() throws Exception { - + public void testUninstallReinstall() throws Exception { AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class); AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba"))); AriesApplicationContext ctx = manager.install(app); + app = ctx.getApplication(); + try { ctx.start(); - BundleContext appContext = null; - for (Bundle sharedBundle : bundleContext.getBundles()) - { - if (sharedBundle.getSymbolicName().equals("shared.bundle.framework")) - { - BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext(); - for (Bundle appBundle : sharedContext.getBundles()) - { - if (appBundle.getSymbolicName().equals("org.apache.aries.sample2")) - { - appContext = ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext(); - break; - } - } - break; - } - } + assertHelloWorldService("org.apache.aries.sample2"); - if (appContext != null) { - // Dive into the context and pull out the composite bundle for the app - Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" + HelloWorld.class.getName() + ")"); - ServiceTracker tracker = new ServiceTracker(appContext, - osgiFilter, - null); - tracker.open(); - - Object hw = tracker.waitForService(DEFAULT_TIMEOUT); - - tracker.close(); - - // We can cast to our version of HelloWorld as it is in a different classloader - // so reflect into it to get the single method - Class returnClass = hw.getClass(); - Method method = returnClass.getDeclaredMethod("getMessage",null); - String result = (String)method.invoke(hw); - assertEquals (result, "hello world"); - - - } - else - fail("No service found inside application framework"); + ctx.stop(); + manager.uninstall(ctx); + + ctx = manager.install(app); + ctx.start(); + + assertHelloWorldService("org.apache.aries.sample2"); } finally { ctx.stop(); manager.uninstall(ctx); + } + } + + + + private void assertHelloWorldService(String appName) throws Exception + { + BundleContext appContext = getAppIsolatedBundleContext(appName); + + if (appContext != null) { + // Dive into the context and pull out the composite bundle for the app + Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" + HelloWorld.class.getName() + ")"); + ServiceTracker tracker = new ServiceTracker(appContext, + osgiFilter, + null); + tracker.open(); + + Object hw = tracker.waitForService(DEFAULT_TIMEOUT); + + tracker.close(); + + // We can cast to our version of HelloWorld as it is in a different classloader + // so reflect into it to get the single method + Class returnClass = hw.getClass(); + Method method = returnClass.getDeclaredMethod("getMessage",null); + String result = (String)method.invoke(hw); + + assertEquals("hello world", result); } + else { + fail("No service found inside application framework"); + } + + } + + private BundleContext getAppIsolatedBundleContext(String appName) + { + for (Bundle sharedBundle : bundleContext.getBundles()) + { + if (sharedBundle.getSymbolicName().equals("shared.bundle.framework")) + { + BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext(); + for (Bundle appBundle : sharedContext.getBundles()) + { + if (appBundle.getSymbolicName().equals(appName)) + { + return ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext(); + } + } + break; + } + } + + return null; } Modified: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java?rev=992259&r1=992258&r2=992259&view=diff ============================================================================== --- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java (original) +++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java Fri Sep 3 10:48:00 2010 @@ -78,6 +78,7 @@ public class BundleFrameworkImpl impleme } _compositeBundle.stop(); + _compositeBundle.uninstall(); } public void start(Bundle b) throws BundleException