Search in sources :

Example 6 with Requirement

use of org.osgi.service.indexer.Requirement in project bnd by bndtools.

the class TestBundleAnalyzer method testContentAndIdentity.

public void testContentAndIdentity() throws Exception {
    BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
    LinkedList<Capability> caps = new LinkedList<Capability>();
    LinkedList<Requirement> reqs = new LinkedList<Requirement>();
    a.analyzeResource(new JarResource(new File("testdata/01-bsn+version.jar")), caps, reqs);
    assertEquals(4, caps.size());
    Capability idcap = caps.get(0);
    assertEquals("osgi.identity", idcap.getNamespace());
    assertEquals("org.example.a", idcap.getAttributes().get("osgi.identity"));
    assertEquals("osgi.bundle", idcap.getAttributes().get("type"));
    assertEquals(new Version("0.0.0"), idcap.getAttributes().get("version"));
    Capability content = caps.get(1);
    assertEquals("osgi.content", content.getNamespace());
    assertEquals("64f661eea43334dc5d38d7f16dbcacd02c799e68332b40e72da8021828e3329c", content.getAttributes().get("osgi.content"));
    assertEquals("testdata/01-bsn+version.jar", content.getAttributes().get("url"));
    assertEquals("application/vnd.osgi.bundle", content.getAttributes().get("mime"));
    assertEquals(1104L, content.getAttributes().get("size"));
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Capability(org.osgi.service.indexer.Capability) Version(org.osgi.framework.Version) File(java.io.File) LinkedList(java.util.LinkedList)

Example 7 with Requirement

use of org.osgi.service.indexer.Requirement in project bnd by bndtools.

the class TestBundleAnalyzer method testPackageExportBundleSymbolicNameAndVersion.

// bundle-symbolic-name and bundle-version must be on package capabilities,
// for the idiots
// who add this to their imports...
public void testPackageExportBundleSymbolicNameAndVersion() throws Exception {
    BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
    LinkedList<Capability> caps = new LinkedList<Capability>();
    LinkedList<Requirement> reqs = new LinkedList<Requirement>();
    a.analyzeResource(new JarResource(new File("testdata/04-export+uses.jar")), caps, reqs);
    List<Capability> exports = findCaps("osgi.wiring.package", caps);
    assertEquals(2, exports.size());
    assertEquals("org.example.b", exports.get(0).getAttributes().get("osgi.wiring.package"));
    assertEquals("org.example.d", exports.get(0).getAttributes().get("bundle-symbolic-name"));
    assertEquals(new Version(0, 0, 0), exports.get(0).getAttributes().get("bundle-version"));
    assertEquals("org.example.a", exports.get(1).getAttributes().get("osgi.wiring.package"));
    assertEquals("org.example.d", exports.get(0).getAttributes().get("bundle-symbolic-name"));
    assertEquals(new Version(0, 0, 0), exports.get(0).getAttributes().get("bundle-version"));
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Capability(org.osgi.service.indexer.Capability) Version(org.osgi.framework.Version) File(java.io.File) LinkedList(java.util.LinkedList)

Example 8 with Requirement

use of org.osgi.service.indexer.Requirement in project bnd by bndtools.

the class TestBundleAnalyzer method testPackageExports.

public void testPackageExports() throws Exception {
    BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
    LinkedList<Capability> caps = new LinkedList<Capability>();
    LinkedList<Requirement> reqs = new LinkedList<Requirement>();
    a.analyzeResource(new JarResource(new File("testdata/03-export.jar")), caps, reqs);
    Capability export = findCaps("osgi.wiring.package", caps).get(0);
    assertEquals("org.example.a", export.getAttributes().get("osgi.wiring.package"));
    assertEquals(new Version(1, 0, 0), export.getAttributes().get("version"));
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Capability(org.osgi.service.indexer.Capability) Version(org.osgi.framework.Version) File(java.io.File) LinkedList(java.util.LinkedList)

Example 9 with Requirement

use of org.osgi.service.indexer.Requirement in project bnd by bndtools.

the class TestBundleAnalyzer method testFragmentHost.

public void testFragmentHost() throws Exception {
    BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
    LinkedList<Capability> caps = new LinkedList<Capability>();
    LinkedList<Requirement> reqs = new LinkedList<Requirement>();
    a.analyzeResource(new JarResource(new File("testdata/08-fragmenthost.jar")), caps, reqs);
    Requirement req = findReqs("osgi.wiring.host", reqs).get(0);
    assertEquals("(&(osgi.wiring.host=org.example.a)(bundle-version>=0.0.0))", req.getDirectives().get("filter"));
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Capability(org.osgi.service.indexer.Capability) File(java.io.File) LinkedList(java.util.LinkedList)

Example 10 with Requirement

use of org.osgi.service.indexer.Requirement in project bnd by bndtools.

the class TestBundleAnalyzer method testPackageImportOptional.

public void testPackageImportOptional() throws Exception {
    BundleAnalyzer a = new BundleAnalyzer(new XNullLogSvc());
    LinkedList<Capability> caps = new LinkedList<Capability>();
    LinkedList<Requirement> reqs = new LinkedList<Requirement>();
    a.analyzeResource(new JarResource(new File("testdata/07-optionalimport.jar")), caps, reqs);
    Requirement pkgImport = findReqs("osgi.wiring.package", reqs).get(0);
    assertEquals("(&(osgi.wiring.package=org.example.a)(version>=1.0.0)(!(version>=2.0.0)))", pkgImport.getDirectives().get("filter"));
    assertEquals("optional", pkgImport.getDirectives().get("resolution"));
}
Also used : Requirement(org.osgi.service.indexer.Requirement) Capability(org.osgi.service.indexer.Capability) File(java.io.File) LinkedList(java.util.LinkedList)

Aggregations

Requirement (org.osgi.service.indexer.Requirement)13 File (java.io.File)10 Capability (org.osgi.service.indexer.Capability)10 LinkedList (java.util.LinkedList)7 Version (org.osgi.framework.Version)6 StringWriter (java.io.StringWriter)2 Builder (org.osgi.service.indexer.Builder)2 ResourceAnalyzer (org.osgi.service.indexer.ResourceAnalyzer)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 URL (java.net.URL)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Manifest (java.util.jar.Manifest)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Filter (org.osgi.framework.Filter)1 FrameworkUtil.createFilter (org.osgi.framework.FrameworkUtil.createFilter)1