geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1166971 - in /geronimo/server/trunk/framework/modules: geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/ geronimo-system/src/main/java/org/apache/geronimo/system/configuration/
Date Fri, 09 Sep 2011 02:43:43 GMT
Author: xuhaihong
Date: Fri Sep  9 02:43:42 2011
New Revision: 1166971

URL: http://svn.apache.org/viewvc?rev=1166971&view=rev
Log:
GERONIMO-6157 Generate fixed version number for the import packages

Modified:
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
    geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java?rev=1166971&r1=1166970&r2=1166971&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiBuildContext.java
Fri Sep  9 02:43:42 2011
@@ -106,7 +106,7 @@ public class OSGiBuildContext {
         Set<ExportPackage> exportPackages = new HashSet<ExportPackage>(dependencyManager.getExportedPackages(bundleId));
         for (Iterator<ExportPackage> it = exportPackages.iterator(); it.hasNext();)
{
             ExportPackage exportPackage = it.next();
-            if (isHiddenExportPackage(exportPackage)) {
+            if (isHiddenExportPackage(exportPackage) || exportPackage.getDirectives().get("mandatory")
!= null) {
                 it.remove();
             }
         }

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java?rev=1166971&r1=1166970&r2=1166971&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/OSGiMetaDataBuilder.java
Fri Sep  9 02:43:42 2011
@@ -46,6 +46,8 @@ public class OSGiMetaDataBuilder {
 
     private static final Logger logger = LoggerFactory.getLogger(OSGiMetaDataBuilder.class);
 
+    private static final boolean USE_FIXED_IMPORT_PACKAGE_VERSION = Boolean.parseBoolean(System.getProperty("org.apache.geronimo.deployment.import_package.fixed_version",
"true"));
+
     private static final Version ZERO_VERSION = new Version(0, 0, 0);
 
     private BundleContext bundleContext;
@@ -156,7 +158,7 @@ public class OSGiMetaDataBuilder {
                 continue;
             }
             if (dynamicImportPackageName.startsWith("!")) {
-                throw new IllegalConfigurationException("DynamicImport-Package " + dynamicImportPackageName
+ " could not configured with ! prefix");
+                throw new IllegalConfigurationException("DynamicImport-Package " + dynamicImportPackageName
+ " could not be configured with ! prefix");
             } else {
                 List<HeaderElement> elements = HeaderParser.parseHeader(dynamicImportPackageName);
                 for (HeaderElement headerElement : elements) {
@@ -182,11 +184,17 @@ public class OSGiMetaDataBuilder {
             if (context.isInverseClassLoading()) {
                 for (ExportPackage exportPackage : entry.getValue()) {
                     String importPackageName = toImportPackageName(exportPackage);
+                    if (importPackageName == null) {
+                        continue;
+                    }
                     environment.addDynamicImportPackage(importPackageName);
                 }
             } else {
                 for (ExportPackage exportPackage : entry.getValue()) {
                     String importPackageName = toImportPackageName(exportPackage);
+                    if (importPackageName == null) {
+                        continue;
+                    }
                     environment.addImportPackage(importPackageName);
                 }
             }
@@ -195,8 +203,16 @@ public class OSGiMetaDataBuilder {
     }
 
     protected String toImportPackageName(ExportPackage exportPackage) {
-        //TODO If mandatory attribute exists, do we need to handle it ?
-        return exportPackage.getVersion().equals(ZERO_VERSION) ? exportPackage.getName()
: exportPackage.getName() + ";version=" + exportPackage.getVersion();
+        /* If mandatory attribute exists, do we need to handle it ?
+        if (exportPackage.getAttributes().get("mandatory") != null) {
+            logger.info("Export package " + exportPackage.getName() + " has mandatory attribute,
it will not be considered, if it is required, please add in the deployment plan");
+            return null;
+        }*/
+        if (USE_FIXED_IMPORT_PACKAGE_VERSION) {
+            return exportPackage.getName() + ";version=" + "\"[" + exportPackage.getVersion()
+ "," + exportPackage.getVersion() + "]\"";
+        } else {
+            return exportPackage.getVersion().equals(ZERO_VERSION) ? exportPackage.getName()
: exportPackage.getName() + ";version=" + exportPackage.getVersion();
+        }
     }
 
     private ArtifactResolver getClientArtifactResolver() {

Modified: geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java?rev=1166971&r1=1166970&r2=1166971&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/DependencyManager.java
Fri Sep  9 02:43:42 2011
@@ -56,6 +56,8 @@ import org.apache.geronimo.system.plugin
 import org.apache.geronimo.system.plugin.model.PluginXmlUtil;
 import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
 import org.apache.xbean.osgi.bundle.util.BundleUtils;
+import org.apache.xbean.osgi.bundle.util.HeaderParser;
+import org.apache.xbean.osgi.bundle.util.HeaderParser.HeaderElement;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
@@ -63,6 +65,7 @@ import org.osgi.framework.BundleExceptio
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.Version;
 import org.osgi.service.packageadmin.ExportedPackage;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
@@ -311,18 +314,33 @@ public class DependencyManager implement
         ServiceReference reference = null;
         try {
             reference = bundleContext.getServiceReference(PackageAdmin.class.getName());
-            if(reference == null) {
+            if (reference == null) {
                 log.warn("No PackageAdmin service is found, fail to get export packages of
" + bundle.getLocation());
-                return Collections.<ExportPackage>emptySet();
+                return Collections.<ExportPackage> emptySet();
+            }
+            String exportPackageHeader = (String)bundle.getHeaders().get(Constants.EXPORT_PACKAGE);
+            Map<String, HeaderElement> nameVersionExportPackageMap = new HashMap<String,
HeaderElement>();
+            if (exportPackageHeader != null) {
+                List<HeaderElement> headerElements = HeaderParser.parseHeader(exportPackageHeader);
+                for (HeaderElement headerElement : headerElements) {
+                    String version = headerElement.getAttribute(Constants.VERSION_ATTRIBUTE);
+                    if (version == null) {
+                        headerElement.addAttribute(Constants.VERSION_ATTRIBUTE, "0.0.0");
+                        nameVersionExportPackageMap.put(headerElement.getName() + "0.0.0",
headerElement);
+                    } else {
+                        nameVersionExportPackageMap.put(headerElement.getName() + new Version(version).toString(),
headerElement);
+                    }
+                }
             }
             PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(reference);
             ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
             if (exportedPackages != null) {
                 Set<ExportPackage> exportPackageNames = new HashSet<ExportPackage>();
                 for (ExportedPackage exportedPackage : exportedPackages) {
-                    Map<String, String> attributes = new HashMap<String, String>();
-                    attributes.put(Constants.VERSION_ATTRIBUTE, exportedPackage.getVersion().toString());
-                    exportPackageNames.add(new ExportPackage(exportedPackage.getName(), attributes,
Collections.<String, String> emptyMap()));
+                    HeaderElement headerElement = nameVersionExportPackageMap.get(exportedPackage.getName()
+ exportedPackage.getVersion());
+                    if (headerElement != null) {
+                        exportPackageNames.add(new ExportPackage(headerElement.getName(),
headerElement.getAttributes(), headerElement.getDirectives()));
+                    }
                 }
                 return exportPackageNames;
             }



Mime
View raw message