1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
---
layout: default
class: Header
title: Require-Capability ::= requirement ( ',' requirement )*
summary: Specifies that a bundle requires other bundles to provide a capability
---
Parameters requirements = new Parameters(annotationHeaders.getHeader(REQUIRE_CAPABILITY));
Parameters capabilities = new Parameters(annotationHeaders.getHeader(PROVIDE_CAPABILITY));
//
// Do any contracts contracts
//
contracts.addToRequirements(requirements);
//
// We want to add the minimum EE as a requirement
// based on the class version
//
if (!isTrue(getProperty(NOEE)) //
&& !ees.isEmpty() // no use otherwise
&& since(About._2_3) // we want people to not have to
// automatically add it
&& !requirements.containsKey(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE) // and
// it
// should
// not
// be
// there
// already
) {
JAVA highest = ees.last();
Attrs attrs = new Attrs();
String filter = doEEProfiles(highest);
attrs.put(Constants.FILTER_DIRECTIVE, filter);
//
// Java 1.8 introduced profiles.
// If -eeprofile= auto | (<profile>="...")+ is set then
// we add a
requirements.add(ExecutionEnvironmentNamespace.EXECUTION_ENVIRONMENT_NAMESPACE, attrs);
}
if (!requirements.isEmpty())
main.putValue(REQUIRE_CAPABILITY, requirements.toString());
/*
* Require-Capability header
*/
private void doRequireCapability(RequireCapability annotation) {
StringBuilder sb = new StringBuilder(annotation.ns());
if (annotation.filter() != null)
sb.append(";filter:='").append(annotation.filter()).append("'");
if (annotation.effective() != null)
sb.append(";effective:='").append(annotation.effective()).append("'");
if (annotation.resolution() != null)
sb.append(";resolution:='").append(annotation.resolution()).append("'");
if (annotation.value() != null)
sb.append(";").append(annotation.value());
add(Constants.REQUIRE_CAPABILITY, sb.toString());
}
package aQute.bnd.annotation.headers;
import java.lang.annotation.*;
/**
* The Bundle’s Require-Capability header
*
* {@link About}
*/
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.ANNOTATION_TYPE, ElementType.TYPE
})
public @interface RequireCapability {
String value() default "";
/**
* The capability namespace. For example: {@code osgi.contract}.
*/
String ns();
/**
* Specifies the time a Requirement is considered, either 'resolve'
* (default) or another name. The OSGi framework resolver only considers
* Requirements without an effective directive or effective:=resolve. Other
* Requirements can be considered by an external agent. Additional names for
* the effective directive should be registered with the OSGi Alliance. See
* <a href="https://www.osgi.org/developer/specifications/reference/">OSGi Reference
* Page</a>
*/
String effective() default "resolve";
/**
* A filter expression that is asserted on the Capabilities belonging to the
* given namespace. The matching of the filter against the Capability is
* done on one Capability at a time. A filter like {@code (&(a=1)(b=2))}
* matches only a Capability that specifies both attributes at the required
* value, not two capabilties that each specify one of the attributes
* correctly. A filter is optional, if no filter directive is specified the
* Requirement always matches.
*/
String filter();
/**
* A mandatory Requirement forbids the bundle to resolve when the
* Requirement is not satisfied; an optional Requirement allows a bundle to
* resolve even if the Requirement is not satisfied. No wirings are created
* when this Requirement cannot be resolved, this can result in Class Not
* Found Exceptions when the bundle attempts to use a package that was not
* resolved because it was optional.
*/
Resolution resolution() default Resolution.mandatory;
}
private void verifyRequirements() {
Parameters map = parseHeader(manifest.getMainAttributes().getValue(Constants.REQUIRE_CAPABILITY));
for (String key : map.keySet()) {
Attrs attrs = map.get(key);
verify(attrs, "filter:", FILTERPATTERN, false, "Requirement %s filter not correct", key);
String filter = attrs.get("filter:");
if (filter != null) {
String verify = new Filter(filter).verify();
if (verify != null)
error("Invalid filter syntax in requirement %s=%s. Reason %s", key, attrs, verify);
}
verify(attrs, "cardinality:", CARDINALITY_PATTERN, false, "Requirement %s cardinality not correct", key);
verify(attrs, "resolution:", RESOLUTION_PATTERN, false, "Requirement %s resolution not correct", key);
if (key.equals("osgi.extender")) {
// No requirements on extender
} else if (key.equals("osgi.serviceloader")) {
verify(attrs, "register:", PACKAGEPATTERN, false,
"Service Loader extender register: directive not a fully qualified Java name");
} else if (key.equals("osgi.contract")) {
} else if (key.equals("osgi.service")) {
} else if (key.equals("osgi.ee")) {
} else if (key.startsWith("osgi.wiring.") || key.startsWith("osgi.identity")) {
error("osgi.wiring.* namespaces must not be specified with generic requirements/capabilities");
}
verifyAttrs(attrs);
if (attrs.containsKey("mandatory:"))
error("mandatory: directive is intended for Capabilities, not Requirement %s", key);
if (attrs.containsKey("uses:"))
error("uses: directive is intended for Capabilities, not Requirement %s", key);
}
}
|