Modified aspects of the core framework that were impacted by the switch
to the capability/requirement model. (FELIX-28)
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@498553 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java b/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
index 07d0cab..3d92ecc 100644
--- a/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ExportedPackageImpl.java
@@ -18,7 +18,7 @@
*/
package org.apache.felix.framework;
-import org.apache.felix.framework.util.manifestparser.R4Export;
+import org.apache.felix.framework.util.manifestparser.Capability;
import org.apache.felix.moduleloader.IModule;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
@@ -29,12 +29,12 @@
private Felix m_felix = null;
private BundleImpl m_exportingBundle = null;
private IModule m_exportingModule = null;
- private R4Export m_export = null;
+ private Capability m_export = null;
private String m_toString = null;
private String m_versionString = null;
public ExportedPackageImpl(
- Felix felix, BundleImpl exporter, IModule module, R4Export export)
+ Felix felix, BundleImpl exporter, IModule module, Capability export)
{
m_felix = felix;
m_exportingBundle = exporter;
@@ -64,25 +64,25 @@
public String getName()
{
- return m_export.getName();
+ return m_export.getPackageName();
}
public String getSpecificationVersion()
{
if (m_versionString == null)
{
- m_versionString = (m_export.getVersion() == null)
+ m_versionString = (m_export.getPackageVersion() == null)
? Version.emptyVersion.toString()
- : m_export.getVersion().toString();
+ : m_export.getPackageVersion().toString();
}
return m_versionString;
}
public Version getVersion()
{
- return (m_export.getVersion() == null)
+ return (m_export.getPackageVersion() == null)
? Version.emptyVersion
- : m_export.getVersion();
+ : m_export.getPackageVersion();
}
public boolean isRemovalPending()
@@ -94,7 +94,7 @@
{
if (m_toString == null)
{
- m_toString = m_export.getName()
+ m_toString = m_export.getPackageName()
+ "; version=" + getSpecificationVersion();
}
return m_toString;
diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java b/framework/src/main/java/org/apache/felix/framework/Felix.java
index 24aaab2..853d7f7 100644
--- a/framework/src/main/java/org/apache/felix/framework/Felix.java
+++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
@@ -387,7 +387,7 @@
// This should never happen.
throw new BundleException(
"Unresolved package in System Bundle:"
- + ex.getPackage());
+ + ex.getRequirement());
}
// Start the system bundle; this will set its state
@@ -456,6 +456,7 @@
{
// TODO: RB - Should this be system bundle, since bundle could be null?
// fireFrameworkEvent(FrameworkEvent.ERROR, systembundle, ex);
+ex.printStackTrace();
fireFrameworkEvent(FrameworkEvent.ERROR, bundle, ex);
try
{
@@ -1347,39 +1348,50 @@
// to import the necessary packages.
if (System.getSecurityManager() != null)
{
-
ProtectionDomain pd = (ProtectionDomain)
bundle.getInfo().getCurrentModule().getSecurityContext();
- R4Import[] imports =
- bundle.getInfo().getCurrentModule().getDefinition().getImports();
+ IRequirement[] imports =
+ bundle.getInfo().getCurrentModule().getDefinition().getRequirements();
- for (int i = 0;i < imports.length; i++)
+/*
+ TODO: RB - We need to fix this import check by looking at the wire
+ associated with it, not the import since we don't know the
+ package name associated with the import since it is a filter.
+
+ for (int i = 0; i < imports.length; i++)
{
- PackagePermission perm = new PackagePermission(imports[i].getName(),
- PackagePermission.IMPORT);
-
- if (!pd.implies(perm))
+ if (imports[i].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
{
- throw new java.security.AccessControlException(
- "PackagePermission.IMPORT denied for import: " +
- imports[i].getName(), perm);
+ PackagePermission perm = new PackagePermission(
+ imports[i].???,
+ PackagePermission.IMPORT);
+
+ if (!pd.implies(perm))
+ {
+ throw new java.security.AccessControlException(
+ "PackagePermission.IMPORT denied for import: " +
+ imports[i].getName(), perm);
+ }
}
}
+*/
// Check export permission for all exports of the current module.
- R4Export[] implicitImports =
- bundle.getInfo().getCurrentModule().getDefinition().getExports();
-
- for (int i = 0;i < implicitImports.length; i++)
+ ICapability[] exports =
+ bundle.getInfo().getCurrentModule().getDefinition().getCapabilities();
+ for (int i = 0; i < exports.length; i++)
{
- PackagePermission perm = new PackagePermission(
- implicitImports[i].getName(), PackagePermission.EXPORT);
-
- if (!pd.implies(perm))
+ if (exports[i].getNamespace().equals(ICapability.PACKAGE_NAMESPACE))
{
- throw new java.security.AccessControlException(
- "PackagePermission.EXPORT denied for implicit export: " +
- implicitImports[i].getName(), perm);
+ PackagePermission perm = new PackagePermission(
+ (String) exports[i].getProperties().get(ICapability.PACKAGE_PROPERTY), PackagePermission.EXPORT);
+
+ if (!pd.implies(perm))
+ {
+ throw new java.security.AccessControlException(
+ "PackagePermission.EXPORT denied for export: " +
+ exports[i].getProperties().get(ICapability.PACKAGE_PROPERTY), perm);
+ }
}
}
}
@@ -1396,7 +1408,7 @@
throw new BundleException(
"Unresolved package in bundle "
+ Util.getBundleIdFromModuleId(ex.getModule().getId())
- + ": " + ex.getPackage());
+ + ": " + ex.getRequirement());
}
else
{
@@ -2311,14 +2323,23 @@
* package name. This is used by the PackageAdmin service
* implementation.
*
- * @param name The name of the exported package to find.
+ * @param pkgName The name of the exported package to find.
* @return The exported package or null if no matching package was found.
**/
- protected ExportedPackage[] getExportedPackages(String name)
+ protected ExportedPackage[] getExportedPackages(String pkgName)
{
- // First, get all exporters of the package.
ExportedPackage[] pkgs = null;
- IModule[] exporters = m_policyCore.getInUseExporters(new R4Import(name, null, null), true);
+
+ // First, get all exporters of the package.
+ R4SearchPolicyCore.ResolverCandidate[] exporters =
+ m_policyCore.getInUseCandidates(
+ new Requirement(
+ ICapability.PACKAGE_NAMESPACE,
+ null,
+ null,
+ new R4Attribute[] { new R4Attribute(ICapability.PACKAGE_PROPERTY, pkgName, false) }),
+ true);
+
if (exporters != null)
{
pkgs = new ExportedPackage[exporters.length];
@@ -2326,7 +2347,7 @@
{
// Get the bundle associated with the current exporting module.
BundleImpl bundle = (BundleImpl) getBundle(
- Util.getBundleIdFromModuleId(exporters[pkgIdx].getId()));
+ Util.getBundleIdFromModuleId(exporters[pkgIdx].m_module.getId()));
// We need to find the version of the exported package, but this
// is tricky since there may be multiple versions of the package
@@ -2341,12 +2362,19 @@
IModule[] modules = bundle.getInfo().getModules();
for (int modIdx = 0; modIdx < modules.length; modIdx++)
{
- R4Export export = Util.getExportPackage(modules[modIdx], name);
- if (export != null)
+ Capability ec = (Capability)
+ Util.getSatisfyingCapability(
+ modules[modIdx],
+ new Requirement(
+ ICapability.PACKAGE_NAMESPACE,
+ null,
+ null,
+ new R4Attribute[] { new R4Attribute(ICapability.PACKAGE_PROPERTY, pkgName, false) }));
+
+ if (ec != null)
{
pkgs[pkgIdx] =
- new ExportedPackageImpl(
- this, bundle, modules[modIdx], export);
+ new ExportedPackageImpl(this, bundle, modules[modIdx], ec);
}
}
}
@@ -2425,24 +2453,29 @@
IModule[] modules = bundle.getInfo().getModules();
for (int modIdx = 0; modIdx < modules.length; modIdx++)
{
- R4Export[] exports = modules[modIdx].getDefinition().getExports();
- if ((exports != null) && (exports.length > 0))
+ ICapability[] caps = modules[modIdx].getDefinition().getCapabilities();
+ if ((caps != null) && (caps.length > 0))
{
- for (int expIdx = 0; expIdx < exports.length; expIdx++)
+ for (int capIdx = 0; capIdx < caps.length; capIdx++)
{
// See if the target bundle's module is one of the
// "in use" exporters of the package.
- IModule[] inUseModules =
- m_policyCore.getInUseExporters(
- new R4Import(exports[expIdx].getName(), null, null), true);
+ R4SearchPolicyCore.ResolverCandidate[] inUseModules = m_policyCore.getInUseCandidates(
+ new Requirement(
+ ICapability.PACKAGE_NAMESPACE,
+ null,
+ null,
+ new R4Attribute[] { new R4Attribute(ICapability.PACKAGE_PROPERTY, ((Capability) caps[capIdx]).getPackageName(), false) }),
+ true);
+
// Search through the current providers to find the target
// module.
for (int i = 0; (inUseModules != null) && (i < inUseModules.length); i++)
{
- if (inUseModules[i] == modules[modIdx])
+ if (inUseModules[i].m_module == modules[modIdx])
{
list.add(new ExportedPackageImpl(
- this, bundle, modules[modIdx], exports[expIdx]));
+ this, bundle, modules[modIdx], (Capability) caps[capIdx]));
}
}
}
@@ -2505,6 +2538,7 @@
// If there are targets, then resolve each one.
if (bundles != null)
{
+long time = System.currentTimeMillis();
for (int i = 0; i < bundles.length; i++)
{
try
@@ -2520,6 +2554,8 @@
ex);
}
}
+time = System.currentTimeMillis() - time;
+System.out.println("!!! ELAPSED RESOLVE TIME : " + time);
}
return result;
@@ -2692,9 +2728,9 @@
// Create the module definition for the new module.
IModuleDefinition md = new ModuleDefinition(
- mp.getExports(),
- mp.getImports(),
- mp.getDynamicImports(),
+ mp.getCapabilities(),
+ mp.getRequirements(),
+ mp.getDynamicRequirements(),
mp.getLibraries(m_cache.getArchive(targetId).getRevision(revision)));
// Create the module using the module definition.
diff --git a/framework/src/main/java/org/apache/felix/framework/SystemBundle.java b/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
index 7868fe5..a8fc45e 100644
--- a/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
+++ b/framework/src/main/java/org/apache/felix/framework/SystemBundle.java
@@ -24,8 +24,9 @@
import org.apache.felix.framework.cache.SystemBundleArchive;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.StringMap;
+import org.apache.felix.framework.util.manifestparser.Capability;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
-import org.apache.felix.framework.util.manifestparser.R4Export;
+import org.apache.felix.moduleloader.ICapability;
import org.apache.felix.moduleloader.IContentLoader;
import org.osgi.framework.*;
@@ -34,7 +35,7 @@
private List m_activatorList = null;
private BundleActivator m_activator = null;
private Thread m_shutdownThread = null;
- private R4Export[] m_exports = null;
+ private ICapability[] m_exports = null;
private IContentLoader m_contentLoader = null;
protected SystemBundle(Felix felix, BundleInfo info, List activatorList)
@@ -64,31 +65,20 @@
// Get system property that specifies which class path
// packages should be exported by the system bundle.
- R4Export[] classPathPkgs = null;
try
{
- classPathPkgs = (R4Export[]) ManifestParser.parseImportExportHeader(
- getFelix().getConfig().get(Constants.FRAMEWORK_SYSTEMPACKAGES), true);
+ m_exports = (ICapability[]) ManifestParser.parseExportHeader(
+ getFelix().getConfig().get(Constants.FRAMEWORK_SYSTEMPACKAGES));
}
catch (Exception ex)
{
- classPathPkgs = new R4Export[0];
+ m_exports = new ICapability[0];
getFelix().getLogger().log(
Logger.LOG_ERROR,
"Error parsing system bundle export statement: "
+ getFelix().getConfig().get(Constants.FRAMEWORK_SYSTEMPACKAGES), ex);
}
- // Now, create the list of standard framework exports for
- // the system bundle.
- m_exports = new R4Export[classPathPkgs.length];
-
- // Copy the class path exported packages.
- for (int i = 0; i < classPathPkgs.length; i++)
- {
- m_exports[i] = classPathPkgs[i];
- }
-
m_contentLoader = new SystemBundleContentLoader(getFelix().getLogger());
StringBuffer exportSB = new StringBuffer("");
@@ -99,9 +89,9 @@
exportSB.append(", ");
}
- exportSB.append(m_exports[i].getName());
+ exportSB.append(((Capability) m_exports[i]).getPackageName());
exportSB.append("; version=\"");
- exportSB.append(m_exports[i].getVersion().toString());
+ exportSB.append(((Capability) m_exports[i]).getPackageVersion().toString());
exportSB.append("\"");
}
@@ -123,7 +113,7 @@
// that will allow for them to be independently configured.
}
- public R4Export[] getExports()
+ public ICapability[] getExports()
{
return m_exports;
}