aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1414213 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/
Date Tue, 27 Nov 2012 14:42:42 GMT
Author: jwross
Date: Tue Nov 27 14:42:41 2012
New Revision: 1414213

URL: http://svn.apache.org/viewvc?rev=1414213&view=rev
Log:
[ARIES-972] Subsystem install fails with NPE if no subsystem manifest is contained in an ESA

The specification does not require implementations to generate symbolic names, so the failure
was intentional, although
a more informative exception could have been used. The specification does not prohibit implementations
from generating
them, however. A symbolic name with the pattern org.apache.aries.subsystem.<subsystem_id>
will now be automatically
generated as a last resort rather than failing the installation.

Added new tests.

Modified:
    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/SubsystemResource.java
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.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/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=1414213&r1=1414212&r2=1414213&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
Tue Nov 27 14:42:41 2012
@@ -93,6 +93,7 @@ public class RawSubsystemResource implem
 	
 	private final List<Capability> capabilities;
 	private final DeploymentManifest deploymentManifest;
+	private final long id;
 	private final Repository localRepository;
 	private final Location location;
 	private final List<Requirement> requirements;
@@ -100,6 +101,7 @@ public class RawSubsystemResource implem
 	private final SubsystemManifest subsystemManifest;
 	
 	public RawSubsystemResource(String location, IDirectory content) throws URISyntaxException,
IOException, ResolutionException, ModellerException {
+		id = SubsystemIdentifier.getNextId();
 		this.location = new Location(location);
 		if (content == null)
 			content = this.location.open();
@@ -129,6 +131,7 @@ public class RawSubsystemResource implem
 		requirements = subsystemManifest.toRequirements(this);
 		capabilities = subsystemManifest.toCapabilities(this);
 		deploymentManifest = initializeDeploymentManifest(idir);
+		id = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue());
 		location = new Location(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_LOCATION).getValue());
 	}
 	
@@ -158,6 +161,10 @@ public class RawSubsystemResource implem
 		return deploymentManifest;
 	}
 	
+	public long getId() {
+		return id;
+	}
+	
 	public Repository getLocalRepository() {
 		return localRepository;
 	}
@@ -379,9 +386,12 @@ public class RawSubsystemResource implem
 	
 	private SubsystemSymbolicNameHeader computeSubsystemSymbolicNameHeader(SubsystemManifest
manifest) {
 		SubsystemSymbolicNameHeader header = manifest.getSubsystemSymbolicNameHeader();
-		if (header == null)
-			header = new SubsystemSymbolicNameHeader(location.getSymbolicName());
-		return header;
+		if (header != null)
+			return header;
+		String symbolicName = location.getSymbolicName();
+		if (symbolicName == null)
+			symbolicName = "org.apache.aries.subsystem." + id;
+		return new SubsystemSymbolicNameHeader(symbolicName);
 	}
 	
 	private SubsystemVersionHeader computeSubsystemVersionHeader(SubsystemManifest manifest)
{

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=1414213&r1=1414212&r2=1414213&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
Tue Nov 27 14:42:41 2012
@@ -77,7 +77,6 @@ public class SubsystemResource implement
 	
 	private final List<Capability> capabilities;
 	private final DeploymentManifest deploymentManifest;
-	private final long id;
 	private final Collection<Resource> installableContent = new HashSet<Resource>();
 	private final Collection<Resource> installableDependencies = new HashSet<Resource>();
 	private final Collection<Resource> mandatoryResources = new HashSet<Resource>();
@@ -96,7 +95,6 @@ public class SubsystemResource implement
 	public SubsystemResource(RawSubsystemResource resource, BasicSubsystem parent) throws IOException,
BundleException, InvalidSyntaxException, URISyntaxException {
 		this.parent = parent;
 		this.resource = resource;
-		id = SubsystemIdentifier.getNextId();
 		preferredProviderRepository = new PreferredProviderRepository(this);
 		computeContentResources(resource.getDeploymentManifest());
 		capabilities = computeCapabilities();
@@ -113,7 +111,6 @@ public class SubsystemResource implement
 		resource = new RawSubsystemResource(directory);
 		preferredProviderRepository = null;
 		deploymentManifest = resource.getDeploymentManifest();
-		id = Long.parseLong(deploymentManifest.getHeaders().get(DeploymentManifest.ARIESSUBSYSTEM_ID).getValue());
 		computeContentResources(deploymentManifest);
 		capabilities = computeCapabilities();
 		computeDependencies(deploymentManifest);
@@ -167,7 +164,7 @@ public class SubsystemResource implement
 	}
 	
 	public long getId() {
-		return id;
+		return resource.getId();
 	}
 	
 	public Collection<Resource> getInstallableContent() {

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=1414213&r1=1414212&r2=1414213&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
Tue Nov 27 14:42:41 2012
@@ -19,10 +19,14 @@
 package org.apache.aries.subsystem.itests;
 
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.aries.subsystem.itests.util.Utils;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
@@ -37,6 +41,7 @@ import org.ops4j.pax.exam.junit.MavenCon
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
 import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemConstants;
 
 @RunWith(MavenConfiguredJUnit4TestRunner.class)
 public class InstallTest extends SubsystemTest {
@@ -89,6 +94,9 @@ public class InstallTest extends Subsyst
 		}
 		createApplication("feature3", new String[]{"tb3.jar"});
 		createApplication("feature2", new String[]{"tb3.jar", "tb2.jar"});
+		createBundleA();
+		createApplicationA();
+		createCompositeA();
 		createdApplications = true;
 	}
 	
@@ -175,4 +183,71 @@ public class InstallTest extends Subsyst
     		fail("Subsystem installation using directory URL as location failed");
     	}
     }
