aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1387701 - 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 Wed, 19 Sep 2012 18:35:54 GMT
Author: jwross
Date: Wed Sep 19 18:35:53 2012
New Revision: 1387701

URL: http://svn.apache.org/viewvc?rev=1387701&view=rev
Log:
Initial support for installing subsystems as directories plus test.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/RawSubsystemResource.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/Location.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java?rev=1387701&r1=1387700&r2=1387701&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java
Wed Sep 19 18:35:53 2012
@@ -13,12 +13,14 @@
  */
 package org.apache.aries.subsystem.core.internal;
 
+import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
 
+import org.apache.aries.util.filesystem.FileSystem;
+import org.apache.aries.util.filesystem.IDirectory;
 import org.osgi.framework.Version;
 
 public class Location {
@@ -45,7 +47,10 @@ public class Location {
 		return uri == null ? null : uri.getVersion();
 	}
 	
-	public InputStream open() throws IOException {
-		return uri == null ? new URL(value).openStream() : uri.getURL().openStream();
+	public IDirectory open() throws IOException, URISyntaxException {
+		URL url = uri == null ? new URL(value) : uri.getURL();
+		if ("file".equals(url.getProtocol()))
+			return FileSystem.getFSRoot(new File(url.toURI()));
+		return FileSystem.getFSRoot(url.openStream());
 	}
 }
\ No newline at end of file

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=1387701&r1=1387700&r2=1387701&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
Wed Sep 19 18:35:53 2012
@@ -99,9 +99,11 @@ public class RawSubsystemResource implem
 	
 	public RawSubsystemResource(String location, InputStream content) throws URISyntaxException,
IOException, UnsupportedOperationException, ResolutionException {
 		this.location = new Location(location);
+		IDirectory idir;
 		if (content == null)
-			content = this.location.open();
-		IDirectory idir = FileSystem.getFSRoot(content);
+			idir = this.location.open();
+		else
+			idir = FileSystem.getFSRoot(content);
 		try {
 			resources = computeResources(idir);
 			localRepository = computeLocalRepository();

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=1387701&r1=1387700&r2=1387701&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
Wed Sep 19 18:35:53 2012
@@ -19,7 +19,13 @@
 package org.apache.aries.subsystem.itests;
 
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
 
+import java.io.File;
+
+import org.apache.aries.util.filesystem.FileSystem;
+import org.apache.aries.util.filesystem.IDirectory;
+import org.apache.aries.util.io.IOUtils;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -28,15 +34,24 @@ import org.osgi.service.subsystem.Subsys
 
 @RunWith(JUnit4TestRunner.class)
 public class InstallTest extends SubsystemTest {
-	
 	@Before
 	public static void createApplications() throws Exception {
 		if (createdApplications) {
 			return;
 		}
+		createApplication("emptySubsystem", new String[0]);
 		createApplication("feature3", new String[]{"tb3.jar"});
 		createdApplications = true;
 	}
+	
+	public void setUp() throws Exception {
+		super.setUp();
+		File userDir = new File(System.getProperty("user.dir"));
+    	IDirectory idir = FileSystem.getFSRoot(userDir);
+    	File emptySubsystem = new File(userDir, "emptySubsystem");
+    	emptySubsystem.mkdir();
+    	IOUtils.unpackZip(idir.getFile("emptySubsystem.esa"), emptySubsystem);
+	}
 
 	@Test
 	public void testReturnExistingSubsystemWithSameLocation() throws Exception {
@@ -49,4 +64,27 @@ public class InstallTest extends Subsyst
 			uninstallSubsystemSilently(subsystem1);
 		}
 	}
+	
+	/*
+     * Install a subsystem using a location string and a null input stream. The
+     * location string is a file URL pointing to a directory.
+     */
+    @Test
+    public void testLocationAsDirectoryUrl() throws Exception {
+    	File file = new File("emptySubsystem");
+    	try {
+    		Subsystem subsystem = installSubsystem(getRootSubsystem(), file.toURI().toString(),
null);
+    		try {
+    			assertEmptySubsystem(subsystem);
+    		}
+    		finally {
+    			uninstallSubsystemSilently(subsystem);
+    		}
+    		
+    	}
+    	catch (Exception e) {
+    		e.printStackTrace();
+    		fail("Subsystem installation using directory URL as location failed");
+    	}
+    }
 }

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=1387701&r1=1387700&r2=1387701&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
Wed Sep 19 18:35:53 2012
@@ -224,6 +224,12 @@ public abstract class SubsystemTest exte
 		super.tearDown();
 	}
 	
+	protected void assertEmptySubsystem(Subsystem subsystem) {
+    	assertSymbolicName("org.apache.aries.subsystem.itests.subsystem.empty", subsystem);
+    	assertVersion("0", subsystem);
+    	assertType(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION, subsystem);
+    }
+	
 	protected void assertBundleState(int state, String symbolicName, Subsystem subsystem) {
     	Bundle bundle = getBundle(subsystem, symbolicName);
     	assertBundleState(bundle, state);



Mime
View raw message