Search in sources :

Example 1 with Domain

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"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 2 with Domain

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"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 3 with Domain

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"));
}
Also used : Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 4 with Domain

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);
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) ResolverValidator(biz.aQute.resolve.ResolverValidator) Domain(aQute.bnd.osgi.Domain) File(java.io.File) Resolution(biz.aQute.resolve.ResolverValidator.Resolution) HashSet(java.util.HashSet)

Example 5 with Domain

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);
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Builder(aQute.bnd.osgi.Builder) ArrayList(java.util.ArrayList) Instructions(aQute.bnd.osgi.Instructions) Instruction(aQute.bnd.osgi.Instruction) Glob(aQute.libg.glob.Glob) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Aggregations

Domain (aQute.bnd.osgi.Domain)36 Parameters (aQute.bnd.header.Parameters)24 Jar (aQute.bnd.osgi.Jar)24 Attrs (aQute.bnd.header.Attrs)18 File (java.io.File)18 Builder (aQute.bnd.osgi.Builder)16 Manifest (java.util.jar.Manifest)15 ArrayList (java.util.ArrayList)8 Resource (aQute.bnd.osgi.Resource)6 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)5 FileResource (aQute.bnd.osgi.FileResource)4 Container (aQute.bnd.build.Container)3 PomFromManifest (aQute.bnd.maven.PomFromManifest)3 Analyzer (aQute.bnd.osgi.Analyzer)3 Version (aQute.bnd.version.Version)3 List (java.util.List)3 DistroOptions (aQute.bnd.main.RemoteCommand.DistroOptions)2 RemoteOptions (aQute.bnd.main.RemoteCommand.RemoteOptions)2 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2