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