diff options
32 files changed, 629 insertions, 73 deletions
diff --git a/bundles/org.eclipse.osgi.tests/.classpath b/bundles/org.eclipse.osgi.tests/.classpath index d1f170448..57d389db3 100644 --- a/bundles/org.eclipse.osgi.tests/.classpath +++ b/bundles/org.eclipse.osgi.tests/.classpath @@ -33,6 +33,13 @@ <classpathentry kind="src" output="bundle_tests/nativetest.b2" path="bundles_src/nativetest.b2"/> <classpathentry kind="src" output="bundle_tests/nativetest.c" path="bundles_src/nativetest.c"/> <classpathentry kind="src" output="bundle_tests/nativetest.d" path="bundles_src/nativetest.d"/> + <classpathentry kind="src" output="bundle_tests/host.multiple.exports" path="bundles_src/host.multiple.exports"/> + <classpathentry kind="src" output="bundle_tests/frag.multiple.exports" path="bundles_src/frag.multiple.exports"/> + <classpathentry kind="src" output="bundle_tests/client1.multiple.exports" path="bundles_src/client1.multiple.exports"/> + <classpathentry kind="src" output="bundle_tests/client2.multiple.exports" path="bundles_src/client2.multiple.exports"/> + <classpathentry kind="src" output="bundle_tests/xfriends.test1" path="bundles_src/xfriends.test1"/> + <classpathentry kind="src" output="bundle_tests/xfriends.test2" path="bundles_src/xfriends.test2"/> + <classpathentry kind="src" output="bundle_tests/xfriends.test3" path="bundles_src/xfriends.test3"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="output" path="bin"/> diff --git a/bundles/org.eclipse.osgi.tests/build.properties b/bundles/org.eclipse.osgi.tests/build.properties index 9d9a553e2..3378c02de 100644 --- a/bundles/org.eclipse.osgi.tests/build.properties +++ b/bundles/org.eclipse.osgi.tests/build.properties @@ -80,6 +80,20 @@ source.bundle_tests/nativetest.c.jar = bundles_src/nativetest.c/ manifest.bundle_tests/nativetest.c.jar = META-INF/MANIFEST.MF source.bundle_tests/nativetest.d.jar = bundles_src/nativetest.d/ manifest.bundle_tests/nativetest.d.jar = META-INF/MANIFEST.MF +source.bundle_tests/host.multiple.exports.jar = bundles_src/host.multiple.exports/ +manifest.bundle_tests/host.multiple.exports.jar = META-INF/MANIFEST.MF +source.bundle_tests/frag.multiple.exports.jar = bundles_src/frag.multiple.exports/ +manifest.bundle_tests/frag.multiple.exports.jar = META-INF/MANIFEST.MF +source.bundle_tests/client1.multiple.exports.jar =bundles_src/client1.multiple.exports/ +manifest.bundle_tests/client1.multiple.exports.jar = META-INF/MANIFEST.MF +source.bundle_tests/client2.multiple.exports.jar = bundles_src/client2.multiple.exports/ +manifest.bundle_tests/client2.multiple.exports.jar = META-INF/MANIFEST.MF +source.bundle_tests/xfriends.test1.jar = bundles_src/xfriends.test1/ +manifest.bundle_tests/xfriends.test1.jar = META-INF/MANIFEST.MF +source.bundle_tests/xfriends.test2.jar = bundles_src/xfriends.test2/ +manifest.bundle_tests/xfriends.test2.jar = META-INF/MANIFEST.MF +source.bundle_tests/xfriends.test3.jar = bundles_src/xfriends.test3/ +manifest.bundle_tests/xfriends.test3.jar = META-INF/MANIFEST.MF jars.compile.order = osgitests.jar,\ bundle_tests/test.jar,\ @@ -113,4 +127,11 @@ jars.compile.order = osgitests.jar,\ bundle_tests/nativetest.b1.jar,\ bundle_tests/nativetest.b2.jar,\ bundle_tests/nativetest.c.jar,\ - bundle_tests/nativetest.d.jar + bundle_tests/nativetest.d.jar,\ + bundle_tests/host.multiple.exports.jar,\ + bundle_tests/frag.multiple.exports.jar,\ + bundle_tests/client1.multiple.exports.jar,\ + bundle_tests/client2.multiple.exports.jar,\ + bundle_tests/xfriends.test1.jar,\ + bundle_tests/xfriends.test2.jar,\ + bundle_tests/xfriends.test3.jar diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/META-INF/MANIFEST.MF new file mode 100644 index 000000000..72374db72 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: client1.multiple.exports +Bundle-SymbolicName: client1.multiple.exports +Bundle-Version: 1.0.0 +Bundle-Activator: client1.multiple.exports.Activator +Import-Package: host.multiple.exports, + host.multiple.exports.onlyone, + org.eclipse.osgi.tests.bundles, + org.osgi.framework diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/client1/multiple/exports/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/client1/multiple/exports/Activator.java new file mode 100644 index 000000000..ff63534b5 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/client1.multiple.exports/client1/multiple/exports/Activator.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package client1.multiple.exports; + +import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PublicClass1").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PublicClass2").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PrivateClass1").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent("success"); //$NON-NLS-1$ + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PrivateClass2").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent("success"); //$NON-NLS-1$ + } + } + + public void stop(BundleContext context) throws Exception { + // nothing + } + +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/META-INF/MANIFEST.MF new file mode 100644 index 000000000..0bf4b9731 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: client2.multiple.exports +Bundle-SymbolicName: client2.multiple.exports +Bundle-Version: 1.0.0 +Bundle-Activator: client2.multiple.exports.Activator +Import-Package: host.multiple.exports; scope="private", + host.multiple.exports.onlyone, + org.eclipse.osgi.tests.bundles, + org.osgi.framework diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/client2/multiple/exports/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/client2/multiple/exports/Activator.java new file mode 100644 index 000000000..35db4f485 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/client2.multiple.exports/client2/multiple/exports/Activator.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package client2.multiple.exports; + +import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PublicClass1").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PublicClass2").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PrivateClass1").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("host.multiple.exports.PrivateClass2").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + } + + public void stop(BundleContext context) throws Exception { + // nothing + } + +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/META-INF/MANIFEST.MF new file mode 100644 index 000000000..cab82b92a --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: frag.multiple.exports +Bundle-SymbolicName: frag.multiple.exports +Bundle-Version: 1.0.0 +Fragment-Host: host.multiple.exports +Export-Package: host.multiple.exports; mandatory:="scope"; scope="private", + host.multiple.exports.onlyone; + version=1.0.0; + include:="Public*"; + exclude:="PublicExclude*"; + uses:="host.multiple.exports"; + mantatory:="test1"; + test1=value; + test2=value diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass1.java b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass1.java new file mode 100644 index 000000000..8011da731 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass1.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package host.multiple.exports; + +public class PrivateClass1 { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass2.java b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass2.java new file mode 100644 index 000000000..286d0e09d --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/frag.multiple.exports/host/multiple/exports/PrivateClass2.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package host.multiple.exports; + +public class PrivateClass2 { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/META-INF/MANIFEST.MF new file mode 100644 index 000000000..47670f82d --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: host.multiple.exports +Bundle-SymbolicName: host.multiple.exports +Bundle-Version: 1.0.0 +Export-Package: host.multiple.exports; include:="Public*", + host.multiple.exports.onlyone; + version=1.0.0; + include:="Public*"; + exclude:="PublicExclude*"; + uses:="host.multiple.exports"; + mantatory:="test1"; + test1=value; + test2=value diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass1.java b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass1.java new file mode 100644 index 000000000..e701713a9 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass1.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package host.multiple.exports; + +public class PublicClass1 { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass2.java b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass2.java new file mode 100644 index 000000000..7776307ca --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/PublicClass2.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package host.multiple.exports; + +public class PublicClass2 { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/onlyone/PublicClass1.java b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/onlyone/PublicClass1.java new file mode 100644 index 000000000..f7df0823b --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/host.multiple.exports/host/multiple/exports/onlyone/PublicClass1.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package host.multiple.exports.onlyone; + +public class PublicClass1 { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/META-INF/MANIFEST.MF new file mode 100644 index 000000000..f0d27c1b4 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/META-INF/MANIFEST.MF @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: xfriends.test1 +Bundle-SymbolicName: xfriends.test1 +Bundle-Version: 1.0.0 +Export-Package: xfriends.test1.onlyforfriends; x-friends:="xfriends.test2", + xfriends.test1.external diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/external/TestFriends.java b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/external/TestFriends.java new file mode 100644 index 000000000..31a14fd4c --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/external/TestFriends.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package xfriends.test1.external; + +public class TestFriends { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/onlyforfriends/TestFriends.java b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/onlyforfriends/TestFriends.java new file mode 100644 index 000000000..a7452bb80 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test1/xfriends/test1/onlyforfriends/TestFriends.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package xfriends.test1.onlyforfriends; + +public class TestFriends { + // nothing +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/META-INF/MANIFEST.MF new file mode 100644 index 000000000..a87ad5480 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: xfriends.test2 +Bundle-SymbolicName: xfriends.test2 +Bundle-Version: 1.0.0 +Bundle-Activator: xfriends.test2.Activator +Require-Bundle: xfriends.test1 +Import-Package: org.osgi.framework, + org.eclipse.osgi.tests.bundles diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/xfriends/test2/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/xfriends/test2/Activator.java new file mode 100644 index 000000000..83649c148 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test2/xfriends/test2/Activator.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package xfriends.test2; + +import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("xfriends.test1.onlyforfriends.TestFriends").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("xfriends.test1.external.TestFriends").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + } + + public void stop(BundleContext context) throws Exception { + // nothing + } + +} diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/META-INF/MANIFEST.MF new file mode 100644 index 000000000..5f0aca53e --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/META-INF/MANIFEST.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: xfriends.test3 +Bundle-SymbolicName: xfriends.test3 +Bundle-Version: 1.0.0 +Bundle-Activator: xfriends.test3.Activator +Require-Bundle: xfriends.test1 +Import-Package: org.osgi.framework, + org.eclipse.osgi.tests.bundles diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/xfriends/test3/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/xfriends/test3/Activator.java new file mode 100644 index 000000000..b03d45285 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/bundles_src/xfriends.test3/xfriends/test3/Activator.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package xfriends.test3; + +import org.eclipse.osgi.tests.bundles.AbstractBundleTests; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator { + + public void start(BundleContext context) throws Exception { + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("xfriends.test1.onlyforfriends.TestFriends").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent("success"); //$NON-NLS-1$ + } + try { + AbstractBundleTests.simpleResults.addEvent(Class.forName("xfriends.test1.external.TestFriends").getName()); //$NON-NLS-1$ + } catch (Throwable t) { + AbstractBundleTests.simpleResults.addEvent(t); + } + } + + public void stop(BundleContext context) throws Exception { + // nothing + } + +} diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java index 980301691..e55aba3b7 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/AbstractBundleTests.java @@ -10,7 +10,8 @@ *******************************************************************************/ package org.eclipse.osgi.tests.bundles; -import junit.framework.*; +import junit.framework.TestCase; +import org.eclipse.osgi.internal.baseadaptor.StateManager; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.BundleEvent; import org.osgi.framework.FrameworkEvent; @@ -37,7 +38,6 @@ public class AbstractBundleTests extends TestCase { frameworkListenerResults = new EventListenerTestResults(); OSGiTestsActivator.getContext().addFrameworkListener(frameworkListenerResults); } - protected void tearDown() throws Exception { installer.shutdown(); @@ -68,7 +68,6 @@ public class AbstractBundleTests extends TestCase { failNotEquals(message, toString(expected), toString(actual)); } - private static boolean isEqual(Object expected, Object actual) { if (!expected.getClass().isAssignableFrom(actual.getClass())) return false; @@ -101,7 +100,7 @@ public class AbstractBundleTests extends TestCase { case FrameworkEvent.ERROR : result.append("ERROR"); break; - case FrameworkEvent.INFO: + case FrameworkEvent.INFO : result.append("INFO"); break; case FrameworkEvent.PACKAGES_REFRESHED : @@ -138,13 +137,13 @@ public class AbstractBundleTests extends TestCase { case BundleEvent.STARTED : result.append("STARTED"); break; - case BundleEvent.STARTING: + case BundleEvent.STARTING : result.append("STARTING"); break; case BundleEvent.STOPPED : result.append("STOPPED"); break; - case BundleEvent.UNINSTALLED: + case BundleEvent.UNINSTALLED : result.append("UNINSTALLED"); break; case BundleEvent.UNRESOLVED : @@ -159,4 +158,9 @@ public class AbstractBundleTests extends TestCase { result.append("] ").append(event.getSource()); return result.toString(); } + + public void setPlatformProperties() { + StateManager stateManager = (StateManager) installer.getPlatformAdmin(); + stateManager.getSystemState().setPlatformProperties(System.getProperties()); + } }
\ No newline at end of file diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java index bfb275702..ea0d50b17 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstaller.java @@ -13,6 +13,7 @@ package org.eclipse.osgi.tests.bundles; import java.io.IOException; import java.net.URL; import java.util.*; +import org.eclipse.osgi.service.resolver.PlatformAdmin; import org.eclipse.osgi.service.urlconversion.URLConverter; import org.osgi.framework.*; import org.osgi.service.packageadmin.PackageAdmin; @@ -26,6 +27,7 @@ public class BundleInstaller { private ServiceTracker packageAdmin; private ServiceTracker startlevel; private ServiceTracker converter; + private ServiceTracker platformAdmin; public BundleInstaller(String bundlesRoot, BundleContext context) throws InvalidSyntaxException { this.context = context; @@ -36,6 +38,8 @@ public class BundleInstaller { startlevel.open(); packageAdmin = new ServiceTracker(context, PackageAdmin.class.getName(), null); packageAdmin.open(); + platformAdmin = new ServiceTracker(context, PlatformAdmin.class.getName(), null); + platformAdmin.open(); } synchronized public Bundle installBundle(String name) throws BundleException { @@ -53,7 +57,7 @@ public class BundleInstaller { String location = bundleURL.toExternalForm(); if ("file".equals(bundleURL.getProtocol())) location = "reference:" + location; - Bundle bundle = context.installBundle(location); + Bundle bundle = context.installBundle(location); bundles.put(name, bundle); return bundle; } @@ -117,6 +121,7 @@ public class BundleInstaller { packageAdmin.close(); startlevel.close(); converter.close(); + platformAdmin.close(); bundles = null; return result; } @@ -165,4 +170,12 @@ public class BundleInstaller { public StartLevel getStartLevel() { return (StartLevel) startlevel.getService(); } + + public PackageAdmin getPackageAdmin() { + return (PackageAdmin) packageAdmin.getService(); + } + + public PlatformAdmin getPlatformAdmin() { + return (PlatformAdmin) platformAdmin.getService(); + } } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java index c4d9fc584..4fd167409 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java @@ -16,8 +16,11 @@ import java.util.ArrayList; import java.util.Enumeration; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.osgi.service.resolver.*; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.*; +import org.osgi.service.packageadmin.ExportedPackage; +import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.startlevel.StartLevel; public class ClassLoadingBundleTests extends AbstractBundleTests { @@ -568,6 +571,88 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { assertEquals("stuff resource", "stuff classpath test2", readURL((URL) resourceURLs.get(3))); //$NON-NLS-1$ //$NON-NLS-2$ } + public void testMultipleExportFragments01() throws Exception { + Bundle host = installer.installBundle("host.multiple.exports"); //$NON-NLS-1$ + Bundle frag = installer.installBundle("frag.multiple.exports"); //$NON-NLS-1$ + installer.resolveBundles(new Bundle[] {host, frag}); + PackageAdmin packageAdmin = installer.getPackageAdmin(); + ExportedPackage[] hostExports = packageAdmin.getExportedPackages(host); + assertEquals("Number host exports", 3, hostExports == null ? 0 : hostExports.length); //$NON-NLS-1$ + + PlatformAdmin platformAdmin = installer.getPlatformAdmin(); + State systemState = platformAdmin.getState(false); + BundleDescription hostDesc = systemState.getBundle(host.getBundleId()); + ExportPackageDescription[] hostExportDescs = hostDesc.getSelectedExports(); + assertEquals("Number host export descriptions", 3, hostExportDescs.length); //$NON-NLS-1$ + + assertEquals("Check export name", "host.multiple.exports", hostExportDescs[0].getName()); //$NON-NLS-1$//$NON-NLS-2$ + assertEquals("Check include directive", "Public*", (String) hostExportDescs[0].getDirective("include")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + + assertEquals("Check export name", "host.multiple.exports.onlyone", hostExportDescs[1].getName()); //$NON-NLS-1$ //$NON-NLS-2$ + + assertEquals("Check export name", "host.multiple.exports", hostExportDescs[2].getName()); //$NON-NLS-1$ //$NON-NLS-2$ + assertEquals("Check include directive", "private", (String) hostExportDescs[2].getAttributes().get("scope")); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testMultipleExportFragments02() throws Exception { + Bundle host = installer.installBundle("host.multiple.exports"); //$NON-NLS-1$ + Bundle frag = installer.installBundle("frag.multiple.exports"); //$NON-NLS-1$ + Bundle client1 = installer.installBundle("client1.multiple.exports"); //$NON-NLS-1$ + + installer.resolveBundles(new Bundle[] {host, frag, client1}); + client1.start(); + client1.stop(); + Object[] expectedEvents = new Object[4]; + expectedEvents[0] = "host.multiple.exports.PublicClass1"; //$NON-NLS-1$ + expectedEvents[1] = "host.multiple.exports.PublicClass2"; //$NON-NLS-1$ + expectedEvents[2] = "success"; //$NON-NLS-1$ + expectedEvents[3] = "success"; //$NON-NLS-1$ + Object[] actualEvents = simpleResults.getResults(4); + compareResults(expectedEvents, actualEvents); + } + + public void testMultipleExportFragments03() throws Exception { + Bundle host = installer.installBundle("host.multiple.exports"); //$NON-NLS-1$ + Bundle frag = installer.installBundle("frag.multiple.exports"); //$NON-NLS-1$ + Bundle client2 = installer.installBundle("client2.multiple.exports"); //$NON-NLS-1$ + + installer.resolveBundles(new Bundle[] {host, frag, client2}); + client2.start(); + client2.stop(); + Object[] expectedEvents = new Object[4]; + expectedEvents[0] = "host.multiple.exports.PublicClass1"; //$NON-NLS-1$ + expectedEvents[1] = "host.multiple.exports.PublicClass2"; //$NON-NLS-1$ + expectedEvents[2] = "host.multiple.exports.PrivateClass1"; //$NON-NLS-1$ + expectedEvents[3] = "host.multiple.exports.PrivateClass2"; //$NON-NLS-1$ + Object[] actualEvents = simpleResults.getResults(4); + compareResults(expectedEvents, actualEvents); + } + + public void testXFriends() throws Exception { + System.setProperty("osgi.resolverMode", "strict"); + setPlatformProperties(); + try { + Bundle test1 = installer.installBundle("xfriends.test1"); //$NON-NLS-1$ + Bundle test2 = installer.installBundle("xfriends.test2"); //$NON-NLS-1$ + Bundle test3 = installer.installBundle("xfriends.test3"); //$NON-NLS-1$ + installer.resolveBundles(new Bundle[] {test1, test2, test3}); + test2.start(); + test2.stop(); + test3.start(); + test3.stop(); + Object[] expectedEvents = new Object[4]; + expectedEvents[0] = "xfriends.test1.onlyforfriends.TestFriends"; //$NON-NLS-1$ + expectedEvents[1] = "xfriends.test1.external.TestFriends"; //$NON-NLS-1$ + expectedEvents[2] = "success"; //$NON-NLS-1$ + expectedEvents[3] = "xfriends.test1.external.TestFriends"; //$NON-NLS-1$ + Object[] actualEvents = simpleResults.getResults(4); + compareResults(expectedEvents, actualEvents); + } finally { + System.getProperties().remove("osgi.resolverMode"); + setPlatformProperties(); + } + } + // TODO temporarily disable til we can debug the build test machine on Win XP // public void testBuddyClassLoadingRegistered1() throws Exception{ // Bundle registeredA = installer.installBundle("buddy.registered.a"); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java index a7ea4e65e..d829ac151 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java @@ -13,11 +13,7 @@ package org.eclipse.osgi.tests.bundles; import java.io.*; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.osgi.internal.baseadaptor.StateManager; -import org.eclipse.osgi.service.resolver.PlatformAdmin; -import org.eclipse.osgi.tests.OSGiTestsActivator; import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceReference; public class NativeCodeBundleTests extends AbstractBundleTests { public static Test suite() { @@ -112,18 +108,6 @@ public class NativeCodeBundleTests extends AbstractBundleTests { assertNull("1.1", results[0]); } - private void setPlatformProperties() { - ServiceReference ref = OSGiTestsActivator.getContext().getServiceReference(PlatformAdmin.class.getName()); - if (ref != null) { - try { - StateManager stateManager = (StateManager) OSGiTestsActivator.getContext().getService(ref); - stateManager.getSystemState().setPlatformProperties(System.getProperties()); - } finally { - OSGiTestsActivator.getContext().ungetService(ref); - } - } - } - private String getContent(String file) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); try { diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java index 1da30f56c..a3ea59925 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/resolver/StateResolverTest.java @@ -1364,6 +1364,73 @@ public class StateResolverTest extends AbstractStateTest { assertNull("1.2 Packages are not consistent: " + isConsistent, isConsistent); } + public void testMultipleExportsUses01() throws BundleException { + State state = buildEmptyState(); + Hashtable manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A1"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.EXPORT_PACKAGE, "a; version=2.0; uses:=d, d; version=2.0"); + BundleDescription a1_100 = state.getFactory().createBundleDescription(state, manifest, "a1_100", 0); + + manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "A2"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.EXPORT_PACKAGE, "a; version=1.0; uses:=d, d; version=1.0"); + BundleDescription a2_100 = state.getFactory().createBundleDescription(state, manifest, "a2_100", 1); + + manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.EXPORT_PACKAGE, "b, b; mandatory:=\"test\"; test=value; uses:=d"); + manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A2, d"); + BundleDescription b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2); + + manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "C1"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.EXPORT_PACKAGE, "c; uses:=b"); + manifest.put(Constants.IMPORT_PACKAGE, "b; test=value, d"); + BundleDescription c1_100 = state.getFactory().createBundleDescription(state, manifest, "c1_100", 3); + + manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "D1"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.IMPORT_PACKAGE, "a, c, d"); + BundleDescription d1_100 = state.getFactory().createBundleDescription(state, manifest, "d1_100", 4); + + state.addBundle(a1_100); + state.addBundle(a2_100); + state.addBundle(b1_100); + state.addBundle(c1_100); + state.addBundle(d1_100); + state.resolve(); + + ExportPackageDescription[] b1ResolvedImports = b1_100.getResolvedImports(); + ExportPackageDescription[] d1ResolvedImports = d1_100.getResolvedImports(); + ExportPackageDescription[] isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports); + assertNull("1.1 Packages are not consistent: " + isConsistent, isConsistent); + + manifest = new Hashtable(); + manifest.put(Constants.BUNDLE_MANIFESTVERSION, "2"); + manifest.put(Constants.BUNDLE_SYMBOLICNAME, "B1"); + manifest.put(Constants.BUNDLE_VERSION, "1.0.0"); + manifest.put(Constants.EXPORT_PACKAGE, "b; uses:=a"); + manifest.put(Constants.IMPORT_PACKAGE, "a;bundle-symbolic-name=A1"); + b1_100 = state.getFactory().createBundleDescription(state, manifest, "b1_100", 2); + state.updateBundle(b1_100); + state.resolve(); + + b1ResolvedImports = b1_100.getResolvedImports(); + d1ResolvedImports = d1_100.getResolvedImports(); + isConsistent = isConsistent(b1ResolvedImports, d1ResolvedImports); + assertNull("1.2 Packages are not consistent: " + isConsistent, isConsistent); + } + public void testRequireBundleUses() throws BundleException { State state = buildEmptyState(); int id = 0; diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java index 0ac1955d5..f78648352 100644 --- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java +++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoader.java @@ -795,7 +795,7 @@ public class BundleLoader implements ClassLoaderDelegate { // now add the locally provided package. if (local != null && local.isFriend(symbolicName)) { if (local instanceof BundleLoaderProxy.ReexportPackageSource) - local = new SingleSourcePackage(packageName, -1, proxy); + local = new SingleSourcePackage(packageName, proxy); result.add(local); } } @@ -984,7 +984,7 @@ public class BundleLoader implements ClassLoaderDelegate { // if the package is exported then we need to get the local source PackageSource localSource = proxy.getPackageSource(pkgName); if (localSource instanceof BundleLoaderProxy.ReexportPackageSource) - localSource = new SingleSourcePackage(pkgName, -1, proxy); + localSource = new SingleSourcePackage(pkgName, proxy); if (result == null) return localSource; if (localSource == null) diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java index e3acede8a..7d5d1b362 100644 --- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java +++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/BundleLoaderProxy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2006 IBM Corporation and others. + * Copyright (c) 2003, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,7 +15,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import org.eclipse.osgi.framework.util.KeyedHashSet; -import org.eclipse.osgi.service.resolver.*; +import org.eclipse.osgi.service.resolver.BundleDescription; +import org.eclipse.osgi.service.resolver.ExportPackageDescription; import org.osgi.framework.*; import org.osgi.service.packageadmin.RequiredBundle; @@ -160,7 +161,7 @@ public class BundleLoaderProxy implements RequiredBundle { // successfully get stored into pkgSources PackageSource pkgSource = (PackageSource) pkgSources.getByKey(pkgName); if (pkgSource == null) { - pkgSource = new SingleSourcePackage(pkgName, -1, this); + pkgSource = new SingleSourcePackage(pkgName, this); synchronized (pkgSources) { pkgSources.add(pkgSource); } @@ -178,6 +179,7 @@ public class BundleLoaderProxy implements RequiredBundle { boolean strict = Constants.STRICT_MODE.equals(bundle.framework.adaptor.getState().getPlatformProperties()[0].get(Constants.OSGI_RESOLVER_MODE)); return (export.getDirective(Constants.INCLUDE_DIRECTIVE) != null) || (export.getDirective(Constants.EXCLUDE_DIRECTIVE) != null) || (strict && export.getDirective(Constants.FRIENDS_DIRECTIVE) != null); } + // creates a PackageSource from an ExportPackageDescription. This is called when initializing // a BundleLoader to ensure that the proper PackageSource gets created and used for // filtered and reexport packages. The storeSource flag is used by initialize to indicate @@ -200,18 +202,7 @@ public class BundleLoaderProxy implements RequiredBundle { friends = null; // do not pay attention to friends if not in strict mode } if (includes != null || excludes != null || friends != null) { - ExportPackageDescription[] exports = description.getExportPackages(); - int index = -1; - int first = -1; - for (int i = 0; i < exports.length; i++) { - if (first == -1 && exports[i].getName().equals(export.getName())) - first = i; - if (exports[i] == export && first != i) { - index = i; - break; - } - } - pkgSource = new FilteredSourcePackage(export.getName(), index, this, includes, excludes, friends); + pkgSource = new FilteredSourcePackage(export.getName(), this, includes, excludes, friends); } } @@ -227,8 +218,12 @@ public class BundleLoaderProxy implements RequiredBundle { } else { // we are not storing the special case sources, but pkgSource == null this means this // is a normal package source; get it and return it. - if (pkgSource == null) + if (pkgSource == null) { pkgSource = getPackageSource(export.getName()); + // the first export cached may not be a simple single source like we need. + if (pkgSource.getClass() != SingleSourcePackage.class) + return new SingleSourcePackage(export.getName(), this); + } } return pkgSource; diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilteredSourcePackage.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilteredSourcePackage.java index e9183c5f3..bb1e4cf55 100644 --- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilteredSourcePackage.java +++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/FilteredSourcePackage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,8 +20,8 @@ public class FilteredSourcePackage extends SingleSourcePackage { String[] excludes; String[] friends; - public FilteredSourcePackage(String name, int expid, BundleLoaderProxy supplier, String includes, String excludes, String[] friends) { - super(name, expid, supplier); + public FilteredSourcePackage(String name, BundleLoaderProxy supplier, String includes, String excludes, String[] friends) { + super(name, supplier); if (includes != null) this.includes = ManifestElement.getArrayFromList(includes); if (excludes != null) @@ -43,11 +43,13 @@ public class FilteredSourcePackage extends SingleSourcePackage { return null; return super.getResource(name); } + public Enumeration getResources(String name) { if (isFiltered(name, getId())) return null; return super.getResources(name); } + public Class loadClass(String name) throws ClassNotFoundException { if (isFiltered(name, getId())) return null; @@ -84,12 +86,12 @@ public class FilteredSourcePackage extends SingleSourcePackage { continue; if (list[i].charAt(0) == ALL && len == 1) return true; // handles "*" wild card - if (list[i].charAt(len-1) == ALL) - if (name.startsWith(list[i].substring(0, len-1))) + if (list[i].charAt(len - 1) == ALL) + if (name.startsWith(list[i].substring(0, len - 1))) return true; if (name.equals(list[i])) return true; - + } return false; } diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PackageSource.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PackageSource.java index ca1b02d08..428dbda29 100644 --- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PackageSource.java +++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/PackageSource.java @@ -19,6 +19,7 @@ public abstract class PackageSource implements KeyedElement { protected String id; public PackageSource(String id) { + // others depend on the id being interned; see SingleSourcePackage.equals this.id = id.intern(); } @@ -49,7 +50,9 @@ public abstract class PackageSource implements KeyedElement { } public abstract Class loadClass(String name) throws ClassNotFoundException; + public abstract URL getResource(String name); + public abstract Enumeration getResources(String name) throws IOException; //TODO See how this relates with FilteredSourcePackage. Overwriting or doing a double dispatch might be good. diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SingleSourcePackage.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SingleSourcePackage.java index e5de392b5..57dba1e06 100644 --- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SingleSourcePackage.java +++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/SingleSourcePackage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. + * Copyright (c) 2003, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,13 +15,9 @@ import java.util.Enumeration; public class SingleSourcePackage extends PackageSource { BundleLoaderProxy supplier; - // this is the index of the ExportPackageDescription - // into the list of exported packages of the supplier - // a valid of -1 indicates it is unknown or does not matter - protected int expid; - public SingleSourcePackage(String id, int expid, BundleLoaderProxy supplier) { + + public SingleSourcePackage(String id, BundleLoaderProxy supplier) { super(id); - this.expid = expid; this.supplier = supplier; } @@ -51,6 +47,7 @@ public class SingleSourcePackage extends PackageSource { if (!(source instanceof SingleSourcePackage)) return false; SingleSourcePackage singleSource = (SingleSourcePackage) source; - return supplier == singleSource.supplier && expid == singleSource.expid; + // we do an == test on id because the id is interned in the constructor of PackageSource + return supplier == singleSource.supplier && id == singleSource.getId(); } } diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/GroupingChecker.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/GroupingChecker.java index 0f196d173..e8a6abb16 100644 --- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/GroupingChecker.java +++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/GroupingChecker.java @@ -147,7 +147,7 @@ public class GroupingChecker { } } // check if the bundle exports the package - ResolverExport export = bundle.getExport(packageName); + ResolverExport[] exports = bundle.getExports(packageName); ArrayList roots = new ArrayList(0); // check roots from required bundles BundleConstraint[] requires = bundle.getRequires(); @@ -176,9 +176,9 @@ public class GroupingChecker { } } } - if (export != null || roots.size() > 1) { + if (exports.length > 0 || roots.size() > 1) { PackageRoots[] requiredRoots = (PackageRoots[]) roots.toArray(new PackageRoots[roots.size()]); - if (export == null) { + if (exports.length == 0) { PackageRoots superSet = requiredRoots[0]; for (int i = 1; i < requiredRoots.length; i++) { if (requiredRoots[i].superSet(superSet)) { @@ -196,9 +196,9 @@ public class GroupingChecker { // first merge all the roots from required bundles for (int i = 0; i < requiredRoots.length; i++) result.merge(requiredRoots[i]); - if (export != null) - // always add this bundles export to the end if it exports the package - result.addRoot(export); + // always add this bundles exports to the end if it exports the package + for (int i = 0; i < exports.length; i++) + result.addRoot(exports[i]); return result; } return (PackageRoots) (roots.size() == 0 ? nullPackageRoots : roots.get(0)); @@ -237,7 +237,7 @@ public class GroupingChecker { if (exportBSN != null) { // first one wins for (int i = 0; i < roots.length; i++) - if (exportBSN.equals(roots[i].getExporter().getName())) + if (export.getExporter() != roots[i].getExporter() && exportBSN.equals(roots[i].getExporter().getName())) return; } if (!contains(export, roots)) { diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java index 008b00f4f..54b6cedb5 100644 --- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java +++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/module/ResolverBundle.java @@ -11,7 +11,7 @@ package org.eclipse.osgi.internal.module; import java.util.*; -import org.eclipse.osgi.internal.resolver.ExportPackageDescriptionImpl; +import java.util.Map.Entry; import org.eclipse.osgi.service.resolver.*; import org.osgi.framework.Constants; @@ -294,14 +294,6 @@ public class ResolverBundle extends VersionSupplier implements Comparable { return false; } - private boolean isExported(String packageName) { - ResolverExport export = getExport(packageName); - if (export == null) - return false; - // let exports from a bundle manifest be exported in addition to the ones from the vm profile - return 0 > ((Integer) export.getExportPackageDescription().getDirective(ExportPackageDescriptionImpl.EQUINOX_EE)).intValue(); - } - private boolean isRequired(String bundleName) { return getRequire(bundleName) != null; } @@ -366,7 +358,13 @@ public class ResolverBundle extends VersionSupplier implements Comparable { if (newExports.length > 0 && dynamicAttach) { StateObjectFactory factory = resolver.getState().getFactory(); for (int i = 0; i < newExports.length; i++) { - if (!isExported(newExports[i].getName())) { + ResolverExport currentExports[] = getExports(newExports[i].getName()); + boolean foundEquivalent = false; + for (int j = 0; j < currentExports.length && !foundEquivalent; j++) { + if (equivalentExports(currentExports[j], newExports[i])) + foundEquivalent = true; + } + if (!foundEquivalent) { ExportPackageDescription hostExport = factory.createExportPackageDescription(newExports[i].getName(), newExports[i].getVersion(), newExports[i].getDirectives(), newExports[i].getAttributes(), newExports[i].isRoot(), getBundle()); hostExports.add(new ResolverExport(this, hostExport)); } @@ -376,6 +374,41 @@ public class ResolverBundle extends VersionSupplier implements Comparable { return (ResolverExport[]) hostExports.toArray(new ResolverExport[hostExports.size()]); } + private boolean equivalentExports(ResolverExport existingExport, ExportPackageDescription newDescription) { + ExportPackageDescription existingDescription = existingExport.getExportPackageDescription(); + if (!existingDescription.getName().equals(newDescription.getName())) + return false; + if (!existingDescription.getVersion().equals(newDescription.getVersion())) + return false; + if (!equivalentMaps(existingDescription.getAttributes(), newDescription.getAttributes())) + return false; + if (!equivalentMaps(existingDescription.getDirectives(), newDescription.getDirectives())) + return false; + return true; + } + + private boolean equivalentMaps(Map existingDirectives, Map newDirectives) { + if (existingDirectives == null && newDirectives == null) + return true; + if (existingDirectives == null ? newDirectives != null : newDirectives == null) + return false; + if (existingDirectives.size() != newDirectives.size()) + return false; + for (Iterator entries = existingDirectives.entrySet().iterator(); entries.hasNext();) { + Entry entry = (Entry) entries.next(); + Object newValue = newDirectives.get(entry.getKey()); + if (newValue == null || entry.getValue().getClass() != newValue.getClass()) + return false; + if (newValue instanceof String[]) { + if (!Arrays.equals((Object[]) entry.getValue(), (Object[]) newValue)) + return false; + } else if (!entry.getValue().equals(newValue)) { + return false; + } + } + return true; + } + boolean constraintsConflict(BundleDescription fragment, ImportPackageSpecification[] newImports, BundleSpecification[] newRequires, GenericSpecification[] newGenericRequires) { // this method iterates over all additional constraints from a fragment // if the host is resolved then the fragment is not allowed to add new constraints; |