/** Check if the getSubBuilders properly predicts the output. */ public static void testSubBuilders() throws Exception { Workspace ws = Workspace.getWorkspace(new File("test/ws")); Project project = ws.getProject("p4-sub"); Collection<? extends Builder> bs = project.getSubBuilders(); assertNotNull(bs); assertEquals(3, bs.size()); Set<String> names = new HashSet<String>(); for (Builder b : bs) { names.add(b.getBsn()); } assertTrue(names.contains("p4-sub.a")); assertTrue(names.contains("p4-sub.b")); assertTrue(names.contains("p4-sub.c")); File[] files = project.build(); assertTrue(project.check()); System.err.println(Processor.join(project.getErrors(), "\n")); System.err.println(Processor.join(project.getWarnings(), "\n")); assertEquals(0, project.getErrors().size()); assertEquals(0, project.getWarnings().size()); assertNotNull(files); assertEquals(3, files.length); for (File file : files) { Jar jar = new Jar(file); Manifest m = jar.getManifest(); assertTrue(names.contains(m.getMainAttributes().getValue("Bundle-SymbolicName"))); } }
public static void testBumpSubBuilders() throws Exception { File tmp = new File("tmp-ws"); if (tmp.exists()) IO.deleteWithException(tmp); tmp.mkdir(); assertTrue(tmp.isDirectory()); try { IO.copy(new File("test/ws"), tmp); Workspace ws = Workspace.getWorkspace(tmp); Project project = ws.getProject("bump-sub"); project.setTrace(true); assertNull(project.getProperty("Bundle-Version")); project.bump("=+0"); assertNull(project.getProperty("Bundle-Version")); for (Builder b : project.getSubBuilders()) { assertEquals(new Version(1, 1, 0), new Version(b.getVersion())); } } finally { IO.deleteWithException(tmp); } }
/** The default policy is truncate micro. Check if this is applied to the import. */ public static void testImportMicroTruncated() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty("Import-Package", "org.osgi.service.event"); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("[1.0,2)", s); }
/** Check if we can set a specific version on the import that does not use a version policy. */ public static void testImportMicroNotTruncated() throws Exception { Builder b = new Builder(); b.addClasspath(IO.getFile("jar/osgi.jar")); b.setProperty( "Import-Package", "org.osgi.service.event;version=${@}, org.osgi.service.log;version=\"${range;[==,=+)}\""); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); String l = b.getImports().getByFQN("org.osgi.service.log").get("version"); assertEquals("1.0.1", s); assertEquals("[1.3,1.4)", l); }
/** Test default package versions. */ public static void testDefaultPackageVersion() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setProperty("Bundle-Version", "1.2.3"); a.setProperty("Export-Package", "test.refer"); Jar jar = a.build(); Manifest m = jar.getManifest(); Parameters exports = Processor.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE), null); Map<String, String> attrs = exports.get("test.refer"); assertNotNull(attrs); assertEquals("1.2.3", attrs.get("version")); }
public static void testEnum() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Enums.xml"); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); Properties p = new Properties(); p.setProperty("r", "requireConfiguration"); p.setProperty("i", "ignoreConfiguration"); p.setProperty("o", "optionalConfiguration"); Enums enums = Configurable.createConfigurable(Enums.class, (Map<Object, Object>) p); assertEquals(Enums.X.requireConfiguration, enums.r()); assertEquals(Enums.X.ignoreConfiguration, enums.i()); assertEquals(Enums.X.optionalConfiguration, enums.o()); }
public static void testADWithInheritance() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.setProperty("-metatype-inherit", "true"); b.build(); Resource r = b.getJar() .getResource( "OSGI-INF/metatype/test.metatype.MetatypeTest$TestADWithInheritanceChild.xml"); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); System.err.println(b.getJar().getResources().keySet()); assertNotNull(r); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertAD( d, "fromChild", "From child", "fromChild", null, null, null, 0, "String", null, null, null); assertAD( d, "fromSuperOne", "From super one", "fromSuperOne", null, null, null, 0, "String", null, null, null); assertAD( d, "fromSuperTwo", "From super two", "fromSuperTwo", null, null, null, 0, "String", null, null, null); }
/** 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); }
/** * See if we a can override the version from the export statement and the version from the source. */ public static void testImportOverridesDiscoveredVersion() 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.setProperty("Import-Package", "org.osgi.service.event;version=2.1.3.q"); b.build(); String s = b.getImports().getByFQN("org.osgi.service.event").get("version"); assertEquals("2.1.3.q", s); }
/** 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); }
private File create(String bsn, Version v) throws Exception { String name = bsn + "-" + v; Builder b = new Builder(); b.setBundleSymbolicName(bsn); b.setBundleVersion(v); b.setProperty("Random", random++ + ""); b.setProperty("-resourceonly", true + ""); b.setIncludeResource("foo;literal='foo'"); Jar jar = b.build(); assertTrue(b.check()); File file = IO.getFile(tmp, name + ".jar"); file.getParentFile().mkdirs(); jar.updateModified(System.currentTimeMillis(), "Force it to now"); jar.write(file); b.close(); return file; }
/** Test import provide:. */ public static void testExportProvided() 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("Export-Package", "org.osgi.service.http;provide:=true"); Jar jar = a.build(); Map<String, String> event = a.getImports().getByFQN("org.osgi.service.event"); assertEquals("[1.0,2)", event.get("version")); Map<String, String> http = a.getImports().getByFQN("org.osgi.service.http"); assertEquals("[1.2,1.3)", http.get("version")); Manifest m = jar.getManifest(); String imports = m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE); assertFalse(imports.contains(Constants.PROVIDE_DIRECTIVE)); }
public static void testSimple() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestSimple.xml"); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); System.err.println(b.getJar().getResources().keySet()); assertNotNull(r); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals("TestSimple", xpath.evaluate("//OCD/@name", d)); assertEquals("simple", xpath.evaluate("//OCD/@description", d)); assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//OCD/@id", d)); assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Designate/@pid", d)); assertEquals("test.metatype.MetatypeTest$TestSimple", xpath.evaluate("//Object/@ocdref", d)); assertEquals("simple", xpath.evaluate("//OCD/AD[@id='simple']/@id", d)); assertEquals("Simple", xpath.evaluate("//OCD/AD[@id='simple']/@name", d)); assertEquals("String", xpath.evaluate("//OCD/AD[@id='simple']/@type", d)); assertEquals("true", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@required", d)); /** * https://github.com/bndtools/bnd/issues/281 * * <p>Using the Bnd annotations library (1.52.3), the generated metatype file will have * required='false' for all fields annotated with @Meta.AD(). When this annotation is omitted, * or when the required property is explicitly set, the field is correctly marked as required. * Taking a glance at the code, the bug appears to be due to aQute.bnd.osgi.Annotation using * aQute.bnd.annotation.metatype.Configurable internally for bridging Bnd-annotations to * Java-annotations. This configurable only obtains the values from the Bnd-annotation, omitting * the defaults defined in the Java annotation. The workaround is to explicitly mention the * required property on each field annotated with @Meta.AD. */ assertEquals("true", xpath.evaluate("//OCD/AD[@id='simple']/@required", d)); assertEquals( Integer.MAX_VALUE + "", xpath.evaluate("//OCD/AD[@id='notSoSimple']/@cardinality", d)); }
/** 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:")); }
/** * Tests if the implementation of the EventAdmin (which is marked as a ProviderType) causes the * import of the api package to use the provider version policy. */ public static void testProviderType() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setPrivatePackage("test.versionpolicy.implemented"); a.setExportPackage("test.versionpolicy.api"); a.setImportPackage("test.versionpolicy.api"); // what changed so this is // not automatically // added? a.setProperty("build", "123"); Jar jar = a.build(); assertTrue(a.check()); Manifest m = jar.getManifest(); m.write(System.err); Domain d = Domain.domain(m); Parameters parameters = d.getImportPackage(); Attrs attrs = parameters.get("test.versionpolicy.api"); assertNotNull(attrs); assertEquals("[1.2,1.3)", attrs.get("version")); }
/** * Tests if the implementation of the EventHandler (which is marked as a ConsumerType) causes the * import of the api package to use the consumer version policy. */ public static void testConsumerType() throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setPrivatePackage("test.versionpolicy.uses"); a.setExportPackage("test.versionpolicy.api"); a.setProperty("build", "123"); Jar jar = a.build(); assertTrue(a.check()); Manifest m = jar.getManifest(); m.write(System.err); Domain d = Domain.domain(m); Parameters parameters = d.getImportPackage(); Attrs attrs = parameters.get("test.versionpolicy.api"); assertNotNull(attrs); assertEquals("[1.2,2)", attrs.get("version")); }
/** * 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")); }
static void assertOCD( Builder b, String cname, String id, String name, String description, String designate, boolean factory, String localization) throws Exception { Resource r = b.getJar().getResource("OSGI-INF/metatype/" + cname + ".xml"); assertNotNull(r); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals(id, xpath.evaluate("//OCD/@id", d, XPathConstants.STRING)); assertEquals(name, xpath.evaluate("//OCD/@name", d, XPathConstants.STRING)); assertEquals( localization == null ? cname : localization, xpath.evaluate("//OCD/@localization", d, XPathConstants.STRING)); assertEquals( description == null ? "" : description, xpath.evaluate("//OCD/@description", d, XPathConstants.STRING)); if (designate == null) { assertEquals(id, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING)); if (factory) assertEquals(id, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING)); } else { assertEquals(designate, xpath.evaluate("//Designate/@pid", d, XPathConstants.STRING)); if (factory) assertEquals( designate, xpath.evaluate("//Designate/@factoryPid", d, XPathConstants.STRING)); } assertEquals(id, xpath.evaluate("//Object/@ocdref", d, XPathConstants.STRING)); }
public static void testReturnTypes() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestReturnTypes.xml"); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); System.err.println(b.getJar().getResources().keySet()); assertNotNull(r); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); // Primitives assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rpBoolean']/@type", d)); assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rpByte']/@type", d)); assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rpCharacter']/@type", d)); assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rpShort']/@type", d)); assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rpInt']/@type", d)); assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rpLong']/@type", d)); assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rpFloat']/@type", d)); assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rpDouble']/@type", d)); // Primitive Wrappers assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rBoolean']/@type", d)); assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rByte']/@type", d)); assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rCharacter']/@type", d)); assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rShort']/@type", d)); assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rInt']/@type", d)); assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rLong']/@type", d)); assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rFloat']/@type", d)); assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rDouble']/@type", d)); // Primitive Arrays assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rpaBoolean']/@type", d)); assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rpaByte']/@type", d)); assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rpaCharacter']/@type", d)); assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rpaShort']/@type", d)); assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rpaInt']/@type", d)); assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rpaLong']/@type", d)); assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rpaFloat']/@type", d)); assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rpaDouble']/@type", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaBoolean']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaByte']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaCharacter']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaShort']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaInt']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaLong']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaFloat']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='rpaDouble']/@cardinality", d)); // Wrapper + Object arrays assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='raBoolean']/@type", d)); assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='raByte']/@type", d)); assertEquals("Character", xpath.evaluate("//OCD/AD[@id='raCharacter']/@type", d)); assertEquals("Short", xpath.evaluate("//OCD/AD[@id='raShort']/@type", d)); assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='raInt']/@type", d)); assertEquals("Long", xpath.evaluate("//OCD/AD[@id='raLong']/@type", d)); assertEquals("Float", xpath.evaluate("//OCD/AD[@id='raFloat']/@type", d)); assertEquals("Double", xpath.evaluate("//OCD/AD[@id='raDouble']/@type", d)); assertEquals("String", xpath.evaluate("//OCD/AD[@id='raString']/@type", d)); assertEquals("String", xpath.evaluate("//OCD/AD[@id='raURI']/@type", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raBoolean']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raByte']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raCharacter']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raShort']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raInt']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raLong']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raFloat']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raDouble']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raString']/@cardinality", d)); assertEquals("2147483647", xpath.evaluate("//OCD/AD[@id='raURI']/@cardinality", d)); // Wrapper + Object collections assertEquals("Boolean", xpath.evaluate("//OCD/AD[@id='rBooleans']/@type", d)); assertEquals("Byte", xpath.evaluate("//OCD/AD[@id='rBytes']/@type", d)); assertEquals("Character", xpath.evaluate("//OCD/AD[@id='rCharacter']/@type", d)); assertEquals("Short", xpath.evaluate("//OCD/AD[@id='rShorts']/@type", d)); assertEquals("Integer", xpath.evaluate("//OCD/AD[@id='rInts']/@type", d)); assertEquals("Long", xpath.evaluate("//OCD/AD[@id='rLongs']/@type", d)); assertEquals("Float", xpath.evaluate("//OCD/AD[@id='rFloats']/@type", d)); assertEquals("Double", xpath.evaluate("//OCD/AD[@id='rDoubles']/@type", d)); assertEquals("String", xpath.evaluate("//OCD/AD[@id='rStrings']/@type", d)); assertEquals("String", xpath.evaluate("//OCD/AD[@id='rURIs']/@type", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rBooleans']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rBytes']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rCharacters']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rShorts']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rInts']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rLongs']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rFloats']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rDoubles']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rStrings']/@cardinality", d)); assertEquals("-2147483648", xpath.evaluate("//OCD/AD[@id='rURIs']/@cardinality", d)); }
public static void testNaming() throws Exception { Map<String, Object> map = Create.map(); map.put("_secret", "_secret"); map.put("_secret", "_secret"); map.put(".secret", ".secret"); map.put("$new", "$new"); map.put("new", "new"); map.put("secret", "secret"); map.put("a_b_c", "a_b_c"); map.put("a.b.c", "a.b.c"); map.put(".a_b", ".a_b"); map.put("$$$$a_b", "$$$$a_b"); map.put("$$$$a.b", "$$$$a.b"); map.put("a", "a"); map.put("a$", "a$"); map.put("a$$", "a$$"); map.put("a$.$", "a$.$"); map.put("a$_$", "a$_$"); map.put("a..", "a.."); map.put("noid", "noid"); map.put("nullid", "nullid"); Naming trt = Configurable.createConfigurable(Naming.class, map); // By name assertEquals("secret", trt.secret()); assertEquals("_secret", trt.__secret()); assertEquals(".secret", trt._secret()); assertEquals("new", trt.$new()); assertEquals("$new", trt.$$new()); assertEquals("a.b.c", trt.a_b_c()); assertEquals("a_b_c", trt.a__b__c()); assertEquals(".a_b", trt._a__b()); assertEquals("$$$$a.b", trt.$$$$$$$$a_b()); assertEquals("$$$$a_b", trt.$$$$$$$$a__b()); assertEquals("a", trt.a$()); assertEquals("a$", trt.a$$()); assertEquals("a$", trt.a$$$()); assertEquals("a$.$", trt.a$$_$$()); assertEquals("a$_$", trt.a$$__$$()); assertEquals("a..", trt.a_$_()); assertEquals("noid", trt.noid()); assertEquals("nullid", trt.nullid()); // By AD assertEquals("secret", trt.xsecret()); assertEquals("_secret", trt.x__secret()); assertEquals(".secret", trt.x_secret()); assertEquals("new", trt.x$new()); assertEquals("$new", trt.x$$new()); assertEquals("a.b.c", trt.xa_b_c()); assertEquals("a_b_c", trt.xa__b__c()); assertEquals(".a_b", trt.x_a__b()); assertEquals("$$$$a.b", trt.x$$$$$$$$a_b()); assertEquals("$$$$a_b", trt.x$$$$$$$$a__b()); assertEquals("a", trt.xa$()); assertEquals("a$", trt.xa$$()); assertEquals("a$", trt.xa$$$()); assertEquals("a$.$", trt.xa$$_$$()); Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$Naming.xml"); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream(), "UTF-8"); assertEquals( "http://www.osgi.org/xmlns/metatype/v1.1.0", d.getDocumentElement().getNamespaceURI()); }
public static void testOCD() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); System.err.println(b.getJar().getResources().keySet()); assertOCD( b, "test.metatype.MetatypeTest$OCDEmpty", "test.metatype.MetatypeTest$OCDEmpty", "Metatype test OCDEmpty", null, "test.metatype.MetatypeTest$OCDEmpty", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDName", "test.metatype.MetatypeTest$OCDName", "name", null, "test.metatype.MetatypeTest$OCDName", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDDescription", "test.metatype.MetatypeTest$OCDDescription", "Metatype test OCDDescription", "description", "test.metatype.MetatypeTest$OCDDescription", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDDesignatePidOnly", "test.metatype.MetatypeTest$OCDDesignatePidOnly", "Metatype test OCDDesignate pid only", null, "test.metatype.MetatypeTest$OCDDesignatePidOnly", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDDesignatePidFactory", "test.metatype.MetatypeTest$OCDDesignatePidFactory", "Metatype test OCDDesignate pid factory", null, "test.metatype.MetatypeTest$OCDDesignatePidFactory", true, null); assertOCD( b, "test.metatype.MetatypeTest$OCDId", "id", "Metatype test OCDId", null, "id", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDIdWithPid", "id", "Metatype test OCDId with pid", null, "id", false, null); assertOCD( b, "test.metatype.MetatypeTest$OCDLocalization", "test.metatype.MetatypeTest$OCDLocalization", "Metatype test OCDLocalization", null, "test.metatype.MetatypeTest$OCDLocalization", false, "localization"); }
public static void testAD() throws Exception { Builder b = new Builder(); b.addClasspath(new File("bin")); b.setProperty("Export-Package", "test.metatype"); b.setProperty("-metatype", "*"); b.build(); Resource r = b.getJar().getResource("OSGI-INF/metatype/test.metatype.MetatypeTest$TestAD.xml"); assertEquals(0, b.getErrors().size()); assertEquals(0, b.getWarnings().size()); System.err.println(b.getJar().getResources().keySet()); assertNotNull(r); IO.copy(r.openInputStream(), System.err); Document d = db.parse(r.openInputStream()); assertAD( d, "noSettings", "No settings", "noSettings", null, null, null, 0, "String", null, null, null); assertAD(d, "withId", "With id", "id", null, null, null, 0, "String", null, null, null); assertAD(d, "name", "name", "withName", null, null, null, 0, "String", null, null, null); assertAD(d, "withMax", "With max", "withMax", null, "1", null, 0, "String", null, null, null); assertAD(d, "withMin", "With min", "withMin", "-1", null, null, 0, "String", null, null, null); assertAD(d, "withC1", "With c1", "withC1", null, null, null, 1, "String", null, null, null); assertAD( d, "withC0", "With c0", "withC0", null, null, null, 2147483647, "String", null, null, null); assertAD(d, "withC_1", "With c 1", "withC.1", null, null, null, -1, "String", null, null, null); assertAD( d, "withC_1ButArray", "With c 1 but array", "withC.1ButArray", null, null, null, -1, "String", null, null, null); assertAD( d, "withC1ButCollection", "With c1 but collection", "withC1ButCollection", null, null, null, 1, "String", null, null, null); assertAD(d, "withInt", "With int", "withInt", null, null, null, 0, "String", null, null, null); assertAD( d, "withString", "With string", "withString", null, null, null, 0, "Integer", null, null, null); assertAD( d, "a", "A", "a", null, null, null, 0, "String", "description_xxx\"xxx'xxx", null, null); assertAD( d, "valuesOnly", "Values only", "valuesOnly", null, null, null, 0, "String", null, new String[] {"a", "b"}, new String[] {"a", "b"}); assertAD( d, "labelsAndValues", "Labels and values", "labelsAndValues", null, null, null, 0, "String", null, new String[] {"a", "b"}, new String[] {"A", "A"}); }
/** Check implementation version policy. Uses the package test.versionpolicy.(uses|implemented) */ static void assertPolicy(String pack, String type) throws Exception { Builder a = new Builder(); a.addClasspath(new File("bin")); a.setProperty("Export-Package", "test.versionpolicy.api"); Jar jar = a.build(); Builder b = new Builder(); b.addClasspath(jar); b.addClasspath(new File("bin")); b.setProperty("-versionpolicy-impl", "IMPL"); b.setProperty("-versionpolicy-uses", "USES"); b.setProperty("Private-Package", pack); b.build(); Manifest m = b.getJar().getManifest(); m.write(System.err); Map<String, String> map = b.getImports().getByFQN("test.versionpolicy.api"); assertNotNull(map); // String s = map.get(Constants.IMPLEMENTED_DIRECTIVE); // assertEquals("true", s); Parameters mp = Processor.parseHeader(m.getMainAttributes().getValue("Import-Package"), null); assertEquals(type, mp.get("test.versionpolicy.api").get("version")); }