aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1704916 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/
Date Wed, 23 Sep 2015 19:07:00 GMT
Author: jwross
Date: Wed Sep 23 19:06:59 2015
New Revision: 1704916

URL: http://svn.apache.org/viewvc?rev=1704916&view=rev
Log:
ARIES-1387 Make equals and hashCode comparisons within the header, clause, and parameter hierarchies
based on equivalency rather than string equals.

Fix a regression causing a CT failure in org.osgi.test.cases.subsystem.junit.InstallSubsystemTests.test2F2
where an empty string is used for the
subsystem location.

First, add a test using an empty string as the subsystem location.

Second, fix issue where a java.lang.StringIndexOutOfBoundsException can be received from AbstractClauseBasedHeader.toString()
because a header with an empty
string value was allowed to be created. One constructor will throw an IAE if there are no
clauses, the other does not. Make it consistent. Since the specification
does not allow empty string header values, continue to throw the IAE. Also, replace the existing
IAE message because it relies on a call to a subclass method where the name will always be
null because the variable has not been
initialized yet.

Finally, add a dedicated class for the internal use only AriesSubsystem-Location header. The
header value is treated as an opaque string
with no syntactic contraints other than it may not be null.

Added:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AriesSubsystemLocationHeader.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AbstractClauseBasedHeader.java
    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/HeaderFactory.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/archive/AbstractClauseBasedHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AbstractClauseBasedHeader.java?rev=1704916&r1=1704915&r2=1704916&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AbstractClauseBasedHeader.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AbstractClauseBasedHeader.java
Wed Sep 23 19:06:59 2015
@@ -19,6 +19,15 @@ import java.util.HashSet;
 import java.util.Set;
 
 public abstract class AbstractClauseBasedHeader<C extends Clause> implements Header<C>
{
+	private static <C> Collection<C> computeClauses(String header, ClauseFactory<C>
factory) {
+		Collection<String> clauseStrs = new ClauseTokenizer(header).getClauses();
+		Set<C> clauses = new HashSet<C>(clauseStrs.size());
+		for (String clause : clauseStrs) {
+			clauses.add(factory.newInstance(clause));
+		}
+		return clauses;
+	}
+	
 	public interface ClauseFactory<C> {
 		public C newInstance(String clause);
 	}
@@ -27,19 +36,13 @@ public abstract class AbstractClauseBase
     
     public AbstractClauseBasedHeader(Collection<C> clauses) {
         if (clauses.isEmpty()) {
-            throw new IllegalArgumentException(String.format(
-                    "The header %s must have at least one clause.", getName()));
+            throw new IllegalArgumentException("No clauses");
         }
         this.clauses = Collections.synchronizedSet(new HashSet<C>(clauses));
     }
 
     public AbstractClauseBasedHeader(String header, ClauseFactory<C> factory) {
-    	Collection<String> clauseStrs = new ClauseTokenizer(header).getClauses();
-		Set<C> clauses = new HashSet<C>(clauseStrs.size());
-		for (String clause : new ClauseTokenizer(header).getClauses()) {
-			clauses.add(factory.newInstance(clause));
-		}
-		this.clauses = Collections.synchronizedSet(clauses);
+    	this(computeClauses(header, factory));
     }
 
