aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1717826 [2/3] - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-core/src/test/java/org/apache/aries/subsystem...
Date Thu, 03 Dec 2015 18:25:00 GMT
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java
Thu Dec  3 18:25:00 2015
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.aries.subsystem.core.archive.AriesSubsystemParentsHeader;
 import org.apache.aries.subsystem.core.archive.Attribute;
 import org.apache.aries.subsystem.core.archive.DeployedContentHeader;
 import org.apache.aries.subsystem.core.archive.DeploymentManifest;
@@ -95,21 +96,34 @@ public class SubsystemResource implement
 		this.resource = resource;
 		computeContentResources(resource.getDeploymentManifest());
 		capabilities = computeCapabilities();
-		computeDependencies(resource.getDeploymentManifest());
+		if (this.getSubsystemManifest().getSubsystemTypeHeader().getAriesProvisionDependenciesDirective().isInstall())
{
+		    /* compute dependencies now only if we intend to provision them during install */
+	        computeDependencies(resource.getDeploymentManifest());		    
+		}
 		deploymentManifest = computeDeploymentManifest();
 	}
 
 	public SubsystemResource(File file) throws IOException, URISyntaxException, ResolutionException,
BundleException, InvalidSyntaxException {
-		this(FileSystem.getFSRoot(file));
+		this(null, FileSystem.getFSRoot(file));
 	}
 
-	public SubsystemResource(IDirectory directory) throws IOException, URISyntaxException, ResolutionException,
BundleException, InvalidSyntaxException {
-		parent = null;
+	public SubsystemResource(BasicSubsystem subsystem, IDirectory directory) throws IOException,
URISyntaxException, ResolutionException, BundleException, InvalidSyntaxException {
+		if (subsystem == null) {
+			// This is intended to only support the case where the root subsystem
+			// is being initialized from a non-persistent state.
+			parent = null;
+		}
+		else {
+			parent = Utils.findScopedSubsystemInRegion(subsystem);
+		}
 		resource = new RawSubsystemResource(directory, parent);
 		deploymentManifest = resource.getDeploymentManifest();
 		computeContentResources(deploymentManifest);
 		capabilities = computeCapabilities();
-		computeDependencies(deploymentManifest);
+        if (getSubsystemManifest().getSubsystemTypeHeader().getAriesProvisionDependenciesDirective().isInstall())
{
+            /* compute dependencies if we intend to provision them during install */
+            computeDependencies(resource.getDeploymentManifest());          
+        }
 	}
 
 	@Override
@@ -193,13 +207,15 @@ public class SubsystemResource implement
 	
 	public Collection<BasicSubsystem> getParents() {
 		if (parent == null) {
-			Header<?> header = getDeploymentManifest().getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_PARENTS);
+			AriesSubsystemParentsHeader header = getDeploymentManifest().getAriesSubsystemParentsHeader();
 			if (header == null)
 				return Collections.emptyList();
-			String[] parentIds = header.getValue().split(",");
-			Collection<BasicSubsystem> result = new ArrayList<BasicSubsystem>(parentIds.length);
-			for (String parentId : parentIds)
-				result.add(Activator.getInstance().getSubsystems().getSubsystemById(Long.valueOf(parentId)));
+			Collection<AriesSubsystemParentsHeader.Clause> clauses = header.getClauses();
+			Collection<BasicSubsystem> result = new ArrayList<BasicSubsystem>(clauses.size());
+			Subsystems subsystems = Activator.getInstance().getSubsystems();
+			for (AriesSubsystemParentsHeader.Clause clause : clauses) {
+				result.add(subsystems.getSubsystemById(clause.getId()));
+			}
 			return result;
 		}
 		return Collections.singleton(parent);
@@ -351,20 +367,21 @@ public class SubsystemResource implement
 		}
 	}
 
