import org.apache.ivy.osgi.util.VersionRange;
public class PluginAdapter {
public static BundleInfo featureAsBundle(URI baseUri, EclipseFeature feature) {
BundleInfo b = new BundleInfo(feature.getId(), feature.getVersion());
if (feature.getUrl() == null) {
b.setUri(baseUri.resolve("features/" + feature.getId() + '_' + feature.getVersion()
+ ".jar"));
} else {
b.setUri(baseUri.resolve(feature.getUrl()));
}
b.setDescription(feature.getDescription());
b.setLicense(feature.getLicense());
Iterator itPlugins = feature.getPlugins().iterator();
while (itPlugins.hasNext()) {
EclipsePlugin plugin = (EclipsePlugin) itPlugins.next();
BundleRequirement r = new BundleRequirement(BundleInfo.BUNDLE_TYPE, plugin.getId(),
new VersionRange(plugin.getVersion()), null);
b.addRequirement(r);
}
Iterator itRequires = feature.getRequires().iterator();
while (itRequires.hasNext()) {
Require require = (Require) itRequires.next();
String id;
if (require.getPlugin() != null) {
id = require.getPlugin();
} else {
id = require.getFeature();
}
VersionRange range;
if (require.getMatch().equals("greaterOrEqual")) {
range = new VersionRange(require.getVersion());
} else {
throw new IllegalStateException("unsupported match " + require.getMatch());
}
BundleRequirement r = new BundleRequirement(BundleInfo.BUNDLE_TYPE, id, range, null);
b.addRequirement(r);
}
return b;
}