List of usage examples for java.util.jar Manifest getMainAttributes
public Attributes getMainAttributes()
From source file:test.BuilderTest.java
/** * Check of SNAPSHOT is replaced with the -snapshot instr * //from w w w . ja v a 2s .c o m * @throws Exception */ public static void testSnapshot() throws Exception { Builder b = new Builder(); try { b.setProperty("-resourceonly", "true"); b.setProperty("-snapshot", "TIMESTAMP"); b.setProperty("Bundle-Version", "1.0-SNAPSHOT"); Jar jar = b.build(); assertTrue(b.check("The JAR is empty")); Manifest m = jar.getManifest(); assertEquals("1.0.0.TIMESTAMP", m.getMainAttributes().getValue("Bundle-Version")); } finally { b.close(); } }
From source file:test.BuilderTest.java
/** * <pre>/*from www .j a v a 2 s. co m*/ * [2013-12-11 15:55:14] BJ Hargrave: init: [echo] Enter project * org.osgi.test.cases.prefs (${top}) [bndprepare] 2 WARNINGS [bndprepare] * No translation found for macro: * classes;extending;junit.framework.TestCase;concrete [bndprepare] No * translation found for macro: classes,concrete [2013-12-11 15:55:31] BJ * Hargrave: I am getting this on the latest bnd.master in the OSGi test * projects * </pre> * * @throws Exception */ public static void testClassQuery() throws Exception { Builder a = new Builder(); try { a.addClasspath(new File("bin")); a.setExportPackage("test.component"); a.setProperty("testcases", "${sort;${classes;extending;junit.framework.TestCase;concrete}}"); a.setProperty("Test-Cases", "${testcases}"); a.setProperty("-dsannotations", "!*"); a.setProperty("-metatypeannotations", "!*"); Jar jar = a.build(); assertTrue(a.check()); Manifest m = jar.getManifest(); Parameters p = new Parameters(m.getMainAttributes().getValue("Test-Cases")); assertTrue(p.size() >= 4); } finally { a.close(); } }
From source file:test.BuilderTest.java
/** * -exportcontents provides a header that is only relevant in the analyze * phase, it augments the Export-Package header. *//*from ww w . java 2 s . c o m*/ public static void testExportContents() throws Exception { Builder builder = new Builder(); try { builder.setProperty(Analyzer.INCLUDE_RESOURCE, "test/activator/inherits=src/test/activator/inherits"); builder.setProperty("-exportcontents", "*;x=true;version=1"); builder.build(); assertTrue(builder.check()); Manifest manifest = builder.calcManifest(); Attributes main = manifest.getMainAttributes(); Parameters map = OSGiHeader.parseHeader(main.getValue("Export-Package")); Map<String, String> export = map.get("test.activator.inherits"); assertNotNull(export); assertEquals("1", export.get("version")); assertEquals("true", export.get("x")); } finally { builder.close(); } }
From source file:test.BuilderTest.java
public static void testNoImportDirective() throws Exception { Builder b = new Builder(); try {//from ww w . j a v a 2s . c o m b.setProperty("Export-Package", "org.osgi.util.measurement, org.osgi.service.http;-noimport:=true"); b.setProperty("Private-Package", "org.osgi.framework, test.refer"); b.addClasspath(IO.getFile("jar/osgi.jar")); b.addClasspath(new File("bin")); Jar jar = b.build(); assertTrue(b.check()); Manifest m = jar.getManifest(); String imports = m.getMainAttributes().getValue("Import-Package"); assertTrue(imports.contains("org.osgi.util.measurement")); // referred // to // but // no // private // references // (does // not // use // fw). assertFalse(imports.contains("org.osgi.service.http")); // referred // to // but no // private // references // (does not // use // fw). } finally { b.close(); } }
From source file:test.BuilderTest.java
public static void testNoImportDirective2() throws Exception { Builder b = new Builder(); try {//from www. ja v a2 s.co m b.setProperty("Export-Package", "org.osgi.util.measurement;-noimport:=true, org.osgi.service.http"); b.setProperty("Private-Package", "org.osgi.framework, test.refer"); b.addClasspath(IO.getFile("jar/osgi.jar")); b.addClasspath(new File("bin")); Jar jar = b.build(); assertTrue(b.check()); Manifest m = jar.getManifest(); String imports = m.getMainAttributes().getValue("Import-Package"); assertFalse(imports.contains("org.osgi.util.measurement")); // referred // to // but // no // private // references // (does // not // use // fw). assertTrue(imports.contains("org.osgi.service.http")); // referred // to // but no // private // references // (does not // use // fw). } finally { b.close(); } }
From source file:test.BuilderTest.java
public static void testAutoNoImport() throws Exception { Builder b = new Builder(); try {//from w w w .j ava 2 s .c o m b.setProperty("Export-Package", "org.osgi.service.event, org.osgi.service.packageadmin, org.osgi.util.measurement, org.osgi.service.http;-noimport:=true"); b.setProperty("Private-Package", "org.osgi.framework, test.refer"); b.addClasspath(IO.getFile("jar/osgi.jar")); b.addClasspath(new File("bin")); Jar jar = b.build(); assertTrue(b.check("has 1, private references")); Manifest m = jar.getManifest(); String imports = m.getMainAttributes().getValue("Import-Package"); assertFalse(imports.contains("org.osgi.service.packageadmin")); // no // internal // references assertFalse(imports.contains("org.osgi.util.event")); // refers to // private // framework assertTrue(imports.contains("org.osgi.util.measurement")); // referred // to // but // no // private // references // (does // not // use // fw). assertFalse(imports.contains("org.osgi.service.http")); // referred // to // but no // private // references // (does not // use // fw). } finally { b.close(); } }
From source file:test.BuilderTest.java
/** * Check if we export META-INF when we export the complete classpath. *//*w ww . j a v a 2 s .c om*/ public static void testVersionCleanupAll() throws Exception { Properties base = new Properties(); base.put(Analyzer.EXPORT_PACKAGE, "*"); base.put(Analyzer.BUNDLE_VERSION, "0.9.0-incubator-SNAPSHOT"); Builder analyzer = new Builder(); try { analyzer.setClasspath(new File[] { IO.getFile("jar/asm.jar") }); analyzer.setProperties(base); analyzer.build(); assertTrue(analyzer.check()); Manifest manifest = analyzer.getJar().getManifest(); String version = manifest.getMainAttributes().getValue(Analyzer.BUNDLE_VERSION); assertEquals("0.9.0.incubator-SNAPSHOT", version); } finally { analyzer.close(); } }
From source file:test.BuilderTest.java
/** * Check if we can use findpath to build the Bundle-Classpath. *//*from ww w . ja va 2 s . co m*/ public static void testFindPathInBundleClasspath() throws Exception { Properties base = new Properties(); base.put(Analyzer.INCLUDE_RESOURCE, "jar=jar"); base.put(Analyzer.BUNDLE_CLASSPATH, "${findpath;jar/.{1,4}\\.jar}"); Builder analyzer = new Builder(); try { analyzer.setProperties(base); analyzer.build(); assertTrue(analyzer.check()); Manifest manifest = analyzer.getJar().getManifest(); String bcp = manifest.getMainAttributes().getValue("Bundle-Classpath"); assertTrue(bcp.indexOf("ds.jar") >= 0); assertTrue(bcp.indexOf("asm.jar") >= 0); assertTrue(bcp.indexOf("bcel.jar") >= 0); assertTrue(bcp.indexOf("mina.jar") >= 0); assertTrue(bcp.indexOf("rox.jar") >= 0); assertTrue(bcp.indexOf("osgi.jar") >= 0); } finally { analyzer.close(); } }
From source file:test.BuilderTest.java
/** * Test where the version comes from: Manifest or packageinfo * /*from w w w . j ava 2 s. c om*/ * @throws Exception */ public static void testImportVersionSource() throws Exception { Jar fromManifest = new Jar("manifestsource"); Jar fromPackageInfo = new Jar("packageinfosource"); Jar fromBoth = new Jar("both"); try { Manifest mms = new Manifest(); mms.getMainAttributes().putValue("Export-Package", "org.osgi.service.event; version=100"); fromManifest.setManifest(mms); fromPackageInfo.putResource("org/osgi/service/event/packageinfo", new EmbeddedResource("version 99".getBytes(), 0)); Manifest mboth = new Manifest(); mboth.getMainAttributes().putValue("Export-Package", "org.osgi.service.event; version=101"); fromBoth.putResource("org/osgi/service/event/packageinfo", new EmbeddedResource("version 199".getBytes(), 0)); fromBoth.setManifest(mboth); // Only version in manifest Builder bms = new Builder(); try { bms.addClasspath(fromManifest); bms.setProperty("Import-Package", "org.osgi.service.event"); bms.build(); assertTrue(bms.check("The JAR is empty")); String s = bms.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[100.0,101)", s); // Only version in packageinfo Builder bpinfos = new Builder(); try { bpinfos.addClasspath(fromPackageInfo); bpinfos.setProperty("Import-Package", "org.osgi.service.event"); bpinfos.build(); assertTrue(bms.check()); s = bpinfos.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[99.0,100)", s); // Version in manifest + packageinfo Builder bboth = new Builder(); try { bboth.addClasspath(fromBoth); bboth.setProperty("Import-Package", "org.osgi.service.event"); bboth.build(); assertTrue(bms.check()); s = bboth.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[101.0,102)", s); } finally { bboth.close(); } } finally { bpinfos.close(); } } finally { bms.close(); } } finally { fromManifest.close(); fromPackageInfo.close(); fromBoth.close(); } }
From source file:test.BuilderTest.java
public static void testDuplicateExport() throws Exception { File cp[] = { IO.getFile("jar/asm.jar") }; Builder bmaker = new Builder(); try {//from ww w . j a v a2 s .c o m Properties p = new Properties(); p.setProperty("Import-Package", "*"); p.setProperty("Export-Package", "org.*;version=1.2,org.objectweb.asm;version=1.3"); bmaker.setProperties(p); bmaker.setClasspath(cp); Jar jar = bmaker.build(); assertTrue(bmaker.check()); Manifest m = jar.getManifest(); m.write(System.err); String ip = m.getMainAttributes().getValue("Export-Package"); assertTrue(ip.indexOf("org.objectweb.asm;version=\"1.2\"") >= 0); } finally { bmaker.close(); } }