use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testOSGiWiringHostBundle.
public void testOSGiWiringHostBundle() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo/generated/demo.jar")));
Resource resource = rb.build();
List<Capability> capabilities = resource.getCapabilities(HostNamespace.HOST_NAMESPACE);
assertEquals(1, capabilities.size());
Map<String, Object> attributes = capabilities.get(0).getAttributes();
assertTrue(attributes.containsKey(HostNamespace.HOST_NAMESPACE));
assertTrue(attributes.containsKey(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
assertEquals("demo", attributes.get(HostNamespace.HOST_NAMESPACE));
assertNotNull(attributes.get(HostNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE));
assertEquals(0, resource.getRequirements(HostNamespace.HOST_NAMESPACE).size());
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testResourceToVersionedClause.
public void testResourceToVersionedClause() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addManifest(Domain.domain(IO.getFile("../demo-fragment/generated/demo-fragment.jar")));
Resource resource = rb.build();
VersionedClause versionClause = ResourceUtils.toVersionClause(resource, "[===,==+)");
StringBuilder sb = new StringBuilder();
versionClause.formatTo(sb);
assertEquals("demo-fragment;version='[1.0.0,1.0.1)'", sb.toString());
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ResourceTest method testImportExportServiceFromManifest.
public void testImportExportServiceFromManifest() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
File f = IO.getFile("testresources/manifest/configadmin-1.8.8.mf");
Manifest m = new Manifest(new FileInputStream(f));
Domain d = Domain.domain(m);
rb.addManifest(d);
assertConfigAdminServices(rb.build());
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ObrContentProvider method parseIndex.
public void parseIndex(InputStream stream, URI baseUri, IRepositoryIndexProcessor listener, LogService log) throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
StreamSource source = new StreamSource(stream, baseUri.toString());
XMLStreamReader reader = inputFactory.createXMLStreamReader(source);
ResourceBuilder resourceBuilder = null;
CapReqBuilder capReqBuilder = null;
while (reader.hasNext()) {
int type = reader.next();
String localName;
switch(type) {
case START_ELEMENT:
localName = reader.getLocalName();
if (TAG_REFERRAL.equals(localName)) {
Referral referral = new Referral(reader.getAttributeValue(null, ATTR_REFERRAL_URL), parseInt(reader.getAttributeValue(null, ATTR_REFERRAL_DEPTH)));
listener.processReferral(baseUri, referral, referral.getDepth(), 1);
} else if (TAG_RESOURCE.equals(localName)) {
resourceBuilder = new ResourceBuilder();
String bsn = reader.getAttributeValue(null, ATTR_RESOURCE_SYMBOLIC_NAME);
String versionStr = reader.getAttributeValue(null, ATTR_RESOURCE_VERSION);
Version version = Version.parseVersion(versionStr);
String uri = reader.getAttributeValue(null, ATTR_RESOURCE_URI);
URI resolvedUri = resolveUri(uri, baseUri);
addBasicCapabilities(resourceBuilder, bsn, version, resolvedUri);
} else if (TAG_CAPABILITY.equals(localName)) {
String obrName = reader.getAttributeValue(null, ATTR_NAME);
String namespace = mapObrNameToR5Namespace(obrName, false);
capReqBuilder = new CapReqBuilder(namespace);
} else if (TAG_REQUIRE.equals(localName)) {
String obrName = reader.getAttributeValue(null, ATTR_NAME);
boolean extend = "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_EXTEND));
String namespace = mapObrNameToR5Namespace(obrName, extend);
boolean optional = "true".equalsIgnoreCase(reader.getAttributeValue(null, ATTR_OPTIONAL));
capReqBuilder = new CapReqBuilder(namespace);
if (optional)
capReqBuilder.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
String filter = translateObrFilter(namespace, reader.getAttributeValue(null, ATTR_FILTER), log);
capReqBuilder.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
} else if (TAG_PROPERTY.equals(localName)) {
String name = reader.getAttributeValue(null, ATTR_PROPERTY_NAME);
String typeStr = reader.getAttributeValue(null, ATTR_PROPERTY_TYPE);
String valueStr = reader.getAttributeValue(null, ATTR_PROPERTY_VALUE);
if (capReqBuilder != null) {
name = mapObrPropertyToR5(capReqBuilder.getNamespace(), name);
if (PROPERTY_USES.equals(name))
capReqBuilder.addDirective(PROPERTY_USES, valueStr);
else {
Object value = convertProperty(valueStr, typeStr);
capReqBuilder.addAttribute(name, value);
}
}
}
break;
case END_ELEMENT:
localName = reader.getLocalName();
if (TAG_RESOURCE.equals(localName)) {
if (resourceBuilder != null) {
Resource resource = resourceBuilder.build();
listener.processResource(resource);
}
} else if (TAG_CAPABILITY.equals(localName)) {
if (resourceBuilder != null && capReqBuilder != null)
resourceBuilder.addCapability(capReqBuilder);
capReqBuilder = null;
} else if (TAG_REQUIRE.equals(localName)) {
if (resourceBuilder != null && capReqBuilder != null)
resourceBuilder.addRequirement(capReqBuilder);
capReqBuilder = null;
}
}
}
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ReleasePluginImpl method createIndex.
private ResourcesRepository createIndex(List<IPom> releasedArtifacts, IMavenRepo storage, String prefix) throws Exception {
ResourcesRepository repo = new ResourcesRepository();
for (IPom pom : releasedArtifacts) {
try {
System.out.println("Indexing " + pom);
Promise<File> promise = storage.get(pom.binaryArchive());
File file = promise.getValue();
ResourceBuilder rb = new ResourceBuilder();
String uri = prefix + pom.binaryArchive().remotePath;
rb.addFile(file, new URI(uri));
repo.add(rb.build());
} catch (Exception e) {
indexProject.exception(e, "Failed to index artifact %s", pom.binaryArchive());
}
}
return repo;
}
Aggregations