use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class VersionPolicyTest method testProviderTypeR6.
/**
* Test if the implementation of "AnnotatedProviderInterface", which is
* annotated with OSGi R6 @ProviderType, causes import of the api package to
* use the provider version policy
*/
public static void testProviderTypeR6() throws Exception {
Builder b = new Builder();
b.addClasspath(new File("bin"));
b.setPrivatePackage("test.versionpolicy.implemented.osgi");
b.setProperty("build", "123");
Jar jar = b.build();
assertTrue(b.check());
Manifest m = jar.getManifest();
m.write(System.err);
Domain d = Domain.domain(m);
Parameters params = d.getImportPackage();
Attrs attrs = params.get("test.version.annotations.osgi");
assertNotNull(attrs);
assertEquals("[1.2,1.3)", attrs.get("version"));
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class BNDAnnotationTest method testBrokenName.
public void testBrokenName() throws Exception {
Builder b = builder("*Broken*", 0, 2);
Jar build = b.getJar();
assertTrue(b.check("Invalid component name"));
Domain m = Domain.domain(build.getManifest());
Parameters parameters = m.getParameters("Service-Component");
assertEquals(2, parameters.size());
System.out.println(parameters);
assertTrue(parameters.keySet().contains("OSGI-INF/Hello-World-Bnd---------$.xml"));
assertTrue(parameters.keySet().contains("OSGI-INF/Hello-World.xml"));
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class VersionPolicyTest method testConsumerType.
/**
* Tests if the implementation of the EventHandler (which is marked as a
* ConsumerType) causes the import of the api package to use the consumer
* version policy.
*/
public static void testConsumerType() throws Exception {
Builder a = new Builder();
a.addClasspath(new File("bin"));
a.setPrivatePackage("test.versionpolicy.uses");
a.setExportPackage("test.versionpolicy.api");
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.getImportPackage();
Attrs attrs = parameters.get("test.versionpolicy.api");
assertNotNull(attrs);
assertEquals("[1.2,2)", attrs.get("version"));
}
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