     @Override

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AriesSubsystemLocationHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AriesSubsystemLocationHeader.java?rev=1704916&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AriesSubsystemLocationHeader.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/AriesSubsystemLocationHeader.java
Wed Sep 23 19:06:59 2015
@@ -0,0 +1,73 @@
+package org.apache.aries.subsystem.core.archive;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class AriesSubsystemLocationHeader implements Header<Clause> {
+	public static final String NAME = "AriesSubsystem-Location";
+	
+	private final String value;
+
+	public AriesSubsystemLocationHeader(String value) {
+		if (value == null) {
+			throw new NullPointerException();
+		}
+		this.value = value;
+	}
+
+	@Override
+	public Collection<Clause> getClauses() {
+		return Collections.<Clause>singleton(
+				new Clause() {
+					@Override
+					public Attribute getAttribute(String name) {
+						return null;
+					}
+
+					@Override
+					public Collection<Attribute> getAttributes() {
+						return Collections.emptyList();
+					}
+
+					@Override
+					public Directive getDirective(String name) {
+						return null;
+					}
+
+					@Override
+					public Collection<Directive> getDirectives() {
+						return Collections.emptyList();
+					}
+
+					@Override
+					public Parameter getParameter(String name) {
+						return null;
+					}
+
+					@Override
+					public Collection<Parameter> getParameters() {
+						return Collections.emptyList();
+					}
+
+					@Override
+					public String getPath() {
+						return value;
+					}
+				});
+	}
+
+	@Override
+	public String getName() {
+		return NAME;
+	}
+
+	@Override
+	public String getValue() {
+		return value;
+	}
+	
+	@Override
+	public String toString() {
+		return value;
+	}
+}

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=1704916&r1=1704915&r2=1704916&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
Wed Sep 23 19:06:59 2015
@@ -51,10 +51,6 @@ public class DeploymentManifest {
 			return this;
 		}
 		
-//		public Builder content(Resource resource) {
-//			return content(resource, true);
-//		}
-		
 		public Builder content(Resource resource, boolean referenced) {
 			DeployedContentHeader header = (DeployedContentHeader)headers.get(DeploymentManifest.DEPLOYED_CONTENT);
 			if (header == null) {
@@ -101,7 +97,7 @@ public class DeploymentManifest {
 		
 		public Builder location(String value) {
 			if (value != null)
-				header(new GenericHeader(ARIESSUBSYSTEM_LOCATION, value));
+				header(new AriesSubsystemLocationHeader(value));
 			return this;
 		}
 		
@@ -168,7 +164,7 @@ public class DeploymentManifest {
 	public static final String ARIESSUBSYSTEM_AUTOSTART = "AriesSubsystem-Autostart";
 	public static final String ARIESSUBSYSTEM_ID = "AriesSubsystem-Id";
 	public static final String ARIESSUBSYSTEM_LASTID = "AriesSubsystem-LastId";
-	public static final String ARIESSUBSYSTEM_LOCATION = "AriesSubsystem-Location";
+	public static final String ARIESSUBSYSTEM_LOCATION = AriesSubsystemLocationHeader.NAME;
 	public static final String ARIESSUBSYSTEM_PARENTS = "AriesSubsystem-Parents";
 	public static final String ARIESSUBSYSTEM_REGION = "AriesSubsystem-Region";
 	public static final String ARIESSUBSYSTEM_STATE = "AriesSubsystem-State";
@@ -220,7 +216,7 @@ public class DeploymentManifest {
 		// TODO DEPLOYMENT_MANIFESTVERSION
 		headers.put(ARIESSUBSYSTEM_AUTOSTART, new GenericHeader(ARIESSUBSYSTEM_AUTOSTART, Boolean.toString(autostart)));
 		headers.put(ARIESSUBSYSTEM_ID, new GenericHeader(ARIESSUBSYSTEM_ID, Long.toString(id)));
-		headers.put(ARIESSUBSYSTEM_LOCATION, new GenericHeader(ARIESSUBSYSTEM_LOCATION, location));
+		headers.put(ARIESSUBSYSTEM_LOCATION, new AriesSubsystemLocationHeader(location));
 		headers.put(ARIESSUBSYSTEM_LASTID, new GenericHeader(ARIESSUBSYSTEM_LASTID, Long.toString(lastId)));
 		this.headers = Collections.unmodifiableMap(headers);
 	}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/HeaderFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/HeaderFactory.java?rev=1704916&r1=1704915&r2=1704916&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/HeaderFactory.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/HeaderFactory.java
Wed Sep 23 19:06:59 2015
@@ -124,6 +124,8 @@ public class HeaderFactory {
 			return new SubsystemLocalizationHeader(value);
 		if (FragmentHostHeader.NAME.equals(name))
 		    return new FragmentHostHeader(value);
+		if (AriesSubsystemLocationHeader.NAME.equals(value))
+			return new AriesSubsystemLocationHeader(value);
 		return new GenericHeader(name, value);
 			
 	}

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=1704916&r1=1704915&r2=1704916&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 23 19:06:59 2015
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.subsystem.itests;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -30,6 +31,8 @@ import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.aries.subsystem.core.archive.DeploymentManifest;
+import org.apache.aries.subsystem.core.internal.BasicSubsystem;
 import org.apache.aries.subsystem.itests.util.Utils;
 import org.apache.aries.unittest.fixture.ArchiveFixture;
 import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
@@ -43,6 +46,7 @@ import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.SubsystemConstants;
+import org.osgi.service.subsystem.SubsystemException;
 
 @ExamReactorStrategy(PerMethod.class)
 public class InstallTest extends SubsystemTest {
@@ -278,4 +282,23 @@ public class InstallTest extends Subsyst
 			uninstallSubsystemSilently(featureA);
 		}
 	}
+	
+	@Test
+    public void testLocationAsEmptyString() throws Exception {
+    	try {
+    		Subsystem a = installSubsystemFromFile(getRootSubsystem(), new File(APPLICATION_A),
"");
+    		try {
+    			BasicSubsystem basic = (BasicSubsystem)a;
+    			String location = basic.getLocation();
+    			assertEquals("Location value should be an empty string", "", location);
+    		}
+    		finally {
+    			uninstallSubsystemSilently(a);
+    		}
+    	}
+    	catch (SubsystemException e) {
+    		e.printStackTrace();
+    		fail("Subsystem should have installed");
+    	}
+    }
 }

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=1704916&r1=1704915&r2=1704916&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 23 19:06:59 2015
@@ -34,6 +34,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Field;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -789,6 +790,10 @@ public abstract class SubsystemTest exte
 	private Subsystem installSubsystemFromFile(File file) throws Exception {
 		return installSubsystem(getRootSubsystem(), file.toURI().toURL().toExternalForm());
 	}
+	
+	protected Subsystem installSubsystemFromFile(Subsystem parent, File file, String location)
throws Exception {
+		return installSubsystem(parent, location, new URL(file.toURI().toURL().toExternalForm()).openStream());
+	}
 
 	protected Subsystem installSubsystem(String location) throws Exception {
 		return installSubsystem(getRootSubsystem(), location);



Mime
View raw message