use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class AbstractOSGiResolver method listTokenValues.
private Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
Map<String, String> stringCriteria = new HashMap<>();
for (Map.Entry<String, Object> entry : criteria.entrySet()) {
Object value = entry.getValue();
if (!(value instanceof String)) {
// no support for matcher for now
return Collections.emptySet();
}
stringCriteria.put(entry.getKey(), (String) value);
}
if (tokens.isEmpty()) {
// no more tokens to resolve
return Collections.singleton(stringCriteria);
}
Set<String> remainingTokens = new HashSet<>(tokens);
remainingTokens.remove(IvyPatternHelper.ORGANISATION_KEY);
String osgiType = stringCriteria.get(IvyPatternHelper.ORGANISATION_KEY);
if (osgiType == null) {
Map<String, Object> newCriteria = new HashMap<>(criteria);
newCriteria.put(IvyPatternHelper.ORGANISATION_KEY, BundleInfo.BUNDLE_TYPE);
Set<Map<String, String>> tokenValues = new HashSet<>(listTokenValues(remainingTokens, newCriteria));
newCriteria = new HashMap<>(criteria);
newCriteria.put(IvyPatternHelper.ORGANISATION_KEY, BundleInfo.PACKAGE_TYPE);
tokenValues.addAll(listTokenValues(remainingTokens, newCriteria));
newCriteria = new HashMap<>(criteria);
newCriteria.put(IvyPatternHelper.ORGANISATION_KEY, BundleInfo.SERVICE_TYPE);
tokenValues.addAll(listTokenValues(remainingTokens, newCriteria));
return tokenValues;
}
Map<String, String> values = new HashMap<>();
values.put(IvyPatternHelper.ORGANISATION_KEY, osgiType);
Set<String> capabilities = getRepoDescriptor().getCapabilityValues(osgiType);
if (capabilities == null || capabilities.isEmpty()) {
return Collections.emptySet();
}
remainingTokens.remove(IvyPatternHelper.MODULE_KEY);
String module = stringCriteria.get(IvyPatternHelper.MODULE_KEY);
if (module == null) {
Set<Map<String, String>> tokenValues = new HashSet<>();
for (String name : capabilities) {
Map<String, Object> newCriteria = new HashMap<>(criteria);
newCriteria.put(IvyPatternHelper.MODULE_KEY, name);
tokenValues.addAll(listTokenValues(remainingTokens, newCriteria));
}
return tokenValues;
}
values.put(IvyPatternHelper.MODULE_KEY, module);
remainingTokens.remove(IvyPatternHelper.REVISION_KEY);
String rev = stringCriteria.get(IvyPatternHelper.REVISION_KEY);
if (rev == null) {
Set<ModuleDescriptorWrapper> mdws = getRepoDescriptor().findModules(osgiType, module);
if (mdws == null || mdws.isEmpty()) {
return Collections.emptySet();
}
Set<Map<String, String>> tokenValues = new HashSet<>();
for (ModuleDescriptorWrapper mdw : mdws) {
Map<String, Object> newCriteria = new HashMap<>(criteria);
newCriteria.put(IvyPatternHelper.REVISION_KEY, mdw.getBundleInfo().getVersion().toString());
tokenValues.addAll(listTokenValues(remainingTokens, newCriteria));
}
return tokenValues;
}
values.put(IvyPatternHelper.REVISION_KEY, rev);
remainingTokens.remove(IvyPatternHelper.CONF_KEY);
String conf = stringCriteria.get(IvyPatternHelper.CONF_KEY);
if (conf == null) {
if (osgiType.equals(BundleInfo.PACKAGE_TYPE)) {
values.put(IvyPatternHelper.CONF_KEY, BundleInfoAdapter.CONF_USE_PREFIX + module);
return Collections.singleton(values);
}
Set<ModuleDescriptorWrapper> bundles = getRepoDescriptor().findModules(osgiType, module);
if (bundles == null) {
return Collections.emptySet();
}
Version v = new Version(rev);
ModuleDescriptorWrapper found = null;
for (ModuleDescriptorWrapper bundle : bundles) {
if (bundle.getBundleInfo().getVersion().equals(v)) {
found = bundle;
}
}
if (found == null) {
return Collections.emptySet();
}
Set<Map<String, String>> tokenValues = new HashSet<>();
List<String> configurations = BundleInfoAdapter.getConfigurations(found.getBundleInfo());
for (String configuration : configurations) {
Map<String, String> newCriteria = new HashMap<>(stringCriteria);
newCriteria.put(IvyPatternHelper.CONF_KEY, configuration);
tokenValues.add(newCriteria);
}
return tokenValues;
}
values.put(IvyPatternHelper.CONF_KEY, conf);
return Collections.singleton(values);
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class CapabilityAdapter method getExportPackage.
private static ExportPackage getExportPackage(BundleInfo bundleInfo, Capability capability) throws ParseException {
String pkgName = null;
Version version = null;
String uses = null;
for (CapabilityProperty property : capability.getProperties()) {
String propName = property.getName();
switch(propName) {
case "package":
pkgName = property.getValue();
break;
case "uses":
uses = property.getValue();
break;
case "version":
version = new Version(property.getValue());
break;
default:
Message.warn("Unsupported property '" + propName + "' on the 'package' capability of the bundle '" + bundleInfo.getSymbolicName() + "'");
break;
}
}
if (pkgName == null) {
throw new ParseException("No package name for the capability", 0);
}
ExportPackage exportPackage = new ExportPackage(pkgName, version);
if (uses != null) {
for (String use : splitToArray(uses)) {
exportPackage.addUse(use);
}
}
return exportPackage;
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class OBRXMLWriter method saxCapability.
private static void saxCapability(BundleCapability capability, ContentHandler handler) throws SAXException {
AttributesImpl atts = new AttributesImpl();
String type = capability.getType();
addAttr(atts, CapabilityHandler.NAME, type);
handler.startElement("", CapabilityHandler.CAPABILITY, CapabilityHandler.CAPABILITY, atts);
switch(type) {
case BundleInfo.BUNDLE_TYPE:
// nothing to do, already handled with the resource tag
break;
case BundleInfo.PACKAGE_TYPE:
{
saxCapabilityProperty("package", capability.getName(), handler);
Version v = capability.getRawVersion();
if (v != null) {
saxCapabilityProperty("version", v.toString(), handler);
}
Set<String> uses = ((ExportPackage) capability).getUses();
if (uses != null && !uses.isEmpty()) {
StringBuilder builder = new StringBuilder();
for (String use : uses) {
if (builder.length() != 0) {
builder.append(',');
}
builder.append(use);
}
saxCapabilityProperty("uses", builder.toString(), handler);
}
break;
}
case BundleInfo.SERVICE_TYPE:
{
saxCapabilityProperty("service", capability.getName(), handler);
Version v = capability.getRawVersion();
if (v != null) {
saxCapabilityProperty("version", v.toString(), handler);
}
break;
}
default:
// oups
break;
}
handler.endElement("", CapabilityHandler.CAPABILITY, CapabilityHandler.CAPABILITY);
handler.characters("\n".toCharArray(), 0, 1);
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class RequirementAdapter method parseCompareFilter.
private void parseCompareFilter(CompareFilter compareFilter, boolean not) throws UnsupportedFilterException {
String att = compareFilter.getLeftValue();
if ("symbolicname".equals(att)) {
att = BundleInfo.BUNDLE_TYPE;
}
switch(att) {
case BundleInfo.BUNDLE_TYPE:
case BundleInfo.EXECUTION_ENVIRONMENT_TYPE:
case BundleInfo.PACKAGE_TYPE:
case BundleInfo.SERVICE_TYPE:
if (not) {
throw new UnsupportedFilterException("Not filter on requirement comparison is not supported");
}
if (compareFilter.getOperator() != Operator.EQUALS) {
throw new UnsupportedFilterException("Filtering is only supported with the operator '='");
}
if (type != null) {
throw new UnsupportedFilterException("Multiple requirement type are not supported");
}
type = att;
name = compareFilter.getRightValue();
break;
case "version":
Version version = new Version(compareFilter.getRightValue());
Operator operator = compareFilter.getOperator();
if (not) {
switch(operator) {
case EQUALS:
throw new UnsupportedFilterException("Not filter on equals comparison is not supported");
case GREATER_OR_EQUAL:
operator = Operator.LOWER_THAN;
break;
case GREATER_THAN:
operator = Operator.LOWER_OR_EQUAL;
break;
case LOWER_OR_EQUAL:
operator = Operator.GREATER_THAN;
break;
case LOWER_THAN:
operator = Operator.GREATER_OR_EQUAL;
break;
}
}
switch(operator) {
case EQUALS:
if (startVersion != null || endVersion != null) {
throw new UnsupportedFilterException("Multiple version matching is not supported");
}
startVersion = version;
startExclusive = false;
endVersion = version;
endExclusive = false;
break;
case GREATER_OR_EQUAL:
if (startVersion != null) {
throw new UnsupportedFilterException("Multiple version matching is not supported");
}
startVersion = version;
startExclusive = false;
break;
case GREATER_THAN:
if (startVersion != null) {
throw new UnsupportedFilterException("Multiple version matching is not supported");
}
startVersion = version;
startExclusive = true;
break;
case LOWER_OR_EQUAL:
if (endVersion != null) {
throw new UnsupportedFilterException("Multiple version matching is not supported");
}
endVersion = version;
endExclusive = false;
break;
case LOWER_THAN:
if (endVersion != null) {
throw new UnsupportedFilterException("Multiple version matching is not supported");
}
endVersion = version;
endExclusive = true;
break;
}
break;
default:
throw new UnsupportedFilterException("Unsupported attribute: " + att);
}
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class P2Descriptor method finish.
public void finish() {
sourceBundles = null;
Set<String> bundleIds = getCapabilityValues(BundleInfo.BUNDLE_TYPE);
if (bundleIds == null) {
return;
}
for (String bundleId : bundleIds) {
for (ModuleDescriptorWrapper mdw : findModules(BundleInfo.BUNDLE_TYPE, bundleId)) {
String symbolicName = mdw.getBundleInfo().getSymbolicName();
Map<Version, BundleInfo> byVersion = sourceTargetBundles.get(symbolicName);
if (byVersion == null) {
continue;
}
BundleInfo source = byVersion.get(mdw.getBundleInfo().getVersion());
if (source == null) {
continue;
}
for (BundleArtifact artifact : source.getArtifacts()) {
mdw.getBundleInfo().addArtifact(artifact);
}
}
}
sourceTargetBundles = null;
}
Aggregations