Search in sources :

Example 16 with Domain

use of aQute.bnd.osgi.Domain in project bndtools by bndtools.

the class MavenWorkspaceRepository method getBsnFromMavenProject.

private String getBsnFromMavenProject(MavenProject mavenProject) throws Exception {
    final File bundleFile = getBundleFile(mavenProject);
    if (bundleFile.exists()) {
        Domain domain = Domain.domain(bundleFile);
        String bsn = domain.getBundleSymbolicName().getKey();
        return bsn;
    }
    return null;
}
Also used : Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 17 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class BuilderTest method testMacroBasedExpansion.

/**
	 * This test checks if
	 * 
	 * @throws Exception
	 */
public static void testMacroBasedExpansion() throws Exception {
    Processor proc = new Processor();
    Builder builder = new Builder(proc);
    try {
        builder.setProperty("Export-Package", "${spec.packages}");
        proc.setProperty("spec.packages", "${core.packages}, ${cmpn.packages}, ${mobile.packages}");
        proc.setProperty("core.specs", "org.osgi.service.packageadmin, org.osgi.service.permissionadmin");
        proc.setProperty("core.packages", "${replace;${core.specs};.+;$0.*}");
        proc.setProperty("cmpn.specs", "org.osgi.service.event, org.osgi.service.cu");
        proc.setProperty("cmpn.packages", "${replace;${cmpn.specs};.+;$0.*}");
        proc.setProperty("mobile.specs", "org.osgi.service.wireadmin, org.osgi.service.log, org.osgi.service.cu");
        proc.setProperty("mobile.packages", "${replace;${mobile.specs};.+;$0.*}");
        builder.addClasspath(IO.getFile("jar/osgi.jar"));
        Jar jar = builder.build();
        // The total set is not uniqued so we're having an unused pattern
        // this could be solved with ${uniq;${spec.packages}} but this is
        // just
        // another test
        assertTrue(builder.check("Unused Export-Package instructions: \\[org.osgi.service.cu.\\*~\\]"));
        Domain domain = Domain.domain(jar.getManifest());
        Parameters h = domain.getExportPackage();
        assertTrue(h.containsKey("org.osgi.service.cu"));
        assertTrue(h.containsKey("org.osgi.service.cu.admin"));
    } finally {
        builder.close();
        proc.close();
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) Parameters(aQute.bnd.header.Parameters) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 18 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class ContractTest method testUnused.

/**
	 * Make sure we do not add a contract if not used
	 * 
	 * @throws Exception
	 */
public void testUnused() throws Exception {
    Jar bjara = getContractExporter("atest", "2.5", "${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());
    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 19 with Domain

use of aQute.bnd.osgi.Domain in project bnd by bndtools.

the class ContractTest method testSimple.

public void testSimple() throws Exception {
    Jar bjar = getContractExporter("test", "2.5", "${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());
    Packages ps = a.getImports();
    assertTrue(ps.containsFQN("org.osgi.service.cm"));
    Attrs attrs = ps.getByFQN("org.osgi.service.cm");
    assertNotNull(attrs);
    assertNull(attrs.getVersion());
}
Also used : Parameters(aQute.bnd.header.Parameters) Packages(aQute.bnd.osgi.Packages) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain)

Example 20 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)

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