You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2014/05/06 17:25:07 UTC

svn commit: r1592777 - /felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java

Author: clement
Date: Tue May  6 15:25:07 2014
New Revision: 1592777

URL: http://svn.apache.org/r1592777
Log:
Migrate the BND plugin to the new manipulator API. The classloader is built from the analyzer jars. (FELIX-4509)

Modified:
    felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java

Modified: felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java?rev=1592777&r1=1592776&r2=1592777&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java (original)
+++ felix/trunk/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/PojoizationPlugin.java Tue May  6 15:25:07 2014
@@ -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.manipulato
 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 @@ public class PojoizationPlugin implement
             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) {