You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by gc...@apache.org on 2011/03/04 18:14:07 UTC
svn commit: r1078060 [2/3] - in /aries/trunk/subsystem:
subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/
subsystem-itests/
subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/
subsystem-itests/src/test/java/org/ops4j/...
Modified: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/internal/Activator.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/internal/Activator.java (original)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/internal/Activator.java Fri Mar 4 17:14:05 2011
@@ -1,91 +1,75 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
package org.apache.aries.subsystem.scope.internal;
import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.List;
+import java.util.Arrays;
+import java.util.Collection;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
-import org.apache.aries.subsystem.scope.impl.ScopeAdminServiceFactory;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.apache.aries.subsystem.scope.impl.ScopeManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.bundle.EventHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.hooks.service.EventListenerHook;
public class Activator implements BundleActivator {
-
- private static BundleContext context;
- private List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
- ScopeAdminServiceFactory scopeAdminFactory;
-
- static BundleContext getContext() {
- return context;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
- * )
- */
- public void start(BundleContext bundleContext) throws Exception {
- Activator.context = bundleContext;
- scopeAdminFactory = new ScopeAdminServiceFactory();
- scopeAdminFactory.init();
- register(ScopeAdmin.class, scopeAdminFactory, null);
-
- }
-
- protected <T> void register(Class<T> clazz, T service, Dictionary props) {
- registrations.add(context.registerService(clazz.getName(), service,
- props));
- }
-
- protected <T> void register(Class<T> clazz, ServiceFactory factory,
- Dictionary props) {
- registrations.add(context.registerService(clazz.getName(), factory,
- props));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
- */
- public void stop(BundleContext bundleContext) throws Exception {
- Activator.context = null;
- for (ServiceRegistration r : registrations) {
- try {
- r.unregister();
- } catch (Exception e) {
- // LOGGER.warn("Scope Activator shut down", e);
- }
- }
-
- scopeAdminFactory.destroy();
- }
-
- public static BundleContext getBundleContext() {
- return context;
- }
-
+ private final Collection<ServiceRegistration<?>> serviceRegistrations = new ArrayList<ServiceRegistration<?>>();
+
+ public void start(BundleContext bundleContext) throws Exception {
+ ScopeManager sm = new ScopeManager(bundleContext);
+ ServiceRegistration<?> sr = bundleContext.registerService(
+ EventHook.class,
+ sm.newEventHook(),
+ null);
+ serviceRegistrations.add(sr);
+ ScopeUpdate su = sm.getRootScope().newScopeUpdate();
+ su.getBundles().addAll(Arrays.asList(bundleContext.getBundles()));
+ su.commit();
+ sr = bundleContext.registerService(
+ org.osgi.framework.hooks.bundle.FindHook.class,
+ sm.newBundleFindHook(),
+ null);
+ serviceRegistrations.add(sr);
+ sr = bundleContext.registerService(
+ ResolverHookFactory.class,
+ sm.newResolverHookFactory(),
+ null);
+ serviceRegistrations.add(sr);
+ sr = bundleContext.registerService(
+ EventListenerHook.class,
+ sm.newEventListenerHook(),
+ null);
+ serviceRegistrations.add(sr);
+ sr = bundleContext.registerService(
+ org.osgi.framework.hooks.service.FindHook.class,
+ sm.newServiceFindHook(),
+ null);
+ serviceRegistrations.add(sr);
+ sr = bundleContext.registerService(
+ Scope.class.getName(),
+ sm.newServiceFactory(),
+ null);
+ serviceRegistrations.add(sr);
+ }
+
+ public void stop(BundleContext bc) throws Exception {
+ unregisterQuietly();
+ }
+
+ private void unregisterQuietly() {
+ for (ServiceRegistration<?> sr : serviceRegistrations)
+ unregisterQuietly(sr);
+ serviceRegistrations.clear();
+ }
+
+ private void unregisterQuietly(ServiceRegistration<?> serviceRegistration) {
+ try {
+ serviceRegistration.unregister();
+ }
+ catch (Exception e) {
+ // ignore
+ }
+ }
}
Modified: aries/trunk/subsystem/subsystem-scope-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/pom.xml?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/pom.xml Fri Mar 4 17:14:05 2011
@@ -30,43 +30,68 @@
Integration tests using the subsystem scope api, impl for the implementation
and subsystem-example helloIsolation and helloIsolationRef for the subsysem to be tested.
</description>
-
+
<dependencies>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.eclipse</groupId>
<artifactId>osgi</artifactId>
- <version>3.7.0.v20101022</version>
+ <version>3.7.0.v20110221</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.api</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.scope.api</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.scope.impl</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries.testsupport</groupId>
<artifactId>org.apache.aries.testsupport.unit</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries</groupId>
<artifactId>org.apache.aries.util</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.ops4j.pax.exam</groupId>
@@ -93,6 +118,10 @@
<artifactId>pax-runner-no-jcl</artifactId>
</dependency>
<dependency>
+ <groupId>org.ops4j.pax.swissbox</groupId>
+ <artifactId>pax-swissbox-tinybundles</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -101,6 +130,12 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
@@ -121,26 +156,198 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.service.obr</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.bundlerepository</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries.application</groupId>
<artifactId>org.apache.aries.application.utils</artifactId>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem.example</groupId>
<artifactId>org.apache.aries.subsystem.example.helloIsolation</artifactId>
+ <version>0.4-SNAPSHOT</version>
<scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
</dependencies>
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3</version>
+ <executions>
+ <execution>
+ <id>tb1</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>1</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb1/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb1/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb2</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>2</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb2/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb2/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb3</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>3</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb3/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb3/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb4</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>4</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb4/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb4/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb5</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>5</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb5/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb5/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb6</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>6</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb6/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb6/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ <execution>
+ <id>tb7</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <configuration>
+ <classifier>7</classifier>
+ <archive>
+ <manifestFile>src/test/bundles/tb7/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ <classesDirectory>${project.build.directory}/test-classes</classesDirectory>
+ <includes>
+ <include>org/apache/aries/subsystem/scope/itests/tb7/*</include>
+ <include>**/META-INF/*</include>
+ </includes>
+ <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
+ <finalName>tb</finalName>
+ </configuration>
+ <phase>process-test-classes</phase>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -170,7 +377,98 @@
</configuration>
</execution>
</executions>
- </plugin>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <id>add-source-tb1</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb1</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb2</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb2</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb3</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb3</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb4</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb4</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb5</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb5</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb6</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb6</source>
+ </sources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>add-source-tb7</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-test-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>src/test/bundles/tb7</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/LICENSE
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/LICENSE?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/LICENSE (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/LICENSE Fri Mar 4 17:14:05 2011
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF Fri Mar 4 17:14:05 2011
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: TB1
+Bundle-SymbolicName: org.apache.aries.subsystem.scope.itests.tb1
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.apache.aries.subsystem.scope.itests.tb1.Activator
+Import-Package: org.junit,
+ org.osgi.framework;version="1.3.0",
+ org.apache.aries.subsystem.scope
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/DEPENDENCIES
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/DEPENDENCIES?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/DEPENDENCIES (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/DEPENDENCIES Fri Mar 4 17:14:05 2011
@@ -0,0 +1,15 @@
+// ------------------------------------------------------------------
+// Transitive dependencies of this project determined from the
+// maven pom organized by organization.
+// ------------------------------------------------------------------
+
+Apache Aries Subsystem iTests
+
+
+From: 'OPS4J - Open Participation Software for Java' (http://www.ops4j.org/)
+ - OPS4J Pax Runner - Core - No JCL (http://www.ops4j.org/projects/runner/pax-runner-no-jcl/) org.ops4j.pax.runner:pax-runner-no-jcl:bundle:1.4.0
+ License: ALv2 (http://www.apache.org/licenses/LICENSE-2.0.html)
+
+
+
+
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/MANIFEST.MF?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/MANIFEST.MF (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/MANIFEST.MF Fri Mar 4 17:14:05 2011
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: TB2
+Bundle-SymbolicName: org.apache.aries.subsystem.scope.itests.tb2
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractIntegrationTest.java?rev=1078060&r1=1075924&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractIntegrationTest.java (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractIntegrationTest.java Fri Mar 4 17:14:05 2011
@@ -16,32 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.aries.subsystem.itests;
+package org.apache.aries.subsystem.scope.itests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
-import java.io.*;
-import java.net.URISyntaxException;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Currency;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.apache.aries.subsystem.scope.SharePolicy;
import org.junit.After;
import org.junit.Before;
import org.ops4j.pax.exam.CoreOptions;
-import static org.ops4j.pax.exam.CoreOptions.options;
-import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
-import static org.ops4j.pax.exam.OptionUtils.combine;
import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -49,7 +45,6 @@ import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.blueprint.container.BlueprintContainer;
import org.osgi.util.tracker.ServiceTracker;
public abstract class AbstractIntegrationTest {
@@ -206,4 +201,15 @@ public abstract class AbstractIntegratio
return options;
}
+ protected void addPackageImportPolicy(String packageName, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
+ Filter filter = bundleContext.createFilter("(osgi.wiring.package=" + packageName + ')');
+ SharePolicy policy = new SharePolicy(SharePolicy.TYPE_IMPORT, "osgi.wiring.package", filter);
+ Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
+ List<SharePolicy> policies = policyMap.get("osgi.wiring.package");
+ if (policies == null) {
+ policies = new ArrayList<SharePolicy>();
+ policyMap.put("osgi.wiring.package", policies);
+ }
+ policies.add(policy);
+ }
}
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractTest.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,215 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.apache.aries.subsystem.scope.SharePolicy;
+import org.junit.After;
+import org.junit.Before;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
+import org.ops4j.pax.swissbox.tinybundles.core.TinyBundles;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+public class AbstractTest extends AbstractIntegrationTest {
+ protected Scope scope;
+
+ private ServiceReference<Scope> scopeRef;
+
+ protected void addPackageExportPolicy(String packageName, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
+ Filter filter = bundleContext.createFilter("(osgi.wiring.package=" + packageName + ')');
+ SharePolicy policy = new SharePolicy(SharePolicy.TYPE_EXPORT, "osgi.wiring.package", filter);
+ Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
+ List<SharePolicy> policies = policyMap.get("osgi.wiring.package");
+ if (policies == null) {
+ policies = new ArrayList<SharePolicy>();
+ policyMap.put("osgi.wiring.package", policies);
+ }
+ policies.add(policy);
+ }
+
+ protected void addPackageImportPolicy(String packageName, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
+ Filter filter = bundleContext.createFilter("(osgi.wiring.package=" + packageName + ')');
+ SharePolicy policy = new SharePolicy(SharePolicy.TYPE_IMPORT, "osgi.wiring.package", filter);
+ Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
+ List<SharePolicy> policies = policyMap.get("osgi.wiring.package");
+ if (policies == null) {
+ policies = new ArrayList<SharePolicy>();
+ policyMap.put("osgi.wiring.package", policies);
+ }
+ policies.add(policy);
+ }
+
+ protected void addServiceExportPolicy(Class<?> clazz, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
+ Filter filter = bundleContext.createFilter('(' + Constants.OBJECTCLASS + '=' + clazz.getName() + ')');
+ SharePolicy policy = new SharePolicy(SharePolicy.TYPE_EXPORT, "scope.share.service", filter);
+ Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_EXPORT);
+ List<SharePolicy> policies = policyMap.get("scope.share.service");
+ if (policies == null) {
+ policies = new ArrayList<SharePolicy>();
+ policyMap.put("scope.share.service", policies);
+ }
+ policies.add(policy);
+ }
+
+ protected void addServiceImportPolicy(Class<?> clazz, ScopeUpdate scopeUpdate) throws InvalidSyntaxException {
+ Filter filter = bundleContext.createFilter('(' + Constants.OBJECTCLASS + '=' + clazz.getName() + ')');
+ SharePolicy policy = new SharePolicy(SharePolicy.TYPE_IMPORT, "scope.share.service", filter);
+ Map<String, List<SharePolicy>> policyMap = scopeUpdate.getSharePolicies(SharePolicy.TYPE_IMPORT);
+ List<SharePolicy> policies = policyMap.get("scope.share.service");
+ if (policies == null) {
+ policies = new ArrayList<SharePolicy>();
+ policyMap.put("scope.share.service", policies);
+ }
+ policies.add(policy);
+ }
+
+ protected void assertEmpty(Collection<?> c) {
+ assertNotNull(c);
+ assertTrue(c.isEmpty());
+ }
+
+ protected void assertEmpty(Map<?, ?> m) {
+ assertNotNull(m);
+ assertTrue(m.isEmpty());
+ }
+
+ protected void assertCollectionEquals(Collection<?> c1, Collection<?> c2) {
+ assertFalse((c1 == null && c2 != null) || (c1 != null && c2 == null));
+ assertTrue(c1.size() == c2.size());
+ for (Iterator<?> i = c2.iterator(); i.hasNext();) {
+ assertTrue(c2.contains(i.next()));
+ }
+ }
+
+ protected Bundle findBundle(String symbolicName, Scope scope) {
+ return Utils.findBundle(symbolicName, scope);
+ }
+
+ protected Bundle findBundleInRootScope(String symbolicName) {
+ return findBundle(symbolicName, scope);
+ }
+
+ protected ScopeUpdate findChildUpdate(String name, ScopeUpdate parent) {
+ assertNotNull(name);
+ assertNotNull(parent);
+ ScopeUpdate result = null;
+ for (ScopeUpdate child : parent.getChildren()) {
+ if (name.equals(child.getName())) {
+ result = child;
+ break;
+ }
+ }
+ assertNotNull(result);
+ return result;
+ }
+
+ protected String getBundleLocation(String bundle) {
+ URL url = AbstractTest.class.getClassLoader().getResource(bundle);
+ return url.toExternalForm();
+ }
+
+ protected Bundle installBundle(String name) throws BundleException {
+ URL url = AbstractTest.class.getClassLoader().getResource(name);
+ return bundleContext.installBundle(url.toExternalForm());
+ }
+
+ protected void installBundles(Scope scope, String[] bundleNames) throws Exception {
+ installBundles(scope, Arrays.asList(bundleNames));
+ }
+
+ protected void installBundles(Scope scope, Collection<String> bundleNames) throws Exception {
+ ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+ for (String bundleName : bundleNames) {
+ URL url = AbstractTest.class.getClassLoader().getResource(bundleName);
+ InstallInfo installInfo = new InstallInfo(url.toExternalForm(), url.openStream());
+ scopeUpdate.getBundlesToInstall().add(installInfo);
+ }
+ scopeUpdate.commit();
+ }
+
+ @Before
+ public void before() throws Exception {
+ assertNotNull(bundleContext);
+ scopeRef = bundleContext.getServiceReference(Scope.class);
+ assertNotNull(scopeRef);
+ scope = bundleContext.getService(scopeRef);
+ assertNotNull(scope);
+ }
+
+ @After
+ public void after() throws Exception {
+ }
+
+ protected void uninstallQuietly(Bundle bundle) {
+ Utils.uninstallQuietly(bundle);
+ }
+
+ @org.ops4j.pax.exam.junit.Configuration
+ public static Option[] configuration() {
+ Option[] options = options(
+ // Log
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+ mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+ // Felix Config Admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+ // Felix mvn url handler
+ mavenBundle("org.ops4j.pax.url", "pax-url-mvn"),
+
+
+ // this is how you set the default log level when using pax logging (logProfile)
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
+
+ // Bundles
+ mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
+ mavenBundle("org.apache.aries", "org.apache.aries.util"),
+ mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
+ mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
+
+ // org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+
+ PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
+
+ equinox().version("3.7.0.v20110221"),
+
+ new Customizer() {
+ @Override
+ public InputStream customizeTestProbe(InputStream testProbe) throws IOException {
+ return TinyBundles.modifyBundle(testProbe).
+ removeHeader(Constants.EXPORT_PACKAGE)
+ .set(Constants.EXPORT_PACKAGE, "org.apache.aries.subsystem.scope.itests")
+ .build();
+ }
+ }
+ );
+ options = updateOptions(options);
+ return options;
+ }
+}
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BasicTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BasicTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BasicTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BasicTest.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,105 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.apache.aries.subsystem.scope.SharePolicy;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+@RunWith(JUnit4TestRunner.class)
+public class BasicTest extends AbstractTest {
+ /**
+ * Basic test of the initial state of the root scope.
+ */
+ @Test
+ public void testRootScopeInitialState() {
+ Collection<Bundle> bundles = Arrays.asList(bundleContext.getBundles());
+ assertCollectionEquals(bundles, scope.getBundles());
+ assertEmpty(scope.getChildren());
+ assertEquals(0, scope.getId());
+ assertNull(scope.getLocation());
+ assertEquals("root", scope.getName());
+ assertNull(scope.getParent());
+ assertEmpty(scope.getSharePolicies(SharePolicy.TYPE_EXPORT));
+ assertEmpty(scope.getSharePolicies(SharePolicy.TYPE_IMPORT));
+ assertNotNull(scope.newScopeUpdate());
+ }
+
+ /**
+ * Basic test of the initial state of the root scope from another bundle.
+ * The root scope instance should be the same as in the previous test.
+ * @throws Exception
+ */
+ @Test
+ public void testRootScopeInitialStateFromOtherBundle() throws Exception {
+ Bundle tb1 = installBundle("tb-1.jar");
+ try {
+ tb1.start();
+ }
+ catch (BundleException e) {
+ if (e.getCause() instanceof AssertionError) {
+ throw (AssertionError)e.getCause();
+ }
+ throw e;
+ }
+ finally {
+ tb1.uninstall();
+ }
+ }
+
+ @Test
+ public void testInstallBundleIntoRootScope() throws Exception {
+ int previousSize = scope.getBundles().size();
+ String location = getBundleLocation("tb-2.jar");
+ URL url = new URL(location);
+ InstallInfo tb2Info = new InstallInfo(location, url.openStream());
+ ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+ scopeUpdate.getBundlesToInstall().add(tb2Info);
+ assertTrue(scopeUpdate.commit());
+ Bundle b = bundleContext.getBundle(location);
+ assertNotNull(b);
+ Collection<Bundle> bundles = scope.getBundles();
+ assertEquals(previousSize + 1, bundles.size());
+ assertTrue(bundles.contains(b));
+ }
+
+ @Test
+ public void testCreateChildScope() throws Exception {
+ String name = "scope1";
+ ScopeUpdate parent = scope.newScopeUpdate();
+ ScopeUpdate child = parent.newChild(name);
+ parent.getChildren().add(child);
+ assertTrue(parent.commit());
+ Collection<Scope> children = scope.getChildren();
+ assertEquals(1, children.size());
+ Scope feature1 = null;
+ for (Scope s : children) {
+ if (name.equals(s.getName())) {
+ feature1 = s;
+ break;
+ }
+ }
+ assertNotNull(feature1);
+ assertEmpty(feature1.getBundles());
+ assertEmpty(feature1.getChildren());
+ assertEquals(1, feature1.getId());
+ assertNull(feature1.getLocation());
+ assertEquals(name, feature1.getName());
+ assertEquals(scope, feature1.getParent());
+ assertEmpty(feature1.getSharePolicies(SharePolicy.TYPE_EXPORT));
+ assertEmpty(feature1.getSharePolicies(SharePolicy.TYPE_IMPORT));
+ }
+}
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BundleProvider.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BundleProvider.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BundleProvider.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BundleProvider.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,11 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import java.util.Collection;
+
+import org.osgi.framework.Bundle;
+
+public interface BundleProvider {
+ Bundle getBundle(long id);
+
+ Collection<Bundle> getBundles();
+}
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/GetScopeServiceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/GetScopeServiceTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/GetScopeServiceTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/GetScopeServiceTest.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,113 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import org.apache.aries.subsystem.scope.InstallInfo;
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Tests that bundles requesting a Scope service receive the correct one.
+ * Bundles should receive the Scope within which they exist. Requesting bundles
+ * are in the root scope by default.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class GetScopeServiceTest extends AbstractTest {
+ /**
+ * The test bundle should be in and receive the root scope by default. The
+ * root scope will always have an ID of '0' and name of 'root'.
+ * @throws Exception
+ */
+ @Test
+ public void test1() throws Exception {
+ assertEquals(0, scope.getId());
+ assertEquals("root", scope.getName());
+ assertTrue(scope.getBundles().contains(bundleContext.getBundle()));
+ }
+
+ /**
+ * The tb3 bundle should also be in and receive the root scope by default.
+ * @throws Exception
+ */
+ @Test
+ public void test2() throws Exception {
+ Bundle bundle = installBundle("tb-3.jar");
+ bundle.start();
+ ServiceReference<ScopeProvider> scopeProviderRef = bundleContext.getServiceReference(ScopeProvider.class);
+ ScopeProvider scopeProvider = bundleContext.getService(scopeProviderRef);
+ Scope scope = scopeProvider.getScope();
+ assertEquals(this.scope, scope);
+ assertTrue(scope.getBundles().contains(bundle));
+ bundleContext.ungetService(scopeProviderRef);
+ bundle.uninstall();
+ }
+
+ /**
+ * A new scope is created as a child of the root scope and the tb3 bundle
+ * is added to it. The tb3 bundle should receive and be in the new scope.
+ * @throws Exception
+ */
+ @Test
+ public void test3() throws Exception {
+ ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+ ScopeUpdate child = scopeUpdate.newChild("tb3");
+ scopeUpdate.getChildren().add(child);
+ String location = getBundleLocation("tb-3.jar");
+ URL url = new URL(location);
+ InstallInfo installInfo = new InstallInfo(location, url.openStream());
+ child.getBundlesToInstall().add(installInfo);
+ addPackageImportPolicy("org.osgi.framework", child);
+ addPackageImportPolicy("org.apache.aries.subsystem.scope", child);
+ addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
+ addServiceImportPolicy(Scope.class, child);
+ addServiceExportPolicy(ScopeProvider.class, child);
+ scopeUpdate.commit();
+ Bundle bundle = bundleContext.getBundle(location);
+ bundle.start();
+ ServiceReference<ScopeProvider> scopeProviderRef = bundleContext.getServiceReference(ScopeProvider.class);
+ ScopeProvider scopeProvider = bundleContext.getService(scopeProviderRef);
+ Scope scope = scopeProvider.getScope();
+ assertEquals("tb3", scope.getName());
+ assertTrue(scope.getBundles().contains(bundle));
+ bundleContext.ungetService(scopeProviderRef);
+ bundle.uninstall();
+ }
+
+ /**
+ * A new scope is created as a child of the root scope and the tb3 bundle
+ * is added to it. The tb3 bundle should receive and be in the new scope.
+ * The bundle is added directly as opposed to via an InstallInfo.
+ * @throws Exception
+ */
+ @Test
+ public void test4() throws Exception {
+ Bundle bundle = installBundle("tb-3.jar");
+ ScopeUpdate scopeUpdate = scope.newScopeUpdate();
+ scopeUpdate.getBundles().remove(bundle);
+ ScopeUpdate child = scopeUpdate.newChild("tb3");
+ scopeUpdate.getChildren().add(child);
+ child.getBundles().add(bundle);
+ addPackageImportPolicy("org.osgi.framework", child);
+ addPackageImportPolicy("org.apache.aries.subsystem.scope", child);
+ addPackageImportPolicy("org.apache.aries.subsystem.scope.itests", child);
+ addServiceImportPolicy(Scope.class, child);
+ addServiceExportPolicy(ScopeProvider.class, child);
+ scopeUpdate.commit();
+ bundle.start();
+ ServiceReference<ScopeProvider> scopeProviderRef = bundleContext.getServiceReference(ScopeProvider.class);
+ ScopeProvider scopeProvider = bundleContext.getService(scopeProviderRef);
+ Scope scope = scopeProvider.getScope();
+ assertEquals("tb3", scope.getName());
+ assertTrue(scope.getBundles().contains(bundle));
+ bundleContext.ungetService(scopeProviderRef);
+ bundle.uninstall();
+ }
+}
Modified: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/JarCreator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/JarCreator.java?rev=1078060&r1=1075924&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/JarCreator.java (original)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/JarCreator.java Fri Mar 4 17:14:05 2011
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.aries.subsystem.itests;
+package org.apache.aries.subsystem.scope.itests;
import java.io.File;
import java.io.FileOutputStream;
@@ -41,8 +41,8 @@ public class JarCreator
}
private static void createJar(String version) throws Exception {
- createJarFromFile("../subsystem-example/subsystem-helloIsolation/target/org.apache.aries.subsystem.example.helloIsolation-0.3-SNAPSHOT.jar", version);
- createJarFromFile("../subsystem-example/subsystem-helloIsolationRef/target/org.apache.aries.subsystem.example.helloIsolationRef-0.3-SNAPSHOT.jar", version);
+ createJarFromFile("../subsystem-example/subsystem-helloIsolation/target/org.apache.aries.subsystem.example.helloIsolation-0.4-SNAPSHOT.jar", version);
+ createJarFromFile("../subsystem-example/subsystem-helloIsolationRef/target/org.apache.aries.subsystem.example.helloIsolationRef-0.4-SNAPSHOT.jar", version);
}
private static void createJarFromFile(String fileName, String version) throws Exception {
JarOutputStream jos = null;
Added: aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/MoveBundleTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/MoveBundleTest.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/MoveBundleTest.java (added)
+++ aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/MoveBundleTest.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,112 @@
+package org.apache.aries.subsystem.scope.itests;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+
+/**
+ * Bundles may be moved from one scope to another.
+ */
+@RunWith(JUnit4TestRunner.class)
+public class MoveBundleTest extends AbstractTest {
+ /**
+ * Create two scopes off of the root scope with the following structure.
+ * R
+ * / \
+ * S1 S2
+ * Install a bundle using the test bundle's bundle context. This should add
+ * the bundle to R since the test bundle is in R. Next, move the bundle
+ * into S1. Finally, move the bundle into S2.
+ * @throws Exception
+ */
+ @Test
+ public void test1() throws Exception {
+ Bundle tb2 = installBundle("tb-2.jar");
+ Scope root = scope;
+ ScopeUpdate rootUpdate = root.newScopeUpdate();
+ ScopeUpdate s1Update = rootUpdate.newChild("S1");
+ ScopeUpdate s2Update = rootUpdate.newChild("S2");
+ rootUpdate.getChildren().add(s1Update);
+ rootUpdate.getChildren().add(s2Update);
+ rootUpdate.commit();
+ Scope s1 = s1Update.getScope();
+ Scope s2 = s2Update.getScope();
+ assertTrue(root.getBundles().contains(tb2));
+ assertFalse(s1.getBundles().contains(tb2));
+ assertFalse(s2.getBundles().contains(tb2));
+
+ rootUpdate = root.newScopeUpdate();
+ rootUpdate.getBundles().remove(tb2);
+ s1Update = findChildUpdate("S1", rootUpdate);
+ s1Update.getBundles().add(tb2);
+ rootUpdate.commit();
+ assertFalse(root.getBundles().contains(tb2));
+ assertTrue(s1.getBundles().contains(tb2));
+ assertFalse(s2.getBundles().contains(tb2));
+
+ rootUpdate = root.newScopeUpdate();
+ s1Update = findChildUpdate("S1", rootUpdate);
+ s1Update.getBundles().remove(tb2);
+ s2Update = findChildUpdate("S2", rootUpdate);
+ s2Update.getBundles().add(tb2);
+ rootUpdate.commit();
+ assertFalse(root.getBundles().contains(tb2));
+ assertFalse(s1.getBundles().contains(tb2));
+ assertTrue(s2.getBundles().contains(tb2));
+
+ tb2.uninstall();
+ }
+
+ /**
+ * Create one scope off of the root scope with the following structure.
+ * R
+ * |
+ * S
+ * Install a bundle using the test bundle's bundle context. This should add
+ * the bundle to R since the test bundle is in R. Next, move the bundle into
+ * S without removing it from R. This should result in an
+ * IllegalStateException. Finally, correct the error using the same
+ * ScopeUpdate objects and commit again. This should succeed, and the bundle
+ * should now be in S.
+ * @throws Exception
+ */
+ @Test
+ public void test2() throws Exception {
+ Bundle tb2 = installBundle("tb-2.jar");
+ Scope root = scope;
+ ScopeUpdate rootUpdate = root.newScopeUpdate();
+ ScopeUpdate sUpdate = rootUpdate.newChild("S");
+ rootUpdate.getChildren().add(sUpdate);
+ rootUpdate.commit();
+ Scope s = sUpdate.getScope();
+ assertTrue(root.getBundles().contains(tb2));
+ assertFalse(s.getBundles().contains(tb2));
+
+ rootUpdate = root.newScopeUpdate();
+ sUpdate = findChildUpdate("S", rootUpdate);
+ sUpdate.getBundles().add(tb2);
+ try {
+ rootUpdate.commit();
+ fail();
+ }
+ catch (IllegalStateException e) {
+ // Okay.
+ }
+ assertTrue(root.getBundles().contains(tb2));
+ assertFalse(s.getBundles().contains(tb2));
+
+ rootUpdate.getBundles().remove(tb2);
+ rootUpdate.commit();
+ assertFalse(root.getBundles().contains(tb2));
+ assertTrue(s.getBundles().contains(tb2));
+
+ tb2.uninstall();
+ }
+}