use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Subsystem method doBuild.
private void doBuild(Collection<Feature> features, boolean mandatory) throws Exception {
for (Subsystem child : children) {
child.doBuild(features, true);
}
if (feature != null) {
for (Dependency dep : feature.getDependencies()) {
Subsystem ss = this;
while (!ss.isAcceptDependencies()) {
ss = ss.getParent();
}
ss.requireFeature(dep.getName(), dep.getVersion(), false);
}
for (Conditional cond : feature.getConditional()) {
Feature fcond = cond.asFeature();
String ssName = this.name + "#" + (fcond.hasVersion() ? fcond.getName() + "-" + fcond.getVersion() : fcond.getName());
Subsystem fs = getChild(ssName);
if (fs == null) {
fs = new Subsystem(ssName, fcond, this, true);
fs.doBuild(features, false);
installable.add(fs);
children.add(fs);
}
}
}
List<Requirement> processed = new ArrayList<>();
while (true) {
List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
requirements.addAll(dependentFeatures);
requirements.removeAll(processed);
if (requirements.isEmpty()) {
break;
}
for (Requirement requirement : requirements) {
String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
if (TYPE_FEATURE.equals(type)) {
for (Feature feature : features) {
if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
if (feature != this.feature) {
String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
Subsystem fs = getChild(ssName);
if (fs == null) {
fs = new Subsystem(ssName, feature, this, mandatory && !SubsystemResolveContext.isOptional(requirement));
fs.build(features);
installable.add(fs);
children.add(fs);
}
}
}
}
}
processed.add(requirement);
}
}
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Blacklist method blacklist.
public static boolean blacklist(Feature feature, Clause[] clauses) {
for (Clause clause : clauses) {
// Check feature name
if (clause.getName().equals(feature.getName())) {
// Check feature version
VersionRange range = VersionRange.ANY_VERSION;
String vr = clause.getAttribute(BLACKLIST_RANGE);
if (vr != null) {
range = new VersionRange(vr, true);
}
if (range.contains(VersionTable.getVersion(feature.getVersion()))) {
String type = clause.getAttribute(BLACKLIST_TYPE);
if (type == null || TYPE_FEATURE.equals(type)) {
return true;
}
}
}
// Check bundles
blacklist(feature.getBundle(), clauses);
// Check conditional bundles
for (Conditional cond : feature.getConditional()) {
blacklist(cond.getBundle(), clauses);
}
}
return false;
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class ResourceUtils method toFeatureRequirement.
public static String toFeatureRequirement(String feature) {
String[] parts = feature.split("/");
Map<String, Object> attrs = new HashMap<>();
attrs.put(IDENTITY_NAMESPACE, parts[0]);
attrs.put(CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE);
if (parts.length > 1) {
attrs.put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange(parts[1]));
}
Map<String, String> dirs = new HashMap<>();
dirs.put(Constants.FILTER_DIRECTIVE, SimpleFilter.convert(attrs).toString());
return new RequirementImpl(null, IDENTITY_NAMESPACE, dirs, attrs).toString();
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class ShowBundleTree method createNodeForImport.
/*
* Create a child node for a given import (by finding a matching export in the currently installed bundles)
*/
private void createNodeForImport(Node<Bundle> node, Bundle bundle, Clause i) {
VersionRange range = VersionRange.parseVersionRange(i.getAttribute(Constants.VERSION_ATTRIBUTE));
boolean foundMatch = false;
for (Bundle b : bundleContext.getBundles()) {
BundleWiring wiring = b.adapt(BundleWiring.class);
if (wiring != null) {
List<BundleCapability> caps = wiring.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
if (caps != null) {
for (BundleCapability cap : caps) {
String n = getAttribute(cap, BundleRevision.PACKAGE_NAMESPACE);
String v = getAttribute(cap, Constants.VERSION_ATTRIBUTE);
if (i.getName().equals(n) && range.contains(VersionTable.getVersion(v))) {
boolean existing = tree.flatten().contains(b);
System.out.printf("- import %s: resolved using %s%n", i, b);
foundMatch = true;
if (!node.hasChild(b)) {
Node<Bundle> child = node.addChild(b);
if (!existing) {
createNode(child);
}
}
}
}
}
}
}
if (!foundMatch) {
System.out.printf("- import %s: WARNING - unable to find matching export%n", i);
}
}
use of org.apache.felix.utils.version.VersionRange in project karaf by apache.
the class Headers method checkBundle.
private boolean checkBundle(String bundleName, String version) {
VersionRange vr = VersionRange.parseVersionRange(version);
Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; (bundles != null) && (i < bundles.length); i++) {
String sym = bundles[i].getSymbolicName();
if ((sym != null) && sym.equals(bundleName)) {
if (vr.contains(bundles[i].getVersion())) {
return true;
}
}
}
return false;
}
Aggregations