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"));
}
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());
}
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();
}
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();
}
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);
}
Aggregations