aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1355479 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core: archive/ internal/
Date Fri, 29 Jun 2012 17:29:44 GMT
Author: jwross
Date: Fri Jun 29 17:29:42 2012
New Revision: 1355479

URL: http://svn.apache.org/viewvc?rev=1355479&view=rev
Log:
ARIES-825: Multiple changes.

(1) Stopping the root subsystem should stop child subsystems but not bundles.

(2) Arbitrary attributes on Subsystem-Content and Subsystem-SymbolicName headers are now honored.

Added:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentRequirement.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentRequirement.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentHeader.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedVersionAttribute.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentHeader.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResource.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentHeader.java?rev=1355479&r1=1355478&r2=1355479&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentHeader.java
Fri Jun 29 17:29:42 2012
@@ -18,6 +18,7 @@ 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 java.util.regex.Matcher;
@@ -26,10 +27,11 @@ import java.util.regex.Pattern;
 import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.apache.aries.subsystem.core.internal.Utils;
 import org.osgi.framework.Version;
+import org.osgi.resource.Requirement;
 import org.osgi.resource.Resource;
 import org.osgi.service.subsystem.SubsystemConstants;
 
-public class DeployedContentHeader implements Header<DeployedContentHeader.Clause>
{
+public class DeployedContentHeader implements RequirementHeader<DeployedContentHeader.Clause>
{
 	public static class Clause implements org.apache.aries.subsystem.core.archive.Clause {
 		public static final String ATTRIBUTE_DEPLOYEDVERSION = DeployedVersionAttribute.NAME;
 		public static final String ATTRIBUTE_RESOURCEID = "resourceId";
@@ -141,6 +143,10 @@ public class DeployedContentHeader imple
 			return ((TypeAttribute)getAttribute(ATTRIBUTE_TYPE)).getType();
 		}
 		
+		public DeployedContentRequirement toRequirement(Resource resource) {
+			return new DeployedContentRequirement(this, resource);
+		}
+		
 		@Override
 		public String toString() {
 			StringBuilder builder = new StringBuilder()
@@ -242,6 +248,14 @@ public class DeployedContentHeader imple
 	}
 	
 	@Override
+	public List<Requirement> toRequirements(Resource resource) {
+		List<Requirement> requirements = new ArrayList<Requirement>(clauses.size());
+		for (Clause clause : clauses)
+			requirements.add(clause.toRequirement(resource));
+		return requirements;
+	}
+	
+	@Override
 	public String toString() {
 		StringBuilder builder = new StringBuilder();
 		for (Clause clause : getClauses()) {

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentRequirement.java?rev=1355479&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentRequirement.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedContentRequirement.java
Fri Jun 29 17:29:42 2012
@@ -0,0 +1,48 @@
+package org.apache.aries.subsystem.core.archive;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.core.internal.AbstractRequirement;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Resource;
+
+public class DeployedContentRequirement extends AbstractRequirement {
+	public static final String DIRECTIVE_FILTER = IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE;
+	public static final String NAMESPACE = IdentityNamespace.IDENTITY_NAMESPACE;
+	
+	private final Map<String, String> directives = new HashMap<String, String>();
+	private final Resource resource;
+	
+	public DeployedContentRequirement(
+			DeployedContentHeader.Clause clause, Resource resource) {
+		StringBuilder builder = new StringBuilder("(&(")
+				.append(NAMESPACE).append('=')
+				.append(clause.getSymbolicName()).append(')');
+		for (Attribute attribute : clause.getAttributes())
+			attribute.appendToFilter(builder);
+		directives.put(DIRECTIVE_FILTER, builder.append(')').toString());
+		this.resource = resource;
+	}
+
+	@Override
+	public Map<String, Object> getAttributes() {
+		return Collections.emptyMap();
+	}
+
+	@Override
+	public Map<String, String> getDirectives() {
+		return Collections.unmodifiableMap(directives);
+	}
+
+	@Override
+	public String getNamespace() {
+		return NAMESPACE;
+	}
+
+	@Override
+	public Resource getResource() {
+		return resource;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedVersionAttribute.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedVersionAttribute.java?rev=1355479&r1=1355478&r2=1355479&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedVersionAttribute.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeployedVersionAttribute.java
Fri Jun 29 17:29:42 2012
@@ -14,6 +14,7 @@
 package org.apache.aries.subsystem.core.archive;
 
 import org.osgi.framework.Version;
+import org.osgi.framework.VersionRange;
 import org.osgi.service.subsystem.SubsystemConstants;
 
 public class DeployedVersionAttribute extends AbstractAttribute {
@@ -25,6 +26,12 @@ public class DeployedVersionAttribute ex
 		super(NAME, value);
 		deployedVersion = Version.parseVersion(value);
 	}
+	
+	@Override
+	public StringBuilder appendToFilter(StringBuilder builder) {
+		VersionRange versionRange = new VersionRange(VersionRange.LEFT_CLOSED, getVersion(), getVersion(),
VersionRange.RIGHT_CLOSED);
+		return builder.append(versionRange.toFilterString(VersionRangeAttribute.NAME));
+	}
 
 	public Version getDeployedVersion() {
 		return deployedVersion;

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentHeader.java?rev=1355479&r1=1355478&r2=1355479&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentHeader.java
Fri Jun 29 17:29:42 2012
@@ -24,7 +24,6 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.aries.subsystem.core.internal.OsgiIdentityRequirement;
 import org.apache.aries.subsystem.core.internal.ResourceHelper;
 import org.osgi.framework.Version;
 import org.osgi.framework.VersionRange;
@@ -161,8 +160,8 @@ public class SubsystemContentHeader impl
 			return ((ResolutionDirective)getDirective(DIRECTIVE_RESOLUTION)).isMandatory();
 		}
 		
-		public OsgiIdentityRequirement toRequirement(Resource resource) {
-			return new OsgiIdentityRequirement(getSymbolicName(), getVersionRange(), getType(), false);
+		public SubsystemContentRequirement toRequirement(Resource resource) {
+			return new SubsystemContentRequirement(this, resource);
 		}
 		
 		@Override
@@ -176,67 +175,6 @@ public class SubsystemContentHeader impl
 		}
 	}
 	
-//	public static class Content {
-//		private final boolean mandatory;
-//		private final String name;
-//		private final int startOrder;
-//		private final String type;
-//		private final VersionRange versionRange;
-//		
-//		public Content(boolean mandatory, String name, String type, VersionRange versionRange,
int startOrder) {
-//			this.mandatory = mandatory;
-//			this.name = name;
-//			this.type = type;
-//			this.versionRange = versionRange;
-//			this.startOrder = startOrder;
-//		}
-//		
-//		public String getName() {
-//			return name;
-//		}
-//		
-//		public int getStartOrder() {
-//			return startOrder;
-//		}
-//		
-//		public String getType() {
-//			return type;
-//		}
-//		
-//		public VersionRange getVersionRange() {
-//			return versionRange;
-//		}
-//		
-//		public boolean isMandatory() {
-//			return mandatory;
-//		}
-//		
-//		public Requirement toRequirement() {
-//			return new OsgiIdentityRequirement(name, versionRange, type, false);
-//		}
-//		
-//		public String toString() {
-//			return new StringBuilder(getName())
-//				.append(';')
-//				.append(VersionAttribute.NAME)
-//				.append('=')
-//				.append(getVersionRange())
-//				.append(';')
-//				.append(TypeAttribute.NAME)
-//				.append("=")
-//				.append(getType())
-//				.append(';')
-//				.append(ResolutionDirective.NAME)
-//				.append(":=")
-//				.append(isMandatory())
-//				.append(';')
-//				.append(StartOrderDirective.NAME)
-//				.append(":=")
-//				.append(getStartOrder())
-//				.toString();
-//		}
-//	}
-	
 	public static final String NAME = SubsystemConstants.SUBSYSTEM_CONTENT;
 	
 	public static SubsystemContentHeader newInstance(Collection<Resource> resources) {
@@ -275,25 +213,6 @@ public class SubsystemContentHeader impl
 		return clauses;
 	}
 	
-//	private static String processResources(Collection<Resource> resources) {
-//		if (resources.isEmpty())
-//			throw new IllegalArgumentException("At least one resource must be specified");
-//		StringBuilder sb = new StringBuilder();
-//		for (Resource resource : resources) {
-//			Capability c = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0);
-//			Map<String, Object> a = c.getAttributes();
-//			String s = (String)a.get(IdentityNamespace.IDENTITY_NAMESPACE);
-//			Version v = (Version)a.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
-//			String t = (String)a.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
-//			sb.append(s).append(';')
-//				.append(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE).append('=').append(v).append(';')
-//				.append(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE).append('=').append(t).append(',');
-//		}
-//		// Remove the trailing comma.
-//		sb.deleteCharAt(sb.length() - 1);
-//		return sb.toString();
-//	}
-	
 	private final Set<Clause> clauses;
 	
 	public SubsystemContentHeader(Collection<Clause> clauses) {
@@ -306,10 +225,6 @@ public class SubsystemContentHeader impl
 		this(processHeader(value));
 	}
 	
-//	public SubsystemContentHeader(Collection<Resource> resources) {
-//		this(processResources(resources));
-//	}
-	
 	public boolean contains(Resource resource) {
 		return getClause(resource) != null;
 	}
@@ -332,38 +247,12 @@ public class SubsystemContentHeader impl
 		return Collections.unmodifiableSet(clauses);
 	}
 	
-//	public Content getContent(Resource resource) {
-//		String symbolicName = ResourceHelper.getSymbolicNameAttribute(resource);
-//		Version version = ResourceHelper.getVersionAttribute(resource);
-//		String type = ResourceHelper.getTypeAttribute(resource);
-//		for (Content content : contents) {
-//			if (symbolicName.equals(content.getName())
-//					&& content.getVersionRange().includes(version)
-//					&& type.equals(content.getType()))
-//				return content;
-//		}
-//		return null;
-//	}
-//
-//	public Collection<Content> getContents() {
-//		return Collections.unmodifiableCollection(contents);
-//	}
-	
 	public boolean isMandatory(Resource resource) {
 		Clause clause = getClause(resource);
 		if (clause == null)
 			return false;
 		return clause.isMandatory();
-//		Content content = getContent(resource);
-//		return content == null ? false : content.isMandatory();
 	}
-	
-//	public List<Requirement> toRequirements() {
-//		ArrayList<Requirement> result = new ArrayList<Requirement>(contents.size());
-//		for (Content content : contents)
-//			result.add(content.toRequirement());
-//		return result;
-//	}
 
 	@Override
 	public String getName() {

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentRequirement.java?rev=1355479&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentRequirement.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemContentRequirement.java
Fri Jun 29 17:29:42 2012
@@ -0,0 +1,48 @@
+package org.apache.aries.subsystem.core.archive;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.core.internal.AbstractRequirement;
+import org.osgi.framework.namespace.IdentityNamespace;
+import org.osgi.resource.Resource;
+
+public class SubsystemContentRequirement extends AbstractRequirement {
+	public static final String DIRECTIVE_FILTER = IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE;
+	public static final String NAMESPACE = IdentityNamespace.IDENTITY_NAMESPACE;
+	
+	private final Map<String, String> directives = new HashMap<String, String>();
+	private final Resource resource;
+	
+	public SubsystemContentRequirement(
+			SubsystemContentHeader.Clause clause, Resource resource) {
+		StringBuilder builder = new StringBuilder("(&(")
+				.append(NAMESPACE).append('=')
+				.append(clause.getSymbolicName()).append(')');
+		for (Attribute attribute : clause.getAttributes())
+			attribute.appendToFilter(builder);
+		directives.put(DIRECTIVE_FILTER, builder.append(')').toString());
+		this.resource = resource;
+	}
+
+	@Override
+	public Map<String, Object> getAttributes() {
+		return Collections.emptyMap();
+	}
+
+	@Override
+	public Map<String, String> getDirectives() {
+		return Collections.unmodifiableMap(directives);
+	}
+
+	@Override
+	public String getNamespace() {
+		return NAMESPACE;
+	}
+
+	@Override
+	public Resource getResource() {
+		return resource;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java?rev=1355479&r1=1355478&r2=1355479&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
Fri Jun 29 17:29:42 2012
@@ -43,24 +43,21 @@ public class StopAction extends Abstract
 			subsystem.stop();
 		}
 		subsystem.setState(State.STOPPING);
-		// For non-root subsystems, stop any remaining constituents.
-		if (!subsystem.isRoot()){
-			List<Resource> resources = new ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(subsystem));
-			SubsystemContentHeader header = subsystem.getSubsystemManifest().getSubsystemContentHeader();
-			if (header != null) {
-				Collections.sort(resources, new StartResourceComparator(subsystem.getSubsystemManifest().getSubsystemContentHeader()));
-				Collections.reverse(resources);
-			}
-			for (Resource resource : resources) {
-				// Don't stop the region context bundle.
-				if (ResourceHelper.getSymbolicNameAttribute(resource).startsWith(RegionContextBundleHelper.SYMBOLICNAME_PREFIX))
-					continue;
-				try {
-					stopResource(resource);
-				} 
-				catch (Exception e) {
-					logger.error("An error occurred while stopping resource " + resource + " of subsystem
" + subsystem, e);
-				}
+		List<Resource> resources = new ArrayList<Resource>(Activator.getInstance().getSubsystems().getResourcesReferencedBy(subsystem));
+		SubsystemContentHeader header = subsystem.getSubsystemManifest().getSubsystemContentHeader();
+		if (header != null) {
+			Collections.sort(resources, new StartResourceComparator(subsystem.getSubsystemManifest().getSubsystemContentHeader()));
+			Collections.reverse(resources);
+		}
+		for (Resource resource : resources) {
+			// Don't stop the region context bundle.
+			if (ResourceHelper.getSymbolicNameAttribute(resource).startsWith(RegionContextBundleHelper.SYMBOLICNAME_PREFIX))
+				continue;
+			try {
+				stopResource(resource);
+			} 
+			catch (Exception e) {
+				logger.error("An error occurred while stopping resource " + resource + " of subsystem
" + subsystem, e);
 			}
 		}
 		// TODO Can we automatically assume it actually is resolved?
@@ -83,6 +80,8 @@ public class StopAction extends Abstract
 	}
 	
 	private void stopBundleResource(Resource resource) throws BundleException {
+		if (subsystem.isRoot())
+			return;
 		((BundleRevision)resource).getBundle().stop();
 	}
 	

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=1355479&r1=1355478&r2=1355479&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
Fri Jun 29 17:29:42 2012
@@ -322,9 +322,7 @@ public class SubsystemResource implement
 		if (contentHeader == null)
 			return;
 		for (SubsystemContentHeader.Clause clause : contentHeader.getClauses()) {
-			OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(
-					clause.getSymbolicName(), clause.getVersionRange(),
-					clause.getType(), false);
+			Requirement requirement = clause.toRequirement(this);
 			Resource resource = findContent(requirement);
 			if (resource == null) {
 				if (clause.isMandatory())
@@ -471,7 +469,7 @@ public class SubsystemResource implement
 		};
 	}
 	
-	private Resource findContent(OsgiIdentityRequirement requirement) {
+	private Resource findContent(Requirement requirement) {
 		Map<Requirement, Collection<Capability>> map;
 		// TODO System repository for scoped subsystems should be searched in
 		// the case of a persisted subsystem.
@@ -510,10 +508,7 @@ public class SubsystemResource implement
 			else
 				return Activator.getInstance().getSubsystems().getSubsystemById(resourceId);
 		}
-		OsgiIdentityRequirement requirement = new OsgiIdentityRequirement(
-				clause.getPath(), clause.getDeployedVersion(),
-				clause.getType(), false);
-		return findContent(requirement);
+		return findContent(clause.toRequirement(this));
 	}
 	
 	private Resource findDependency(ProvisionResourceHeader.ProvisionedResource provisionedResource)
{



Mime
View raw message