Search in sources :

Example 11 with Domain

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

Example 12 with Domain

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

Example 13 with Domain

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:"));
}
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 14 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 15 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