-	private void computeDependencies(DeploymentManifest manifest) {
-		if (manifest == null)
-			computeDependencies(getSubsystemManifest());
-		else {
-			ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
-			if (header == null)
-				return;
-			for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
-				Resource resource = findDependency(clause);
-				if (resource == null)
-					throw new SubsystemException("A required dependency could not be found. This means the
resource was either missing or not recognized as a supported resource format due to, for example,
an invalid bundle manifest or blueprint XML file. Turn on debug logging for more information.
The resource was: " + resource);
-				addDependency(resource);
-			}
-		}
+	void computeDependencies(DeploymentManifest manifest) {
+	    if (manifest == null) {
+	        computeDependencies(getSubsystemManifest());
+	    }
+	    else {
+	        ProvisionResourceHeader header = manifest.getProvisionResourceHeader();
+	        if (header == null)
+	            return;
+	        for (ProvisionResourceHeader.Clause clause : header.getClauses()) {
+	            Resource resource = findDependency(clause);
+	            if (resource == null)
+	                throw new SubsystemException("A required dependency could not be found.
This means the resource was either missing or not recognized as a supported resource format
due to, for example, an invalid bundle manifest or blueprint XML file. Turn on debug logging
for more information. The resource was: " + resource);
+	            addDependency(resource);
+	        }
+	    }
 	}
 
 	private void computeDependencies(SubsystemManifest manifest)  {
@@ -426,7 +443,7 @@ public class SubsystemResource implement
 		return resource.getDeploymentManifest();
 	}
 
-	private ProvisionResourceHeader computeProvisionResourceHeader() {
+	ProvisionResourceHeader computeProvisionResourceHeader() {
 		Collection<Resource> dependencies = getDependencies();
 		if (dependencies.isEmpty())
 			return null;
@@ -569,7 +586,22 @@ public class SubsystemResource implement
 	}
 	
 	boolean isContent(Resource resource) {
-	   return installableContent.contains(resource) || sharedContent.contains(resource); 
+		if (installableContent.contains(resource) || sharedContent.contains(resource)) {
+			return true;
+		}
+		// Allow for implicit subsystem installations. An implicit installation
+		// occurs when a subsystem containing other subsystems as content is
+		// installed. When identifying the region to be used for validation
+		// purposes during resolution, resources that are content of children
+		// must be treated as content of this subsystem. See ResolveContext.isValid().
+		for (Resource installableResource : installableContent) {
+			if (installableResource instanceof RawSubsystemResource) {
+				if (((RawSubsystemResource)installableResource).getSubsystemManifest().getSubsystemContentHeader().contains(resource))
{
+					return true;
+				}
+			}
+		}
+		return false;
 	}
 	
 	private boolean isInstallable(Resource resource) {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceInstaller.java
Thu Dec  3 18:25:00 2015
@@ -52,35 +52,13 @@ public class SubsystemResourceInstaller
 		if (resource.equals(provisionTo))
 			return;
 		Activator.getInstance().getSubsystems().addChild(provisionTo, child, !isDependency());
-		coordination.addParticipant(new Participant() {
-			@Override
-			public void ended(Coordination arg0) throws Exception {
-				// Nothing
-			}
-
-			@Override
-			public void failed(Coordination arg0) throws Exception {
-				Activator.getInstance().getSubsystems().removeChild(provisionTo, child);
-			}
-		});
 	}
 
 	private void addSubsystem(final BasicSubsystem subsystem) {
 		Activator.getInstance().getSubsystems().addSubsystem(subsystem);
-		coordination.addParticipant(new Participant() {
-			@Override
-			public void ended(Coordination arg0) throws Exception {
-				// Nothing
-			}
-
-			@Override
-			public void failed(Coordination arg0) throws Exception {
-				Activator.getInstance().getSubsystems().removeSubsystem(subsystem);
-			}
-		});
 	}
 
-	private BasicSubsystem installAriesSubsystem(BasicSubsystem subsystem) throws Exception
{
+	private BasicSubsystem installAriesSubsystem(final BasicSubsystem subsystem) throws Exception
{
 		addChild(subsystem);
 		addReference(subsystem);
 		addConstituent(subsystem);
@@ -88,29 +66,32 @@ public class SubsystemResourceInstaller
 		installRegionContextBundle(subsystem);
 		// This will emit the initial service event for INSTALLING subsystems.
 		// The first event for RESOLVED (i.e. persisted) subsystems is emitted later.
-		if (State.INSTALLING.equals(subsystem.getState()))
+		if (State.INSTALLING.equals(subsystem.getState())) {
 			Activator.getInstance().getSubsystemServiceRegistrar().register(subsystem, this.subsystem);
+			coordination.addParticipant(new Participant() {
+				@Override
+				public void ended(Coordination coordination) throws Exception {
+					// Nothing.
+				}
+
+				@Override
+				public void failed(Coordination coordination) throws Exception {
+					subsystem.setState(State.INSTALL_FAILED);
+					subsystem.uninstall();
+				}
+			});
+		}
 		Comparator<Resource> comparator = new InstallResourceComparator();
-		// Install dependencies first...
-		List<Resource> dependencies = new ArrayList<Resource>(subsystem.getResource().getInstallableDependencies());
-		Collections.sort(dependencies, comparator);
-		for (Resource dependency : dependencies)
-			ResourceInstaller.newInstance(coordination, dependency, subsystem).install();
-		for (Resource dependency : subsystem.getResource().getSharedDependencies()) {
-			// TODO This needs some more thought. The following check
-			// protects against a child subsystem that has its parent as a
-			// dependency. Are there other places of concern as well? Is it
-			// only the current parent that is of concern or should all
-			// parents be checked?
-			if (!dependency.equals(this.subsystem))
-				ResourceInstaller.newInstance(coordination, dependency, subsystem).install();
+		// Install dependencies first if appropriate...
+		if (Utils.isProvisionDependenciesInstall(subsystem)) {
+		    new InstallDependencies().install(subsystem, this.subsystem, coordination);
 		}
 		// ...followed by content.
 		// Simulate installation of shared content so that necessary relationships are established.
-		for (Resource content : subsystem.getResource().getSharedContent()) {
-			ResourceInstaller.newInstance(coordination, content, subsystem).install();
-		}
-		// Now take care of the installable content.
+        for (Resource content : subsystem.getResource().getSharedContent()) {
+            ResourceInstaller.newInstance(coordination, content, subsystem).install();
+        }
+        // Now take care of the installable content.
 		if (State.INSTALLING.equals(subsystem.getState())) {
 			List<Resource> installableContent = new ArrayList<Resource>(subsystem.getResource().getInstallableContent());
 			Collections.sort(installableContent, comparator);
@@ -119,11 +100,14 @@ public class SubsystemResourceInstaller
 		}
 		// Only brand new subsystems should have acquired the INSTALLING state,
 		// in which case an INSTALLED event must be propagated.
-		if (State.INSTALLING.equals(subsystem.getState()))
+		if (State.INSTALLING.equals(subsystem.getState()) && 
+		        Utils.isProvisionDependenciesInstall(subsystem)) {
 			subsystem.setState(State.INSTALLED);
-		else
+		}
+		else {
 			// This is a persisted subsystem in the RESOLVED state. Emit the first service event.
 			Activator.getInstance().getSubsystemServiceRegistrar().register(subsystem, this.subsystem);
+		}
 		return subsystem;
 	}
 
@@ -136,17 +120,6 @@ public class SubsystemResourceInstaller
 		if (!subsystem.isScoped())
 			return;
 		RegionContextBundleHelper.installRegionContextBundle(subsystem, coordination);
-		coordination.addParticipant(new Participant() {
-			@Override
-			public void ended(Coordination coordination) throws Exception {
-				// Nothing
-			}
-
-			@Override
-			public void failed(Coordination coordination) throws Exception {
-				RegionContextBundleHelper.uninstallRegionContextBundle(subsystem);
-			}
-		});
 	}
 
 	private BasicSubsystem installRepositoryContent(Resource resource) throws Exception {

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/TargetRegion.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/TargetRegion.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/TargetRegion.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/TargetRegion.java
Thu Dec  3 18:25:00 2015
@@ -24,25 +24,16 @@ public class TargetRegion {
 
 	public TargetRegion(BasicSubsystem subsystem) {
 		// Find the scoped subsystem that controls the region.
-		BasicSubsystem controllingScopedSubsystem = subsystem;
-		while (controllingScopedSubsystem.isFeature())
-			controllingScopedSubsystem = (BasicSubsystem)subsystem.getParents().iterator().next();
-		// The scoped subsystem controlling the region is part of the region.
-		region.add(controllingScopedSubsystem);
-		// All children of the scoped subsystem are part of the region. If the
-		// child is a feature, then all descendants of the child that are
-		// features and part of an unbroken line of features are part of the
-		// region.
-		addChildrenToRegion(controllingScopedSubsystem);
+		while (!subsystem.isScoped()) {
+			subsystem = (BasicSubsystem) subsystem.getParents().iterator().next();
+		}
+		// All children of the scoped subsystem controlling the region are
+		// part of the target region, even those that are scoped subsystems.
+		add(subsystem.getChildren());
 	}
 
 	public boolean contains(Subsystem subsystem) {
-		for (Subsystem s : region) {
-			if (s.getSymbolicName().equals(subsystem.getSymbolicName())
-					&& s.getVersion().equals(subsystem.getVersion()))
-				return true;
-		}
-		return false;
+		return find(subsystem.getSymbolicName(), subsystem.getVersion()) != null;
 	}
 	
 	public Subsystem find(String symbolicName, Version version) {
@@ -54,24 +45,15 @@ public class TargetRegion {
 		return null;
 	}
 	
-	private void addChildrenToRegion(BasicSubsystem controllingScopedSubsystem) {
-		for (Subsystem child : controllingScopedSubsystem.getChildren()) {
+	private void add(Collection<Subsystem> children) {
+		for (Subsystem child : children) {
 			region.add(child);
-			// If the child is a feature, all of its children that are features
-			// must be added as well.
-			if (((BasicSubsystem)child).isFeature())
-				addFeatureDescendentsToRegion((BasicSubsystem)child);
-		}
-	}
-	
-	private void addFeatureDescendentsToRegion(BasicSubsystem parent) {
-		for (Subsystem child : parent.getChildren())
-			// If the descendant is not a feature, skip it.
-			if (((BasicSubsystem)child).isFeature()) {
-				region.add(child);
-				// All descendants that are features and part of an unbroken
-				// line of features must be added.
-				addFeatureDescendentsToRegion((BasicSubsystem)child);
+			if (((BasicSubsystem) child).isScoped()) {
+				// Children of scoped children are not part of the target region.
+				continue;
 			}
+			// Children of unscoped children are part of the target region.
+			add(child.getChildren());
+		}
 	}
 }

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/UninstallAction.java
Thu Dec  3 18:25:00 2015
@@ -29,7 +29,8 @@ public class UninstallAction extends Abs
 		State state = target.getState();
 		if (EnumSet.of(State.UNINSTALLED).contains(state))
 			return null;
-		else if (EnumSet.of(State.INSTALL_FAILED, State.INSTALLING, State.RESOLVING, State.STARTING,
State.STOPPING, State.UNINSTALLING).contains(state)) {
+		else if ((State.INSTALLING.equals(state) && Utils.isProvisionDependenciesInstall(target))
+				|| EnumSet.of(State.RESOLVING, State.STARTING, State.STOPPING, State.UNINSTALLING).contains(state))
{
 			waitForStateChange(state);
 			target.uninstall();
 		}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
Thu Dec  3 18:25:00 2015
@@ -13,6 +13,8 @@
  */
 package org.apache.aries.subsystem.core.internal;
 
+import java.util.Collection;
+
 import org.apache.aries.subsystem.core.archive.DeploymentManifest;
 import org.apache.aries.subsystem.core.archive.ProvisionResourceHeader;
 import org.apache.aries.subsystem.core.archive.SubsystemContentHeader;
@@ -24,6 +26,7 @@ import org.osgi.service.coordinator.Coor
 import org.osgi.service.coordinator.CoordinationException;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.SubsystemConstants;
+import org.osgi.service.subsystem.Subsystem.State;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,12 +53,35 @@ public class Utils {
 		return subsystem;
 	}
 	
+	public static BasicSubsystem findFirstScopedAncestorWithSharingPolicy(SubsystemResource
descendant) {
+		Collection<BasicSubsystem> parents = descendant.getParents();
+		if (parents == null || parents.isEmpty()) {
+			return null;
+		}
+		BasicSubsystem result = (BasicSubsystem) parents.iterator().next();
+		// The result is defined as the first scoped ancestor whose sharing 
+		// policy has already been set. This covers the case of multiple 
+		// subsystems from the same archive being installed whose regions will 
+		// form a tree of depth N.
+		while (	// We only want scoped subsystems because they control 
+				// the region.
+				!result.isScoped()
+				// If the state is INSTALLING then the sharing policy 
+				// has not yet been set. This means we cannot use the
+				// region in order to test visibility and must proceed
+				// to the next parent.
+				|| result.getState().equals(State.INSTALLING)) {
+			result = result.getResource().getParents().iterator().next();
+		}
+		return result;
+	}
+	
 	public static BasicSubsystem findScopedSubsystemInRegion(BasicSubsystem subsystem) {
 		while (!subsystem.isScoped())
 			subsystem = (BasicSubsystem)subsystem.getParents().iterator().next();
 		return subsystem;
 	}
-	
+
 	public static int getActiveUseCount(Resource resource) {
 		int result = 0;
 		for (BasicSubsystem subsystem : Activator.getInstance().getSubsystems().getSubsystemsReferencing(resource))
@@ -146,4 +172,8 @@ public class Utils {
 				SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE.equals(type) ||
 				SubsystemConstants.SUBSYSTEM_TYPE_FEATURE.equals(type);
 	}
+	
+	public static boolean isProvisionDependenciesInstall(BasicSubsystem subsystem) {
+		return subsystem.getSubsystemManifest().getSubsystemTypeHeader().getAriesProvisionDependenciesDirective().isInstall();
+	}
 }

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/AriesProvisionDependenciesHeaderTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/AriesProvisionDependenciesHeaderTest.java?rev=1717826&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/AriesProvisionDependenciesHeaderTest.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/AriesProvisionDependenciesHeaderTest.java
Thu Dec  3 18:25:00 2015
@@ -0,0 +1,21 @@
+package org.apache.aries.subsystem.core.archive;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class AriesProvisionDependenciesHeaderTest {
+    @Test
+    public void testClauseGetValue() {
+        assertTrue("resolve".equals(AriesProvisionDependenciesDirective.RESOLVE.getValue()));
+        assertTrue("install".equals(AriesProvisionDependenciesDirective.INSTALL.getValue()));
+    }
+
+    @Test
+    public void testClauseGetInstance() {
+        assertTrue(AriesProvisionDependenciesDirective.getInstance("resolve")==
+                AriesProvisionDependenciesDirective.RESOLVE);
+        assertTrue(AriesProvisionDependenciesDirective.getInstance("install")==
+                AriesProvisionDependenciesDirective.INSTALL);
+    }
+}

Modified: aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.1
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.1?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.1 (original)
+++ aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.1 Thu Dec 
3 18:25:00 2015
@@ -1,6 +1,6 @@
 Export-Package: a.b.c;version="1.0",x.y.z;uses:="m.n"; version="1.1.1",		m.n;version="0"
 Subsystem-Type: osgi.subsystem.composite; provision-policy:=rejectDependencies
-Subsystem-SymbolicName: com.acme.rocket;a=b;apachearies-provision-dependencies:=start
+Subsystem-SymbolicName: com.acme.rocket;a=b;apache-aries-provision-dependencies:=resolve
 Import-Package: c.b.a, z.y.x;version=9;resolution:=optional,	n.m;version="[3.1,4.0)";resolution:=mandatory
 Preferred-Provider: foo, org.bar;version="[1,2)";type=osg.bundle
 Provide-Capability: x;a=b, osgi.service;objectClass=o.p.Quick;b=a;effective:=active

Modified: aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.2
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.2?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.2 (original)
+++ aries/trunk/subsystem/subsystem-core/src/test/resources/files/SUBSYSTEM.MF.2 Thu Dec 
3 18:25:00 2015
@@ -1,6 +1,6 @@
 Export-Package: a.b.c;version="1.0",	x.y.z;version="1.1.1";uses:="m.n",m.n
 Subsystem-Type: osgi.subsystem.composite
-Subsystem-SymbolicName: com.acme.rocket; apachearies-provision-dependencies:=start;  a=b
+Subsystem-SymbolicName: com.acme.rocket; apache-aries-provision-dependencies:=resolve;  a=b
 Import-Package: z.y.x;resolution:=optional;version="9",  n.m;version="[3.1.0, 4)";resolution:=mandatory,c.b.a;resolution:=mandatory;version="0.0"
 Preferred-Provider: org.bar;type=osg.bundle;version="[1,2)",foo;version=0;type=osgi.subsystem.composite
 Provide-Capability: x;  effective:=resolve;a=b, osgi.service;	effective:=active;b=a; objectClass=o.p.Quick

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/HelloWorldTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/HelloWorldTest.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/HelloWorldTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/HelloWorldTest.java
Thu Dec  3 18:25:00 2015
@@ -79,7 +79,7 @@ public class HelloWorldTest extends Subs
     // Sanity check, application should not install if no IDirectoryFinder 
     // services are registered, which should be the case on entry to this test.
     try {
-      installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING, null);
+      installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING, null, (Boolean[])
null);
       fail("installed esa application from idir without an idirfinder service, shouldn't
be possible.");
     } catch (SubsystemException se) {
       // expected exception
@@ -95,7 +95,7 @@ public class HelloWorldTest extends Subs
     // Call the SubsystemTest.installSubsystem method that does not create a URL
     // and stream from the location, as we just need the location string passed 
     // through to the installing root subsystem.
-    Subsystem subsystem = installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING,
null);    
+    Subsystem subsystem = installSubsystem(getRootSubsystem(), TestIDirectoryFinder.HELLO_ID_STRING,
null, (Boolean[]) null);    
     try {
       checkHelloSubsystem(subsystem);
     } finally {

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
Thu Dec  3 18:25:00 2015
@@ -31,7 +31,6 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.aries.subsystem.core.archive.DeploymentManifest;
 import org.apache.aries.subsystem.core.internal.BasicSubsystem;
 import org.apache.aries.subsystem.itests.util.Utils;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
@@ -120,7 +119,7 @@ public class InstallTest extends Subsyst
     public void testLocationAsDirectoryUrl() throws Exception {
     	File file = new File("compositeDir");
     	try {
-    		Subsystem subsystem = installSubsystem(getRootSubsystem(), file.toURI().toString(),
null);
+    		Subsystem subsystem = installSubsystem(getRootSubsystem(), file.toURI().toString(),
null, (Boolean[]) null);
     		try {
     			assertSymbolicName("org.apache.aries.subsystem.itests.composite.dir", subsystem);

     			assertConstituents(3, subsystem);

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemEventHandler.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemEventHandler.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemEventHandler.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemEventHandler.java
Thu Dec  3 18:25:00 2015
@@ -8,10 +8,10 @@ import java.util.Map;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.Version;
-import org.osgi.service.subsystem.SubsystemConstants;
 import org.osgi.service.subsystem.Subsystem.State;
+import org.osgi.service.subsystem.SubsystemConstants;
 
-class SubsystemEventHandler implements ServiceListener {
+public class SubsystemEventHandler implements ServiceListener {
 	static class ServiceEventInfo {
 		private final ServiceEvent event;
 		private final long id;

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java?rev=1717826&r1=1717825&r2=1717826&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java
Thu Dec  3 18:25:00 2015
@@ -34,6 +34,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -42,16 +43,18 @@ import java.util.EnumSet;
 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 java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.aries.itest.AbstractIntegrationTest;
 import org.apache.aries.itest.RichBundleContext;
 import org.apache.aries.subsystem.AriesSubsystem;
+import org.apache.aries.subsystem.core.archive.AriesProvisionDependenciesDirective;
 import org.apache.aries.subsystem.core.archive.ProvisionPolicyDirective;
 import org.apache.aries.subsystem.core.archive.SubsystemTypeHeader;
 import org.apache.aries.subsystem.core.archive.TypeAttribute;
+import org.apache.aries.subsystem.core.internal.BasicSubsystem;
 import org.apache.aries.subsystem.core.internal.BundleResource;
 import org.apache.aries.subsystem.core.internal.SubsystemIdentifier;
 import org.apache.aries.subsystem.itests.util.TestRepository;
@@ -158,6 +161,12 @@ public abstract class SubsystemTest exte
     protected void init() throws Exception {
 
     }
+    
+    protected long lastSubsystemId() throws Exception {
+    	Method method = SubsystemIdentifier.class.getDeclaredMethod("getLastId");
+    	method.setAccessible(true);
+    	return (Long)method.invoke(null);
+    }
 
     private Option modelerBundles() {
         return CoreOptions.composite(
@@ -301,14 +310,26 @@ public abstract class SubsystemTest exte
  	}
 
 	protected void assertEvent(Subsystem subsystem, Subsystem.State state, SubsystemEventHandler.ServiceEventInfo
event, int type) {
+		assertEvent(subsystem.getSubsystemId(), subsystem.getSymbolicName(), 
+				subsystem.getVersion(), subsystem.getType(), state, event, type);
+	}
+	
+	protected void assertEvent(
+			long id, 
+			String symbolicName, 
+			Version version, 
+			String type, 
+			Subsystem.State state,
+			SubsystemEventHandler.ServiceEventInfo event,
+			int eventType) {
 		// TODO Could accept a ServiceRegistration as an argument and verify it against the one
in the event.
 		assertNotNull("No event", event);
-		assertEquals("Wrong ID", subsystem.getSubsystemId(), event.getId());
-		assertEquals("Wrong symbolic name", subsystem.getSymbolicName(), event.getSymbolicName());
-		assertEquals("Wrong version", subsystem.getVersion(), event.getVersion());
-		assertEquals("Wrong type", subsystem.getType(), event.getType());
+		assertEquals("Wrong ID", id, event.getId());
+		assertEquals("Wrong symbolic name", symbolicName, event.getSymbolicName());
+		assertEquals("Wrong version", version, event.getVersion());
+		assertEquals("Wrong type", type, event.getType());
 		assertEquals("Wrong state", state, event.getState());
-		assertEquals("Wrong event type", type, event.getEventType());
+		assertEquals("Wrong event type", eventType, event.getEventType());
 	}
 
 	protected String assertHeaderExists(Subsystem subsystem, String name) {
@@ -782,16 +803,16 @@ public abstract class SubsystemTest exte
 		return installSubsystemFromFile(parent, new File(fileName));
 	}
 
-	protected Subsystem installSubsystemFromFile(String fileName) throws Exception {
-		return installSubsystemFromFile(new File(fileName));
+	protected Subsystem installSubsystemFromFile(String fileName, Boolean ... configChecks)
throws Exception {
+		return installSubsystemFromFile(new File(fileName), configChecks);
 	}
 
 	protected Subsystem installSubsystemFromFile(Subsystem parent, File file) throws Exception
{
 		return installSubsystem(parent, file.toURI().toURL().toExternalForm());
 	}
 
-	private Subsystem installSubsystemFromFile(File file) throws Exception {
-		return installSubsystem(getRootSubsystem(), file.toURI().toURL().toExternalForm());
+	private Subsystem installSubsystemFromFile(File file, Boolean ... configChecks) throws Exception
{
+		return installSubsystem(getRootSubsystem(), file.toURI().toURL().toExternalForm(), configChecks);
 	}
 	
 	protected Subsystem installSubsystemFromFile(Subsystem parent, File file, String location)
throws Exception {
@@ -806,26 +827,36 @@ public abstract class SubsystemTest exte
 		return installSubsystem(getRootSubsystem(), location, content);
 	}
 
-	protected Subsystem installSubsystem(Subsystem parent, String location) throws Exception
{
+	protected Subsystem installSubsystem(Subsystem parent, String location, Boolean ... configChecks)
throws Exception {
 		// The following input stream is closed by Subsystem.install.
-		return installSubsystem(parent, location, new URL(location).openStream());
+		return installSubsystem(parent, location, new URL(location).openStream(), configChecks);
 	}
 
-	protected Subsystem installSubsystem(Subsystem parent, String location, InputStream content)
throws Exception {
-		subsystemEvents.clear();
-		Subsystem subsystem = parent.install(location, content);
-		assertSubsystemNotNull(subsystem);
-		assertEvent(subsystem, State.INSTALLING, 5000);
-		assertEvent(subsystem, State.INSTALLED, 5000);
-		assertChild(parent, subsystem);
-		assertLocation(location, subsystem);
-		assertParent(parent, subsystem);
-		assertState(State.INSTALLED, subsystem);
-		assertLocation(location, subsystem);
-		assertId(subsystem);
-		// TODO This does not take into account nested directories.
-//		assertDirectory(subsystem);
-		return subsystem;
+	protected Subsystem installSubsystem(Subsystem parent, String location, InputStream content,
Boolean ... configChecks) throws Exception {
+	    boolean ariesProvisionDepsAtInstall = true; //set default value
+	    if (configChecks!=null && configChecks.length > 0) {
+	        ariesProvisionDepsAtInstall = configChecks[0].booleanValue();
+	    }
+	    subsystemEvents.clear();
+	    Subsystem subsystem = parent.install(location, content);
+	    assertSubsystemNotNull(subsystem);
+	    assertEvent(subsystem, State.INSTALLING, 5000);
+	    if (ariesProvisionDepsAtInstall) {
+	        assertEvent(subsystem, State.INSTALLED, 5000);
+	    }
+	    assertChild(parent, subsystem);
+	    assertLocation(location, subsystem);
+	    assertParent(parent, subsystem);
+	    State finalState=State.INSTALLED;
+	    if (!ariesProvisionDepsAtInstall) {
+	        finalState=State.INSTALLING;
+	    }
+	    assertState(finalState, subsystem);
+	    assertLocation(location, subsystem);
+	    assertId(subsystem);
+	    // TODO This does not take into account nested directories.
+	    //		assertDirectory(subsystem);
+	    return subsystem;
 	}
 
 	protected void registerRepositoryService(Repository repository) {
@@ -879,14 +910,27 @@ public abstract class SubsystemTest exte
 		assertBundleState(Bundle.ACTIVE, bundle.getSymbolicName(), subsystem);
 	}
 
-	protected void startSubsystem(Subsystem subsystem) throws Exception {
-		startSubsystemFromInstalled(subsystem);
+	protected void startSubsystem(Subsystem subsystem, Boolean ... configChecks) throws Exception
{
+		startSubsystemFromInstalled(subsystem, configChecks);
 	}
 
-	protected void startSubsystemFromInstalled(Subsystem subsystem) throws InterruptedException
{
-		assertState(State.INSTALLED, subsystem);
+	protected void startSubsystemFromInstalled(Subsystem subsystem, Boolean ... configChecks)
throws InterruptedException {
+	    boolean ariesProvisionDependenciesAtInstall = true; //set default value
+	    if (configChecks.length>0) {
+	        ariesProvisionDependenciesAtInstall = configChecks[0].booleanValue();
+	    }
+	    if (ariesProvisionDependenciesAtInstall) {
+		    assertState(State.INSTALLED, subsystem);
+	    }
+	    else {
+	        assertState(State.INSTALLING, subsystem);
+	    }
+	        
 		subsystemEvents.clear();
 		subsystem.start();
+		if (!ariesProvisionDependenciesAtInstall) {
+		    assertEvent(subsystem, State.INSTALLED, 5000);
+		}
 		assertEvent(subsystem, State.RESOLVING, 5000);
 		assertEvent(subsystem, State.RESOLVED, 5000);
 		assertEvent(subsystem, State.STARTING, 5000);
@@ -936,27 +980,44 @@ public abstract class SubsystemTest exte
 	}
 
 	protected void uninstallSubsystem(Subsystem subsystem) throws Exception {
-		assertState(EnumSet.of(State.INSTALLED, State.RESOLVED), subsystem);
-		subsystemEvents.clear();
-		Collection<Subsystem> parents = subsystem.getParents();
+		uninstallSubsystem(subsystem, false);
+	}
+	
+	protected void uninstallSubsystem(Subsystem subsystem, boolean quietly) throws Exception
{
+		BasicSubsystem basicSubsystem = (BasicSubsystem)subsystem;
+		AriesProvisionDependenciesDirective directive = basicSubsystem.getAriesProvisionDependenciesDirective();
 		Bundle b = null;
 		Region region = null;
 		RegionDigraph digraph = context().getService(RegionDigraph.class);
-		if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
-				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
-			b = getRegionContextBundle(subsystem);
-			region = digraph.getRegion(b);
+		if (!quietly) {
+			if (directive.isResolve()) {
+				assertState(EnumSet.of(State.INSTALLING, State.INSTALLED, State.RESOLVED), subsystem);
+			}
+			else {
+				assertState(EnumSet.of(State.INSTALLED, State.RESOLVED), subsystem);
+			}
+			subsystemEvents.clear();
+			if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
+					|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
+				b = getRegionContextBundle(subsystem);
+				region = digraph.getRegion(b);
+			}
 		}
 		State state = subsystem.getState();
 		subsystem.uninstall();
-		if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state))
+		if (quietly) {
+			return;
+		}
+		Collection<Subsystem> parents = subsystem.getParents();
+		if (!EnumSet.of(State.INSTALL_FAILED, State.INSTALLED, State.INSTALLING).contains(state))
{
 			assertEvent(subsystem, State.INSTALLED, 5000);
+		}
 		assertEvent(subsystem, State.UNINSTALLING, 5000);
 		assertEvent(subsystem, State.UNINSTALLED, 5000);
 		assertState(State.UNINSTALLED, subsystem);
-		for (Subsystem parent : parents)
+		for (Subsystem parent : parents) {
 			assertNotChild(parent, subsystem);
-//		assertNotDirectory(subsystem);
+		}
 		if (subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION)
 				|| subsystem.getType().equals(SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE)) {
 			assertEquals("Region context bundle not uninstalled", Bundle.UNINSTALLED, b.getState());
@@ -968,7 +1029,7 @@ public abstract class SubsystemTest exte
 		if (subsystem == null)
 			return;
 		try {
-			uninstallSubsystem(subsystem);
+			uninstallSubsystem(subsystem, true);
 		}
 		catch (Throwable t) {
 			t.printStackTrace();




Mime
View raw message