use of org.osgi.framework.VersionRange in project aries by apache.
the class AbstractClause method parseParameters.
protected static Map<String, Parameter> parseParameters(String clause, boolean replaceVersionWithVersionRange) {
Map<String, Parameter> parameters = new HashMap<String, Parameter>();
Matcher matcher = Patterns.PARAMETER.matcher(clause);
while (matcher.find()) {
Parameter parameter = ParameterFactory.create(matcher.group());
if (replaceVersionWithVersionRange && (parameter instanceof VersionAttribute)) {
parameter = new VersionRangeAttribute(new VersionRange(String.valueOf(parameter.getValue())));
}
parameters.put(parameter.getName(), parameter);
}
return parameters;
}
use of org.osgi.framework.VersionRange in project aries by apache.
the class SimpleFilter method convert.
/**
* Converts a attribute map to a filter. The filter is created by iterating
* over the map's entry set. If ordering of attributes is important (e.g.,
* for hitting attribute indices), then the map's entry set should iterate
* in the desired order. Equality testing is assumed for all attribute types
* other than version ranges, which are handled appropriated. If the attribute
* map is empty, then a filter that matches anything is returned.
* @param attrs Map of attributes to convert to a filter.
* @return A filter corresponding to the attributes.
*/
public static SimpleFilter convert(Map<String, Object> attrs) {
// Rather than building a filter string to be parsed into a SimpleFilter,
// we will just create the parsed SimpleFilter directly.
List<SimpleFilter> filters = new ArrayList<SimpleFilter>();
for (Entry<String, Object> entry : attrs.entrySet()) {
if (entry.getValue() instanceof VersionRange) {
VersionRange vr = (VersionRange) entry.getValue();
if (vr.getLeftType() == VersionRange.RIGHT_OPEN) {
filters.add(new SimpleFilter(entry.getKey(), vr.getLeft().toString(), SimpleFilter.GTE));
} else {
SimpleFilter not = new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
((List) not.getValue()).add(new SimpleFilter(entry.getKey(), vr.getLeft().toString(), SimpleFilter.LTE));
filters.add(not);
}
if (vr.getRight() != null) {
if (vr.getRightType() == VersionRange.RIGHT_OPEN) {
filters.add(new SimpleFilter(entry.getKey(), vr.getRight().toString(), SimpleFilter.LTE));
} else {
SimpleFilter not = new SimpleFilter(null, new ArrayList(), SimpleFilter.NOT);
((List) not.getValue()).add(new SimpleFilter(entry.getKey(), vr.getRight().toString(), SimpleFilter.GTE));
filters.add(not);
}
}
} else {
List<String> values = SimpleFilter.parseSubstring(entry.getValue().toString());
if (values.size() > 1) {
filters.add(new SimpleFilter(entry.getKey(), values, SimpleFilter.SUBSTRING));
} else {
filters.add(new SimpleFilter(entry.getKey(), values.get(0), SimpleFilter.EQ));
}
}
}
SimpleFilter sf = null;
if (filters.size() == 1) {
sf = filters.get(0);
} else if (attrs.size() > 1) {
sf = new SimpleFilter(null, filters, SimpleFilter.AND);
} else if (filters.isEmpty()) {
sf = new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
}
return sf;
}
use of org.osgi.framework.VersionRange in project aries by apache.
the class FragmentHostHeaderTest method testSymbolicName.
@Test
public void testSymbolicName() {
String headerStr = "org.foo";
FragmentHostHeader header = new FragmentHostHeader(headerStr);
assertClauses(header, 1);
assertSymbolicName(header.getClauses().iterator().next(), headerStr);
assertBundleVersionAttribute(header.getClauses().iterator().next(), new VersionRange(VersionRange.LEFT_CLOSED, new Version("0"), null, VersionRange.RIGHT_OPEN));
}
use of org.osgi.framework.VersionRange in project aries by apache.
the class FragmentHostHeaderTest method testBundleVersionSingle.
@Test
public void testBundleVersionSingle() {
String headerStr = "com.bar.foo;bundle-version=1.0";
FragmentHostHeader header = new FragmentHostHeader(headerStr);
assertClauses(header, 1);
assertSymbolicName(header.getClauses().iterator().next(), "com.bar.foo");
assertBundleVersionAttribute(header.getClauses().iterator().next(), new VersionRange("1.0"));
}
use of org.osgi.framework.VersionRange in project rt.equinox.framework by eclipse.
the class PackageAdminImpl method getBundles.
public Bundle[] getBundles(String symbolicName, String versionRange) {
if (symbolicName == null) {
throw new IllegalArgumentException();
}
if (Constants.SYSTEM_BUNDLE_SYMBOLICNAME.equals(symbolicName)) {
// need to alias system.bundle to the implementation BSN
symbolicName = EquinoxContainer.NAME;
}
VersionRange range = versionRange == null ? null : new VersionRange(versionRange);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
String filter = (range != null ? "(&" : "") + "(" + IdentityNamespace.IDENTITY_NAMESPACE + "=" + symbolicName + ")" + (range != null ? range.toFilterString(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE) + ")" : "");
Requirement identityReq = ModuleContainer.createRequirement(IdentityNamespace.IDENTITY_NAMESPACE, Collections.<String, String>singletonMap(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter), Collections.<String, Object>emptyMap());
Collection<BundleCapability> identityCaps = container.getFrameworkWiring().findProviders(identityReq);
if (identityCaps.isEmpty()) {
return null;
}
List<Bundle> sorted = new ArrayList<>(identityCaps.size());
for (BundleCapability capability : identityCaps) {
Bundle b = capability.getRevision().getBundle();
// a sanity check incase this is an old revision
if (symbolicName.equals(b.getSymbolicName()) && !sorted.contains(b)) {
sorted.add(b);
}
}
Collections.sort(sorted, new Comparator<Bundle>() {
@Override
public int compare(Bundle b1, Bundle b2) {
return b2.getVersion().compareTo(b1.getVersion());
}
});
if (sorted.isEmpty()) {
return null;
}
return sorted.toArray(new Bundle[sorted.size()]);
}
Aggregations