Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 00C8DEAB2 for ; Sat, 23 Feb 2013 04:59:31 +0000 (UTC) Received: (qmail 47057 invoked by uid 500); 23 Feb 2013 04:59:29 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 46918 invoked by uid 500); 23 Feb 2013 04:59:27 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 46884 invoked by uid 99); 23 Feb 2013 04:59:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Feb 2013 04:59:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Feb 2013 04:59:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DBD9C23888E7; Sat, 23 Feb 2013 04:58:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1449267 - /aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java Date: Sat, 23 Feb 2013 04:58:59 -0000 To: commits@aries.apache.org From: jwross@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130223045859.DBD9C23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jwross Date: Sat Feb 23 04:58:59 2013 New Revision: 1449267 URL: http://svn.apache.org/r1449267 Log: Don't treat optional requirements as mandatory. Fixes issue where optional requirements from a Felix OBR repository were treated as mandatory. Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java Modified: aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java?rev=1449267&r1=1449266&r2=1449267&view=diff ============================================================================== --- aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java (original) +++ aries/trunk/subsystem/subsystem-obr/src/main/java/org/apache/aries/subsystem/obr/internal/FelixRequirementAdapter.java Sat Feb 23 04:58:59 2013 @@ -17,11 +17,12 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.osgi.framework.Constants; import org.osgi.resource.Capability; +import org.osgi.resource.Namespace; import org.osgi.resource.Resource; public class FelixRequirementAdapter extends AbstractRequirement { + private final Map directives; private final org.apache.felix.bundlerepository.Requirement requirement; private final Resource resource; @@ -32,6 +33,7 @@ public class FelixRequirementAdapter ext throw new NullPointerException("Missing required parameter: resource"); this.requirement = requirement; this.resource = resource; + directives = computeDirectives(); } public Map getAttributes() { @@ -39,16 +41,7 @@ public class FelixRequirementAdapter ext } public Map getDirectives() { - Map result = new HashMap(1); - /* (1) The Felix OBR specific "mandatory:<*" syntax must be stripped out of the filter. - * (2) The namespace must be translated. - */ - result.put(Constants.FILTER_DIRECTIVE, requirement.getFilter() - .replaceAll("\\(mandatory\\:\\<\\*[^\\)]*\\)", "") - .replaceAll("\\(service\\=[^\\)]*\\)", "") - .replaceAll("objectclass", "objectClass") - .replaceAll(requirement.getName() + '=', getNamespace() + '=')); - return result; + return directives; } public String getNamespace() { @@ -62,4 +55,19 @@ public class FelixRequirementAdapter ext public boolean matches(Capability capability) { return requirement.isSatisfied(new OsgiCapabilityAdapter(capability)); } + + private Map computeDirectives() { + Map result = new HashMap(3); + /* (1) The Felix OBR specific "mandatory:<*" syntax must be stripped out of the filter. + * (2) The namespace must be translated. + */ + result.put(Namespace.REQUIREMENT_FILTER_DIRECTIVE, requirement.getFilter() + .replaceAll("\\(mandatory\\:\\<\\*[^\\)]*\\)", "") + .replaceAll("\\(service\\=[^\\)]*\\)", "") + .replaceAll("objectclass", "objectClass") + .replaceAll(requirement.getName() + '=', getNamespace() + '=')); + result.put(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, requirement.isOptional() ? Namespace.RESOLUTION_OPTIONAL : Namespace.RESOLUTION_MANDATORY); + result.put(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, requirement.isMultiple() ? Namespace.CARDINALITY_MULTIPLE : Namespace.CARDINALITY_SINGLE); + return Collections.unmodifiableMap(result); + } }