geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r978790 - in /geronimo/server/trunk/plugins/aries: ./ aries-deployer/ aries-deployer/src/main/history/ geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/ ger...
Date Sat, 24 Jul 2010 04:02:33 GMT
Author: gawor
Date: Sat Jul 24 04:02:32 2010
New Revision: 978790

URL: http://svn.apache.org/viewvc?rev=978790&view=rev
Log:
switch to obr resolver from apache aries

Added:
    geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
  (with props)
Removed:
    geronimo/server/trunk/plugins/aries/geronimo-aries-resolver/
Modified:
    geronimo/server/trunk/plugins/aries/aries-deployer/pom.xml
    geronimo/server/trunk/plugins/aries/aries-deployer/src/main/history/dependencies.xml
    geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationGBean.java
    geronimo/server/trunk/plugins/aries/pom.xml

Modified: geronimo/server/trunk/plugins/aries/aries-deployer/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/aries-deployer/pom.xml?rev=978790&r1=978789&r2=978790&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/aries-deployer/pom.xml (original)
+++ geronimo/server/trunk/plugins/aries/aries-deployer/pom.xml Sat Jul 24 04:02:32 2010
@@ -55,10 +55,10 @@
             <version>${project.version}</version>
         </dependency>
 -->
+
         <dependency>
-            <groupId>org.apache.geronimo.modules</groupId>
-            <artifactId>geronimo-aries-resolver</artifactId>
-            <version>${project.version}</version>
+            <groupId>org.apache.aries.application</groupId>
+            <artifactId>org.apache.aries.application.resolver.obr</artifactId>
         </dependency>
 
         <dependency>

Modified: geronimo/server/trunk/plugins/aries/aries-deployer/src/main/history/dependencies.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/aries-deployer/src/main/history/dependencies.xml?rev=978790&r1=978789&r2=978790&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/aries-deployer/src/main/history/dependencies.xml (original)
+++ geronimo/server/trunk/plugins/aries/aries-deployer/src/main/history/dependencies.xml Sat
Jul 24 04:02:32 2010
@@ -23,6 +23,11 @@
     </dependency>
     <dependency>
         <groupId>org.apache.aries.application</groupId>
+        <artifactId>org.apache.aries.application.resolver.obr</artifactId>
+        <type>jar</type>
+    </dependency>
+    <dependency>
+        <groupId>org.apache.aries.application</groupId>
         <artifactId>org.apache.aries.application.utils</artifactId>
         <type>jar</type>
     </dependency>
@@ -83,11 +88,6 @@
     </dependency>
     <dependency>
         <groupId>org.apache.geronimo.modules</groupId>
-        <artifactId>geronimo-aries-resolver</artifactId>
-        <type>jar</type>
-    </dependency>
-    <dependency>
-        <groupId>org.apache.geronimo.modules</groupId>
         <artifactId>geronimo-j2ee</artifactId>
         <type>jar</type>
     </dependency>

Modified: geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationGBean.java?rev=978790&r1=978789&r2=978790&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationGBean.java
(original)
+++ geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/java/org/apache/geronimo/aries/builder/ApplicationGBean.java
Sat Jul 24 04:02:32 2010
@@ -43,8 +43,10 @@ import org.apache.geronimo.kernel.reposi
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -72,18 +74,42 @@ public class ApplicationGBean implements
         this.installer = installer;
         this.configId = configId;
                 
-        // XXX: fix me
         BundleContext bundleContext = bundle.getBundleContext();
-        DeploymentMetadataFactory deploymentFactory = getDeploymentMetadataFactory(bundleContext);
-        ApplicationMetadataFactory applicationFactory = getApplicationMetadataFactory(bundleContext);
+
+        DeploymentMetadataFactory deploymentFactory = null;
+        ApplicationMetadataFactory applicationFactory  = null;
         
-        this.application = new GeronimoApplication(bundle, applicationFactory, deploymentFactory);
+        ServiceReference deploymentFactoryReference = 
+            bundleContext.getServiceReference(DeploymentMetadataFactory.class.getName());
+        ServiceReference applicationFactoryReference =
+            bundleContext.getServiceReference(ApplicationMetadataFactory.class.getName());
+        
+        try {
+            deploymentFactory = getService(deploymentFactoryReference, DeploymentMetadataFactory.class);
+            applicationFactory = getService(applicationFactoryReference, ApplicationMetadataFactory.class);
+        
+            this.application = new GeronimoApplication(bundle, applicationFactory, deploymentFactory);
+        } finally {
+            if (deploymentFactory != null) {
+                bundleContext.ungetService(deploymentFactoryReference);
+            }
+            if (applicationFactory != null) {
+                bundleContext.ungetService(applicationFactoryReference);
+            }
+        }
         
         install();
