aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwr...@apache.org
Subject svn commit: r1489503 - in /aries/trunk/subsystem: subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/ subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/ subsystem-core/src/test/java/org/apache/aries/subsystem/core/...
Date Tue, 04 Jun 2013 16:25:32 GMT
Author: jwross
Date: Tue Jun  4 16:25:20 2013
New Revision: 1489503

URL: http://svn.apache.org/r1489503
Log:
[aries-1072] Bundle BREE headers must be converted to osgi.ee requirements for proper resolution
at subsystem install time.

Added functionality plus unit tests.

Added new itest.

Removed unnecessary BREE header from test bundles that caused them to be unresolvable.

Added:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeader.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/OsgiExecutionEnvironmentRequirement.java
    aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeaderTest.java
Modified:
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/HeaderFactory.java
    aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
    aries/trunk/subsystem/subsystem-itests/src/test/bundles/blueprint/META-INF/MANIFEST.MF
    aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF
    aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb3/META-INF/MANIFEST.MF
    aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeader.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeader.java?rev=1489503&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeader.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeader.java
Tue Jun  4 16:25:20 2013
@@ -0,0 +1,198 @@
+/*
+ * Licensed 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.core.archive;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+public class BundleRequiredExecutionEnvironmentHeader implements RequirementHeader<BundleRequiredExecutionEnvironmentHeader.Clause>
{
+	public static class Clause implements org.apache.aries.subsystem.core.archive.Clause {
+		public static class ExecutionEnvironment {
+			public static class Parser {
+				private static final String BREE = "(" + Grammar.TOKEN + ")(?:-(" + Grammar.VERSION +
"))?(?:/(" + Grammar.TOKEN + ")(?:-(" + Grammar.VERSION + "))?)?";
+				private static final Pattern PATTERN = Pattern.compile(BREE);
+				
+				public ExecutionEnvironment parse(String clause) {
+					Matcher matcher = PATTERN.matcher(clause);
+					if (matcher.matches() && versionsMatch(matcher)) {
+						return new ExecutionEnvironment(
+								computeName(matcher),
+								computeVersion(matcher));
+					}
+					else
+						return new ExecutionEnvironment(clause);
+				}
+				
+				private String computeName(Matcher matcher) {
+					return computeName(matcher.group(1), matcher.group(3));
+				}
+				
+				private String computeName(String left, String right) {
+					if (left.equalsIgnoreCase("J2SE"))
+						left = "JavaSE";
+					if (right == null)
+						return left;
+					return new StringBuilder(left).append('/').append(right).toString();
+				}
+				
+				private Version computeVersion(Matcher matcher) {
+					String version = matcher.group(2);
+					if (version == null)
+						version = matcher.group(4);
+					if (version == null)
+						return null;
+					return Version.parseVersion(version);
+				}
+				
+				private boolean versionsMatch(Matcher matcher) {
+					String version1 = matcher.group(2);
+					String version2 = matcher.group(4);
+					if (version1 == null || version2 == null)
+						return true;
+					return version1.equals(version2);
+				}
+			}
+			
+			private final String name;
+			private final Version version;
+			
+			public ExecutionEnvironment(String name) {
+				this(name, null);
+			}
+			
+			public ExecutionEnvironment(String name, Version version) {
+				if (name == null)
+					throw new NullPointerException();
+				this.name = name;
+				this.version = version;
+			}
+			
+			public String getName() {
+				return name;
+			}
+			
+			public Version getVersion() {
+				return version;
+			}
+		}
+		
+		private final ExecutionEnvironment executionEnvironment;
+		private final String path;
+		
+		public Clause(String clause) {
+			path = clause;
+			executionEnvironment = new ExecutionEnvironment.Parser().parse(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();
+		}
+		
+		public ExecutionEnvironment getExecutionEnvironment() {
+			return executionEnvironment;
+		}
+
+		@Override
+		public Parameter getParameter(String name) {
+			return null;
+		}
+
+		@Override
+		public Collection<Parameter> getParameters() {
+			return Collections.emptyList();
+		}
+
+		@Override
+		public String getPath() {
+			return path;
+		}
+		
+		public OsgiExecutionEnvironmentRequirement toRequirement(Resource resource) {
+			return new OsgiExecutionEnvironmentRequirement(this, resource);
+		}
+		
+		@Override
+		public String toString() {
+			return getPath();
+		}
+	}
+	
+	@SuppressWarnings("deprecation")
+	public static final String NAME = Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT;
+	
+	private final Collection<Clause> clauses;
+
+	public BundleRequiredExecutionEnvironmentHeader(String value) {
+		ClauseTokenizer tokenizer = new ClauseTokenizer(value);
+		clauses = new ArrayList<Clause>(tokenizer.getClauses().size());
+		for (String clause : tokenizer.getClauses())
+			clauses.add(new Clause(clause));
+	}
+
+	@Override
+	public Collection<Clause> getClauses() {
+		return Collections.unmodifiableCollection(clauses);
+	}
+
+	@Override
+	public String getName() {
+		return NAME;
+	}
+
+	@Override
+	public String getValue() {
+		StringBuilder builder = new StringBuilder();
+		for (Clause clause : getClauses()) {
+			builder.append(clause).append(',');
+		}
+		// Remove the trailing comma. Note at least one clause is guaranteed to exist.
+		builder.deleteCharAt(builder.length() - 1);
+		return builder.toString();
+	}
+
+	@Override
+	public List<? extends Requirement> toRequirements(Resource resource) {
+		return Collections.singletonList(new OsgiExecutionEnvironmentRequirement(getClauses(),
resource));
+	}
+	
+	@Override
+	public String toString() {
+		return getValue();
+	}
+}

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=1489503&r1=1489502&r2=1489503&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
Tue Jun  4 16:25:20 2013
@@ -113,6 +113,8 @@ public class HeaderFactory {
 			return new PreferredProviderHeader(value);
 		if (AriesSubsystemParentsHeader.NAME.equals(name))
 			return new AriesSubsystemParentsHeader(value);
+		if (BundleRequiredExecutionEnvironmentHeader.NAME.equals(name))
+			return new BundleRequiredExecutionEnvironmentHeader(value);
 		return new GenericHeader(name, value);
 			
 	}

Added: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/OsgiExecutionEnvironmentRequirement.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/OsgiExecutionEnvironmentRequirement.java?rev=1489503&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/OsgiExecutionEnvironmentRequirement.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/archive/OsgiExecutionEnvironmentRequirement.java
Tue Jun  4 16:25:20 2013
@@ -0,0 +1,74 @@
+/*
+ * Licensed 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.core.archive;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.aries.subsystem.core.archive.BundleRequiredExecutionEnvironmentHeader.Clause.ExecutionEnvironment;
+import org.apache.aries.subsystem.core.internal.AbstractRequirement;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
+import org.osgi.resource.Resource;
+
+public class OsgiExecutionEnvironmentRequirement extends AbstractRequirement {
+	public static final String ATTRIBUTE_VERSION = ExecutionEnvironmentNamespace.CAPABILITY_VERSION_ATTRIBUTE;
+	public static final String DIRECTIVE_FILTER = ExecutionEnvironmentNamespace.REQUIREMENT_FILTER_DIRECTIVE;
+	public static final String NAMESPACE = ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE;
+	
+	private final Map<String, String> directives;
+	private final Resource resource;
+	
+	public OsgiExecutionEnvironmentRequirement(BundleRequiredExecutionEnvironmentHeader.Clause
clause, Resource resource) {
+		this(Collections.singleton(clause), resource);
+	}
+	
+	public OsgiExecutionEnvironmentRequirement(Collection<BundleRequiredExecutionEnvironmentHeader.Clause>
clauses, Resource resource) {
+		StringBuilder filter = new StringBuilder("(|");
+		for (BundleRequiredExecutionEnvironmentHeader.Clause clause : clauses) {
+			ExecutionEnvironment ee = clause.getExecutionEnvironment();
+			filter.append("(&(").append(NAMESPACE).append('=').append(ee.getName()).append(')');
+			Version version = ee.getVersion();
+			if (version != null)
+				filter.append('(').append(ATTRIBUTE_VERSION).append('=')
+						.append(version).append(')');
+			filter.append(')');
+		}
+		directives = new HashMap<String, String>(1);
+		directives.put(DIRECTIVE_FILTER, filter.append(')').toString());
+		this.resource = resource;
+	}
+	
+	@Override
+	public Map<String, Object> getAttributes() {
+		return Collections.emptyMap();
+	}
+
+	@Override
+	public Map<String, String> getDirectives() {
+		return Collections.unmodifiableMap(directives);
+	}
+
+	@Override
+	public String getNamespace() {
+		return NAMESPACE;
+	}
+
+	@Override
+	public Resource getResource() {
+		return resource;
+	}
+}

Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java?rev=1489503&r1=1489502&r2=1489503&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
(original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResource.java
Tue Jun  4 16:25:20 2013
@@ -31,6 +31,7 @@ import org.apache.aries.application.mode
 import org.apache.aries.application.modelling.ModelledResourceManager;
 import org.apache.aries.application.modelling.ModellerException;
 import org.apache.aries.subsystem.core.archive.BundleManifest;
+import org.apache.aries.subsystem.core.archive.BundleRequiredExecutionEnvironmentHeader;
 import org.apache.aries.subsystem.core.archive.BundleSymbolicNameHeader;
 import org.apache.aries.subsystem.core.archive.BundleVersionHeader;
 import org.apache.aries.subsystem.core.archive.ExportPackageHeader;
@@ -42,6 +43,7 @@ import org.apache.aries.subsystem.core.a
 import org.apache.aries.subsystem.core.archive.RequireBundleRequirement;
 import org.apache.aries.subsystem.core.archive.RequireCapabilityHeader;
 import org.apache.aries.subsystem.core.archive.RequireCapabilityRequirement;
+import org.apache.aries.subsystem.core.archive.RequirementHeader;
 import org.apache.aries.util.filesystem.IDirectory;
 import org.apache.aries.util.filesystem.IFile;
 import org.apache.aries.util.io.IOUtils;
@@ -156,6 +158,13 @@ public class BundleResource implements R
 				requirements.add(new RequireCapabilityRequirement(clause, this));
 	}
 	
+	private void computeOsgiExecutionEnvironmentRequirement() {
+		RequirementHeader<?> header = (RequirementHeader<?>)manifest.getHeader(BundleRequiredExecutionEnvironmentHeader.NAME);
+		if (header == null)
+			return;
+		requirements.addAll(header.toRequirements(this));
+	}
+	
 	private void computeOsgiIdentityCapability() {
 		capabilities.add(new OsgiIdentityCapability(this, manifest));
 	}
@@ -228,7 +237,7 @@ public class BundleResource implements R
 		computeGenericRequirements();
 		computeOsgiWiringBundleRequirements();
 		computeOsgiServiceRequirements(resource);
-		// TODO Bundle-RequiredExecutionEnvironment
+		computeOsgiExecutionEnvironmentRequirement();
 	}
 	
 	private String getFileName(IFile file) {

Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeaderTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeaderTest.java?rev=1489503&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeaderTest.java
(added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/archive/BundleRequiredExecutionEnvironmentHeaderTest.java
Tue Jun  4 16:25:20 2013
@@ -0,0 +1,185 @@
+/*
+ * Licensed 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.core.archive;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.aries.subsystem.core.archive.BundleRequiredExecutionEnvironmentHeader.Clause.ExecutionEnvironment;
+import org.apache.aries.subsystem.core.archive.BundleRequiredExecutionEnvironmentHeader.Clause.ExecutionEnvironment.Parser;
+import org.apache.aries.subsystem.core.internal.BasicRequirement;
+import org.easymock.EasyMock;
+import org.junit.Test;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
+import org.osgi.resource.Requirement;
+import org.osgi.resource.Resource;
+
+public class BundleRequiredExecutionEnvironmentHeaderTest {
+	@Test
+	public void testClause() {
+		String clauseStr = "CDC-1.0/Foundation-1.0";
+		BundleRequiredExecutionEnvironmentHeader.Clause clause = new BundleRequiredExecutionEnvironmentHeader.Clause(clauseStr);
+		assertClause(clause, clauseStr, "CDC/Foundation", "1.0", "(|(&(osgi.ee=CDC/Foundation)(version=1.0.0)))");
+	}
+	
+	@Test
+	public void testExecutionEnvironment1() {
+		String name = "foo";
+		ExecutionEnvironment ee = new ExecutionEnvironment(name);
+		assertExecutionEnvironmentName(ee, name);
+		assertExecutionEnvironmentVersion(ee, (Version)null);
+	}
+	
+	@Test
+	public void testExecutionEnvironment2() {
+		String name = "bar";
+		Version version = Version.parseVersion("2.0.0.qualifier");
+		ExecutionEnvironment ee = new ExecutionEnvironment(name, version);
+		assertExecutionEnvironmentName(ee, name);
+		assertExecutionEnvironmentVersion(ee, version);
+	}
+	
+	@SuppressWarnings("deprecation")
+	@Test
+	public void testHeaderWithOneClause() {
+		String value = "OSGi/Minimum-1.2";
+		String filter = "(|(&(osgi.ee=OSGi/Minimum)(version=1.2.0)))";
+		BundleRequiredExecutionEnvironmentHeader header = new BundleRequiredExecutionEnvironmentHeader(value);
+		assertEquals("Wrong number of clauses", 1, header.getClauses().size());
+		assertClause(header.getClauses().iterator().next(), value, "OSGi/Minimum", "1.2", filter);
+		assertEquals("Wrong name", Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, header.getName());
+		assertEquals("Wrong value", value, header.getValue());
+		Resource resource = EasyMock.createNiceMock(Resource.class);
+		List<? extends Requirement> requirements = header.toRequirements(resource);
+		assertEquals("Wrong number of requirements", 1, requirements.size());
+		assertRequirement(requirements.get(0), filter, resource);
+	}
+	
+	@Test
+	public void testHeaderWithMultipleClauses() {
+		String value = "CDC-1.0/Foundation-1.0,OSGi/Minimum-1.2,J2SE-1.4,JavaSE-1.6,AA/BB-1.7,V1-1.5/V2-1.6,MyEE-badVersion";
+		String filter = "(|" +
+				"(&(osgi.ee=CDC/Foundation)(version=1.0.0))" +
+				"(&(osgi.ee=OSGi/Minimum)(version=1.2.0))" +
+				"(&(osgi.ee=JavaSE)(version=1.4.0))" +
+				"(&(osgi.ee=JavaSE)(version=1.6.0))" +
+				"(&(osgi.ee=AA/BB)(version=1.7.0))" +
+				"(&(osgi.ee=V1-1.5/V2-1.6))" +
+				"(&(osgi.ee=MyEE-badVersion)))";
+		BundleRequiredExecutionEnvironmentHeader header = new BundleRequiredExecutionEnvironmentHeader(value);
+		assertEquals("Wrong number of clauses", 7, header.getClauses().size());
+		assertClause(header.getClauses().iterator().next(), "CDC-1.0/Foundation-1.0", "CDC/Foundation",
"1.0", "(|(&(osgi.ee=CDC/Foundation)(version=1.0.0)))");
+		assertEquals("Wrong name", Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, header.getName());
+		assertEquals("Wrong value", value, header.getValue());
+		Resource resource = EasyMock.createNiceMock(Resource.class);
+		List<? extends Requirement> requirements = header.toRequirements(resource);
+		assertEquals("Wrong number of requirements", 1, requirements.size());
+		assertRequirement(requirements.get(0), filter, resource);
+	}
+	
+	@Test
+	public void testParser1() {
+		doTestParser("CDC-1.0/Foundation-1.0", "CDC/Foundation", "1.0");
+	}
+	
+	@Test
+	public void testParser2() {
+		doTestParser("OSGi/Minimum-1.2", "OSGi/Minimum", "1.2");
+	}
+	
+	@Test
+	public void testParser3() {
+		doTestParser("J2SE-1.4", "JavaSE", "1.4");
+	}
+	
+	@Test
+	public void testParser4() {
+		doTestParser("JavaSE-1.6", "JavaSE", "1.6");
+	}
+	
+	@Test
+	public void testParser5() {
+		doTestParser("AA/BB-1.7", "AA/BB", "1.7");
+	}
+	
+	@Test
+	public void testParser6() {
+		doTestParser("V1-1.5/V2-1.6", "V1-1.5/V2-1.6", (Version)null);
+	}
+	
+	@Test
+	public void testParser7() {
+		doTestParser("MyEE-badVersion", "MyEE-badVersion", (Version)null);
+	}
+	
+	private void assertClause(BundleRequiredExecutionEnvironmentHeader.Clause clause, String
clauseStr, String name, String version, String filter) {
+		assertClause(clause, clauseStr, name, Version.parseVersion(version), filter);
+	}
+	
+	private void assertClause(BundleRequiredExecutionEnvironmentHeader.Clause clause, String
clauseStr, String name, Version version, String filter) {
+		assertNull("Attribute should not exist", clause.getAttribute(ExecutionEnvironmentNamespace.CAPABILITY_VERSION_ATTRIBUTE));
+		assertTrue("Should have no attributes", clause.getAttributes().isEmpty());
+		assertNull("Directive should not exist", clause.getDirective(ExecutionEnvironmentNamespace.REQUIREMENT_FILTER_DIRECTIVE));
+		assertExecutionEnvironmentName(clause.getExecutionEnvironment(), name);
+		assertExecutionEnvironmentVersion(clause.getExecutionEnvironment(), version);
+		assertNull("Parameter should not exist", clause.getAttribute(ExecutionEnvironmentNamespace.CAPABILITY_VERSION_ATTRIBUTE));
+		assertTrue("Should have no parameters", clause.getParameters().isEmpty());
+		assertEquals("Wrong path", clauseStr, clause.getPath());
+		assertRequirement(clause, filter);
+	}
+	
+	private void assertExecutionEnvironmentName(ExecutionEnvironment ee, String name) {
+		assertEquals("Wrong name", name, ee.getName());
+	}
+	
+	private void assertExecutionEnvironmentVersion(ExecutionEnvironment ee, Version version)
{
+		assertEquals("Wrong version", version, ee.getVersion());
+	}
+	
+	private void assertRequirement(BundleRequiredExecutionEnvironmentHeader.Clause clause, String
filter) {
+		Resource resource = EasyMock.createNiceMock(Resource.class);
+		assertRequirement(clause.toRequirement(resource), filter, resource);
+	}
+	
+	private void assertRequirement(Requirement requirement, String filter, Resource resource)
{
+		Requirement r = new BasicRequirement.Builder()
+				.namespace(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE)
+				.directive(ExecutionEnvironmentNamespace.REQUIREMENT_FILTER_DIRECTIVE, filter)
+				.resource(resource)
+				.build();
+		assertEquals("Wrong requirement", r, requirement);
+	}
+	
+	private void doTestParser(String clause, String name, String version) {
+		doTestParser(clause, name, Version.parseVersion(version));
+	}
+	
+	private void doTestParser(String clause, String name, Version version) {
+		ExecutionEnvironment ee = null;
+		try {
+			ee = new Parser().parse(clause);
+		}
+		catch (Exception e) {
+			fail("Unable to parse execution environment from clause " + clause);
+		}
+		assertExecutionEnvironmentName(ee, name);
+		assertExecutionEnvironmentVersion(ee, version);
+	}
+}

Modified: aries/trunk/subsystem/subsystem-itests/src/test/bundles/blueprint/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/bundles/blueprint/META-INF/MANIFEST.MF?rev=1489503&r1=1489502&r2=1489503&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/bundles/blueprint/META-INF/MANIFEST.MF
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/bundles/blueprint/META-INF/MANIFEST.MF
Tue Jun  4 16:25:20 2013
@@ -3,5 +3,4 @@ Bundle-ManifestVersion: 2
 Bundle-Name: Subsystem itests blueprint bundle
 Bundle-SymbolicName: org.apache.aries.subsystem.itests.blueprint
 Bundle-Version: 1.0.0
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Import-Package: org.apache.aries.subsystem.itests.hello.api

Modified: aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF?rev=1489503&r1=1489502&r2=1489503&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb1/META-INF/MANIFEST.MF Tue Jun
 4 16:25:20 2013
@@ -3,6 +3,5 @@ Bundle-ManifestVersion: 2
 Bundle-Name: TB1
 Bundle-SymbolicName: org.apache.aries.subsystem.itests.tb1
 Bundle-Version: 1.0.0
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.apache.aries.subsystem.itests.tb1
 Import-Package: org.apache.aries.subsystem.itests.tb3

Modified: aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb3/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb3/META-INF/MANIFEST.MF?rev=1489503&r1=1489502&r2=1489503&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb3/META-INF/MANIFEST.MF (original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/bundles/tb3/META-INF/MANIFEST.MF Tue Jun
 4 16:25:20 2013
@@ -3,5 +3,4 @@ Bundle-ManifestVersion: 2
 Bundle-Name: TB3
 Bundle-SymbolicName: org.apache.aries.subsystem.itests.tb3
 Bundle-Version: 1.0.0
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.apache.aries.subsystem.itests.tb3

Modified: aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java?rev=1489503&r1=1489502&r2=1489503&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
(original)
+++ aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/ResolutionTest.java
Tue Jun  4 16:25:20 2013
@@ -19,6 +19,7 @@
 package org.apache.aries.subsystem.itests;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
@@ -33,6 +34,7 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.service.resolver.ResolutionException;
 import org.osgi.service.subsystem.Subsystem;
 import org.osgi.service.subsystem.SubsystemConstants;
 import org.osgi.service.subsystem.SubsystemException;
@@ -48,6 +50,11 @@ public class ResolutionTest extends Subs
 	 */
 	private static final String APPLICATION_A = "application.a.esa";
 	/*
+	 * Subsystem-SymbolicName: application.b.esa
+	 * Subsystem-Content: bundle.d.jar
+	 */
+	private static final String APPLICATION_B = "application.b.esa";
+	/*
 	 * Bundle-SymbolicName: bundle.a.jar
 	 * Require-Capability: a
 	 */
