Search in sources :

Example 41 with Resource

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

the class JarTest method testDeletePrefix.

public void testDeletePrefix() {
    Resource r = new EmbeddedResource(new byte[1], 0);
    Jar jar = new Jar("test");
    jar.putResource("META-INF/maven/org/osgi/test/test.pom", r);
    jar.putResource("META-INF/maven/org/osgi/test/test.properties", r);
    jar.putResource("META-INF/MANIFEST.MF", r);
    jar.putResource("com/example/foo.jar", r);
    assertTrue(jar.getDirectories().containsKey("META-INF/maven/org/osgi/test"));
    assertTrue(jar.getDirectories().containsKey("META-INF/maven"));
    jar.removePrefix("META-INF/maven/");
    assertNotNull(jar.getResource("META-INF/MANIFEST.MF"));
    assertNotNull(jar.getResource("com/example/foo.jar"));
    assertNull(jar.getResource("META-INF/maven/org/osgi/test/test.pom"));
    assertNull(jar.getResource("META-INF/maven/org/osgi/test/test.properties"));
    assertFalse(jar.getDirectories().containsKey("META-INF/maven"));
    assertFalse(jar.getDirectories().containsKey("META-INF/maven/org/osgi/test"));
}
Also used : EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) Jar(aQute.bnd.osgi.Jar)

Example 42 with Resource

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

the class JarTest method testNoManifest.

public static void testNoManifest() throws Exception {
    Jar jar = new Jar("dot");
    jar.setManifest(new Manifest());
    jar.setDoNotTouchManifest();
    jar.putResource("a/b", new FileResource(IO.getFile("testresources/bnd.jar")));
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    jar.write(bout);
    Jar jin = new Jar("dotin", new ByteArrayInputStream(bout.toByteArray()));
    Resource m = jin.getResource("META-INF/MANIFEST.MF");
    assertNull(m);
    Resource r = jin.getResource("a/b");
    assertNotNull(r);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileResource(aQute.bnd.osgi.FileResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) Jar(aQute.bnd.osgi.Jar) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Example 43 with Resource

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

the class LauncherTest method testShaPackager.

/**
	 * Test the sha packager
	 * 
	 * @throws Exception
	 */
public static void testShaPackager() throws Exception {
    Project project = getProject();
    project.clear();
    project.setProperty("-package", "jpm");
    ProjectLauncher l = project.getProjectLauncher();
    l.setTrace(true);
    Jar executable = l.executable();
    assertNotNull(executable);
    Manifest m = executable.getManifest();
    m.write(System.out);
    System.out.flush();
    assertNotNull(m.getMainAttributes().getValue("JPM-Classpath"));
    assertNotNull(m.getMainAttributes().getValue("JPM-Runbundles"));
    Resource r = executable.getResource("launcher.properties");
    assertNotNull(r);
    Properties p = new Properties();
    try (InputStream in = r.openInputStream()) {
        p.load(in);
    }
    System.out.println(p);
    String s = p.getProperty("launch.bundles");
    assertTrue(s.contains("${JPMREPO}/"));
    assertEquals("false", p.getProperty("launch.embedded"));
}
Also used : Project(aQute.bnd.build.Project) InputStream(java.io.InputStream) Resource(aQute.bnd.osgi.Resource) ProjectLauncher(aQute.bnd.build.ProjectLauncher) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Properties(java.util.Properties)

Example 44 with Resource

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

the class DSAnnotationTest method testValidNamespaceVersion.

public void testValidNamespaceVersion() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*ValidNSVersion");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    // v1.0.0
    b.addClasspath(new File("jar/osgi.jar"));
    Jar jar = b.build();
    if (!b.check())
        fail();
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null);
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$ValidNSVersion.xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
}
Also used : Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 45 with Resource

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

the class DSAnnotationTest method testBinds13.

public void testBinds13() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*CheckBinds13");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/" + CheckBinds13.class.getName() + ".xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    for (int i = 1; i <= 8; i++) {
        xt.assertAttribute(LogService.class.getName(), "scr:component/reference[" + i + "]/@interface");
    }
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Aggregations

Resource (aQute.bnd.osgi.Resource)147 Jar (aQute.bnd.osgi.Jar)87 Builder (aQute.bnd.osgi.Builder)83 File (java.io.File)76 XmlTester (aQute.bnd.test.XmlTester)48 JarResource (aQute.bnd.osgi.JarResource)20 Attributes (java.util.jar.Attributes)20 Map (java.util.Map)19 Manifest (java.util.jar.Manifest)19 FileResource (aQute.bnd.osgi.FileResource)17 LogService (org.osgi.service.log.LogService)15 HashMap (java.util.HashMap)14 Document (org.w3c.dom.Document)14 Properties (java.util.Properties)12 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 InputStream (java.io.InputStream)9 Attrs (aQute.bnd.header.Attrs)8 ArrayList (java.util.ArrayList)8 TreeMap (java.util.TreeMap)8