use of org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider in project felix by apache.
the class PojoizationPlugin method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
long start = System.currentTimeMillis();
// Wraps the Bnd Reporter
BndReporter reporter = new BndReporter(this.m_reporter);
// Build ResourceStore
BndJarResourceStore store = new BndJarResourceStore(analyzer, this.m_reporter);
store.setIncludeEmbedComponents(m_includeEmbedBundles);
CompositeMetadataProvider provider = buildMetadataProvider(analyzer, reporter, store);
// Quick exit
CacheableMetadataProvider cache = new CacheableMetadataProvider(provider);
if (cache.getMetadatas().isEmpty() && !hasEmbedComponents(analyzer)) {
return false;
}
// Compute the classpath to build the classloader.
List<Jar> jars = analyzer.getClasspath();
Jar jar = analyzer.getJar();
Set<String> paths = new LinkedHashSet<String>();
if (jar != null && jar.getSource() != null) {
paths.add(jar.getSource().getAbsolutePath());
}
for (Jar j : jars) {
if (j.getSource() != null) {
paths.add(j.getSource().getAbsolutePath());
}
}
Classpath cp = new Classpath(paths);
manipulateComponents(reporter, store, cache, cp.createClassLoader());
int nbComponents = findElements(cache.getMetadatas(), "component").size();
int nbHandlers = findElements(cache.getMetadatas(), "handler").size();
this.m_reporter.trace("iPOJO manipulation performed performed in %s ms (%d components, %d handlers).", (System.currentTimeMillis() - start), nbComponents, nbHandlers);
// Return true if a new run should be performed after the analyze
return false;
}
use of org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider 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 org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider in project felix by apache.
the class IPOJOURLHandler method openConnection.
/**
* Opens a connection using the ipojo url handler.
* This methods parses the URL and manipulate the given bundle.
*
* @param url the url.
* @return the URL connection on the manipulated bundle
* @throws java.io.IOException occurs when the bundle cannot be either downloaded, or manipulated or
* installed correctly.
* @see org.osgi.service.url.AbstractURLStreamHandlerService#openConnection(java.net.URL)
*/
public URLConnection openConnection(URL url) throws IOException {
logger.log(LOG_DEBUG, format("Processing URL %s", url));
String full = removeScheme(url);
// Now full is like : URL!URL or URL
String[] urls = full.split("!");
URL bundleURL = null;
URL metadataURL = null;
if (urls.length == 1) {
// URL form
bundleURL = new URL(urls[0]);
} else if (urls.length == 2) {
// URL!URL form
bundleURL = new URL(urls[0]);
metadataURL = new URL(urls[1]);
} else {
throw new MalformedURLException("The iPOJO url is not formatted correctly, ipojo:bundle_url[!metadata_url] expected");
}
logger.log(LOG_DEBUG, format("Extracted URL %s", url));
// Dump the referenced bundle on disk
File original = File.createTempFile("original-", ".jar", m_temp);
dump(bundleURL.openStream(), original);
JarFile jf = new JarFile(original);
File metadata = null;
if (metadataURL != null) {
metadata = File.createTempFile("ipojo-", ".xml", m_temp);
dump(metadataURL, metadata);
} else {
// Check that the metadata are in the jar file
metadata = findMetadata(jf);
}
Reporter reporter = new SystemReporter();
File out = File.createTempFile("ipojo-", ".jar", m_temp);
ResourceStore store = new BundleAwareJarFileResourceStore(jf, out, m_context);
CompositeMetadataProvider composite = new CompositeMetadataProvider(reporter);
if (metadata != null) {
FileMetadataProvider provider = new FileMetadataProvider(metadata, reporter);
composite.addMetadataProvider(provider);
}
ClassLoader classloader = new BridgeClassLoader(original, m_context);
// Pojoization
Pojoization pojoizator = new Pojoization(createModuleProvider());
try {
pojoizator.pojoization(store, composite, createVisitor(store, reporter), classloader);
} catch (Exception e) {
if (!pojoizator.getErrors().isEmpty()) {
throw new IOException("Errors occurred during the manipulation : " + pojoizator.getErrors(), e);
}
e.printStackTrace();
throw new IOException("Cannot manipulate the Url: " + url, e);
}
if (!pojoizator.getErrors().isEmpty()) {
throw new IOException("Errors occurred during the manipulation : " + pojoizator.getErrors());
}
if (!pojoizator.getWarnings().isEmpty()) {
logger.log(LOG_WARNING, format("Warnings occurred during the manipulation %s", pojoizator.getWarnings()));
}
logger.log(LOG_DEBUG, format("Manipulation done %s", out.exists()));
// Cleanup
if (metadata != null) {
metadata.delete();
}
original.delete();
out.deleteOnExit();
// Returns the URL Connection
return out.toURI().toURL().openConnection();
}
Aggregations