You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by xu...@apache.org on 2011/01/24 10:40:11 UTC
svn commit: r1062704 - in /geronimo/server/trunk/framework/modules:
geronimo-deployment/src/main/java/org/apache/geronimo/deployment/
geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/
geronimo-system/src/main/java/org/apache/g...
Author: xuhaihong
Date: Mon Jan 24 09:40:11 2011
New Revision: 1062704
URL: http://svn.apache.org/viewvc?rev=1062704&view=rev
Log:
Use client artifact resolver while generating import packages for client module, as it uses different artifact aliases mapping
Modified:
geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java
geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java
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/DeploymentContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java?rev=1062704&r1=1062703&r2=1062704&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/DeploymentContext.java Mon Jan 24 09:40:11 2011
@@ -550,6 +550,7 @@ public class DeploymentContext {
// TODO OSGI leave out if we use a extender mechanism
if (environment.getBundleActivator() == null) {
environment.setBundleActivator(ConfigurationActivator.class.getName());
+ environment.addImportPackage(getImportPackageName(ConfigurationActivator.class.getName()));
}
List<GBeanData> gbeans = new ArrayList<GBeanData>(configuration.getGBeans().values());
Collections.sort(gbeans, new GBeanData.PriorityComparator());
@@ -567,7 +568,7 @@ public class DeploymentContext {
}
try {
- osgiMetaDataBuilder.build(environment);
+ osgiMetaDataBuilder.build(environment, configuration.getModuleType() == ConfigurationModuleType.CAR);
} catch (IllegalConfigurationException e) {
throw new DeploymentException(e);
}
@@ -618,8 +619,18 @@ public class DeploymentContext {
}
private static void addImport(LinkedHashSet<String> imports, String className) {
+ String packageName = getImportPackageName(className);
+ if (packageName == null || packageName.startsWith("java.")) {
+ return;
+ }
+ imports.add(packageName);
+ }
+
+ private static String getImportPackageName(String className) {
int pos = className.lastIndexOf('.');
- if (pos < 0 ) return;
+ if (pos < 0) {
+ return null;
+ }
int count = 0;
while (className.charAt(count) == '[') {
count++;
@@ -628,11 +639,9 @@ public class DeploymentContext {
count++;
}
className = className.substring(count, pos);
- if (className.startsWith("java.")) return;
- imports.add(className);
+ return className;
}
-
public void addAdditionalDeployment(ConfigurationData configurationData) {
additionalDeployment.add(configurationData);
}
Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java?rev=1062704&r1=1062703&r2=1062704&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/util/osgi/HighVersionFirstExportPackagesSelector.java Mon Jan 24 09:40:11 2011
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.Dependency;
import org.apache.geronimo.system.configuration.DependencyManager;
import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
@@ -44,7 +45,12 @@ public class HighVersionFirstExportPacka
Map<String, Version> packageNameVersionMap = new HashMap<String, Version>();
DependencyManager dependencyManager = context.getDependencyManager();
for (Dependency dependency : context.getEnvironment().getDependencies()) {
- Bundle dependentBundle = dependencyManager.getBundle(dependency.getArtifact());
+ Artifact resolvedArtifact = context.resolveArtifact(dependency.getArtifact());
+ if(resolvedArtifact == null) {
+ logger.warn("Dependency " + dependency.getArtifact() + " could not be resolved, its export packages are ignored");
+ continue;
+ }
+ Bundle dependentBundle = dependencyManager.getBundle(resolvedArtifact);
if (dependentBundle == null) {
logger.warn("Fail to resolve the bundle corresponding to the artifact " + dependency.getArtifact() + ", its export packages are ignored");
continue;
@@ -54,7 +60,7 @@ public class HighVersionFirstExportPacka
bundleIdExportPackages.put(dependentBundle.getBundleId(), exportPackages);
recordHighestPackageVersion(packageNameVersionMap, exportPackages);
}
- for (Long parentDependentBundleId : dependencyManager.getFullDependentBundleIds(dependentBundle)) {
+ for (Long parentDependentBundleId : context.getFullDependentBundleIds(dependentBundle)) {
if (!bundleIdExportPackages.containsKey(parentDependentBundleId)) {
Set<ExportPackage> parentExportPackages = context.getEffectExportPackages(parentDependentBundleId);
if (parentExportPackages.size() > 0) {
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=1062704&r1=1062703&r2=1062704&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 Mon Jan 24 09:40:11 2011
@@ -17,6 +17,7 @@
package org.apache.geronimo.deployment.util.osgi;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -24,15 +25,25 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.MissingDependencyException;
import org.apache.geronimo.system.configuration.DependencyManager;
+import org.apache.geronimo.system.plugin.model.DependencyType;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
+import org.osgi.framework.Bundle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
*/
public class OSGiBuildContext {
+ private static final Logger logger = LoggerFactory.getLogger(OSGiBuildContext.class);
+
private List<String> hiddenImportPackageNamePrefixes;
private Set<String> hiddenImportPackageNames;
@@ -43,6 +54,10 @@ public class OSGiBuildContext {
private boolean inverseClassLoading;
+ private boolean clientModule;
+
+ private ArtifactResolver clientArtifactResolver;
+
public OSGiBuildContext(Environment environment, List<String> hiddenImportPackageNamePrefixes, Set<String> hiddenImportPackageNames, DependencyManager dependencyManager,
boolean inverseClassLoading) {
this.hiddenImportPackageNamePrefixes = hiddenImportPackageNamePrefixes;
@@ -97,4 +112,75 @@ public class OSGiBuildContext {
}
return exportPackages;
}
+
+ public Artifact resolveArtifact(Artifact artifact) {
+ if (clientModule) {
+ try {
+ return clientArtifactResolver.resolveInClassLoader(artifact);
+ } catch (MissingDependencyException e) {
+ logger.warn("Fail to resovle artifact " + artifact + " with client artifact resolver", e);
+ return null;
+ }
+ }
+ return artifact;
+ }
+
+ public Set<Long> getFullDependentBundleIds(Bundle bundle) {
+ if (clientModule) {
+ return getFullClientDependentBundleIds(bundle.getBundleId());
+ }
+ return dependencyManager.getFullDependentBundleIds(bundle);
+ }
+
+ private Set<Long> getFullClientDependentBundleIds(long bundleId) {
+ Artifact artifact = dependencyManager.getArtifact(bundleId);
+ if (artifact == null) {
+ return Collections.emptySet();
+ }
+ Artifact resolvedDependentArtifact = resolveArtifact(artifact);
+ if (resolvedDependentArtifact == null) {
+ return Collections.emptySet();
+ }
+ Set<Long> dependentBundleIds = new HashSet<Long>();
+ searchFullClientDependentBundleIds(resolvedDependentArtifact, dependentBundleIds);
+ return dependentBundleIds;
+
+ }
+
+ private void searchFullClientDependentBundleIds(Artifact resolvedClientArtifact, Set<Long> dependentBundleIds) {
+ if (resolvedClientArtifact == null) {
+ return;
+ }
+ Bundle resolvedBundle = dependencyManager.getBundle(resolvedClientArtifact);
+ if (resolvedBundle == null || dependentBundleIds.contains(resolvedBundle.getBundleId())) {
+ return;
+ }
+ PluginArtifactType pluginArtifact = dependencyManager.getCachedPluginMetadata(resolvedBundle);
+ if (pluginArtifact != null) {
+ for (DependencyType dependency : pluginArtifact.getDependency()) {
+ Artifact resolvedDependentArtifact = resolveArtifact(dependency.toArtifact());
+ if (resolvedDependentArtifact == null) {
+ continue;
+ }
+ searchFullClientDependentBundleIds(resolvedDependentArtifact, dependentBundleIds);
+ }
+ }
+ dependentBundleIds.add(resolvedBundle.getBundleId());
+ }
+
+ public boolean isClientModule() {
+ return clientModule;
+ }
+
+ public void setClientModule(boolean clientModule) {
+ this.clientModule = clientModule;
+ }
+
+ public ArtifactResolver getClientArtifactResolver() {
+ return clientArtifactResolver;
+ }
+
+ public void setClientArtifactResolver(ArtifactResolver clientArtifactResolver) {
+ this.clientArtifactResolver = clientArtifactResolver;
+ }
}
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=1062704&r1=1062703&r2=1062704&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 Mon Jan 24 09:40:11 2011
@@ -24,6 +24,10 @@ import java.util.Map;
import java.util.Set;
import org.apache.geronimo.common.IllegalConfigurationException;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
import org.apache.geronimo.kernel.repository.Environment;
import org.apache.geronimo.system.configuration.DependencyManager;
import org.apache.xbean.osgi.bundle.util.BundleDescription.ExportPackage;
@@ -32,12 +36,16 @@ import org.apache.xbean.osgi.bundle.util
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @version $Rev$ $Date$
*/
public class OSGiMetaDataBuilder {
+ private static final Logger logger = LoggerFactory.getLogger(OSGiMetaDataBuilder.class);
+
private static final Version ZERO_VERSION = new Version(0, 0, 0);
private BundleContext bundleContext;
@@ -55,6 +63,10 @@ public class OSGiMetaDataBuilder {
}
public void build(Environment environment) throws IllegalConfigurationException {
+ build(environment, false);
+ }
+
+ public void build(Environment environment, boolean clientModule) throws IllegalConfigurationException {
processClassloadingRules(environment);
ServiceReference serviceReference = null;
try {
@@ -63,7 +75,7 @@ public class OSGiMetaDataBuilder {
if (serviceReference != null) {
dependencyManager = (DependencyManager) bundleContext.getService(serviceReference);
}
- OSGiBuildContext context = createOSGiBuildContext(environment, dependencyManager);
+ OSGiBuildContext context = createOSGiBuildContext(environment, dependencyManager, clientModule);
processImportPackages(context);
} finally {
if (serviceReference != null) {
@@ -83,7 +95,7 @@ public class OSGiMetaDataBuilder {
}*/
}
- protected OSGiBuildContext createOSGiBuildContext(Environment environment, DependencyManager dependencyManager) throws IllegalConfigurationException {
+ protected OSGiBuildContext createOSGiBuildContext(Environment environment, DependencyManager dependencyManager, boolean clientModule) throws IllegalConfigurationException {
List<String> hiddenImportPackageNamePrefixes = new ArrayList<String>();
Set<String> hiddenImportPackageNames = new HashSet<String>();
@@ -133,7 +145,13 @@ public class OSGiMetaDataBuilder {
}
environment.removeDynamicImportPackages(removedDynamicImportPackages);
- return new OSGiBuildContext(environment, hiddenImportPackageNamePrefixes, hiddenImportPackageNames, dependencyManager, environment.getClassLoadingRules().isInverseClassLoading());
+ OSGiBuildContext osgiBuildContext = new OSGiBuildContext(environment, hiddenImportPackageNamePrefixes, hiddenImportPackageNames, dependencyManager, environment.getClassLoadingRules()
+ .isInverseClassLoading());
+ osgiBuildContext.setClientModule(clientModule);
+ if (clientModule) {
+ osgiBuildContext.setClientArtifactResolver(getClientArtifactResolver());
+ }
+ return osgiBuildContext;
}
protected void processImportPackages(OSGiBuildContext context) {
@@ -159,4 +177,31 @@ public class OSGiMetaDataBuilder {
//TODO If mandatory attribute exists, do we need to handle it ?
return exportPackage.getVersion().equals(ZERO_VERSION) ? exportPackage.getName() : exportPackage.getName() + ";version=" + exportPackage.getVersion();
}
+
+ private ArtifactResolver getClientArtifactResolver() {
+ ServiceReference kernelReference = null;
+ try {
+ kernelReference = bundleContext.getServiceReference(Kernel.class.getName());
+ if (kernelReference == null) {
+ return null;
+ }
+ Kernel kernel = (Kernel) bundleContext.getService(kernelReference);
+ return (ArtifactResolver) kernel.getGBean("ClientArtifactResolver");
+ } catch (GBeanNotFoundException e) {
+ logger.warn("Fail to get client artifact resolver, OSGi metadata for client module might not generate correctly", e);
+ return null;
+ } catch (InternalKernelException e) {
+ logger.warn("Fail to get client artifact resolver, OSGi metadata for client module might not generate correctly", e);
+ return null;
+ } catch (IllegalStateException e) {
+ logger.warn("Fail to get client artifact resolver, OSGi metadata for client module might not generate correctly", e);
+ return null;
+ } finally {
+ if (kernelReference != null)
+ try {
+ bundleContext.ungetService(kernelReference);
+ } catch (Exception e) {
+ }
+ }
+ }
}
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=1062704&r1=1062703&r2=1062704&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 Mon Jan 24 09:40:11 2011
@@ -92,6 +92,7 @@ public class DependencyManager implement
private final Map<Artifact, Bundle> artifactBundleMap = new ConcurrentHashMap<Artifact, Bundle>();
+ private final Map<Long, Artifact> bundleIdArtifactMap = new ConcurrentHashMap<Long, Artifact>();
public DependencyManager(@ParamSpecial(type = SpecialAttributeType.bundleContext) BundleContext bundleContext,
@ParamReference(name = "Repositories", namingType = "Repository") Collection<Repository> repositories,
@@ -205,6 +206,10 @@ public class DependencyManager implement
return artifactBundleMap.get(artifact);
}
+ public Artifact getArtifact(long bundleId) {
+ return bundleIdArtifactMap.get(bundleId);
+ }
+
public Artifact toArtifact(String installationLocation) {
if (installationLocation == null) {
return null;
@@ -247,6 +252,7 @@ public class DependencyManager implement
Artifact artifact = toArtifact(bundle.getLocation());
if (artifact != null) {
artifactBundleMap.put(artifact, bundle);
+ bundleIdArtifactMap.put(bundle.getBundleId(), artifact);
} else {
if (log.isDebugEnabled()) {
log.debug("fail to resovle artifact from the bundle location " + bundle.getLocation());
@@ -258,6 +264,7 @@ public class DependencyManager implement
Artifact artifact = toArtifact(bundle.getLocation());
if (artifact != null) {
artifactBundleMap.remove(artifact);
+ bundleIdArtifactMap.remove(bundle.getBundleId());
}
}
@@ -342,7 +349,7 @@ public class DependencyManager implement
}
}
- private PluginArtifactType getCachedPluginMetadata(Bundle bundle) {
+ public PluginArtifactType getCachedPluginMetadata(Bundle bundle) {
PluginArtifactType pluginArtifactType = pluginMap.get(bundle.getBundleId());
if (pluginArtifactType == null) {
pluginArtifactType = getPluginMetadata(bundle);