+    
+    /*
+	 * Bundle-SymbolicName: bundle.a.jar
+	 */
+	private static final String BUNDLE_A = "bundle.a.jar";
+	
+	private static void createBundleA() throws IOException {
+		createBundle(BUNDLE_A);
+	}
+    
+    /*
+	 * No symbolic name. No manifest.
+	 */
+	private static final String APPLICATION_A = "application.a.esa";
+	
+	private static void createApplicationA() throws IOException {
+		createApplicationAManifest();
+		createSubsystem(APPLICATION_A, BUNDLE_A);
+	}
+	
+	private static void createApplicationAManifest() throws IOException {
+		File manifest = new File(APPLICATION_A + ".mf");
+		if (manifest.exists())
+			assertTrue("Could not delete manifest", manifest.delete());
+	}
+    
+    @Test
+    public void testGeneratedSymbolicNameWithoutManifest() throws Exception {
+    	String expected = "org.apache.aries.subsystem.1";
+    	Subsystem a = installSubsystemFromFile(APPLICATION_A);
+    	try {
+    		assertSymbolicName(expected, a);
+    		assertSymbolicName(expected, a.getSubsystemHeaders(null).get(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME));
+    	}
+    	finally {
+    		uninstallSubsystemSilently(a);
+    	}
+    }
+    
+    /*
+	 * Manifest with no symbolic name header.
+	 */
+	private static final String COMPOSITE_A = "composite.a.esa";
+	
+	private static void createCompositeA() throws IOException {
+		createCompositeAManifest();
+		createSubsystem(COMPOSITE_A);
+	}
+	
+	private static void createCompositeAManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_TYPE, SubsystemConstants.SUBSYSTEM_TYPE_COMPOSITE);
+		createManifest(COMPOSITE_A + ".mf", attributes);
+	}
+	
+	@Test
+    public void testGeneratedSymbolicNameWithManifest() throws Exception {
+    	String expected = "org.apache.aries.subsystem.1";
+    	Subsystem a = installSubsystemFromFile(COMPOSITE_A);
+    	try {
+    		assertSymbolicName(expected, a);
+    		assertSymbolicName(expected, a.getSubsystemHeaders(null).get(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME));
+    	}
+    	finally {
+    		uninstallSubsystemSilently(a);
+    	}
+    }
 }

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=1414213&r1=1414212&r2=1414213&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
Tue Nov 27 14:42:41 2012
@@ -484,7 +484,11 @@ public abstract class SubsystemTest exte
 	}
 	
 	protected void assertSymbolicName(String expected, Subsystem subsystem) {
-		assertEquals("Wrong symbolic name: " + subsystem.getSymbolicName(), expected, subsystem.getSymbolicName());
+		assertSymbolicName(expected, subsystem.getSymbolicName());
+	}
+	
+	protected void assertSymbolicName(String expected, String actual) {
+		assertEquals("Wrong symbolic name", expected, actual);
 	}
 	
 	protected void assertType(String expected, Subsystem subsystem) {
@@ -552,8 +556,11 @@ public abstract class SubsystemTest exte
 	}
 	
 	protected static void createSubsystem(String name, String...contents) throws IOException
{
-		// The following input stream is closed by ArchiveFixture.copy.
-		ZipFixture fixture = ArchiveFixture.newZip().binary("OSGI-INF/SUBSYSTEM.MF", new FileInputStream(name
+ ".mf"));
+		File manifest = new File(name + ".mf");
+		ZipFixture fixture = ArchiveFixture.newZip();
+		if (manifest.exists())
+			// The following input stream is closed by ArchiveFixture.copy.
+			fixture.binary("OSGI-INF/SUBSYSTEM.MF", new FileInputStream(name + ".mf"));
 		if (contents != null) {
 			for (String content : contents) {
 				// The following input stream is closed by ArchiveFixture.copy.



Mime
View raw message