use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ProjectResolverTest method add.
private void add(ResourcesRepository fr, File file) throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addFile(file, file.toURI());
Resource resource = rb.build();
fr.add(resource);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ValidatorTest method testValidatingResourcesWithDocumentaryAttributes.
public void testValidatingResourcesWithDocumentaryAttributes() throws Exception {
try (ResolverValidator validator = new ResolverValidator()) {
ResourceBuilder system = new ResourceBuilder();
system.addEE(EE.JavaSE_1_8);
system.addManifest(OSGI_CORE.R6_0_0.getManifest());
validator.setSystem(system.build());
validator.setTrace(true);
ResourcesRepository repository = new ResourcesRepository();
ResourceBuilder builder = new ResourceBuilder();
File file = IO.getFile("testdata/osgi.cmpn-4.3.0.jar");
builder.addFile(file, file.toURI());
repository.add(builder.build());
builder = new ResourceBuilder();
file = IO.getFile("testdata/org.apache.felix.framework-4.0.0.jar");
builder.addFile(file, file.toURI());
repository.add(builder.build());
List<Resource> resources = repository.getResources();
validator.validateResources(repository, resources);
assertTrue(validator.check());
}
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class ValidatorTest method testDelibarateFail.
public void testDelibarateFail() throws Exception {
try (ResolverValidator validator = new ResolverValidator()) {
ResourceBuilder system = new ResourceBuilder();
system.addEE(EE.JavaSE_1_8);
system.addManifest(OSGI_CORE.R6_0_0.getManifest());
validator.setSystem(system.build());
validator.setTrace(true);
validator.addRepository(IO.getFile("testdata/repo5-broken.index.xml").toURI());
List<Resolution> resolutions = validator.validate();
assertFalse(validator.check());
assertEquals(1, resolutions.size());
String message = resolutions.get(0).message;
String expectedToContain = "missing requirement org.apache.felix.gogo.api";
assertTrue(String.format("expected to contain <%s> but was <%s>", expectedToContain, message), message.contains(expectedToContain));
}
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class XMLResourceParser method parseResource.
private void parseResource(List<Resource> resources) throws Exception {
ResourceBuilder resourceBuilder = new ResourceBuilder();
next();
while (reader.isStartElement()) {
parseCapabilityOrRequirement(resourceBuilder);
}
Resource resource = resourceBuilder.build();
resources.add(resource);
tagEnd(TAG_RESOURCE);
}
use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.
the class R5RepoContentProvider method parseIndex.
public void parseIndex(InputStream stream, URI baseUri, IRepositoryIndexProcessor listener, LogService log) throws Exception {
XMLStreamReader reader = null;
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
inputFactory.setProperty(XMLInputFactory.IS_VALIDATING, false);
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
reader = inputFactory.createXMLStreamReader(stream);
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)) {
String url = reader.getAttributeValue(null, ATTR_REFERRAL_URL);
String depth = reader.getAttributeValue(null, ATTR_REFERRAL_DEPTH);
Referral referral = new Referral(url, parseInt(depth));
listener.processReferral(baseUri, referral, 0, 0);
} else if (TAG_RESOURCE.equals(localName)) {
resourceBuilder = new ResourceBuilder();
} else if (TAG_CAPABILITY.equals(localName) || TAG_REQUIREMENT.equals(localName)) {
String namespace = reader.getAttributeValue(null, ATTR_NAMESPACE);
capReqBuilder = new CapReqBuilder(namespace);
} else if (TAG_ATTRIBUTE.equals(localName)) {
String name = reader.getAttributeValue(null, ATTR_NAME);
String valueStr = reader.getAttributeValue(null, ATTR_VALUE);
String typeAttr = reader.getAttributeValue(null, ATTR_TYPE);
if (capReqBuilder != null) {
// base URI.
if (ContentNamespace.CONTENT_NAMESPACE.equals(capReqBuilder.getNamespace()) && ContentNamespace.CAPABILITY_URL_ATTRIBUTE.equals(name)) {
URI resolvedUri = resolveUri(valueStr, baseUri);
capReqBuilder.addAttribute(name, resolvedUri);
} else {
Object convertedAttr = convertAttribute(valueStr, typeAttr);
capReqBuilder.addAttribute(name, convertedAttr);
}
}
} else if (TAG_DIRECTIVE.equals(localName)) {
String name = reader.getAttributeValue(null, ATTR_NAME);
String valueStr = reader.getAttributeValue(null, ATTR_VALUE);
if (capReqBuilder != null)
capReqBuilder.addDirective(name, valueStr);
}
break;
case END_ELEMENT:
localName = reader.getLocalName();
if (TAG_CAPABILITY.equals(localName)) {
if (resourceBuilder != null && capReqBuilder != null)
resourceBuilder.addCapability(capReqBuilder);
capReqBuilder = null;
} else if (TAG_REQUIREMENT.equals(localName)) {
if (resourceBuilder != null && capReqBuilder != null)
resourceBuilder.addRequirement(capReqBuilder);
capReqBuilder = null;
} else if (TAG_RESOURCE.equals(localName)) {
if (resourceBuilder != null) {
Resource resource = resourceBuilder.build();
listener.processResource(resource);
resourceBuilder = null;
}
}
break;
}
}
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception e) {
}
}
}
}
Aggregations