@@ -63,6 +70,11 @@ public class ResolutionTest extends Subs
 	 * Provide-Capability: b
 	 */
 	private static final String BUNDLE_C = "bundle.c.jar";
+	/*
+	 * Bundle-SymbolicName: bundle.d.jar
+	 * Bundle-RequiredExecutionEnvironment: JavaSE-100.100
+	 */
+	private static final String BUNDLE_D = "bundle.d.jar";
 	
 	@Before
 	public static void createApplications() throws Exception {
@@ -72,7 +84,9 @@ public class ResolutionTest extends Subs
 		createBundleA();
 		createBundleB();
 		createBundleC();
+		createBundleD();
 		createApplicationA();
+		createApplicationB();
 		createdApplications = true;
 	}
 	
@@ -87,6 +101,17 @@ public class ResolutionTest extends Subs
 		createManifest(APPLICATION_A + ".mf", attributes);
 	}
 	
+	private static void createApplicationB() throws IOException {
+		createApplicationBManifest();
+		createSubsystem(APPLICATION_B, BUNDLE_D);
+	}
+	
+	private static void createApplicationBManifest() throws IOException {
+		Map<String, String> attributes = new HashMap<String, String>();
+		attributes.put(SubsystemConstants.SUBSYSTEM_SYMBOLICNAME, APPLICATION_B);
+		createManifest(APPLICATION_B + ".mf", attributes);
+	}
+	
 	private static void createBundleA() throws IOException {
 		Map<String, String> headers = new HashMap<String, String>();
 		headers.put(Constants.REQUIRE_CAPABILITY, "a");
@@ -106,6 +131,13 @@ public class ResolutionTest extends Subs
 		createBundle(BUNDLE_C, headers);
 	}
 	
+	@SuppressWarnings("deprecation")
+	private static void createBundleD() throws IOException {
+		Map<String, String> headers = new HashMap<String, String>();
+		headers.put(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, "JavaSE-100.100");
+		createBundle(BUNDLE_D, headers);
+	}
+	
 	/*
 	 * Test that the right regions are used when validating capabilities.
 	 * 
@@ -158,4 +190,25 @@ public class ResolutionTest extends Subs
 			uninstallSilently(bundleC);
 		}
 	}
+	
+	/*
+	 * BREE headers must be converted into osgi.ee requirements.
+	 * 
+	 * The subsystem should fail to resolve and install if the required
+	 * execution environment is not present.
+	 */
+	@Test
+	public void testMissingBundleRequiredExecutionEnvironment() throws Exception {
+		Subsystem applicationB = null;
+		try {
+			applicationB = installSubsystemFromFile(APPLICATION_B);
+			fail("Missing BREE should result in installation failure");
+		}
+		catch (Exception e) {
+			assertTrue("Installation failure should be due to resolution error", e.getCause() instanceof
ResolutionException);
+		}
+		finally {
+			uninstallSubsystemSilently(applicationB);
+		}
+	}
 }



Mime
View raw message