Author: thomas.diesler(a)jboss.com
Date: 2010-03-26 06:50:26 -0400 (Fri, 26 Mar 2010)
New Revision: 103027
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/log4j.xml
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java
Log:
Add DynamicImport-Package support to OSGiManifestBuilder
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java 2010-03-26
10:24:57 UTC (rev 103026)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/DynamicImportPackageTestCase.java 2010-03-26
10:50:26 UTC (rev 103027)
@@ -52,7 +52,6 @@
{
bundle.start();
assertBundleState(Bundle.ACTIVE, bundle.getState());
-
assertLoadClass(bundle, LogService.class.getName());
}
finally
@@ -75,7 +74,6 @@
{
bundle.start();
assertBundleState(Bundle.ACTIVE, bundle.getState());
-
assertLoadClassFail(bundle, LogService.class.getName());
Bundle cmpd = installBundle("bundles/org.osgi.compendium.jar");
@@ -97,14 +95,14 @@
private JavaArchive getBundleArchive()
{
- JavaArchive archive = Archives.create("dynamic-log-service",
JavaArchive.class);
+ final JavaArchive archive = Archives.create("dynamic-log-service",
JavaArchive.class);
archive.setManifest(new Asset()
{
public InputStream openStream()
{
OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
builder.addBundleManifestVersion(2);
- builder.addBundleSymbolicName("dynamic-log-service");
+ builder.addBundleSymbolicName(archive.getName());
builder.addDynamicImportPackages("org.osgi.service.log");
return builder.openStream();
}
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/log4j.xml
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/log4j.xml 2010-03-26
10:24:57 UTC (rev 103026)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/log4j.xml 2010-03-26
10:50:26 UTC (rev 103027)
@@ -33,9 +33,12 @@
<!-- ================ -->
<!-- Show jboss deployer traces - ->
- <category name="org.jboss.deployer">
+ <category name="org.jboss.classloading">
<priority value="TRACE" />
</category>
+ <category name="org.jboss.classloader">
+ <priority value="TRACE" />
+ </category>
-->
<!-- ======================= -->
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2010-03-26
10:24:57 UTC (rev 103026)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/classloading/OSGiPackageRequirement.java 2010-03-26
10:50:26 UTC (rev 103027)
@@ -105,20 +105,26 @@
super(name, versionRange);
if (bundleState == null)
throw new IllegalArgumentException("Null bundleState");
- if (packageAttribute == null)
- throw new IllegalArgumentException("Null packageAttribute");
+
+ // TODO enable this check when BasicResolver does not abuse
+ // PackageRequirement for RequireBundle any more
+ //if (packageAttribute == null)
+ // throw new IllegalArgumentException("Null packageAttribute");
this.bundleState = bundleState;
this.packageAttribute = packageAttribute;
- // resolution:=optional
- String resolution =
packageAttribute.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
- if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
- setOptional(true);
+ if (packageAttribute != null)
+ {
+ // resolution:=optional
+ String resolution =
packageAttribute.getDirectiveValue(Constants.RESOLUTION_DIRECTIVE, String.class);
+ if (Constants.RESOLUTION_OPTIONAL.equals(resolution))
+ setOptional(true);
- // DynamicImport-Package
- if (isDynamic == true)
- setDynamic(true);
+ // DynamicImport-Package
+ if (isDynamic == true)
+ setDynamic(true);
+ }
}
/**
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java
===================================================================
---
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java 2010-03-26
10:24:57 UTC (rev 103026)
+++
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiManifestBuilder.java 2010-03-26
10:50:26 UTC (rev 103027)
@@ -47,6 +47,7 @@
private PrintWriter pw;
private List<String> importPackages = new ArrayList<String>();
private List<String> exportPackages = new ArrayList<String>();
+ private List<String> dynamicImportPackages = new ArrayList<String>();
public static OSGiManifestBuilder newInstance()
{
@@ -86,6 +87,14 @@
return this;
}
+ public OSGiManifestBuilder addDynamicImportPackages(String... packages)
+ {
+ for (String aux : packages)
+ dynamicImportPackages.add(aux);
+
+ return this;
+ }
+
public OSGiManifestBuilder addExportPackages(String... packages)
{
for (String aux : packages)
@@ -102,6 +111,7 @@
public Manifest getManifest()
{
+ // Export-Package
if (exportPackages.size() > 0)
{
pw.print(Constants.EXPORT_PACKAGE + ": ");
@@ -115,6 +125,7 @@
pw.println();
}
+ // Import-Package
if (importPackages.size() > 0)
{
pw.print(Constants.IMPORT_PACKAGE + ": ");
@@ -128,6 +139,20 @@
pw.println();
}
+ // DynamicImport-Package
+ if (dynamicImportPackages.size() > 0)
+ {
+ pw.print(Constants.DYNAMICIMPORT_PACKAGE + ": ");
+ for (int i = 0; i < dynamicImportPackages.size(); i++)
+ {
+ if (i > 0)
+ pw.print(",");
+
+ pw.print(dynamicImportPackages.get(i));
+ }
+ pw.println();
+ }
+
try
{
Manifest manifest = new Manifest(new
ByteArrayInputStream(sw.toString().getBytes()));