use of org.osgi.resource.dto.CapabilityDTO in project bnd by bndtools.
the class RemoteCommand method _distro.
public void _distro(DistroOptions opts) throws Exception {
List<String> args = opts._arguments();
String bsn;
String version;
bsn = args.remove(0);
if (!Verifier.isBsn(bsn)) {
error("Not a bundle symbolic name %s", bsn);
}
if (args.isEmpty())
version = "0";
else {
version = args.remove(0);
if (!Version.isVersion(version)) {
error("Invalid version %s", version);
}
}
File output = getFile(opts.output("distro.jar"));
if (output.getParentFile() == null || !output.getParentFile().isDirectory()) {
error("Cannot write to %s because parent not a directory", output);
}
if (output.isFile() && !output.canWrite()) {
error("Cannot write to %s", output);
}
logger.debug("Starting distro {};{}", bsn, version);
List<BundleRevisionDTO> bundleRevisons = agent.getBundleRevisons();
logger.debug("Found {} bundle revisions", bundleRevisons.size());
Parameters packages = new Parameters();
List<Parameters> provided = new ArrayList<>();
for (BundleRevisionDTO brd : bundleRevisons) {
for (CapabilityDTO c : brd.capabilities) {
CapabilityBuilder cb = new CapabilityBuilder(c.namespace);
for (Entry<String, Object> e : c.attributes.entrySet()) {
String key = e.getKey();
Object value = e.getValue();
if (key.equals("version")) {
if (value instanceof Collection || value.getClass().isArray())
value = Converter.cnv(tref, value);
else
value = new Version((String) value);
}
cb.addAttribute(key, value);
}
cb.addDirectives(c.directives);
Attrs attrs = cb.toAttrs();
if (cb.isPackage()) {
attrs.remove(Constants.BUNDLE_SYMBOLIC_NAME_ATTRIBUTE);
attrs.remove(Constants.BUNDLE_VERSION_ATTRIBUTE);
String pname = attrs.remove(PackageNamespace.PACKAGE_NAMESPACE);
if (pname == null) {
warning("Invalid package capability found %s", c);
} else
packages.put(pname, attrs);
logger.debug("P: {};{}", pname, attrs);
} else if (NativeNamespace.NATIVE_NAMESPACE.equals(c.namespace)) {
Attrs newAttrs = new Attrs();
for (Entry<String, String> entry : attrs.entrySet()) {
if (entry.getKey().startsWith(NativeNamespace.NATIVE_NAMESPACE)) {
newAttrs.put(entry.getKey(), entry.getValue());
}
}
Parameters p = new Parameters();
p.put(c.namespace, newAttrs);
provided.add(p);
} else if (!IGNORED_NAMESPACES.contains(c.namespace)) {
logger.debug("C {};{}", c.namespace, attrs);
Parameters p = new Parameters();
p.put(c.namespace, attrs);
provided.add(p);
}
}
}
if (isOk()) {
Manifest m = new Manifest();
Attributes main = m.getMainAttributes();
main.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
main.putValue(Constants.BUNDLE_SYMBOLICNAME, bsn);
main.putValue(Constants.BUNDLE_VERSION, version);
main.putValue(Constants.EXPORT_PACKAGE, packages.toString());
// Make distro unresolvable
Parameters unresolveable = new Parameters("osgi.unresolvable; filter:='(&(must.not.resolve=*)(!(must.not.resolve=*)))'");
main.putValue(Constants.REQUIRE_CAPABILITY, unresolveable.toString());
provided.add(new Parameters("osgi.unresolvable"));
StringBuilder sb = new StringBuilder();
for (Parameters parameter : provided) {
sb.append(parameter.toString());
sb.append(",");
}
String capabilities = sb.toString().substring(0, sb.length() - 1);
main.putValue(Constants.PROVIDE_CAPABILITY, capabilities);
if (opts.description() != null)
main.putValue(Constants.BUNDLE_DESCRIPTION, opts.description());
if (opts.license() != null)
main.putValue(Constants.BUNDLE_LICENSE, opts.license());
if (opts.copyright() != null)
main.putValue(Constants.BUNDLE_COPYRIGHT, opts.copyright());
if (opts.vendor() != null)
main.putValue(Constants.BUNDLE_VENDOR, opts.vendor());
Jar jar = new Jar("distro");
jar.setManifest(m);
Verifier v = new Verifier(jar);
v.setProperty(Constants.FIXUPMESSAGES, "osgi.* namespace must not be specified with generic capabilities");
v.verify();
v.getErrors();
if (isFailOk() || v.isOk()) {
jar.updateModified(System.currentTimeMillis(), "Writing distro jar");
jar.write(output);
} else
getInfo(v);
}
}
use of org.osgi.resource.dto.CapabilityDTO in project bnd by bndtools.
the class AgentServer method toDTO.
/*
* Turn a bundle in a Bundle Revision dto. On a r6 framework we could do
* this with adapt but on earlier frameworks we're on our own
*/
private BundleRevisionDTO toDTO(BundleRevision resource) {
BundleRevisionDTO brd = new BundleRevisionDTO();
brd.bundle = resource.getBundle().getBundleId();
brd.id = sequence.getAndIncrement();
brd.symbolicName = resource.getSymbolicName();
brd.type = resource.getTypes();
brd.version = resource.getVersion().toString();
brd.requirements = new ArrayList<RequirementDTO>();
for (Requirement r : resource.getRequirements(null)) {
brd.requirements.add(toDTO(brd.id, r));
}
brd.capabilities = new ArrayList<CapabilityDTO>();
for (Capability c : resource.getCapabilities(null)) {
brd.capabilities.add(toDTO(brd.id, c));
}
return brd;
}
use of org.osgi.resource.dto.CapabilityDTO in project bnd by bndtools.
the class AgentServer method toDTO.
private CapabilityDTO toDTO(int resource, Capability r) {
CapabilityDTO rd = new CapabilityDTO();
rd.id = sequence.getAndIncrement();
rd.resource = resource;
rd.namespace = r.getNamespace();
rd.directives = r.getDirectives();
rd.attributes = r.getAttributes();
return rd;
}
Aggregations