Migrate the BND plugin to the new manipulator API. The classloader is built from the analyzer jars. (FELIX-4509)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1592777 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
index b2ad670..09dc02a 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
@@ -19,11 +19,12 @@
package org.apache.felix.ipojo.bnd;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+import aQute.bnd.service.AnalyzerPlugin;
+import aQute.bnd.service.Plugin;
+import aQute.service.reporter.Reporter;
import org.apache.felix.ipojo.manipulator.ManipulationVisitor;
import org.apache.felix.ipojo.manipulator.Pojoization;
import org.apache.felix.ipojo.manipulator.ResourceStore;
@@ -31,15 +32,13 @@
import org.apache.felix.ipojo.manipulator.metadata.CacheableMetadataProvider;
import org.apache.felix.ipojo.manipulator.metadata.CompositeMetadataProvider;
import org.apache.felix.ipojo.manipulator.metadata.FileMetadataProvider;
+import org.apache.felix.ipojo.manipulator.util.Classpath;
import org.apache.felix.ipojo.manipulator.visitor.check.CheckFieldConsistencyVisitor;
import org.apache.felix.ipojo.manipulator.visitor.writer.ManipulatedResourcesWriter;
import org.apache.felix.ipojo.metadata.Element;
-import aQute.bnd.osgi.Analyzer;
-import aQute.bnd.osgi.Resource;
-import aQute.bnd.service.AnalyzerPlugin;
-import aQute.bnd.service.Plugin;
-import aQute.service.reporter.Reporter;
+import java.io.File;
+import java.util.*;
/**
* A {@code BndIpojoPlugin} is ...
@@ -103,27 +102,41 @@
return false;
}
- manipulateComponents(reporter, store, cache);
+ // 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);
-
+ (System.currentTimeMillis() - start),
+ nbComponents,
+ nbHandlers);
// Return true if a new run should be performed after the analyze
return false;
}
- protected void manipulateComponents(BndReporter reporter, BndJarResourceStore store, CacheableMetadataProvider cache) {
+ protected void manipulateComponents(BndReporter reporter, BndJarResourceStore store,
+ CacheableMetadataProvider cache, ClassLoader classLoader) {
Pojoization pojoization = new Pojoization(reporter);
pojoization.disableAnnotationProcessing();
if (m_useLocalSchemas) {
pojoization.setUseLocalXSD();
}
- pojoization.pojoization(store, cache, createVisitor(store, reporter));
+ pojoization.pojoization(store, cache, createVisitor(store, reporter), classLoader);
}
protected CompositeMetadataProvider buildMetadataProvider(Analyzer analyzer, BndReporter reporter, BndJarResourceStore store) {