You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jw...@apache.org on 2016/02/24 20:18:59 UTC

svn commit: r1732208 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java

Author: jwross
Date: Wed Feb 24 19:18:59 2016
New Revision: 1732208

URL: http://svn.apache.org/viewvc?rev=1732208&view=rev
Log:
[ARIES-1338] Bundle manifest parser does not allow multiple packages on Import-Package clause

When converting an import package header into a requirement, the implementation now checks each clause for the presence of multiple package names and, if necessary, creates multiple
requirements for that clause.

Added:
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java?rev=1732208&r1=1732207&r2=1732208&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ImportPackageHeader.java Wed Feb 24 19:18:59 2016
@@ -73,7 +73,7 @@ public class ImportPackageHeader extends
 		}
 		
 		public Clause(String path, Map<String, Parameter> parameters, Collection<Parameter> defaultParameters) {
-			super(path, parameters, defaultParameters);
+			super(path, parameters, defaultParameters == null ? Clause.defaultParameters : defaultParameters);
 		}
 		
 		public Clause(String clause) {
@@ -136,7 +136,20 @@ public class ImportPackageHeader extends
 		Collection<Clause> clauses = getClauses();
 		List<ImportPackageRequirement> result = new ArrayList<ImportPackageRequirement>(clauses.size());
 		for (Clause clause : clauses) {
-			result.add(clause.toRequirement(resource));
+			Collection<String> packageNames = clause.getPackageNames();
+			if (packageNames.size() > 1) {
+				for (String packageName : packageNames) {
+					Collection<Parameter> parameters = clause.getParameters();
+					Map<String, Parameter> name2parameter = new HashMap<String, Parameter>(parameters.size());
+					for (Parameter parameter : parameters) {
+						name2parameter.put(parameter.getName(), parameter);
+					}
+					result.add(new Clause(packageName, name2parameter, null).toRequirement(resource));
+				}
+			}
+			else {
+				result.add(clause.toRequirement(resource));
+			}
 		}
 		return result;
 	}

Added: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java?rev=1732208&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java (added)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/defect/Aries1338Test.java Wed Feb 24 19:18:59 2016
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.subsystem.itests.defect;
+
+import static org.junit.Assert.fail;
+
+import org.apache.aries.subsystem.itests.SubsystemTest;
+import org.apache.aries.subsystem.itests.util.BundleArchiveBuilder;
+import org.apache.aries.subsystem.itests.util.SubsystemArchiveBuilder;
+import org.junit.Test;
+import org.osgi.service.subsystem.Subsystem;
+import org.osgi.service.subsystem.SubsystemException;
+
+public class Aries1338Test extends SubsystemTest {
+	@Test
+	public void test() throws Exception {
+		test("x;y;z;version=1", "x;version=1,y;version=1,z;version=1", false);
+	}
+	
+	@Test
+	public void testMissingExportPackageX() throws Exception {
+		test("x;y;z;version=1", "y;version=1,z;version=1", true);
+	}
+	
+	@Test
+	public void testMissingExportPackageY() throws Exception {
+		test("x;y;z;version=1", "x;version=1,z;version=1", true);
+	}
+	
+	@Test
+	public void testMissingExportPackageZ() throws Exception {
+		test("x;y;z;version=1", "x;version=1,y;version=1", true);
+	}
+	
+	@Test
+	public void testWrongVersionExportPackageX() throws Exception {
+		test("x;y;z;version=\"[1,2)\"", "x;version=0,y;version=1,z;version=1.1", true);
+	}
+	
+	@Test
+	public void testWrongVersionExportPackageY() throws Exception {
+		test("x;y;z;version=\"[1,2)\"", "x;version=1.9,y;version=2,z;version=1.1", true);
+	}
+	
+	@Test
+	public void testWrongVersionExportPackageZ() throws Exception {
+		test("x;y;z;version=\"[1,2)\"", "x;version=1.9,y;version=1.0.1,z", true);
+	}
+	
+	private void test(String importPackage, String exportPackage, boolean shouldFail) throws Exception {
+		Subsystem root = getRootSubsystem();
+		try {
+			Subsystem subsystem = installSubsystem(
+					root,
+					"subsystem",
+					new SubsystemArchiveBuilder()
+							.symbolicName("subsystem")
+							.bundle(
+									"a", 
+									new BundleArchiveBuilder()
+											.symbolicName("a")
+											.importPackage(importPackage)
+											.build())
+							.bundle(
+									"b", 
+									new BundleArchiveBuilder()
+											.symbolicName("b")
+											.exportPackage(exportPackage)
+											.build())
+							.build());
+			uninstallableSubsystems.add(subsystem);
+			if (shouldFail) {
+				fail("Subsystem should not have installed");
+			}
+		}
+		catch (SubsystemException e) {
+			e.printStackTrace();
+			if (!shouldFail) {
+				fail("Subsystem should have installed");
+			}
+		}
+	}
+}