use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class ContractTest method testWarningVersion.
/**
* Test the warnings that we have no no version
*
* @throws Exception
*/
public void testWarningVersion() throws Exception {
Jar bjara = getContractExporter("abc", (String[]) null, "${exports}");
Builder a = newBuilder();
a.setTrace(true);
a.addClasspath(bjara);
a.setProperty(Constants.CONTRACT, "*");
a.setImportPackage("test.packageinfo,*");
a.setProperty("Export-Package", "test.refer");
Jar ajar = a.build();
assertTrue(a.check("Contract \\[name=abc;version=0.0.0;from=biz.aQute.bndlib.tests] does not declare a version"));
Domain domain = Domain.domain(ajar.getManifest());
Parameters p = domain.getRequireCapability();
p.remove("osgi.ee");
assertEquals(0, p.size());
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class ContractTest method testMultiple.
public void testMultiple() throws Exception {
Jar bjar = getContractExporter("abc", new String[] { "2.5", "2.6", "3.0", "3.1" }, "${exports}");
Builder a = newBuilder();
a.setTrace(true);
a.addClasspath(bjar);
a.setProperty(Constants.CONTRACT, "*");
a.setImportPackage("org.osgi.service.cm,*");
a.setProperty("Export-Package", "test.refer");
Jar ajar = a.build();
assertTrue(a.check());
Domain domain = Domain.domain(ajar.getManifest());
Parameters rc = domain.getRequireCapability();
rc.remove("osgi.ee");
System.out.println(rc);
assertEquals(1, rc.size());
assertNotNull(rc);
assertEquals(1, rc.size());
Attrs attrs = rc.get("osgi.contract");
assertEquals("(&(osgi.contract=abc)(version=3.1.0))", attrs.get("filter:"));
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class UsesTest method checkUses.
private static void checkUses(String export, String uses) throws IOException, Exception {
Builder a = new Builder();
a.addClasspath(new File("bin"));
a.setExportPackage(export);
a.setProperty("build", "123");
Jar jar = a.build();
assertTrue(a.check());
Manifest m = jar.getManifest();
m.write(System.err);
Domain d = Domain.domain(m);
Parameters parameters = d.getExportPackage();
Attrs attrs = parameters.get(export);
assertNotNull(attrs);
assertEquals(uses, attrs.get("uses:"));
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class ResolveCommand method _validate.
public void _validate(ValidateOptions options) throws Exception {
ResourceBuilder system = new ResourceBuilder();
system.addEE(options.ee(EE.JavaSE_1_8));
if (options.core() != null)
system.addManifest(options.core().getManifest());
if (options.packages() != null)
system.addExportPackages(options.packages());
if (options.capabilities() != null)
system.addProvideCapabilities(options.capabilities());
if (options.system() != null) {
File f = IO.getFile(options.system());
if (!f.isFile()) {
error("Specified system file but not found: %s", f);
return;
}
Domain domain = Domain.domain(f);
system.addManifest(domain);
}
List<String> args = options._arguments();
File index = getFile(args.remove(0));
logger.debug("validating {}", index);
ResolverValidator validator = new ResolverValidator(bnd);
validator.use(bnd);
validator.addRepository(index.toURI());
validator.setSystem(system.build());
List<Resolution> result = validator.validate();
Set<Requirement> done = new HashSet<>();
for (Resolution res : result) {
if (options.all()) {
bnd.out.format("%s %-60s%n", res.succeeded ? "OK" : "**", res.resource, res.message == null ? "" : res.message);
}
if (!res.succeeded) {
for (Requirement req : res.missing) {
if (done.contains(req))
continue;
bnd.out.format(" missing %s%n", req);
done.add(req);
}
if (options.all()) {
for (Requirement req : res.repos) {
bnd.out.format(" repos %s%n", req);
}
for (Requirement req : res.system) {
bnd.out.format(" system %s%n", req);
}
for (Requirement req : res.optionals) {
bnd.out.format(" optional %s%n", req);
}
}
}
}
bnd.getInfo(validator);
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class Profiles method _create.
public void _create(CreateOptions options) throws Exception {
Builder b = new Builder();
bnd.addClose(b);
b.setBase(bnd.getBase());
if (options.properties() != null) {
for (String propertyFile : options.properties()) {
File pf = bnd.getFile(propertyFile);
b.addProperties(pf);
}
}
if (options.bsn() != null)
b.setProperty(Constants.BUNDLE_SYMBOLICNAME, options.bsn());
if (options.version() != null)
b.setProperty(Constants.BUNDLE_VERSION, options.version().toString());
Instructions match = options.match();
Parameters packages = new Parameters();
Parameters capabilities = new Parameters();
Collection<String> paths = new ArrayList<String>(new Parameters(b.getProperty("-paths"), bnd).keySet());
if (paths.isEmpty())
paths = options._arguments();
logger.debug("input {}", paths);
ResourceBuilder pb = new ResourceBuilder();
for (String root : paths) {
File f = bnd.getFile(root);
if (!f.exists()) {
error("could not find %s", f);
} else {
Glob g = options.extension();
if (g == null)
g = new Glob("*.jar");
Collection<File> files = IO.tree(f, "*.jar");
logger.debug("will profile {}", files);
for (File file : files) {
Domain domain = Domain.domain(file);
if (domain == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
String bsn = domain.getBundleSymbolicName().getKey();
if (bsn == null) {
error("Not a bundle because no manifest %s", file);
continue;
}
if (match != null) {
Instruction instr = match.finder(bsn);
if (instr == null || instr.isNegated()) {
logger.debug("skipped {} because of non matching bsn {}", file, bsn);
continue;
}
}
Parameters eps = domain.getExportPackage();
Parameters pcs = domain.getProvideCapability();
logger.debug("parse {}:\ncaps: {}\npac: {}\n", file, pcs, eps);
packages.mergeWith(eps, false);
capabilities.mergeWith(pcs, false);
}
}
}
b.setProperty(Constants.PROVIDE_CAPABILITY, capabilities.toString());
b.setProperty(Constants.EXPORT_PACKAGE, packages.toString());
logger.debug("Found {} packages and {} capabilities", packages.size(), capabilities.size());
Jar jar = b.build();
File f = b.getOutputFile(options.output());
logger.debug("Saving as {}", f);
jar.write(f);
}
Aggregations