+                        
+        ServiceReference applicationManagerReference = 
+            bundleContext.getServiceReference(AriesApplicationContextManager.class.getName());
         
         GeronimoApplicationContextManager applicationManager = 
-            (GeronimoApplicationContextManager) getApplicationContextManager(bundleContext);
-        applicationManager.registerApplicationContext(new GeronimoApplicationContext(this));
+            getService(applicationManagerReference, GeronimoApplicationContextManager.class);
+        try {
+            applicationManager.registerApplicationContext(new GeronimoApplicationContext(this));
+        } finally {
+            bundleContext.ungetService(applicationManagerReference);
+        }
     }
     
     protected Bundle getBundle() {
@@ -101,53 +127,17 @@ public class ApplicationGBean implements
     protected ApplicationState getApplicationState() {
         return applicationState;
     }
-        
-    private AriesApplicationContextManager getApplicationContextManager(BundleContext bundleContext)
{
-        ServiceReference ref = 
-            bundleContext.getServiceReference(AriesApplicationContextManager.class.getName());
-        if (ref != null) {
-            return (AriesApplicationContextManager) bundleContext.getService(ref);
-        } else {
-            return null;
-        }
-    }
-    
-    private DeploymentMetadataFactory getDeploymentMetadataFactory(BundleContext bundleContext)
{
-        ServiceReference ref = 
-            bundleContext.getServiceReference(DeploymentMetadataFactory.class.getName());
-        if (ref != null) {
-            return (DeploymentMetadataFactory) bundleContext.getService(ref);
-        } else {
-            return null;
-        }
-    }
-    
-    private ApplicationMetadataFactory getApplicationMetadataFactory(BundleContext bundleContext)
{
-        ServiceReference ref = 
-            bundleContext.getServiceReference(ApplicationMetadataFactory.class.getName());
-        if (ref != null) {
-            return (ApplicationMetadataFactory) bundleContext.getService(ref);
-        } else {
-            return null;
-        }
-    }
-    
+            
     private void install() throws Exception {
 
         BundleContext bundleContext = bundle.getBundleContext();
         
         AriesApplicationResolver resolver = null;
-
-        ServiceReference ref = bundleContext.getServiceReference(AriesApplicationResolver.class.getName());
-
-        if (ref != null) {
-            resolver = (AriesApplicationResolver) bundleContext.getService(ref);
-        }
-
-        if (resolver == null) {
-            throw new ManagementException("AriesApplicationResolver service not found");
-        }
-
+        PackageAdmin packageAdmin = null;
+        
+        ServiceReference resolverRef = bundleContext.getServiceReference(AriesApplicationResolver.class.getName());
+        ServiceReference packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
+                
         DeploymentMetadata meta = application.getDeploymentMetadata();
         
         List<DeploymentContent> bundlesToInstall = new ArrayList<DeploymentContent>();
@@ -156,29 +146,29 @@ public class ApplicationGBean implements
         
         applicationBundles = new HashSet<Bundle>();
         try {
+            resolver = getService(resolverRef, AriesApplicationResolver.class);
+            packageAdmin = getService(packageAdminRef, PackageAdmin.class);
+            
             for (DeploymentContent content : bundlesToInstall) {
                 String bundleSymbolicName = content.getContentName();
                 Version bundleVersion = content.getExactVersion();
 
-                BundleInfo bundleInfo = null;
-
-                for (BundleInfo info : application.getBundleInfo()) {
-                    if (info.getSymbolicName().equals(bundleSymbolicName)
-                        && info.getVersion().equals(bundleVersion)) {
-                        bundleInfo = info;
-                        break;
-                    }
+                // Step 1: See if bundle is already installed in the framework
+                if (findBundleInFramework(packageAdmin, bundleSymbolicName, bundleVersion)
!= null) {
+                    continue;
                 }
-
+                
+                // Step 2: See if the bundle is included in the application
+                BundleInfo bundleInfo = findBundleInfoInApplication(bundleSymbolicName, bundleVersion);
                 if (bundleInfo == null) {
-                    // call out to the bundle repository.
-                    bundleInfo = resolver.getBundleInfo(bundleSymbolicName, bundleVersion);
+                    // Step 3: Lookup bundle location using the resolver
+                    bundleInfo = findBundleInfoUsingResolver(resolver, bundleSymbolicName,
bundleVersion);
                 }
-
+                
                 if (bundleInfo == null) {
                     throw new ManagementException("Cound not find bundles: " + bundleSymbolicName
+ "_" + bundleVersion);
                 }
-
+                    
                 Bundle bundle = bundleContext.installBundle(bundleInfo.getLocation());
 
                 applicationBundles.add(bundle);
@@ -193,13 +183,53 @@ public class ApplicationGBean implements
             throw be;
         } finally {
             if (resolver != null) {
-                bundleContext.ungetService(ref);
+                bundleContext.ungetService(resolverRef);
+            }
+            if (packageAdmin != null) {
+                bundleContext.ungetService(packageAdminRef);
             }
         }
 
         applicationState = ApplicationState.INSTALLED;
     }
     
+    private Bundle findBundleInFramework(PackageAdmin admin, String symbolicName, Version
version) {
+        String exactVersion = "[" + version + "," + version + "]";
+        Bundle[] bundles = admin.getBundles(symbolicName, exactVersion);
+        if (bundles != null && bundles.length == 1) {
+            return bundles[0];
+        } else {
+            return null;
+        }
+    }
+    
+    private BundleInfo findBundleInfoInApplication(String symbolicName, Version version)
{
+        for (BundleInfo info : application.getBundleInfo()) {
+            if (info.getSymbolicName().equals(symbolicName)
+                && info.getVersion().equals(version)) {
+                return info;
+            }
+        }
+        return null;
+    }
+    
+    private BundleInfo findBundleInfoUsingResolver(AriesApplicationResolver resolver, String
symbolicName, Version version) {
+        return resolver.getBundleInfo(symbolicName, version);
+    }
+    
+    private <T> T getService(ServiceReference ref, Class<T> type) throws ManagementException
{
+        Object service = null;
+        if (ref != null) {
+            service = bundle.getBundleContext().getService(ref);
+        }
+        
+        if (service == null) {
+            throw new ManagementException(new ServiceException(type.getName(), ServiceException.UNREGISTERED));
+        }
+        
+        return type.cast(service);
+    }
+    
     public void doStart() throws Exception {
         LOG.debug("Starting {}", application.getApplicationMetadata().getApplicationScope());
         

Added: geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml?rev=978790&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
(added)
+++ geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
Sat Jul 24 04:02:32 2010
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+    <bean id="obr-resolver" class="org.apache.aries.application.resolver.obr.OBRAriesResolver"
scope="singleton"
+          activation="eager">
+        <argument>
+            <reference interface="org.apache.felix.bundlerepository.RepositoryAdmin"/>
+        </argument>
+        <property name="returnOptionalResources" value="false"/>
+    </bean>
+
+    <service interface="org.apache.aries.application.management.AriesApplicationResolver"
ref="obr-resolver" ranking="5" />
+
+</blueprint>

Propchange: geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/aries/geronimo-aries-builder/src/main/resources/OSGI-INF/blueprint/obr-resolver.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: geronimo/server/trunk/plugins/aries/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/pom.xml?rev=978790&r1=978789&r2=978790&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/pom.xml (original)
+++ geronimo/server/trunk/plugins/aries/pom.xml Sat Jul 24 04:02:32 2010
@@ -38,7 +38,6 @@
     
     <modules>
         <module>geronimo-aries-builder</module>
-        <module>geronimo-aries-resolver</module>
 <!--
         <module>geronimo-aries-shell</module>
 -->
@@ -62,6 +61,11 @@
                 <artifactId>org.apache.aries.application.management</artifactId>
                 <version>0.2-incubating-SNAPSHOT</version>
             </dependency>
+            <dependency>
+                <groupId>org.apache.aries.application</groupId>
+                <artifactId>org.apache.aries.application.resolver.obr</artifactId>
+                <version>0.2-incubating-SNAPSHOT</version>
+            </dependency>
         </dependencies>
     </dependencyManagement>
 



Mime
View raw message