Search in sources :

Example 96 with Resource

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

the class ManifestTest method testUnicode.

public static void testUnicode() throws Exception {
    Builder b = new Builder();
    String longSentence = "ᐁᐂᐃᐄᐅᐆᐇᐈᐉᐊᐋᐌᐍᐎᐏᐐᐑᐒᐓᐔᐕᐖᐗᐘᐙᐚᐛᐜᐝᐞᐟᐠᐡᐢᐢᐣᐤᐥᐦᐧᐨᐩᐩᐪᐫᐬᐭᐮᐯᐰᐱᐲᐳᐴᐵᐶᐷᐸᐹᐺᐻᐼᐽᐾᐿᑀᑁᑂᑃᑄᑄᑅᑆᑇᑈᑉᑊᑋᑌᑍ";
    String shortSentence = "ᐁᐂᐃᐄᐅᐆᐇᐈᐉᐊᐋᐌᐍᐎᐏᐐᐑᐒᐓᐔᐕᐖ";
    assertEquals(66, shortSentence.getBytes("UTF-8").length);
    assertEquals(22, shortSentence.length());
    b.setProperty("A1", shortSentence);
    b.setProperty("A11", shortSentence);
    b.setProperty("A111", shortSentence);
    b.setProperty("A1111", shortSentence);
    b.setProperty("Long", longSentence);
    b.setProperty("-resourceonly", "true");
    b.setProperty("Include-Resource", "jar/osgi.jar");
    Jar jar = b.build();
    File f = File.createTempFile("abc", ".jar");
    f.deleteOnExit();
    jar.write(f);
    jar = new Jar(f);
    f.delete();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    Resource r = jar.getResource("META-INF/MANIFEST.MF");
    assertNotNull(r);
    Manifest m = new Manifest(r.openInputStream());
    // String ms = IO.collect(r.openInputStream());
    assertEquals(shortSentence, m.getMainAttributes().getValue("A1"));
    assertEquals(shortSentence, m.getMainAttributes().getValue("A11"));
    assertEquals(shortSentence, m.getMainAttributes().getValue("A111"));
    assertEquals(shortSentence, m.getMainAttributes().getValue("A1111"));
    assertEquals(longSentence, m.getMainAttributes().getValue("Long"));
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 97 with Resource

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

the class ManifestTest method test72.

public static void test72() throws Exception {
    Builder b = new Builder();
    b.setProperty("H65", "01234567890123456789012345678901234567890123456789012345678901234");
    b.setProperty("H66", "012345678901234567890123456789012345678901234567890123456789012345");
    b.setProperty("H67", "0123456789012345678901234567890123456789012345678901234567890123456");
    b.setProperty("H68", "01234567890123456789012345678901234567890123456789012345678901234567");
    b.setProperty("H69", "012345678901234567890123456789012345678901234567890123456789012345678");
    b.setProperty("-resourceonly", "true");
    b.setProperty("Include-Resource", "jar/osgi.jar");
    Jar jar = b.build();
    File f = File.createTempFile("abc", ".jar");
    f.deleteOnExit();
    jar.write(f);
    jar = new Jar(f);
    f.delete();
    assertEquals(0, b.getErrors().size());
    assertEquals(0, b.getWarnings().size());
    Resource r = jar.getResource("META-INF/MANIFEST.MF");
    assertNotNull(r);
    Manifest m = new Manifest(r.openInputStream());
    String ms = IO.collect(r.openInputStream());
    assertEquals(65, m.getMainAttributes().getValue("H65").length());
    assertEquals(66, m.getMainAttributes().getValue("H66").length());
    assertEquals(67, m.getMainAttributes().getValue("H67").length());
    assertEquals(68, m.getMainAttributes().getValue("H68").length());
    assertEquals(69, m.getMainAttributes().getValue("H69").length());
    assertTrue(Pattern.compile("H65: \\d{65}\r\n").matcher(ms).find());
    assertTrue(Pattern.compile("H66: \\d{65}\r\n \\d{1}\r\n").matcher(ms).find());
    assertTrue(Pattern.compile("H67: \\d{65}\r\n \\d{2}\r\n").matcher(ms).find());
    assertTrue(Pattern.compile("H68: \\d{65}\r\n \\d{3}\r\n").matcher(ms).find());
    assertTrue(Pattern.compile("H69: \\d{65}\r\n \\d{4}\r\n").matcher(ms).find());
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File)

Example 98 with Resource

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

the class PreprocessTest method testPreProcessDefaultExclusion.

/**
	 * Preprocess now tries not to preprocess binary files, it uses an exclusion
	 * list by default. This list contains JAR files.
	 */
public static void testPreProcessDefaultExclusion() throws Exception {
    Builder b = new Builder();
    b.setProperty(Analyzer.INCLUDE_RESOURCE, "{src/test/tb1.jar}     ");
    b.build();
    assertTrue(b.check());
    Jar jar = b.getJar();
    Resource resource = jar.getResource("tb1.jar");
    assertNotNull(resource);
    File f = IO.getFile("src/test/tb1.jar");
    SHA1 d1 = SHA1.digest(f);
    SHA1 d2 = SHA1.digest(resource.openInputStream());
    assertEquals(d1, d2);
    b.close();
}
Also used : SHA1(aQute.libg.cryptography.SHA1) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 99 with Resource

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

the class PreprocessTest method testPreProcessExcludeExtensionLocal.

/**
	 * Exclude a file with a specific extension from being processed
	 */
public static void testPreProcessExcludeExtensionLocal() throws Exception {
    Builder b = new Builder();
    b.setProperty(Analyzer.INCLUDE_RESOURCE, "{src/test/builder-preprocess.txt};-preprocessmatchers='!*.TXT:i,*'");
    b.setProperty("var", "Yes!");
    ;
    b.build();
    assertTrue(b.check());
    Jar jar = b.getJar();
    Resource resource = jar.getResource("builder-preprocess.txt");
    assertNotNull(resource);
    String s = IO.collect(resource.openInputStream());
    assertNotNull(s);
    assertTrue(s.contains("${var}"));
    b.close();
}
Also used : Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Example 100 with Resource

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

the class ResourcesTest method testOnDemandResource.

/**
	 * Check if we can create a jar on demand through the make facility.
	 * 
	 * @throws Exception
	 */
public static void testOnDemandResource() throws Exception {
    Builder bmaker = new Builder();
    Properties p = new Properties();
    p.setProperty("-resourceonly", "true");
    p.setProperty("-plugin", "aQute.bnd.make.MakeBnd, aQute.bnd.make.MakeCopy");
    p.setProperty("-make", "(*).jar;type=bnd;recipe=bnd/$1.bnd");
    p.setProperty("Include-Resource", "ondemand.jar");
    bmaker.setProperties(p);
    bmaker.setClasspath(new String[] { "bin" });
    Jar jar = bmaker.build();
    Resource resource = jar.getResource("ondemand.jar");
    assertNotNull(resource);
    assertTrue(bmaker.check());
    assertTrue(resource instanceof JarResource);
    report(bmaker);
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

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