aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1430023 - in /aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal: Constants.java DependencyCalculator.java RawSubsystemResource.java ResourceInstaller.java
Date Mon, 07 Jan 2013 21:32:51 GMT
Author: jwross
Date: Mon Jan  7 21:32:50 2013
New Revision: 1430023

URL: http://svn.apache.org/viewvc?rev=1430023&view=rev
Log:
[ARIES-997] Support for the Aries Application header Application-ImportService

This solution adds a new "fake" resource to the LocalRepository for subsystems that are being
installed which have an
Application-ImportService header. The fake resource has no requirements and only contains
osgi.service capabilities
that can be used to satisfy the imported services specified by the Application-ImportService
header. These capabilities
can then be used during resolution to help resolve any osgi.service requirements from content
resources when provisioning
the ESA. A new internal resource type (org.apache.aries.subsystem.resource.synthesized) is
used to indicate to the
ResourceInstaller to ignore the fake resources during installation.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Constants.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Constants.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Constants.java?rev=1430023&r1=1430022&r2=1430023&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Constants.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Constants.java
Mon Jan  7 21:32:50 2013
@@ -21,6 +21,7 @@ public class Constants {
 	public static final String RegionContextBundleSymbolicNamePrefix = "org.osgi.service.subsystem.region.context.";
 	public static final String ResourceTypeBundle = IdentityNamespace.TYPE_BUNDLE;
 	public static final String ResourceTypeFragment = IdentityNamespace.TYPE_FRAGMENT;
+	public static final String ResourceTypeSynthesized = "org.apache.aries.subsystem.resource.synthesized";
 	public static final String SubsystemServicePropertyRegions = "org.apache.aries.subsystem.service.regions";
 	
 	private Constants() {}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java?rev=1430023&r1=1430022&r2=1430023&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/DependencyCalculator.java
Mon Jan  7 21:32:50 2013
@@ -87,8 +87,8 @@ public class DependencyCalculator {
 			
 			public Resource() {
 				Map<String, Object> attributes = new HashMap<String, Object>();
-				attributes.put(IdentityNamespace.IDENTITY_NAMESPACE, "org.apache.aries.subsystem.resource.dummy");
-				attributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, IdentityNamespace.TYPE_UNKNOWN);
+				attributes.put(IdentityNamespace.IDENTITY_NAMESPACE, org.apache.aries.subsystem.core.internal.Constants.ResourceTypeSynthesized);
+				attributes.put(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE, org.apache.aries.subsystem.core.internal.Constants.ResourceTypeSynthesized);
 				identity = new BasicCapability(IdentityNamespace.IDENTITY_NAMESPACE, attributes, null,
this);
 			}
 			

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java?rev=1430023&r1=1430022&r2=1430023&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.java
Mon Jan  7 21:32:50 2013
@@ -18,9 +18,13 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -41,9 +45,11 @@ import org.apache.aries.util.filesystem.
 import org.apache.aries.util.filesystem.IDirectory;
 import org.apache.aries.util.filesystem.IFile;
 import org.apache.aries.util.io.IOUtils;
+import org.apache.aries.util.manifest.ManifestHeaderProcessor;
 import org.apache.aries.util.manifest.ManifestProcessor;
 import org.osgi.framework.Version;
 import org.osgi.framework.namespace.BundleNamespace;
+import org.osgi.framework.namespace.IdentityNamespace;
 import org.osgi.framework.namespace.PackageNamespace;
 import org.osgi.namespace.service.ServiceNamespace;
 import org.osgi.resource.Capability;
@@ -56,6 +62,7 @@ import org.osgi.service.subsystem.Subsys
 
 public class RawSubsystemResource implements Resource {
 	private static final Pattern PATTERN = Pattern.compile("([^@/\\\\]+)(?:@(.+))?.esa");
+	private static final String APPLICATION_IMPORT_SERVICE_HEADER = "Application-ImportService";
 	
 	private static SubsystemManifest computeExistingSubsystemManifest(IDirectory directory)
throws IOException {
 		Manifest manifest = ManifestProcessor.obtainManifestFromAppDir(directory, "OSGI-INF/SUBSYSTEM.MF");
@@ -98,6 +105,7 @@ public class RawSubsystemResource implem
 	private final Location location;
 	private final List<Requirement> requirements;
 	private final Collection<Resource> resources;
+	private final Resource fakeImportServiceResource;
 	private final SubsystemManifest subsystemManifest;
 	
 	public RawSubsystemResource(String location, IDirectory content) throws URISyntaxException,
IOException, ResolutionException, ModellerException {
@@ -107,8 +115,9 @@ public class RawSubsystemResource implem
 			content = this.location.open();
 		try {
 			resources = computeResources(content);
-			localRepository = computeLocalRepository();
 			SubsystemManifest manifest = computeSubsystemManifest(content);
+			fakeImportServiceResource = createFakeResource(manifest);
+			localRepository = computeLocalRepository();
 			manifest = computeSubsystemManifestBeforeRequirements(manifest);
 			requirements = computeRequirements(manifest);
 			subsystemManifest = computeSubsystemManifestAfterRequirements(manifest);
@@ -126,6 +135,7 @@ public class RawSubsystemResource implem
 	
 	public RawSubsystemResource(IDirectory idir) throws IOException, URISyntaxException, ResolutionException
{
 		resources = Collections.emptyList();
+		fakeImportServiceResource = null; // not needed for persistent subsystems
 		localRepository = computeLocalRepository();
 		subsystemManifest = initializeSubsystemManifest(idir);
 		requirements = subsystemManifest.toRequirements(this);
@@ -134,7 +144,54 @@ public class RawSubsystemResource implem
 		id = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue());
 		location = new Location(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LOCATION).getValue());
 	}
-	
+
+	private static Resource createFakeResource(SubsystemManifest manifest) {
+		Header<?> importServiceHeader = manifest.getHeaders().get(APPLICATION_IMPORT_SERVICE_HEADER);
+		if (importServiceHeader == null) {
+			return null;
+		}
+		List<Capability> modifiableCaps = new ArrayList<Capability>();
+		final List<Capability> fakeCapabilities = Collections.unmodifiableList(modifiableCaps);
+		Resource fakeResource = new Resource() {
+
+			@Override
+			public List<Capability> getCapabilities(String namespace) {
+				if (namespace == null) {
+					return fakeCapabilities;
+				}
+				List<Capability> results = new ArrayList<Capability>();
+				for (Capability capability : fakeCapabilities) {
+					if (namespace.equals(capability.getNamespace())) {
+						results.add(capability);
+					}
+				}
+				return results;
+			}
+
+			@Override
+			public List<Requirement> getRequirements(String namespace) {
+				return Collections.emptyList();
+			}
+		};
+
+		modifiableCaps.add(new OsgiIdentityCapability(fakeResource, Constants.ResourceTypeSynthesized,
new Version(1,0,0), Constants.ResourceTypeSynthesized));
+    	Map<String, Map<String, String>> serviceImports = ManifestHeaderProcessor.parseImportString(importServiceHeader.getValue());
+    	for (Entry<String, Map<String, String>> serviceImport : serviceImports.entrySet())
{
+			Collection<String> objectClasses = new ArrayList<String>(Arrays.asList(serviceImport.getKey()));
+			String filter = serviceImport.getValue().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
+			BasicCapability.Builder capBuilder = new BasicCapability.Builder();
+			capBuilder.namespace(ServiceNamespace.SERVICE_NAMESPACE);
+			capBuilder.attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClasses);
+			if (filter != null)
+				capBuilder.attributes(new HashMap<String, Object>(ManifestHeaderProcessor.parseFilter(filter)));
+			capBuilder.attribute("service.imported", "");
+			capBuilder.resource(fakeResource);
+			modifiableCaps.add(capBuilder.build());
+		}
+
+    	return fakeResource;
+	}
+
 	@Override
 	public boolean equals(Object o) {
 		if (o == this)
@@ -265,6 +322,11 @@ public class RawSubsystemResource implem
 	}
 	
 	private Repository computeLocalRepository() {
+		if (fakeImportServiceResource != null) {
+			Collection<Resource> temp = new ArrayList<Resource>(resources);
+			temp.add(fakeImportServiceResource);
+			return new LocalRepository(temp);
+		}
 		return new LocalRepository(resources);
 	}
 	

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java?rev=1430023&r1=1430022&r2=1430023&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ResourceInstaller.java
Mon Jan  7 21:32:50 2013
@@ -31,7 +31,16 @@ public abstract class ResourceInstaller 
 			return new SubsystemResourceInstaller(coordination, resource, subsystem);
 		else if (IdentityNamespace.TYPE_BUNDLE.equals(type) || IdentityNamespace.TYPE_FRAGMENT.equals(type))
 			return new BundleResourceInstaller(coordination, resource, subsystem);
-		else
+		else if (Constants.ResourceTypeSynthesized.equals(type)) {
+			return new ResourceInstaller(coordination, resource, subsystem) {
+				
+				@Override
+				public Resource install() throws Exception {
+					// do nothing;
+					return resource;
+				}
+			};
+		}
 			throw new SubsystemException("No installer exists for resource type: " + type);
 	}
 	



Mime
View raw message