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 [1/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/...
Author: gcc
Date: Fri Mar 4 17:14:05 2011
New Revision: 1078060
URL: http://svn.apache.org/viewvc?rev=1078060&view=rev
Log:
ARIES-594
Committing patch to improve scopeadmin implementation and move to latest resolver hook design.
Added:
aries/trunk/subsystem/subsystem-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeManager.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/LICENSE
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/DEPENDENCIES
aries/trunk/subsystem/subsystem-scope-itests/src/test/bundles/tb2/META-INF/MANIFEST.MF
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/
- copied from r1075924, aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/itests/
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BasicTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/BundleProvider.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/GetScopeServiceTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/MoveBundleTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeProvider.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Service.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ServiceVisibilityTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/SharePolicyTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/UninstallBundleTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/Utils.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml
Removed:
aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeAdmin.java
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/DictionaryBuilder.java
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminImpl.java
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminServiceFactory.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/itests/
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
aries/trunk/subsystem/subsystem-itests/pom.xml
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/AbstractIntegrationTest.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java
aries/trunk/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java
aries/trunk/subsystem/subsystem-itests/src/test/resources/ss-runner.properties
aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/InstallInfo.java
aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/Scope.java
aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeUpdate.java
aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/SharePolicy.java
aries/trunk/subsystem/subsystem-scope-impl/pom.xml
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java
aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/internal/Activator.java
aries/trunk/subsystem/subsystem-scope-itests/pom.xml
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/AbstractIntegrationTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/JarCreator.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeAdminTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/apache/aries/subsystem/scope/itests/ScopeSecurityTest.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java
aries/trunk/subsystem/subsystem-scope-itests/src/test/resources/ss-runner.properties
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Activator.java Fri Mar 4 17:14:05 2011
@@ -24,7 +24,7 @@ import org.apache.aries.subsystem.Subsys
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.Scope;
import org.apache.aries.subsystem.spi.ResourceProcessor;
import org.apache.aries.subsystem.spi.ResourceResolver;
import org.osgi.framework.Bundle;
@@ -116,7 +116,7 @@ public class Activator implements Bundle
//private final List<ScopeAdmin> scopeAdmins = new ArrayList<ScopeAdmin>();
private final List<SubsystemAdmin> admins = new ArrayList<SubsystemAdmin>();
private final Map<SubsystemAdmin, Long> references = new HashMap<SubsystemAdmin, Long>();
- private ScopeAdmin scopeAdmin; // scope admin for the root scope.
+ private Scope scopeAdmin; // scope admin for the root scope.
private static ServiceTracker serviceTracker;
private SubsystemAdmin defaultAdmin;
private ServiceRegistration rootAdminReg;
@@ -124,11 +124,10 @@ public class Activator implements Bundle
public SubsystemAdminFactory() throws InvalidSyntaxException {
context = Activator.getBundleContext();
- ServiceReference[] reference = Activator.getBundleContext().getServiceReferences(ScopeAdmin.class.getName(),
- "(&(ScopeName=root))");
- if (reference != null && reference.length == 1) {
- ScopeAdmin scopeAdmin = (ScopeAdmin)Activator.getBundleContext().getService(reference[0]);
- Subsystem subsystem = new SubsystemImpl(scopeAdmin.getScope(), new HashMap<String, String>());
+ ServiceReference reference = Activator.getBundleContext().getServiceReference(Scope.class.getName());
+ if (reference != null) {
+ Scope scopeAdmin = (Scope)Activator.getBundleContext().getService(reference);
+ Subsystem subsystem = new SubsystemImpl(scopeAdmin, new HashMap<String, String>());
defaultAdmin = new SubsystemAdminImpl(scopeAdmin, subsystem, null);
rootAdminReg = context.registerService(SubsystemAdmin.class.getName(),
defaultAdmin,
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceProcessor.java Fri Mar 4 17:14:05 2011
@@ -18,15 +18,14 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemException;
import org.apache.aries.subsystem.scope.InstallInfo;
import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.subsystem.scope.ScopeUpdate;
import org.apache.aries.subsystem.spi.Resource;
import org.apache.aries.subsystem.spi.ResourceProcessor;
@@ -42,7 +41,7 @@ public class BundleResourceProcessor imp
public static class BundleSession implements Session {
- private final ScopeAdmin scopeAdmin;
+ private final Scope scopeAdmin;
private final List<Bundle> installed = new ArrayList<Bundle>();
private final Map<Resource, Bundle> updated = new HashMap<Resource, Bundle>();
private final Map<Resource, Bundle> removed = new HashMap<Resource, Bundle>();
@@ -60,7 +59,7 @@ public class BundleResourceProcessor imp
if (bundle == null) {
// fresh install
- InstallInfo installInfo = new InstallInfo(new URL(resource.getLocation()), resource.getLocation());
+ InstallInfo installInfo = new InstallInfo(resource.getLocation(), new URL(resource.getLocation()));
ScopeUpdate scopeUpdate = scopeAdmin.newScopeUpdate();
scopeUpdate.getBundlesToInstall().add(installInfo);
scopeUpdate.commit();
@@ -138,7 +137,7 @@ public class BundleResourceProcessor imp
Bundle bundle = entry.getValue();
Resource res = entry.getKey();
try {
- InstallInfo installInfo = new InstallInfo(res.open(), res.getLocation());
+ InstallInfo installInfo = new InstallInfo(res.getLocation(), res.open());
ScopeUpdate scopeUpdate = scopeAdmin.newScopeUpdate();
scopeUpdate.getBundlesToInstall().add(installInfo);
scopeUpdate.commit();
@@ -152,7 +151,7 @@ public class BundleResourceProcessor imp
}
protected Bundle findBundle(Resource resource) {
- Scope scope = scopeAdmin.getScope();
+ Scope scope = scopeAdmin;
for (Bundle b : scope.getBundles()) {
if (resource.getLocation().equals(scope.getLocation())) {
return b;
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemAdminImpl.java Fri Mar 4 17:14:05 2011
@@ -28,7 +28,7 @@ import org.apache.aries.subsystem.Subsys
import org.apache.aries.subsystem.SubsystemEvent;
import org.apache.aries.subsystem.SubsystemException;
import org.apache.aries.subsystem.SubsystemListener;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.Scope;
import org.apache.aries.subsystem.spi.Resource;
import org.apache.aries.subsystem.spi.ResourceResolver;
import org.osgi.framework.BundleContext;
@@ -44,7 +44,7 @@ public class SubsystemAdminImpl implemen
private static final Version SUBSYSTEM_MANIFEST_VERSION = new Version("1.0");
final BundleContext context;
- final ScopeAdmin scopeAdmin;
+ final Scope scopeAdmin;
final Map<Long, Subsystem> subsystems = new HashMap<Long, Subsystem>();
final ServiceTracker resourceResolverTracker;
final SubsystemEventDispatcher eventDispatcher;
@@ -52,7 +52,7 @@ public class SubsystemAdminImpl implemen
final Subsystem subsystem;
final Subsystem parentSubsystem;
- public SubsystemAdminImpl(ScopeAdmin scopeAdmin, Subsystem subsystem, Subsystem parentSubsystem) {
+ public SubsystemAdminImpl(Scope scopeAdmin, Subsystem subsystem, Subsystem parentSubsystem) {
context = Activator.getBundleContext();
this.eventDispatcher = Activator.getEventDispatcher();
this.scopeAdmin = scopeAdmin;
@@ -283,7 +283,7 @@ public class SubsystemAdminImpl implemen
}
// return the scope admin associated with the subsystemadmin.
- protected ScopeAdmin getScopeAdmin() {
+ protected Scope getScopeAdmin() {
return this.scopeAdmin;
}
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemImpl.java Fri Mar 4 17:14:05 2011
@@ -14,16 +14,18 @@
*/
package org.apache.aries.subsystem.core.internal;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemEvent;
import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.Subsystem.State;
import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceProcessor.java Fri Mar 4 17:14:05 2011
@@ -29,15 +29,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
-import java.util.Dictionary;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -47,8 +45,7 @@ import org.apache.aries.subsystem.Subsys
import org.apache.aries.subsystem.SubsystemAdmin;
import org.apache.aries.subsystem.SubsystemConstants;
import org.apache.aries.subsystem.SubsystemException;
-import org.apache.aries.subsystem.scope.InstallInfo;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.Scope;
import org.apache.aries.subsystem.scope.ScopeUpdate;
import org.apache.aries.subsystem.scope.SharePolicy;
import org.apache.aries.subsystem.spi.Resource;
@@ -106,7 +103,7 @@ public class SubsystemResourceProcessor
try {
SubsystemAdminImpl adminImpl = (SubsystemAdminImpl)subsystemAdmin;
- ScopeAdmin admin = adminImpl.getScopeAdmin();
+ Scope admin = adminImpl.getScopeAdmin();
ResourceResolver resolver = getService(ResourceResolver.class);
if (manifest == null) {
@@ -176,7 +173,9 @@ public class SubsystemResourceProcessor
setupSharePolicies(exportSharePolicies, importSharePolicies, headers);
scopeUpdate.commit();
- ScopeAdmin childScopeAdmin = getService(ScopeAdmin.class, "ScopeId=" + childScopeUpdate.getScope().getId());
+ // ScopeAdmin childScopeAdmin = getService(ScopeAdmin.class, "ScopeId=" + childScopeUpdate.getScope().getId());
+
+ Scope childScopeAdmin = childScopeUpdate.getScope();
subsystem = new SubsystemImpl(childScopeUpdate.getScope(), headers);
SubsystemAdmin childSubsystemAdmin = new SubsystemAdminImpl(childScopeAdmin, subsystem, subsystemAdmin.getSubsystem());
Modified: aries/trunk/subsystem/subsystem-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/pom.xml?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-itests/pom.xml Fri Mar 4 17:14:05 2011
@@ -33,14 +33,9 @@
<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.v20110110</version>
+ <version>3.7.0.v20110221</version>
<scope>provided</scope>
</dependency>
<dependency>
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/AbstractIntegrationTest.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/AbstractIntegrationTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/AbstractIntegrationTest.java Fri Mar 4 17:14:05 2011
@@ -18,30 +18,23 @@
*/
package org.apache.aries.subsystem.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.Properties;
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 +42,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 {
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java Fri Mar 4 17:14:05 2011
@@ -19,43 +19,28 @@
package org.apache.aries.subsystem.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.equinox;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.io.File;
import java.io.FileOutputStream;
-import java.net.URL;
-import java.text.SimpleDateFormat;
import java.util.Collection;
-import java.util.Currency;
-import java.util.Hashtable;
-import java.util.HashMap;
-import java.util.Map;
-
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.Scope;
import org.apache.aries.unittest.fixture.ArchiveFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
-
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
@RunWith(JUnit4TestRunner.class)
@@ -85,7 +70,7 @@ public class SubsystemAdmin2Test extends
@Test
public void test() throws Exception {
// make sure we are using a framework that provides scope admin service
- ScopeAdmin scopeA = getOsgiService(ScopeAdmin.class);
+ Scope scopeA = getOsgiService(Scope.class);
assertNotNull("scope admin should not be null", scopeA);
System.out.println("able to get scope admin service");
@@ -138,7 +123,7 @@ public class SubsystemAdmin2Test extends
PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- equinox().version("3.7.0.v20110110")
+ equinox().version("3.7.0.v20110221")
);
options = updateOptions(options);
return options;
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java Fri Mar 4 17:14:05 2011
@@ -19,45 +19,27 @@
package org.apache.aries.subsystem.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.equinox;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.io.File;
import java.io.FileOutputStream;
-import java.net.URL;
-import java.text.SimpleDateFormat;
import java.util.Collection;
-import java.util.Currency;
-import java.util.Hashtable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
+import org.apache.aries.subsystem.scope.Scope;
import org.apache.aries.unittest.fixture.ArchiveFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
-
+import org.junit.Before;
+import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
@RunWith(JUnit4TestRunner.class)
@@ -90,7 +72,7 @@ public class SubsystemAdminTest extends
//@Test
public void test() throws Exception {
// make sure we are using a framework that provides composite admin service
- ScopeAdmin scopeA = getOsgiService(ScopeAdmin.class);
+ Scope scopeA = getOsgiService(Scope.class);
assertNotNull("composite admin should not be null", scopeA);
System.out.println("able to get composite admin service");
Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java Fri Mar 4 17:14:05 2011
@@ -25,6 +25,7 @@ public class SsActivator extends Abstrac
new EquinoxPlatformBuilder( bundleContext, "3.5.1" ),
new EquinoxPlatformBuilder( bundleContext, "3.6.0" ),
new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20110110" ),
+ new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20110221" ),
new EquinoxPlatformBuilderSnapshot( bundleContext )
};
}
Added: aries/trunk/subsystem/subsystem-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/resources/META-INF/platform-equinox/definition-3.7.0.V20110221.xml Fri Mar 4 17:14:05 2011
@@ -0,0 +1,8 @@
+<platform>
+
+ <name>Equinox 3.7.0</name>
+ <system>mvn:org.eclipse/osgi/3.7.0.v20110221</system>
+
+ <profile name="minimal" default="true"/>
+
+</platform>
Modified: aries/trunk/subsystem/subsystem-itests/src/test/resources/ss-runner.properties
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/resources/ss-runner.properties?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/resources/ss-runner.properties (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/resources/ss-runner.properties Fri Mar 4 17:14:05 2011
@@ -64,6 +64,7 @@ platform.equinox.3.5.1=org.ops4j.pax.run
platform.equinox.3.6.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
platform.equinox.SNAPSHOT=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
platform.equinox.3.7.0.V20110110=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
+platform.equinox.3.7.0.V20110221=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
# Felix
platform.felix.1.0.0=org.ops4j.pax.runner.platform.felix.internal.Activator
platform.felix.1.0.1=org.ops4j.pax.runner.platform.felix.internal.Activator
Modified: aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/InstallInfo.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/InstallInfo.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/InstallInfo.java (original)
+++ aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/InstallInfo.java Fri Mar 4 17:14:05 2011
@@ -18,6 +18,7 @@
*/
package org.apache.aries.subsystem.scope;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -26,15 +27,37 @@ import java.net.URL;
* update}.
*/
public class InstallInfo {
- private final URL content;
+ private final InputStream content;
private final String location;
- private final InputStream is;
+
+ /**
+ * Constructor for a bundle install info.
+ * @param content the content of the bundle.
+ * @param location the location of the bundle.
+ */
+ public InstallInfo(String location, URL content) throws IOException {
+ this(location == null ? content.toExternalForm() : location, content.openStream());
+ }
+
+ /**
+ * Constructor for a bundle install info.
+ * @param content the content of the bundle.
+ * @param location the location of the bundle.
+ */
+ public InstallInfo(String location, InputStream content) {
+ if (location == null || location.length() == 0)
+ throw new IllegalArgumentException("Missing required parameter: location");
+ if (content == null)
+ throw new NullPointerException("Missing required parameter: content");
+ this.location = location;
+ this.content = content;
+ }
/**
* Returns a url to the content of the bundle to install.
* @return a url to the content of the bundle to install.
*/
- public URL getContent() {
+ public InputStream getContent() {
return content;
}
@@ -45,26 +68,4 @@ public class InstallInfo {
public String getLocation() {
return location;
}
-
- /**
- * Constructor for a bundle install info.
- * @param content the content of the bundle.
- * @param location the location of the bundle.
- */
- public InstallInfo(URL content, String location) {
- this.content = content;
- this.location = location;
- this.is = null;
- }
-
- /**
- * Constructor for a bundle install info.
- * @param content the content of the bundle.
- * @param location the location of the bundle.
- */
- public InstallInfo(InputStream is, String location) {
- this.is = is;
- this.location = location;
- this.content = null;
- }
}
Modified: aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/Scope.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/Scope.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/Scope.java (original)
+++ aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/Scope.java Fri Mar 4 17:14:05 2011
@@ -74,13 +74,12 @@ public interface Scope {
long getId();
/**
- * destoy the scope
- */
- void destroy();
-
- /**
* Returns the install location String of the scope
* @return the install location String of the scope
*/
String getLocation();
+
+ Scope getParent();
+
+ ScopeUpdate newScopeUpdate();
}
Modified: aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeUpdate.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeUpdate.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeUpdate.java (original)
+++ aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/ScopeUpdate.java Fri Mar 4 17:14:05 2011
@@ -212,12 +212,6 @@ public interface ScopeUpdate {
boolean commit() throws BundleException;
/**
- * Returns the children scope to be removed
- * @return the to be removed children.
- */
- Collection<Scope> getToBeRemovedChildren();
-
- /**
* Returns the scope it is updating
* @return the scope it is updating
*/
Modified: aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/SharePolicy.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/SharePolicy.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/SharePolicy.java (original)
+++ aries/trunk/subsystem/subsystem-scope-api/src/main/java/org/apache/aries/subsystem/scope/SharePolicy.java Fri Mar 4 17:14:05 2011
@@ -50,8 +50,14 @@ public class SharePolicy {
* @param filter the filter for matching capabilities this policy controls.
*/
public SharePolicy(String type, String namespace, Filter filter) {
+ if (!(TYPE_EXPORT.equals(type) || TYPE_IMPORT.equals(type)))
+ throw new IllegalArgumentException("Invalid parameter value: type = " + type);
this.type = type;
+ if (namespace == null || namespace.length() == 0)
+ throw new IllegalArgumentException("Missing required paramater: namespace");
this.namespace = namespace;
+ if (filter == null)
+ throw new NullPointerException("Missing required parameter: filter");
this.filter = filter;
}
Modified: aries/trunk/subsystem/subsystem-scope-impl/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/pom.xml?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/pom.xml (original)
+++ aries/trunk/subsystem/subsystem-scope-impl/pom.xml Fri Mar 4 17:14:05 2011
@@ -45,38 +45,69 @@
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.api</artifactId>
+ <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>
+ <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.api</artifactId>
+ <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>
+ <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.eclipse</groupId>
<artifactId>osgi</artifactId>
- <version>3.7.0.v20101022</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
+ <version>3.7.0.v20110221</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.utils</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
@@ -90,6 +121,12 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.bundlerepository</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
Modified: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java (original)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java Fri Mar 4 17:14:05 2011
@@ -1,186 +1,161 @@
-/*
- * 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.impl;
-import java.lang.IllegalArgumentException;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.ScopeUpdate;
import org.apache.aries.subsystem.scope.SharePolicy;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.util.tracker.BundleTracker;
-import org.osgi.util.tracker.BundleTrackerCustomizer;
public class ScopeImpl implements Scope {
-
- private String name;
- private String location;
- private BundleContext context;
- private List<Scope> children = new ArrayList<Scope>();
- private List<Bundle> bundles = new ArrayList<Bundle>();
- private Map<String, List<SharePolicy>> importPolicies = new HashMap<String, List<SharePolicy>>();
- private Map<String, List<SharePolicy>> exportPolicies = new HashMap<String, List<SharePolicy>>();
- private BundleTracker bt;
- private long id;
- private List<String> bundleLocations = new ArrayList<String>();
-
- public ScopeImpl(String name) {
- this.name = name;
- this.id = getId();
- }
-
- public ScopeImpl(String name, String location) {
- this.name = name;
- this.location = location;
- this.id = getId();
- }
- // assume this constructor would be used to construct the root scope
- public ScopeImpl(String name, BundleContext context) {
- this(name);
-
- this.context = context;
- if (name.equals("root")) {
- bundles.addAll(Arrays.asList(context.getBundles()));
- }
-
-
- // let's use a bundle tracker to dynamically update the bundle list - need to wait on the resolution of the new rfc 138 bug
- // we cannot really use bundle tracker because the hooks may not work here
- //bt = new BundleTracker(context, Bundle.INSTALLED | Bundle.UNINSTALLED, new ScopeBundleTrackerCustomizer());
- //bt.open();
- }
-
- public void destroy() {
- /*if (bt != null) {
- bt.close();
- }*/
- }
-
- public Collection<Bundle> getBundles() {
- return Collections.unmodifiableCollection(bundles);
- }
-
- protected Collection<String> getToBeInstalledBundleLocation() {
- return bundleLocations;
- }
-
- protected void clearBundleLocations() {
- bundleLocations = new ArrayList<String>();
- }
-
- protected Collection<Bundle> getModifiableBundles() {
- return this.bundles;
- }
-
- public Collection<Scope> getChildren() {
- return Collections.unmodifiableList(children);
- }
-
- protected Collection<Scope> getModifiableChildren() {
- return this.children;
- }
-
- public String getName() {
- return this.name;
- }
-
- public Map<String, List<SharePolicy>> getSharePolicies(String type) {
- if (type.equals(SharePolicy.TYPE_IMPORT)) {
- return Collections.unmodifiableMap(this.importPolicies);
- } else if (type.equals(SharePolicy.TYPE_EXPORT)) {
- return Collections.unmodifiableMap(this.exportPolicies);
- }
- throw new IllegalArgumentException("Valid Types are : " + SharePolicy.TYPE_EXPORT + " & " +
- SharePolicy.TYPE_IMPORT + " Invalid type: " + type);
-
- }
-
- protected Map<String, List<SharePolicy>> getModifiableSharePolicies(String type) {
- if (type.equals(SharePolicy.TYPE_IMPORT)) {
- return this.importPolicies;
- } else if (type.equals(SharePolicy.TYPE_EXPORT)) {
- return this.exportPolicies;
- }
- throw new IllegalArgumentException("Valid Types are : " + SharePolicy.TYPE_EXPORT + " & " +
- SharePolicy.TYPE_IMPORT + " Invalid type: " + type);
- }
-
- private class ScopeBundleTrackerCustomizer implements BundleTrackerCustomizer {
-
- public Object addingBundle(Bundle bundle, BundleEvent event) {
- if (event.getType() == BundleEvent.INSTALLED) {
- bundles.add(bundle);
- } else if (event.getType() == BundleEvent.UNINSTALLED) {
- bundles.remove(bundle);
- }
-
- return bundle;
- }
-
- public void modifiedBundle(Bundle bundle, BundleEvent event,
- Object object) {
- if (event.getType() == BundleEvent.INSTALLED) {
- bundles.add(bundle);
- } else if (event.getType() == BundleEvent.UNINSTALLED) {
- bundles.remove(bundle);
- }
-
- }
-
- public void removedBundle(Bundle bundle, BundleEvent event,
- Object object) {
- if (event.getType() == BundleEvent.INSTALLED) {
- bundles.add(bundle);
- } else if (event.getType() == BundleEvent.UNINSTALLED) {
- bundles.remove(bundle);
- }
- }
-
- }
-
- public long getId() {
- if (id == 0) {
- id = IdGenerator.next();
- }
-
- return id;
- }
-
- private static class IdGenerator {
- static long newId;
-
- protected static synchronized long next() {
- newId++;
- return newId;
- }
- }
-
- public String getLocation() {
- return this.location;
- }
-
+ private static class UnmodifiableSharePolicyMap implements Map<String, List<SharePolicy>> {
+ private final Map<String, List<SharePolicy>> map;
+
+ public UnmodifiableSharePolicyMap(Map<String, List<SharePolicy>> map) {
+ this.map = map;
+ }
+
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsKey(Object key) {
+ return map.containsKey(key);
+ }
+
+ public boolean containsValue(Object value) {
+ return map.containsValue(value);
+ }
+
+ public Set<java.util.Map.Entry<String, List<SharePolicy>>> entrySet() {
+ Set<Map.Entry<String, List<SharePolicy>>> result = new HashSet<Map.Entry<String, List<SharePolicy>>>(map.size());
+ for (final Map.Entry<String, List<SharePolicy>> entry : map.entrySet()) {
+ result.add(new Map.Entry<String, List<SharePolicy>>() {
+ public String getKey() {
+ return entry.getKey();
+ }
+
+ public List<SharePolicy> getValue() {
+ return entry.getValue();
+ }
+
+ public List<SharePolicy> setValue(List<SharePolicy> object) {
+ throw new UnsupportedOperationException();
+ }
+ });
+ }
+ return Collections.unmodifiableSet(result);
+ }
+
+ public List<SharePolicy> get(Object key) {
+ List<SharePolicy> result = map.get(key);
+ return result == null ? null : Collections.unmodifiableList(result);
+ }
+
+ public boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ public Set<String> keySet() {
+ return Collections.unmodifiableSet(map.keySet());
+ }
+
+ public List<SharePolicy> put(String key, List<SharePolicy> value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void putAll(Map<? extends String, ? extends List<SharePolicy>> map) {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<SharePolicy> remove(Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ public int size() {
+ return map.size();
+ }
+
+ public Collection<List<SharePolicy>> values() {
+ return Collections.unmodifiableCollection(map.values());
+ }
+ }
+
+ private static long lastId = -1;
+
+ private static synchronized long nextId() {
+ if (lastId == Long.MAX_VALUE)
+ throw new IllegalStateException("The next ID would exceed Long.MAX_VALUE");
+ return ++lastId;
+ }
+
+ volatile boolean updating;
+
+ long lastUpdate;
+
+ final BundleContext bundleContext;
+ final Set<Bundle> bundles = Collections.synchronizedSet(new HashSet<Bundle>());
+ final Set<Scope> children = Collections.synchronizedSet(new HashSet<Scope>());
+ final Map<String, List<SharePolicy>> exportPolicies = Collections.synchronizedMap(new HashMap<String, List<SharePolicy>>());
+ final Map<String, List<SharePolicy>> importPolicies = Collections.synchronizedMap(new HashMap<String, List<SharePolicy>>());
+
+ private final long id;
+ private final String location;
+ private final String name;
+ private final Scope parent;
+
+ public ScopeImpl(
+ BundleContext bundleContext,
+ String name,
+ String location,
+ Scope parent) {
+ this.bundleContext = bundleContext;
+ this.name = name;
+ this.location = location;
+ this.parent = parent;
+ id = nextId();
+ }
+
+ public Collection<Bundle> getBundles() {
+ return Collections.unmodifiableCollection(bundles);
+ }
+
+ public Collection<Scope> getChildren() {
+ return Collections.unmodifiableCollection(children);
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Scope getParent() {
+ return parent;
+ }
+
+ public Map<String, List<SharePolicy>> getSharePolicies(String type) {
+ if (SharePolicy.TYPE_EXPORT.equals(type))
+ return new UnmodifiableSharePolicyMap(exportPolicies);
+ else if (SharePolicy.TYPE_IMPORT.equals(type))
+ return new UnmodifiableSharePolicyMap(importPolicies);
+ throw new IllegalArgumentException(type);
+ }
+
+ public ScopeUpdate newScopeUpdate() {
+ return ScopeUpdateImpl.newInstance(this);
+ }
}
Added: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeManager.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeManager.java?rev=1078060&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeManager.java (added)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeManager.java Fri Mar 4 17:14:05 2011
@@ -0,0 +1,340 @@
+package org.apache.aries.subsystem.scope.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.aries.subsystem.scope.Scope;
+import org.apache.aries.subsystem.scope.SharePolicy;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.hooks.service.ListenerHook.ListenerInfo;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+public class ScopeManager {
+ static final Map<Bundle, ScopeImpl> bundleToScope = Collections.synchronizedMap(new HashMap<Bundle, ScopeImpl>());
+ static final Map<String, ScopeImpl> installingBundleToScope = Collections.synchronizedMap(new HashMap<String, ScopeImpl>());
+
+ final ScopeImpl rootScope;
+
+ private final BundleContext bundleContext;
+
+ public ScopeManager(BundleContext bundleContext) throws BundleException {
+ this.bundleContext = bundleContext;
+ rootScope = new ScopeImpl(bundleContext, "root", null, null);
+ }
+
+ public Scope getRootScope() {
+ return rootScope;
+ }
+
+ public EventHook newEventHook() {
+ return new EventHook();
+ }
+
+ public EventListenerHook newEventListenerHook() {
+ return new EventListenerHook();
+ }
+
+ public org.osgi.framework.hooks.bundle.FindHook newBundleFindHook() {
+ return new BundleFindHook();
+ }
+
+ public ResolverHook newResolverHook() {
+ return new ResolverHook();
+ }
+
+ public ResolverHookFactory newResolverHookFactory() {
+ return new ResolverHookFactory();
+ }
+
+ public ServiceFactory newServiceFactory() {
+ return new ServiceFactory();
+ }
+
+ public org.osgi.framework.hooks.service.FindHook newServiceFindHook() {
+ return new ServiceFindHook();
+ }
+
+ private class EventHook implements org.osgi.framework.hooks.bundle.EventHook {
+ public void event(BundleEvent event, Collection<BundleContext> contexts) {
+ int type = event.getType();
+ if (type == BundleEvent.INSTALLED)
+ handleInstalledEvent(event);
+ handleAnyEvent(event, contexts);
+ if (type == BundleEvent.UNINSTALLED)
+ handleUninstalledEvent(event);
+ }
+
+ private void handleAnyEvent(BundleEvent event, Collection<BundleContext> contexts) {
+ // All bundles may see system bundle lifecycle changes.
+ if (event.getBundle().getBundleId() != 0) {
+ // Otherwise, only bundles in the same scope as the bundle undergoing
+ // the state change may see the event.
+ ScopeImpl scope = bundleToScope.get(event.getBundle());
+ Collection<Bundle> bundles = scope.getBundles();
+ for (Iterator<BundleContext> i = contexts.iterator(); i.hasNext();) {
+ BundleContext bc = i.next();
+ if (!bundles.contains(bc.getBundle()))
+ i.remove();
+ }
+ }
+ }
+
+ private void handleInstalledEvent(BundleEvent event) {
+ processOriginBundleOnInstall(event);
+ processSourceBundleOnInstall(event);
+ }
+
+ private void handleUninstalledEvent(BundleEvent event) {
+ processSourceBundleOnUninstall(event);
+ }
+
+ private void processOriginBundleOnInstall(BundleEvent event) {
+ Bundle b = event.getOrigin();
+ // There's a brief window when Scope Admin is initializing where it's
+ // possible for the origin bundle to not be in a scope.
+ if (bundleToScope.get(b) == null) {
+ bundleToScope.put(b, rootScope);
+ rootScope.bundles.add(b);
+ }
+ }
+
+ private void processSourceBundleOnInstall(BundleEvent event) {
+ Bundle b = event.getBundle();
+ // If the installer is not Scope Admin, add the installed bundle
+ // to the installer's scope.
+ if (event.getOrigin().getBundleId() != bundleContext.getBundle().getBundleId()) {
+ ScopeImpl s = bundleToScope.get(event.getOrigin());
+ bundleToScope.put(b, s);
+ s.bundles.add(b);
+ }
+ else {
+ ScopeImpl s = installingBundleToScope.remove(b.getLocation());
+ bundleToScope.put(b, s);
+ s.bundles.add(b);
+ }
+ }
+
+ private void processSourceBundleOnUninstall(BundleEvent event) {
+ Bundle b = event.getBundle();
+ ScopeImpl s = bundleToScope.remove(b);
+ // There's a brief window when Scope Admin is initializing where it's
+ // possible for the scope to be null.
+ if (s != null) {
+ s.bundles.remove(b);
+ }
+ }
+ }
+
+ private class BundleFindHook implements org.osgi.framework.hooks.bundle.FindHook {
+ public void find(BundleContext context, Collection<Bundle> bundles) {
+ Scope scope = bundleToScope.get(context.getBundle());
+ // A bundle may only see other bundles within its scope.
+ bundles.retainAll(scope.getBundles());
+ }
+ }
+
+ private class EventListenerHook implements org.osgi.framework.hooks.service.EventListenerHook {
+ public void event(ServiceEvent event, Map<BundleContext, Collection<ListenerInfo>> listeners) {
+ Bundle bundle = event.getServiceReference().getBundle();
+ ScopeImpl scope = bundleToScope.get(bundle);
+ for (Iterator<BundleContext> i = listeners.keySet().iterator(); i.hasNext();) {
+ if (!scope.getBundles().contains(i.next().getBundle()))
+ i.remove();
+ }
+ }
+ }
+
+ private class ResolverHook implements org.osgi.framework.hooks.resolver.ResolverHook {
+ public void end() {
+ }
+
+ public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
+ for (Iterator<BundleCapability> i = candidates.iterator(); i.hasNext();) {
+ if (filterMatch(requirement, i.next()))
+ i.remove();
+ }
+ }
+
+ public void filterResolvable(Collection<BundleRevision> candidates) {
+ for (Iterator<BundleRevision> i = candidates.iterator(); i.hasNext();) {
+ BundleRevision candidate = i.next();
+ ScopeImpl scope = bundleToScope.get(candidate.getBundle());
+ if (scope.updating)
+ i.remove();
+ }
+ }
+
+ public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
+ ScopeImpl scope = bundleToScope.get(singleton.getRevision().getBundle());
+ for (Iterator<BundleCapability> i = collisionCandidates.iterator(); i.hasNext();) {
+ BundleCapability collisionCandidate = i.next();
+ if (!scope.getBundles().contains(collisionCandidate.getRevision().getBundle())) {
+ i.remove();
+ }
+ }
+ }
+
+ private boolean filterMatch(BundleRequirement requirement, BundleCapability capability) {
+ Scope scope = bundleToScope.get(requirement.getRevision().getBundle());
+ if (scope.getBundles().contains(capability.getRevision().getBundle()))
+ return false;
+ if (scope.getId() < bundleToScope.get(capability.getRevision().getBundle()).getId()) {
+ if (matchesDescendants(scope.getChildren(), capability, null))
+ return false;
+ }
+ return !matchesAncestry(scope, capability);
+ }
+
+ private boolean matchesPolicyAndContainsBundle(Scope scope, BundleCapability capability, String sharePolicyType) {
+ if (matchesPolicy(scope, capability, sharePolicyType)) {
+ if (scope.getBundles().contains(capability.getRevision().getBundle())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesPolicy(Scope scope, BundleCapability capability, String sharePolicyType) {
+ List<SharePolicy> policies = scope.getSharePolicies(sharePolicyType).get(capability.getNamespace());
+ if (policies == null) return false;
+ for (SharePolicy policy : policies) {
+ if (policy.getFilter().matches(capability.getAttributes())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesAncestry(Scope scope, BundleCapability capability) {
+ if (matchesPolicy(scope, capability, SharePolicy.TYPE_IMPORT)) {
+ Scope parent = scope.getParent();
+ if (parent != null) {
+ if (parent.getBundles().contains(capability.getRevision().getBundle()))
+ return true;
+ if (matchesDescendants(parent.getChildren(), capability, scope))
+ return true;
+ return matchesAncestry(parent, capability);
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesDescendant(Scope child, BundleCapability capability) {
+ if (matchesPolicyAndContainsBundle(child, capability, SharePolicy.TYPE_EXPORT))
+ return true;
+ return matchesDescendants(child.getChildren(), capability, null);
+ }
+
+ private boolean matchesDescendants(Collection<Scope> children, BundleCapability capability, Scope skip) {
+ for (Scope child : children) {
+ if (child.equals(skip))
+ continue;
+ if (matchesDescendant(child, capability)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
+ private class ResolverHookFactory implements org.osgi.framework.hooks.resolver.ResolverHookFactory {
+ public ResolverHook begin(java.util.Collection<BundleRevision> triggers) {
+ return new ResolverHook();
+ }
+ }
+
+ private class ServiceFactory implements org.osgi.framework.ServiceFactory<Scope> {
+ public Scope getService(Bundle b, ServiceRegistration<Scope> sr) {
+ ScopeImpl scope = bundleToScope.get(b);
+ if (scope == null) {
+ scope = rootScope;
+ bundleToScope.put(b, scope);
+ }
+ return scope;
+ }
+
+ public void ungetService(Bundle b, ServiceRegistration<Scope> sr, Scope s) {
+ }
+ }
+
+ private class ServiceFindHook implements org.osgi.framework.hooks.service.FindHook {
+ public void find(BundleContext context, String name, String filter, boolean allServices, Collection<ServiceReference<?>> references) {
+ // System bundle can see all services.
+ if (context.getBundle().getBundleId() == 0) return;
+ for (Iterator<ServiceReference<?>> i = references.iterator(); i.hasNext();) {
+ if (filterMatch(context, i.next()))
+ i.remove();
+ }
+ }
+
+ private boolean filterMatch(BundleContext context, ServiceReference<?> reference) {
+ Scope scope = bundleToScope.get(context.getBundle());
+ if (scope.getBundles().contains(reference.getBundle()))
+ return false;
+ if (scope.getId() < bundleToScope.get(reference.getBundle()).getId()) {
+ if (matchesDescendants(scope.getChildren(), reference))
+ return false;
+ }
+ return !matchesAncestry(scope, reference);
+ }
+
+ private boolean matchesPolicyAndContainsBundle(Scope scope, ServiceReference<?> reference, String sharePolicyType) {
+ if (matchesPolicy(scope, reference, sharePolicyType)) {
+ if (scope.getBundles().contains(reference.getBundle())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesPolicy(Scope scope, ServiceReference<?> reference, String sharePolicyType) {
+ List<SharePolicy> policies = scope.getSharePolicies(sharePolicyType).get("scope.share.service");
+ if (policies == null) return false;
+ for (SharePolicy policy : policies) {
+ if (policy.getFilter().match(reference)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesAncestry(Scope scope, ServiceReference<?> reference) {
+ if (matchesPolicy(scope, reference, SharePolicy.TYPE_IMPORT)) {
+ Scope parent = scope.getParent();
+ if (parent != null) {
+ if (parent.getBundles().contains(reference.getBundle()))
+ return true;
+ return matchesAncestry(parent, reference);
+ }
+ }
+ return false;
+ }
+
+ private boolean matchesDescendant(Scope child, ServiceReference<?> reference) {
+ if (matchesPolicyAndContainsBundle(child, reference, SharePolicy.TYPE_EXPORT))
+ return true;
+ return matchesDescendants(child.getChildren(), reference);
+ }
+
+ private boolean matchesDescendants(Collection<Scope> children, ServiceReference<?> reference) {
+ for (Scope child : children) {
+ if (matchesDescendant(child, reference)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+}
Modified: aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java?rev=1078060&r1=1078059&r2=1078060&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java (original)
+++ aries/trunk/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java Fri Mar 4 17:14:05 2011
@@ -1,336 +1,213 @@
-/*
- * 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.impl;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.Set;
import org.apache.aries.subsystem.scope.InstallInfo;
import org.apache.aries.subsystem.scope.Scope;
-import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.subsystem.scope.ScopeUpdate;
import org.apache.aries.subsystem.scope.SharePolicy;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.condpermadmin.ConditionInfo;
-import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
-import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
-import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;
-import org.osgi.service.permissionadmin.PermissionInfo;
public class ScopeUpdateImpl implements ScopeUpdate {
-
- private ScopeImpl scope;
- private List<InstallInfo> installInfo = new ArrayList<InstallInfo>();
- private List<ScopeUpdate> children = new ArrayList<ScopeUpdate>();
- private List<Scope> tbrChildren = new ArrayList<Scope>();
- private BundleContext bc;
- private static ConcurrentHashMap<Long, ServiceRegistration> srs = new ConcurrentHashMap<Long, ServiceRegistration>();
- private final static PermissionInfo[] denyInfo =
- {
- new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.condpermadmin.ConditionalPermissionAdmin", "*"),
- new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.permissionadmin.PermissionAdmin", "*"),
- new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.framework.hooks.service.*", "*"),
- new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.packageadmin.PackageAdmin", "*")
- };
-
- private final static PermissionInfo[] allowInfo = {
- new PermissionInfo("org.osgi.framework.PackagePermission", "*", "import"),
- new PermissionInfo("org.osgi.framework.BundlePermission", "*", "host,provide,fragment"),
- };
-
- private final static PermissionInfo[] defaultAllowInfo = {
- new PermissionInfo("java.lang.RuntimePermission", "loadLibrary.*", "*"),
- new PermissionInfo("java.lang.RuntimePermission", "queuePrintJob", "*"),
- new PermissionInfo("java.net.SocketPermission", "*", "connect"),
- new PermissionInfo("java.util.PropertyPermission", "*", "read"),
- new PermissionInfo("org.osgi.framework.PackagePermission", "*", "exportonly,import"),
- new PermissionInfo("org.osgi.framework.ServicePermission", "*", "get,register"),
- };
-
- public ScopeUpdateImpl(ScopeImpl scope, BundleContext bc) {
- this.scope = scope;
- this.bc = bc;
- }
-
- public ScopeUpdateImpl(ScopeImpl scope, List<InstallInfo> installInfo) {
- this.scope = scope;
- this.installInfo = installInfo;
- }
-
-
- public ScopeUpdateImpl(ScopeImpl scope, List<InstallInfo> installInfo, List<ScopeUpdate> children) {
- this.scope = scope;
- this.installInfo = installInfo;
- this.children = children;
- }
-
- public ScopeImpl getScope() {
- return this.scope;
- }
-
- public boolean commit() throws BundleException {
- // process installedBundle
- boolean success = false;
- int numException = 0;
-
- List<Bundle> installedBundle = new ArrayList<Bundle>();
- for (InstallInfo info : this.installInfo) {
- URL url = info.getContent();
- String loc = info.getLocation();
- Bundle b;
- Bundle oldB = alreadyInstalled(info);
-
- // in case of modify, uninstall the previous bundle first.
- if (oldB != null) {
- oldB.uninstall();
- getBundles().remove(oldB);
- }
-
- try {
- // prefix location with scope-scopeId:
- loc = "scope-" + this.getScope().getId() + ": " + loc;
- scope.getToBeInstalledBundleLocation().add(loc);
- b = bc.installBundle(loc, url.openStream());
- installedBundle.add(b);
- } catch (IOException e) {
- // clear bundle location off the list.
- scope.getToBeInstalledBundleLocation().remove(loc);
- numException++;
- throw new BundleException("problem when opening url " + e.getCause());
- }
- scope.getToBeInstalledBundleLocation().remove(loc);
- }
-
- // clear bundle location list since all install is finished.
- scope.clearBundleLocations();
-
- // update bundle list for the scope
- getBundles().addAll(installedBundle);
-
-
- // Sets up Java 2 security permissions for the application
- try {
- boolean suc = setupJava2Security(scope.getLocation());
- if (!suc) {
- numException++;
- }
- } catch (BundleException ex) {
- numException++;
- throw ex;
- }
-
- // process child scopes
- Collection<ScopeUpdate> children = getChildren();
- for (ScopeUpdate child : children) {
-
- ScopeUpdateImpl scopeUpdateImpl = (ScopeUpdateImpl)child;
- ServiceRegistration sr = null;
- try {
- // also create a new scopeAdmin as scopeadmin and scope is 1-1 relationship
- ScopeAdminImpl newScopeAdmin = new ScopeAdminImpl(this.scope, scopeUpdateImpl.getScope());
-
-
- sr = this.bc.registerService(ScopeAdmin.class.getName(),
- newScopeAdmin,
- DictionaryBuilder.build("ScopeName", child.getName(), "ScopeId", scopeUpdateImpl.getScope().getId()));
- srs.put(scopeUpdateImpl.getScope().getId(), sr);
- child.commit();
- } catch (BundleException e) {
- if (sr != null) {
- sr.unregister();
- srs.remove(scopeUpdateImpl.getScope().getId());
- }
- numException++;
- throw new BundleException("problem when commiting child scope: " + child.getName() + " " + e.getCause());
- }
-
-
- // update current scope to specify the children.
- getExistingChildren().add(scopeUpdateImpl.getScope());
-
-
- }
- // remove any scopes in to be removed children list
- for (Scope scope : tbrChildren) {
- removeChildScope(scope);
- }
-
- return numException == 0 ? true : false;
- }
-
- private boolean setupJava2Security(String location) throws BundleException {
- // obtain security manager
- SecurityManager secMan = System.getSecurityManager();
-
- if (secMan == null) {
- return true;
- }
-
- ServiceReference permRef = bc.getServiceReference(ConditionalPermissionAdmin.class.getName());
-
- ConditionalPermissionAdmin permAdmin = (ConditionalPermissionAdmin) bc.getService(permRef);
- ConditionalPermissionUpdate update = permAdmin.newConditionalPermissionUpdate();
-
- List<ConditionalPermissionInfo> infos = update.getConditionalPermissionInfos();
- //infos.clear();
-
- // set up the conditionInfo
- String scopePrefix = "scope-" + this.scope.getId() + "-*";
- ConditionInfo[] conditionInfo = new ConditionInfo[] {new ConditionInfo("org.osgi.service.condpermadmin.BundleLocationCondition", new String[]{scopePrefix})};
- // Set up permissions which are common to all applications
- infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, denyInfo, "deny"));
- infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, allowInfo, "allow"));
-
- // exact scope permission from scope installation loc
- // TODO: need to figure out the permFile from the scope/subsystem, META-INF/permissions.perm
- // Also add code to handle the permission file
- File permFile = new File("META-INF/permissions.perm");
- if (!permFile.exists()) {
- /*
- * If there is no specific permissions file provided, the following
- * default permissions are provided.
- */
- infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, defaultAllowInfo, "allow"));
-
- }
-
- if (!update.commit()) {
- return false;
- }
-
- return true;
-
-
- }
-
- // check if the install info is already installed in the scope
- private Bundle alreadyInstalled(InstallInfo info) {
- String loc = info.getLocation();
-
- Collection<Bundle> bundles = scope.getBundles();
-
- for (Bundle b : bundles) {
- if (b.getLocation().equals(loc)) {
- return b;
- }
- }
-
- return null;
- }
-
- public Collection<Bundle> getBundles() {
- return scope.getModifiableBundles();
- }
-
- public List<InstallInfo> getBundlesToInstall() {
- return this.installInfo;
- }
-
- /*public List<InstallInfo> getBundlesToDelete() {
- return this.installInfo;
- }
-
- public List<InstallInfo> getBundlesToModify() {
- return this.installInfo;
- }*/
-
- public Collection<ScopeUpdate> getChildren() {
- return this.children;
- }
-
- public Collection<Scope> getExistingChildren() {
- return scope.getModifiableChildren();
- }
-
- public Collection<Scope> getToBeRemovedChildren() {
- return this.tbrChildren;
- }
-
- // this would remove the child off the scope and uninstall the scope.
- private void removeChildScope(Scope sc) {
- removeChildScope(sc.getId());
- }
- // this would remove the child off the scope and uninstall the scope.
- private void removeChildScope(long id) {
- Collection<Scope> scopes = scope.getModifiableChildren();
- for (Scope scope : scopes) {
- if (scope.getId() == id) {
- for (Bundle b : scope.getBundles()) {
- try {
- b.uninstall();
- } catch (BundleException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- scopes.remove(scope);
- // unregister the associated ScopeAdmin in service registry
- ServiceRegistration sr = srs.get(id);
- if (sr != null) {
- sr.unregister();
- srs.remove(id);
- } else {
- throw new NullPointerException ("Unable to find the ScopeAdmin service Registration in the map");
- }
- return;
- }
- }
- }
-
- public String getName() {
- return scope.getName();
- }
-
- public Map<String, List<SharePolicy>> getSharePolicies(String type) {
- return scope.getModifiableSharePolicies(type);
- }
-
- public ScopeUpdate newChild(String name) {
- ScopeImpl newScope = new ScopeImpl(name);
-
- // create scope update
- ScopeUpdate scopeUpdate = new ScopeUpdateImpl(newScope, this.bc);
- this.children.add(scopeUpdate);
- return scopeUpdate;
- }
-
- public ScopeUpdate newChild(String name, String location) {
- ScopeImpl newScope = new ScopeImpl(name, location);
-
- // create scope update
- ScopeUpdate scopeUpdate = new ScopeUpdateImpl(newScope, this.bc);
- this.children.add(scopeUpdate);
- return scopeUpdate;
- }
-}
+ public static ScopeUpdateImpl newInstance(ScopeImpl scope) {
+ ScopeUpdateImpl scopeUpdate = new ScopeUpdateImpl(null, null, scope, null);
+ for (Scope child : scopeUpdate.scope.getChildren()) {
+ scopeUpdate.children.add(new ScopeUpdateImpl(null, null, (ScopeImpl)child, scopeUpdate));
+ }
+ return scopeUpdate;
+ }
+
+ public static ScopeUpdateImpl newInstance(String name, String location, ScopeUpdateImpl parent) {
+ return new ScopeUpdateImpl(name, location, null, parent);
+ }
+
+ private static long lastId;
+ private static synchronized long nextId() {
+ if (lastId == Long.MAX_VALUE)
+ throw new IllegalStateException("The next ID would exceed Long.MAX_VALUE");
+ return ++lastId;
+ }
+
+ private final Set<Bundle> bundles;
+ private final List<InstallInfo> bundlesToInstall = new ArrayList<InstallInfo>();
+ private final Set<ScopeUpdate> children = new HashSet<ScopeUpdate>();
+ private final Map<String, List<SharePolicy>> exportPolicies;
+ private final long id = nextId();
+ private final Map<String, List<SharePolicy>> importPolicies;
+ private final ScopeUpdateImpl parent;
+ private final ScopeImpl scope;
+
+ private ScopeUpdateImpl(
+ String name,
+ String location,
+ ScopeImpl scope,
+ ScopeUpdateImpl parent) {
+ if (scope == null)
+ scope = new ScopeImpl(parent.scope.bundleContext, name, location, parent.scope);
+ this.scope = scope;
+ this.parent = parent;
+ bundles = new HashSet<Bundle>(scope.getBundles());
+ exportPolicies = new HashMap<String, List<SharePolicy>>(scope.getSharePolicies(SharePolicy.TYPE_EXPORT));
+ importPolicies = new HashMap<String, List<SharePolicy>>(scope.getSharePolicies(SharePolicy.TYPE_IMPORT));
+ }
+
+ public boolean commit() throws BundleException {
+ if (parent != null)
+ throw new IllegalStateException("Only the root ScopeUpdate may be committed");
+ return commit0();
+ }
+
+ public Collection<Bundle> getBundles() {
+ return bundles;
+ }
+
+ public List<InstallInfo> getBundlesToInstall() {
+ return bundlesToInstall;
+ }
+
+ public Collection<ScopeUpdate> getChildren() {
+ return children;
+ }
+
+ public String getName() {
+ return scope.getName();
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ public Map<String, List<SharePolicy>> getSharePolicies(String type) {
+ if (SharePolicy.TYPE_EXPORT.equals(type))
+ return exportPolicies;
+ else if (SharePolicy.TYPE_IMPORT.equals(type))
+ return importPolicies;
+ throw new IllegalArgumentException(type);
+ }
+
+ public ScopeUpdate newChild(String name) {
+ return newChild(name, null);
+ }
+
+ public ScopeUpdate newChild(String name, String location) {
+ return ScopeUpdateImpl.newInstance(name, location, this);
+ }
+
+ private void addBundles() {
+ for (Bundle b : getBundles()) {
+ if (!getScope().getBundles().contains(b)) {
+ if (contains(b, this)) {
+ throw new IllegalStateException("Bundle " + b.getSymbolicName() + " being added to scope " + getName() + " but already exists in another scope");
+ }
+ scope.bundles.add(b);
+ ScopeManager.bundleToScope.put(b, scope);
+ }
+ }
+ }
+
+ private boolean commit0() throws BundleException {
+ if (scope.lastUpdate > id)
+ return false;
+ scope.updating = true;
+ for (ScopeUpdate child : children) {
+ if (!((ScopeUpdateImpl)child).commit0())
+ return false;
+ }
+ removeBundles();
+ addBundles();
+ installBundles();
+ uninstallScopes();
+ installScopes();
+ updateSharePolicies();
+ scope.lastUpdate = id;
+ scope.updating = false;
+ return true;
+ }
+
+ private boolean contains(Bundle bundle, ScopeUpdateImpl scopeUpdate) {
+ // Recurse to the top of the tree and then perform a depth-first search.
+ return parent == null ? contains0(bundle, scopeUpdate) : parent.contains(bundle, scopeUpdate);
+ }
+
+ private boolean contains0(Bundle bundle, ScopeUpdateImpl scopeUpdate) {
+ if (!equals(scopeUpdate) && bundles.contains(bundle))
+ return true;
+ // Depth-first search.
+ for (ScopeUpdate child : children) {
+ if (((ScopeUpdateImpl)child).contains0(bundle, scopeUpdate)) return true;
+ }
+ return false;
+ }
+
+ private void installBundles() throws BundleException {
+ for (InstallInfo installInfo : getBundlesToInstall()) {
+ ScopeManager.installingBundleToScope.put(installInfo.getLocation(), scope);
+ scope.bundleContext.installBundle(installInfo.getLocation(), installInfo.getContent());
+ }
+ }
+
+ private void installScopes() {
+ for (ScopeUpdate child : getChildren()) {
+ if (!getScope().getChildren().contains(child.getScope())) {
+ scope.children.add(child.getScope());
+ }
+ }
+ }
+
+ private void removeBundles() throws BundleException {
+ Collection<Bundle> bundles = new HashSet<Bundle>(scope.getBundles());
+ for (Bundle b : bundles) {
+ if (!getBundles().contains(b)) {
+ if (!contains(b, null)) {
+ b.uninstall();
+ }
+ else {
+ scope.bundles.remove(b);
+ }
+ }
+ }
+ }
+
+ private void uninstallScopes() throws BundleException {
+ for (Iterator<Scope> i = scope.children.iterator(); i.hasNext();) {
+ Scope child = i.next();
+ boolean found = false;
+ for (ScopeUpdate su : getChildren()) {
+ if (child.equals(su.getScope())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ Collection<Bundle> bundles = new HashSet<Bundle>(child.getBundles());
+ for (Bundle b : bundles) {
+ b.uninstall();
+ }
+ i.remove();
+ }
+ }
+ }
+
+ private void updateSharePolicies() {
+ updateExportSharePolicies(getSharePolicies(SharePolicy.TYPE_EXPORT));
+ updateImportSharePolicies(getSharePolicies(SharePolicy.TYPE_IMPORT));
+ }
+
+ private void updateExportSharePolicies(Map<String, List<SharePolicy>> exportPolicies) {
+ scope.exportPolicies.clear();
+ scope.exportPolicies.putAll(exportPolicies);
+ }
+
+ private void updateImportSharePolicies(Map<String, List<SharePolicy>> importPolicies) {
+ scope.importPolicies.clear();
+ scope.importPolicies.putAll(importPolicies);
+ }
+ }