Search in sources :

Example 1 with Resource

use of aQute.bnd.osgi.Resource in project felix by apache.

the class BndJarResourceStore method read.

public byte[] read(String path) throws IOException {
    // Find the resource either in the global jar or in one of the embed dependencies
    Resource resource = m_analyzer.getJar().getResource(path);
    if (resource == null) {
        Jar embed = findJar(path);
        if (embed == null) {
            throw new IOException(format("Cannot find resource %s in jar and classpath", path));
        }
        resource = embed.getResource(path);
    }
    InputStream is = null;
    try {
        is = resource.openInputStream();
    } catch (Exception e) {
        throw new IOException("Cannot read " + path);
    }
    return Streams.readBytes(is);
}
Also used : InputStream(java.io.InputStream) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with Resource

use of aQute.bnd.osgi.Resource in project felix by apache.

the class PojoizationPlugin method buildMetadataProvider.

protected CompositeMetadataProvider buildMetadataProvider(Analyzer analyzer, BndReporter reporter, BndJarResourceStore store) {
    // Build MetadataProvider
    CompositeMetadataProvider provider = new CompositeMetadataProvider(reporter);
    File file = new File(m_metadata);
    if (file.exists()) {
        // Absolute file system resource
        FileMetadataProvider fmp = new FileMetadataProvider(file, reporter);
        fmp.setValidateUsingLocalSchemas(m_useLocalSchemas);
        provider.addMetadataProvider(fmp);
    } else {
        // In archive resource
        Resource resource = analyzer.getJar().getResource(m_metadata);
        if (resource != null) {
            ResourceMetadataProvider rmp = new ResourceMetadataProvider(resource, reporter);
            rmp.setValidateUsingLocalSchemas(m_useLocalSchemas);
            provider.addMetadataProvider(rmp);
        }
    }
    provider.addMetadataProvider(new AnnotationMetadataProvider(store, reporter));
    return provider;
}
Also used : FileMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.FileMetadataProvider) Resource(aQute.bnd.osgi.Resource) CompositeMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider) AnnotationMetadataProvider(org.apache.felix.ipojo.manipulator.metadata.AnnotationMetadataProvider) File(java.io.File)

Example 3 with Resource

use of aQute.bnd.osgi.Resource in project felix by apache.

the class BndJarResourceStoreTestCase method testAnalysisWithOnlyEmbedComponents.

public void testAnalysisWithOnlyEmbedComponents() throws Exception {
    PojoizationPlugin plugin = new PojoizationPlugin();
    Map<String, String> props = new HashMap<String, String>();
    props.put("include-embed-bundles", "true");
    Resource resource = new URLResource(getClass().getResource("/EMBED-MANIFEST.MF"));
    doReturn(dot).when(analyzer).getJar();
    doReturn(resource).when(embed).getResource(eq("META-INF/MANIFEST.MF"));
    analyzer.setClasspath(new Jar[] { embed });
    plugin.setReporter(reporter);
    plugin.setProperties(props);
    plugin.analyzeJar(analyzer);
    assertContains("instance { $component=\"org.apache.felix.ipojo.IPOJOURLHandler\" }", analyzer.getProperty("IPOJO-Components"));
}
Also used : URLResource(aQute.bnd.osgi.URLResource) HashMap(java.util.HashMap) Resource(aQute.bnd.osgi.Resource) URLResource(aQute.bnd.osgi.URLResource)

Example 4 with Resource

use of aQute.bnd.osgi.Resource in project felix by apache.

the class BndJarResourceStoreTestCase method testAnalysisWithBothLocalAndEmbedComponents.

public void testAnalysisWithBothLocalAndEmbedComponents() throws Exception {
    PojoizationPlugin plugin = new PojoizationPlugin();
    Map<String, String> props = new HashMap<String, String>();
    props.put("include-embed-bundles", "true");
    Resource resource = new URLResource(getClass().getResource("/EMBED-MANIFEST.MF"));
    Resource resource2 = new URLResource(getClass().getResource("/metadata-components-only.xml"));
    doReturn(dot).when(analyzer).getJar();
    doReturn(resource).when(embed).getResource(eq("META-INF/MANIFEST.MF"));
    doReturn(resource2).when(dot).getResource(eq("META-INF/metadata.xml"));
    analyzer.setClasspath(new Jar[] { embed });
    plugin.setReporter(reporter);
    plugin.setProperties(props);
    plugin.analyzeJar(analyzer);
    assertContains("instance { $component=\"org.apache.felix.ipojo.IPOJOURLHandler\" }", analyzer.getProperty("IPOJO-Components"));
    assertContains("component { $class=\"com.acme.Thermometer\" }", analyzer.getProperty("IPOJO-Components"));
}
Also used : URLResource(aQute.bnd.osgi.URLResource) HashMap(java.util.HashMap) Resource(aQute.bnd.osgi.Resource) URLResource(aQute.bnd.osgi.URLResource)

Example 5 with Resource

use of aQute.bnd.osgi.Resource in project felix by apache.

the class PojoizationPluginTestCase method testAnalysisWithComponentsAndInstancesMetadataXml.

public void testAnalysisWithComponentsAndInstancesMetadataXml() throws Exception {
    PojoizationPlugin plugin = new PojoizationPlugin();
    Map<String, String> props = new HashMap<String, String>();
    Resource resource = new URLResource(getClass().getResource("/metadata-components-and-instances.xml"));
    doReturn(jar).when(analyzer).getJar();
    doReturn(resource).when(jar).getResource(eq("META-INF/metadata.xml"));
    plugin.setReporter(reporter);
    plugin.setProperties(props);
    plugin.analyzeJar(analyzer);
    assertEquals("component { $class=\"com.acme.Thermometer\" }" + "instance { $component=\"com.acme.Thermometer\" }" + "instance { $component=\"com.acme.Thermometer\" }", analyzer.getProperty("IPOJO-Components"));
}
Also used : URLResource(aQute.bnd.osgi.URLResource) HashMap(java.util.HashMap) Resource(aQute.bnd.osgi.Resource) URLResource(aQute.bnd.osgi.URLResource)

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