Search in sources :

Example 11 with Builder

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

the class VersionPolicyTest method testImportProvided.

/**
	 * Test import provide:.
	 */
public static void testImportProvided() throws Exception {
    Builder a = new Builder();
    a.addClasspath(IO.getFile("jar/osgi.jar"));
    a.addClasspath(new File("bin"));
    a.setProperty("Private-Package", "test.refer");
    a.setProperty("Import-Package", "org.osgi.service.event;provide:=true,*");
    Jar jar = a.build();
    Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event");
    assertEquals("[1.0,1.1)", event.get("version"));
    Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http");
    assertEquals("[1.2,2)", http.get("version"));
    Manifest m = jar.getManifest();
    String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE);
    assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE));
}
Also used : Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 12 with Builder

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

the class VersionPolicyTest method testVersionPolicyImportedExportsDefaultPolicy.

/**
	 * Test if we can get the version from the source and apply the default
	 * policy.
	 */
public static void testVersionPolicyImportedExportsDefaultPolicy() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.addClasspath(new File("bin"));
    b.setProperty("Export-Package", "org.osgi.service.event");
    b.setProperty("Private-Package", "test.refer");
    b.build();
    String s = b.getImports().getByFQN("org.osgi.service.event").get("version");
    assertEquals("[1.0,2)", s);
}
Also used : Builder(aQute.bnd.osgi.Builder) File(java.io.File)

Example 13 with Builder

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

the class VersionPolicyTest method testHardcodedImports.

/**
	 * hardcoded imports
	 */
public static void testHardcodedImports() throws Exception {
    Builder b = new Builder();
    b.addClasspath(IO.getFile("jar/osgi.jar"));
    b.setProperty("-versionpolicy", "${range;[==,+)}");
    b.setProperty("Private-Package", "org.objectweb.asm");
    b.setProperty("Import-Package", "org.osgi.framework,org.objectweb.asm,abc;version=2.0.0,*");
    b.build();
    Manifest m = b.getJar().getManifest();
    m.write(System.err);
    String s = b.getImports().getByFQN("org.objectweb.asm").get("version");
    assertNull(s);
    s = b.getImports().getByFQN("abc").get("version");
    assertEquals("2.0.0", s);
    s = b.getImports().getByFQN("org.osgi.framework").get("version");
    assertEquals("[1.3,2)", s);
}
Also used : Builder(aQute.bnd.osgi.Builder) Manifest(java.util.jar.Manifest)

Example 14 with Builder

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

the class VersionPolicyTest method testExportAnnotation.

/**
	 * Test export annotation.
	 */
public static void testExportAnnotation() throws Exception {
    Builder a = new Builder();
    a.addClasspath(new File("bin"));
    a.setProperty("build", "xyz");
    a.setProperty("Export-Package", "test.versionpolicy.api");
    a.build();
    Map<String, String> attrs = a.getExports().getByFQN("test.versionpolicy.api");
    assertEquals("1.2.0.xyz", attrs.get("version"));
    assertEquals("PrivateImpl", attrs.get("exclude:"));
    assertEquals("a", attrs.get("mandatory:"));
}
Also used : Builder(aQute.bnd.osgi.Builder) File(java.io.File)

Example 15 with Builder

use of aQute.bnd.osgi.Builder 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)

Aggregations

Builder (aQute.bnd.osgi.Builder)426 Jar (aQute.bnd.osgi.Jar)225 File (java.io.File)197 Manifest (java.util.jar.Manifest)93 Properties (java.util.Properties)91 Resource (aQute.bnd.osgi.Resource)82 Attributes (java.util.jar.Attributes)43 DocumentBuilder (javax.xml.parsers.DocumentBuilder)41 XmlTester (aQute.bnd.test.XmlTester)39 Parameters (aQute.bnd.header.Parameters)35 Document (org.w3c.dom.Document)27 Attrs (aQute.bnd.header.Attrs)21 JarResource (aQute.bnd.osgi.JarResource)20 LogService (org.osgi.service.log.LogService)17 Domain (aQute.bnd.osgi.Domain)16 ArrayList (java.util.ArrayList)13 Project (aQute.bnd.build.Project)10 Baseline (aQute.bnd.differ.Baseline)9 Packages (aQute.bnd.osgi.Packages)9 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)9