You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/07/03 11:09:19 UTC
svn commit: r418715 -
/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Author: rickhall
Date: Mon Jul 3 02:09:18 2006
New Revision: 418715
URL: http://svn.apache.org/viewvc?rev=418715&view=rev
Log:
Reorganized/improved R3 manifest header conversion to R4 metadata. Fixed
a bug that was allowing duplicate import declarations when an R3 bundle
had both an import and export header for a given package.
Modified:
incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=418715&r1=418714&r2=418715&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java Mon Jul 3 02:09:18 2006
@@ -2953,8 +2953,30 @@
// Create map to check for duplicate imports/exports.
Map dupeMap = new HashMap();
- // Get import packages from bundle manifest.
+ // Get export packages from bundle manifest.
R4Package[] pkgs = R4Package.parseImportOrExportHeader(
+ (String) headerMap.get(Constants.EXPORT_PACKAGE));
+
+ // Create non-duplicated export array.
+ dupeMap.clear();
+ for (int i = 0; i < pkgs.length; i++)
+ {
+ if (dupeMap.get(pkgs[i].getName()) == null)
+ {
+ dupeMap.put(pkgs[i].getName(), new R4Export(pkgs[i]));
+ }
+ else
+ {
+ // TODO: FRAMEWORK - Exports can be duplicated, so fix this.
+ m_logger.log(Logger.LOG_WARNING,
+ "Duplicate export - " + pkgs[i].getName());
+ }
+ }
+ R4Export[] exports =
+ (R4Export[]) dupeMap.values().toArray(new R4Export[dupeMap.size()]);
+
+ // Get import packages from bundle manifest.
+ pkgs = R4Package.parseImportOrExportHeader(
(String) headerMap.get(Constants.IMPORT_PACKAGE));
// Create non-duplicated import array.
@@ -2975,60 +2997,34 @@
R4Import[] imports =
(R4Import[]) dupeMap.values().toArray(new R4Import[dupeMap.size()]);
- // Check to make sure that R3 bundles have only specified
- // the 'specification-version' attribute and no directives.
- if (version.equals("1"))
- {
- for (int i = 0; (imports != null) && (i < imports.length); i++)
- {
- if (imports[i].getDirectives().length != 0)
- {
- throw new BundleException("R3 imports cannot contain directives.");
- }
- // NOTE: This is checking for "version" rather than "specification-version"
- // because the package class normalizes to "version" to avoid having
- // future special cases. This could be changed if more strict behavior
- // is required.
- if ((imports[i].getVersionHigh() != null) ||
- (imports[i].getAttributes().length > 1) ||
- ((imports[i].getAttributes().length == 1) &&
- (!imports[i].getAttributes()[0].getName().equals(FelixConstants.VERSION_ATTRIBUTE))))
- {
- throw new BundleException(
- "Import does not conform to R3 syntax: " + imports[i]);
- }
- }
- }
-
- // Get export packages from bundle manifest.
+ // Get dynamic import packages from bundle manifest.
pkgs = R4Package.parseImportOrExportHeader(
- (String) headerMap.get(Constants.EXPORT_PACKAGE));
+ (String) headerMap.get(Constants.DYNAMICIMPORT_PACKAGE));
- // Create non-duplicated export array.
+ // Create non-duplicated dynamic import array.
dupeMap.clear();
for (int i = 0; i < pkgs.length; i++)
{
if (dupeMap.get(pkgs[i].getName()) == null)
{
- dupeMap.put(pkgs[i].getName(), new R4Export(pkgs[i]));
+ dupeMap.put(pkgs[i].getName(), new R4Import(pkgs[i]));
}
else
{
- // TODO: FRAMEWORK - Exports can be duplicated, so fix this.
+ // TODO: FRAMEWORK - Determine if we should error here.
m_logger.log(Logger.LOG_WARNING,
- "Duplicate export - " + pkgs[i].getName());
+ "Duplicate import - " + pkgs[i].getName());
}
}
- R4Export[] exports =
- (R4Export[]) dupeMap.values().toArray(new R4Export[dupeMap.size()]);
-
+ R4Import[] dynamics =
+ (R4Import[]) dupeMap.values().toArray(new R4Import[dupeMap.size()]);
- // Check to make sure that R3 bundles have only specified
- // the 'specification-version' attribute and no directives.
- // In addition, all R3 exports imply imports, so add a
- // corresponding import for each export.
+ // Do validity checking and conversion on bundles with R3 headers.
if (version.equals("1"))
{
+ // Check to make sure that R3 bundles have only specified
+ // the 'specification-version' attribute and no directives
+ // on their exports.
for (int i = 0; (exports != null) && (i < exports.length); i++)
{
if (exports[i].getDirectives().length != 0)
@@ -3048,22 +3044,53 @@
}
}
- R4Import[] newImports = new R4Import[imports.length + exports.length];
- System.arraycopy(imports, 0, newImports, 0, imports.length);
+ // Check to make sure that R3 bundles have only specified
+ // the 'specification-version' attribute and no directives
+ // on their imports.
+ for (int i = 0; (imports != null) && (i < imports.length); i++)
+ {
+ if (imports[i].getDirectives().length != 0)
+ {
+ throw new BundleException("R3 imports cannot contain directives.");
+ }
+ // NOTE: This is checking for "version" rather than "specification-version"
+ // because the package class normalizes to "version" to avoid having
+ // future special cases. This could be changed if more strict behavior
+ // is required.
+ if ((imports[i].getVersionHigh() != null) ||
+ (imports[i].getAttributes().length > 1) ||
+ ((imports[i].getAttributes().length == 1) &&
+ (!imports[i].getAttributes()[0].getName().equals(FelixConstants.VERSION_ATTRIBUTE))))
+ {
+ throw new BundleException(
+ "Import does not conform to R3 syntax: " + imports[i]);
+ }
+ }
+
+ // Since all R3 exports imply an import, add a corresponding
+ // import for each existing export. Create non-duplicated import array.
+ dupeMap.clear();
+ // Add existing imports.
+ for (int i = 0; i < imports.length; i++)
+ {
+ dupeMap.put(imports[i].getName(), imports[i]);
+ }
+ // Add import for each export.
for (int i = 0; i < exports.length; i++)
{
- newImports[i + imports.length] = new R4Import(exports[i]);
+ if (dupeMap.get(exports[i].getName()) == null)
+ {
+ dupeMap.put(exports[i].getName(), new R4Import(exports[i]));
+ }
}
- imports = newImports;
- }
+ imports =
+ (R4Import[]) dupeMap.values().toArray(new R4Import[dupeMap.size()]);
- // For R3 bundles, add a "uses" directive onto each export
- // that references every other import (which will include
- // exports, since export implies import); this is
- // necessary since R3 bundles assumed a single class space,
- // but R4 allows for multiple class spaces.
- if (version.equals("1"))
- {
+ // Add a "uses" directive onto each export of R3 bundles
+ // that references every other import (which will include
+ // exports, since export implies import); this is
+ // necessary since R3 bundles assumed a single class space,
+ // but R4 allows for multiple class spaces.
String usesValue = "";
for (int i = 0; (imports != null) && (i < imports.length); i++)
{
@@ -3080,43 +3107,21 @@
new R4Directive[] { uses },
exports[i].getAttributes());
}
- }
-
- // Get dynamic import packages from bundle manifest.
- pkgs = R4Package.parseImportOrExportHeader(
- (String) headerMap.get(Constants.DYNAMICIMPORT_PACKAGE));
-
- // Create non-duplicated dynamic import array.
- dupeMap.clear();
- for (int i = 0; i < pkgs.length; i++)
- {
- if (dupeMap.get(pkgs[i].getName()) == null)
- {
- dupeMap.put(pkgs[i].getName(), new R4Import(pkgs[i]));
- }
- else
- {
- // TODO: FRAMEWORK - Determine if we should error here.
- m_logger.log(Logger.LOG_WARNING,
- "Duplicate import - " + pkgs[i].getName());
- }
- }
- R4Import[] dynamics =
- (R4Import[]) dupeMap.values().toArray(new R4Import[dupeMap.size()]);
- // Check to make sure that R3 bundles have no attributes or
- // directives.
- if (version.equals("1"))
- {
- for (int i = 0; (dynamics != null) && (i < dynamics.length); i++)
- {
- if (dynamics[i].getDirectives().length != 0)
- {
- throw new BundleException("R3 dynamic imports cannot contain directives.");
- }
- if (dynamics[i].getAttributes().length != 0)
- {
- throw new BundleException("R3 dynamic imports cannot contain attributes.");
+ // Check to make sure that R3 bundles have no attributes or
+ // directives on their dynamic imports.
+ if (version.equals("1"))
+ {
+ for (int i = 0; (dynamics != null) && (i < dynamics.length); i++)
+ {
+ if (dynamics[i].getDirectives().length != 0)
+ {
+ throw new BundleException("R3 dynamic imports cannot contain directives.");
+ }
+ if (dynamics[i].getAttributes().length != 0)
+ {
+ throw new BundleException("R3 dynamic imports cannot contain attributes.");
+ }
}
}
}