aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1242600 - 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/main/java/org/apache/aries/subsystem/core/...
Date Thu, 09 Feb 2012 23:14:15 GMT
Author: jwross
Date: Thu Feb  9 23:14:14 2012
New Revision: 1242600

URL: http://svn.apache.org/viewvc?rev=1242600&view=rev
Log:
ARIES-825: Update subsystems to latest Subsystem, Resolver, and Repository APIs.

Initial support for region context bundle.

Added:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/BasicRequirement.java
Removed:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RootSubsystem.java
    aries/trunk/subsystem/subsystem-itests/src/test/resources/feature3/tb3.jar
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemFileResource.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemTest.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java?rev=1242600&r1=1242599&r2=1242600&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/DeploymentManifest.java
Thu Feb  9 23:14:14 2012
@@ -64,7 +64,7 @@ public class DeploymentManifest extends 
 				resources.add(resource);
 			}
 			// TODO This does not validate that all content bundles were found.
-			Map<Resource, List<Wire>> resolution = Activator.getInstance().getServiceProvider().getService(Resolver.class).resolve(environment,
resources, Collections.EMPTY_LIST);
+			Map<Resource, List<Wire>> resolution = Activator.getInstance().getServiceProvider().getService(Resolver.class).resolve(environment,
new ArrayList<Resource>(resources), Collections.EMPTY_LIST);
 			// TODO Once we have a resolver that actually returns lists of wires, we can use them
