use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class P2Descriptor method addBundle.
public void addBundle(BundleInfo bundleInfo) {
if (bundleInfo.isSource()) {
if (bundleInfo.getSymbolicNameTarget() == null || bundleInfo.getVersionTarget() == null) {
if (getLogLevel() <= Message.MSG_VERBOSE) {
Message.verbose("The source bundle " + bundleInfo.getSymbolicName() + " did not declare its target. Ignoring it");
}
return;
}
Map<Version, BundleInfo> byVersion = sourceBundles.get(bundleInfo.getSymbolicName());
if (byVersion == null) {
byVersion = new HashMap<>();
sourceBundles.put(bundleInfo.getSymbolicName(), byVersion);
}
byVersion.put(bundleInfo.getVersion(), bundleInfo);
Map<Version, BundleInfo> byTargetVersion = sourceTargetBundles.get(bundleInfo.getSymbolicNameTarget());
if (byTargetVersion == null) {
byTargetVersion = new HashMap<>();
sourceTargetBundles.put(bundleInfo.getSymbolicNameTarget(), byTargetVersion);
}
BundleInfo old = byTargetVersion.put(bundleInfo.getVersionTarget(), bundleInfo);
if (old != null && !old.equals(bundleInfo)) {
if (getLogLevel() <= Message.MSG_VERBOSE) {
Message.verbose("Duplicate source for the bundle " + bundleInfo.getSymbolicNameTarget() + "@" + bundleInfo.getVersionTarget() + " : " + bundleInfo + " is replacing " + old);
}
}
return;
}
super.addBundle(bundleInfo);
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class P2Descriptor method addArtifactUrl.
public void addArtifactUrl(String classifier, String id, Version version, URI uri, String format) {
if (!classifier.equals("osgi.bundle")) {
// we only support OSGi bundle, no Eclipse feature or anything else
return;
}
ModuleDescriptorWrapper module = findModule(id, version);
if (module != null) {
addArtifact(module.getBundleInfo(), new BundleArtifact(false, uri, format));
return;
}
// not found in the regular bundle. Let's look up in the source ones
Map<Version, BundleInfo> byVersion = sourceBundles.get(id);
if (byVersion == null) {
return;
}
BundleInfo source = byVersion.get(version);
if (source == null) {
return;
}
addArtifact(source, new BundleArtifact(true, uri, format));
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class CapabilityAdapter method getOSGiService.
private static BundleCapability getOSGiService(BundleInfo bundleInfo, Capability capability) throws ParseException {
String name = null;
Version version = null;
for (CapabilityProperty property : capability.getProperties()) {
String propName = property.getName();
switch(propName) {
case "service":
name = 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 (name == null) {
throw new ParseException("No service name for the capability", 0);
}
return new BundleCapability(BundleInfo.SERVICE_TYPE, name, version);
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class OBRXMLWriter method appendVersion.
private static void appendVersion(StringBuilder filter, VersionRange v) {
filter.append("(&");
Version start = v.getStartVersion();
if (start != null) {
if (!v.isStartExclusive()) {
filter.append("(version>=");
filter.append(start.toString());
filter.append(')');
} else {
filter.append("(!");
filter.append("(version<=");
filter.append(start.toString());
filter.append("))");
}
}
Version end = v.getEndVersion();
if (end != null) {
if (!v.isEndExclusive()) {
filter.append("(version<=");
filter.append(end.toString());
filter.append(')');
} else {
filter.append("(!");
filter.append("(version>=");
filter.append(end.toString());
filter.append("))");
}
}
}
use of org.apache.ivy.osgi.util.Version in project ant-ivy by apache.
the class ManifestParser method parseManifest.
public static BundleInfo parseManifest(Manifest manifest) throws ParseException {
Attributes mainAttributes = manifest.getMainAttributes();
// Eclipse source bundle doesn't have it. Disable it until proven actually useful
// String manifestVersion = mainAttributes.getValue(BUNDLE_MANIFEST_VERSION);
// if (manifestVersion == null) {
// // non OSGi manifest
// throw new ParseException("No " + BUNDLE_MANIFEST_VERSION + " in the manifest", 0);
// }
String symbolicName = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_SYMBOLIC_NAME)).getSingleValue();
if (symbolicName == null) {
throw new ParseException("No " + BUNDLE_SYMBOLIC_NAME + " in the manifest", 0);
}
String description = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_DESCRIPTION)).getSingleValue();
if (description == null) {
description = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_DESCRIPTION)).getSingleValue();
}
String vBundle = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_VERSION)).getSingleValue();
Version version;
try {
version = versionOf(vBundle);
} catch (NumberFormatException e) {
throw new ParseException("The " + BUNDLE_VERSION + " has an incorrect version: " + vBundle + " (" + e.getMessage() + ")", 0);
}
BundleInfo bundleInfo = new BundleInfo(symbolicName, version);
bundleInfo.setDescription(description);
List<String> environments = new ManifestHeaderValue(mainAttributes.getValue(BUNDLE_REQUIRED_EXECUTION_ENVIRONMENT)).getValues();
bundleInfo.setExecutionEnvironments(environments);
parseRequirement(bundleInfo, mainAttributes, REQUIRE_BUNDLE, BundleInfo.BUNDLE_TYPE, ATTR_BUNDLE_VERSION);
parseRequirement(bundleInfo, mainAttributes, IMPORT_PACKAGE, BundleInfo.PACKAGE_TYPE, ATTR_VERSION);
parseRequirement(bundleInfo, mainAttributes, IMPORT_SERVICE, BundleInfo.SERVICE_TYPE, ATTR_VERSION);
ManifestHeaderValue exportElements = new ManifestHeaderValue(mainAttributes.getValue(EXPORT_PACKAGE));
for (ManifestHeaderElement exportElement : exportElements.getElements()) {
String vExport = exportElement.getAttributes().get(ATTR_VERSION);
Version v = null;
try {
v = versionOf(vExport);
} catch (NumberFormatException e) {
throw new ParseException("The " + EXPORT_PACKAGE + " has an incorrect version: " + vExport + " (" + e.getMessage() + ")", 0);
}
for (String name : exportElement.getValues()) {
ExportPackage export = new ExportPackage(name, v);
String uses = exportElement.getDirectives().get(ATTR_USE);
if (uses != null) {
for (String use : splitToArray(uses)) {
export.addUse(use);
}
}
bundleInfo.addCapability(export);
}
}
parseCapability(bundleInfo, mainAttributes, EXPORT_SERVICE, BundleInfo.SERVICE_TYPE);
// handle Eclipse specific source attachment
String eclipseSourceBundle = mainAttributes.getValue(ECLIPSE_SOURCE_BUNDLE);
if (eclipseSourceBundle != null) {
bundleInfo.setSource(true);
ManifestHeaderValue eclipseSourceBundleValue = new ManifestHeaderValue(eclipseSourceBundle);
ManifestHeaderElement element = eclipseSourceBundleValue.getElements().iterator().next();
String symbolicNameTarget = element.getValues().iterator().next();
bundleInfo.setSymbolicNameTarget(symbolicNameTarget);
String v = element.getAttributes().get(ATTR_VERSION);
if (v != null) {
bundleInfo.setVersionTarget(new Version(v));
}
}
String bundleClasspath = mainAttributes.getValue(BUNDLE_CLASSPATH);
if (bundleClasspath != null) {
ManifestHeaderValue bundleClasspathValue = new ManifestHeaderValue(bundleClasspath);
bundleInfo.setClasspath(bundleClasspathValue.getValues());
bundleInfo.setHasInnerClasspath(true);
}
return bundleInfo;
}
Aggregations