aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1558324 - in /aries/trunk/subsystem/subsystem-core/src: main/java/org/apache/aries/subsystem/core/internal/Location.java test/java/org/apache/aries/subsystem/core/internal/LocationTest.java
Date Wed, 15 Jan 2014 09:30:20 GMT
Author: davidb
Date: Wed Jan 15 09:30:20 2014
New Revision: 1558324

URL: http://svn.apache.org/r1558324
Log:
Fix for ARIES-1147

Solution as suggested by John Ross.
Includes new unit tests.

Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Location.java
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.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=1558324&r1=1558323&r2=1558324&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 Jan 15 09:30:20 2014
@@ -55,9 +55,21 @@ public class Location {
       String scheme = locationUri.getScheme();
       if (LocationType.SUBSYSTEM.scheme.equals(scheme)) {
         type = LocationType.SUBSYSTEM;
-        subsystemUri = new SubsystemUri(location);
-        url = subsystemUri.getURL(); // subsystem uris may contain a nested url.
-        uri = (url==null) ? null : url.toURI(); 
+        SubsystemUri ssUri;
+        try {
+          ssUri = new SubsystemUri(location);
+        } catch (Exception ex) {
+          // In some cases the SubsystemUri can't be parsed by the SubsystemUri parser.
+          ssUri = null;
+        }
+        subsystemUri = ssUri;
+        if (subsystemUri != null) {
+          url = subsystemUri.getURL(); // subsystem uris may contain a nested url.
+          uri = (url==null) ? null : url.toURI();
+        } else {
+          url = null;
+          uri = locationUri;
+        }
       } else if (LocationType.IDIRFINDER.scheme.equals(scheme)) {
         type = LocationType.IDIRFINDER;
         subsystemUri = null;
@@ -82,11 +94,11 @@ public class Location {
   }
     
   public String getSymbolicName() {
-    return (type==LocationType.SUBSYSTEM) ? subsystemUri.getSymbolicName() : null;
+    return (subsystemUri!=null) ? subsystemUri.getSymbolicName() : null;
   }
     
   public Version getVersion() {
-    return (type==LocationType.SUBSYSTEM) ? subsystemUri.getVersion() : null;
+    return (subsystemUri!=null) ? subsystemUri.getVersion() : null;
   }
 
   public IDirectory open() throws IOException, URISyntaxException {
@@ -127,4 +139,4 @@ public class Location {
     throw new IOException("cannot find IDirectory corresponding to id " + uri);
   }
 
-}
\ No newline at end of file
+}

Modified: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java?rev=1558324&r1=1558323&r2=1558324&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/LocationTest.java
Wed Jan 15 09:30:20 2014
@@ -20,6 +20,7 @@ import static org.junit.Assert.fail;
 import java.net.MalformedURLException;
 
 import org.junit.Test;
+import org.osgi.framework.Version;
 
 public class LocationTest {
 	@Test
@@ -48,4 +49,26 @@ public class LocationTest {
 			fail("Wrong exception");
 		}
 	}
+
+    @Test
+    public void testSubsystemLocation() throws Exception {
+        // In some cases the following location string is generated
+        String locationString = "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.2.3";
+
+        Location location = new Location(locationString);
+        assertEquals(locationString, location.getValue());
+        assertEquals("org.osgi.service.subsystem.root", location.getSymbolicName());
+        assertEquals(Version.parseVersion("1.2.3"), location.getVersion());
+    }
+
+    @Test
+	public void testSubsystemLocationInvalid() throws Exception {
+	    // In some cases the following location string is generated
+	    String locationString = "subsystem://?Subsystem-SymbolicName=org.osgi.service.subsystem.root&Subsystem-Version=1.0.0!/my-subsystem@0.5.0";
+
+	    Location location = new Location(locationString);
+	    assertEquals(locationString, location.getValue());
+	    assertNull(location.getSymbolicName());
+	    assertNull(location.getVersion());
+	}
 }



Mime
View raw message