to compute other manifest headers such as Import-Package.
 			Collection<Resource> deployedContent = new HashSet<Resource>();
 			Collection<Resource> provisionResource = new HashSet<Resource>();

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java?rev=1242600&r1=1242599&r2=1242600&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/SubsystemArchive.java
Thu Feb  9 23:14:14 2012
@@ -335,7 +335,8 @@ public class SubsystemArchive implements
 		OutputStream out = new FileOutputStream(file);
 		try {
 			dataFile.write(out);
-			resources.remove(old);
+			if (old != null)
+				resources.remove(old);
 			resources.put(dataFile, file.toURI().toURL());
 		} finally {
 			out.close();
@@ -354,7 +355,8 @@ public class SubsystemArchive implements
 		OutputStream out = new FileOutputStream(file);
 		try {
 			manifest.write(out);
-			resources.remove(old);
+			if (old != null)
+				resources.remove(old);
 			resources.put(manifest, file.toURI().toURL());
 		} finally {
 			out.close();
@@ -373,7 +375,8 @@ public class SubsystemArchive implements
 		OutputStream out = new FileOutputStream(file);
 		try {
 			manifest.write(out);
-			resources.remove(old);
+			if (old != null)
+				resources.remove(old);
 			resources.put(manifest, file.toURI().toURL());
 		}
 		finally {
@@ -387,17 +390,17 @@ public class SubsystemArchive implements
 			return new SubsystemArchive(file);
 		if (file.getName().endsWith(".jar"))
 			return BundleResource.newInstance(file.toURI().toURL());
-		else if (!file.getName().startsWith("subsystem") && file.getName().endsWith(".ssa"))
+		if (!file.getName().startsWith("subsystem") && file.getName().endsWith(".ssa"))
 			return new SubsystemFileResource(file);
-		else if (file.getName().endsWith("SUBSYSTEM.MF"))
+		if (file.getName().endsWith("SUBSYSTEM.MF"))
 			return new SubsystemManifest(file);
-		else if (file.getName().endsWith("DEPLOYMENT.MF"))
+		if (file.getName().endsWith("DEPLOYMENT.MF"))
 			return new DeploymentManifest(file);
-		else if (file.getName().endsWith(DataFile.IDENTITY_TYPE))
+		if (file.getName().endsWith(DataFile.IDENTITY_TYPE))
 			return new DataFile(file);
-		else if (file.getName().endsWith(StaticDataFile.IDENTITY_TYPE))
+		if (file.getName().endsWith(StaticDataFile.IDENTITY_TYPE))
 			return new StaticDataFile(file);
-		logger.warn("Ignoring unsupported resource type: " + file.getCanonicalPath());
+		logger.warn("Ignoring unsupported resource type: " + file.getAbsolutePath());
 		return null;
 	}
 	

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java?rev=1242600&r1=1242599&r2=1242600&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/AriesSubsystem.java
Thu Feb  9 23:14:14 2012
@@ -78,7 +78,7 @@ import org.osgi.service.subsystem.Subsys
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class AriesSubsystem implements Subsystem, Resource, RepositoryContent {
+public class AriesSubsystem implements Subsystem, Resource {
 	public static final String ROOT_SYMBOLIC_NAME = "org.osgi.service.subsystem.root";
 	public static final Version ROOT_VERSION = Version.parseVersion("1.0.0");
 	public static final String ROOT_LOCATION = "subsystem://?"
@@ -331,63 +331,18 @@ public class AriesSubsystem implements S
 		this.parents.add(parent);
 		id = data.getSubsystemId();
 		String directoryName = "subsystem" + id;
-//		String fileName = directoryName + ".ssa";
 		directory = new File(parent.directory, directoryName);
-//		if (!directory.mkdir())
-//			throw new IOException("Unable to make directory for "
-//					+ directory.getCanonicalPath());
-//		File zipFile = new File(directory, fileName);
-//		try {
-//			copyContent(content, zipFile);
-//			unzipContent(zipFile);
-//			archive = new SubsystemArchive(directory);
-//		} catch (Exception e) {
-//			deleteFile(directory);
-//			deleteFile(zipFile);
-//			throw new SubsystemException(e);
-//		}
 		environment = new SubsystemEnvironment(this);
-//		if (archive.getSubsystemManifest() == null) {
-//			// TODO Since it's optional to use the subsystem URI, it might be
-//			// better to create the URI in a try/catch block and throw an
-//			// exception with a message indicating we received a subsystem
-//			// with no manifest and no subsystem URI.
-//			archive.setSubsystemManifest(SubsystemManifest.newInstance(
-//					uri.getSymbolicName(), uri.getVersion(),
-//					archive.getResources()));
-//			// TODO If the subsystem manifest is not null, need to provide
-//			// default headers if subsystem URI was used.
-//		}
 		region = createRegion(data.getRegionName());
 	}
 	
-//	public AriesSubsystem(File content, AriesSubsystem parent) throws Exception {
-//		// Create a non-root, persisted subsystem.
-//		if (!content.isDirectory())
-//			throw new IllegalArgumentException(content.getCanonicalPath());
-//		this.parents.add(parent);
-//		directory = content;
-//		// TODO The following call leads to a potentially dangerous escaping 'this' reference
to this subsystem
-//		// (as the parent) if there is an embedded subsystem archive within this subsystem's
archive.
-//		// Need to investigate.
-//		archive = new SubsystemArchive(directory);
-//		environment = new SubsystemEnvironment(this);
-//		DataFile data = archive.getDataFile();
-//		id = data.getSubsystemId();
-//		location = data.getLocation();
-//		ServiceProvider sp = Activator.getInstance().getServiceProvider();
-//		RegionDigraph digraph = sp.getService(RegionDigraph.class);
-//		region = digraph.getRegion(data.getRegionName());
-//	}
-	
 	public SubsystemArchive getArchive() {
 		return archive;
 	}
 	
 	@Override
 	public BundleContext getBundleContext() {
-		// TODO Auto-generated method stub
-		return null;
+		return region.getBundle(RegionContextBundleHelper.SYMBOLICNAME_PREFIX + id, RegionContextBundleHelper.VERSION).getBundleContext();
 	}
 	
 	@Override
@@ -403,35 +358,16 @@ public class AriesSubsystem implements S
 	}
 
 	@Override
-	public Collection<Resource> getConstituents() {
-		/* 
-		 * TODO The definition of constituents needs to be worked out from both a design and implementation
perspective.
-		 * (1) In general, any Resource type except for osgi.subsystem.
-		 * (2) A transitive dependency if this is the root subsystem or provision-policy:=acceptTransitive.
-		 * (3) A content Resource of this subsystem if the Resource is not also a subsystem (also,
doesn't apply to 
-		 *     the root subsystem since it has no content resources).
-		 * (4) A bundle Resource installed into a region by means other than the subsystem API
(primarily for the 
-		 *     root subsystem which shares the kernel region but could apply to any subsystem).
-		 * (5) Caution with 4: this does not include feature content resources installed into a
non-feature subsystem region. 
-		 *     These are constituents of the feature itself.
-		 */
-		if (isRoot()) {
-			// TODO This does not take into account the possibility that resource types other than
bundle became part of the root subsystem.
+	public synchronized Collection<Resource> getConstituents() {
+		Collection<Resource> resources = new ArrayList<Resource>();
+		if (isRoot() || isApplication() || isComposite()) {
 			Set<Long> bundleIds = region.getBundleIds();
-			Collection<Resource> resources = new ArrayList<Resource>(bundleIds.size());
 			BundleContext context = Activator.getInstance().getBundleContext();
 			for (Long bundleId : bundleIds)
 				resources.add(context.getBundle(bundleId).adapt(BundleRevision.class));
-			return resources;
 		}
-		return Collections.unmodifiableCollection(constituents);
-	}
-	
-	@Override
-	public InputStream getContent() throws IOException {
-		// TODO Assumes original archive location remains valid. Might want to
-		// copy zipped archive to subsystem directory as well as extracted contents.
-		return new URL(location).openStream();
+		resources.addAll(constituents);
+		return Collections.unmodifiableCollection(resources);
 	}
 
 	@Override
@@ -717,7 +653,8 @@ public class AriesSubsystem implements S
 		return region;
 	}
 	
-	void install() throws Exception {
+	synchronized void install() throws Exception {
+		RegionContextBundleHelper.installRegionContextBundle(this);
 		Activator.getInstance().getSubsystemServiceRegistrar().register(this);
 		List<Resource> contentResources = new ArrayList<Resource>();
 		List<Resource> transitiveDependencies = new ArrayList<Resource>();

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java?rev=1242600&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RegionContextBundleHelper.java
Thu Feb  9 23:14:14 2012
@@ -0,0 +1,65 @@
+package org.apache.aries.subsystem.core.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+
+public class RegionContextBundleHelper {
+	public static final String SYMBOLICNAME_PREFIX = "org.osgi.service.subsystem.region.context.";
+	public static final Version VERSION = Version.parseVersion("1.0.0");
+	
+	public static void installRegionContextBundle(AriesSubsystem subsystem) throws BundleException,
IOException {
+		String symbolicName = SYMBOLICNAME_PREFIX + subsystem.getSubsystemId();
+		String location = subsystem.getLocation() + '/' + subsystem.getSubsystemId();
+		Bundle b = subsystem.getRegion().getBundle(symbolicName, VERSION);
+		if (b != null)
+			return;
+		Bundle t = subsystem.getRegion().installBundle(location + "/temp", createTempBundle(symbolicName));
+		try {
+			t.start();
+			b = t.getBundleContext().installBundle(location, createRegionContextBundle(symbolicName));
+		}
+		finally {
+			try {
+				t.uninstall();
+			}
+			catch (BundleException e) {}
+		}
+		b.start(Bundle.START_TRANSIENT);
+	}
+	
+	private static InputStream createRegionContextBundle(String symbolicName) throws IOException
{
+		Manifest manifest = createManifest(symbolicName);
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		JarOutputStream jos = new JarOutputStream(baos, manifest);
+		jos.close();
+		return new ByteArrayInputStream(baos.toByteArray());
+	}
+	
+	private static Manifest createManifest(String symbolicName) {
+		Manifest manifest = new Manifest();
+		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+		manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, symbolicName);
+		manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, VERSION.toString());
+		return manifest;
+	}
+	
+	private static InputStream createTempBundle(String symbolicName) throws IOException {
+		Manifest manifest = new Manifest();
+		manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
+		manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, symbolicName + ".temp");
+		ByteArrayOutputStream baos = new ByteArrayOutputStream();
+		JarOutputStream jos = new JarOutputStream(baos, manifest);
+		jos.close();
+		return new ByteArrayInputStream(baos.toByteArray());
+	}
+}

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/BasicRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/BasicRequirement.java?rev=1242600&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/BasicRequirement.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/BasicRequirement.java
Thu Feb  9 23:14:14 2012
@@ -0,0 +1,54 @@
+package org.apache.aries.subsystem.core.resource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.resource.Resource;
+
+public class BasicRequirement extends AbstractRequirement {
+	private final Map<String, Object> attributes;
+	private final Map<String, String> directives;
+	private final String namespace;
+	private final Resource resource;
+	
+	public BasicRequirement(String namespace, String filter) throws InvalidSyntaxException {
+		this(namespace, FrameworkUtil.createFilter(filter));
+	}
+	
+	public BasicRequirement(String namespace, Filter filter) {
+		if (namespace == null)
+			throw new NullPointerException("Missing required parameter: namespace");
+		attributes = Collections.emptyMap();
+		Map<String, String> directives = new HashMap<String, String>(1);
+		directives.put(Constants.FILTER_DIRECTIVE, filter.toString());
+		this.directives = Collections.unmodifiableMap(directives);
+		this.namespace = namespace;
+		resource = null;
+	}
+
+	@Override
+	public Map<String, Object> getAttributes() {
+		return attributes;
+	}
+
+	@Override
+	public Map<String, String> getDirectives() {
+		return 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/resource/SubsystemFileResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemFileResource.java?rev=1242600&r1=1242599&r2=1242600&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemFileResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/resource/SubsystemFileResource.java
Thu Feb  9 23:14:14 2012
@@ -10,7 +10,6 @@ import java.util.List;
 import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.zip.ZipInputStream;
 
 import org.apache.aries.subsystem.core.archive.SubsystemSymbolicNameHeader;
 import org.apache.aries.subsystem.core.internal.OsgiIdentityCapability;

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java?rev=1242600&r1=1242599&r2=1242600&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/RootSubsystemTest.java
Thu Feb  9 23:14:14 2012
@@ -6,6 +6,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.Version;
 import org.osgi.service.subsystem.Subsystem;
@@ -25,6 +26,14 @@ public class RootSubsystemTest extends S
 	}
 	
 	@Test
+	public void testRegionContextBundle() throws BundleException {
+		assertRegionContextBundle(getRootSubsystem());
+		getSubsystemCoreBundle().stop();
+		getSubsystemCoreBundle().start();
+		assertRegionContextBundle(getRootSubsystem());
+	}
+	
+	@Test
 	public void testServiceEventsFresh() throws Exception {
 		Subsystem root = getRootSubsystem();
 		Bundle core = getSubsystemCoreBundle();

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=1242600&r1=1242599&r2=1242600&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 Feb  9 23:14:14 2012
@@ -43,6 +43,7 @@ import org.apache.felix.bundlerepository
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceEvent;
@@ -50,6 +51,7 @@ import org.osgi.framework.ServiceListene
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.Version;
 import org.osgi.framework.resource.Resource;
+import org.osgi.framework.resource.ResourceConstants;
 import org.osgi.service.repository.Repository;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.Subsystem.State;
@@ -316,6 +318,17 @@ public abstract class SubsystemTest exte
 		fail("Parent did not exist: " + expected.getSymbolicName());
 	}
 	
+	protected void assertRegionContextBundle(Subsystem s) {
+		BundleContext bc = s.getBundleContext();
+		assertNotNull("No region context bundle", bc);
+		Bundle b = bc.getBundle();
+		assertEquals("Not active", Bundle.ACTIVE, b.getState());
+		assertEquals("Wrong location", s.getLocation() + '/' + s.getSubsystemId(), b.getLocation());
+		assertEquals("Wrong symbolic name", "org.osgi.service.subsystem.region.context." + s.getSubsystemId(),
b.getSymbolicName());
+		assertEquals("Wrong version", Version.parseVersion("1.0.0"), b.getVersion());
+		assertConstituent(s, "org.osgi.service.subsystem.region.context." + s.getSubsystemId(),
Version.parseVersion("1.0.0"), ResourceConstants.IDENTITY_TYPE_BUNDLE);
+	}
+	
 	protected void assertState(State expected, State actual) {
 		assertState(EnumSet.of(expected), actual);
 	}



Mime
View raw message