FELIX-4155 Update bnd-ipojo-plugin for bndlib 2.x

* Clazz.getPath() is now getAbsolutePath()
* Analyzer.getReferrers() now gives Packages instead of a Map<String, Map<String, String>>
* Uses Attrs type instead of the attributes Map
* Attrs attributes can mow specify a type (Version is useful for us)
* Imports have been cleaned

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1499811 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/pom.xml b/ipojo/manipulator/bnd-ipojo-plugin/pom.xml
index fd4f967..a8db27c 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/pom.xml
+++ b/ipojo/manipulator/bnd-ipojo-plugin/pom.xml
@@ -32,9 +32,9 @@
 
     <dependencies>
         <dependency>
-            <groupId>biz.aQute</groupId>
+            <groupId>biz.aQute.bnd</groupId>
             <artifactId>bndlib</artifactId>
-            <version>1.43.0</version>
+            <version>2.1.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
index 0d6c5e9..00ee352 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndJarResourceStore.java
@@ -21,11 +21,16 @@
 
 import static java.lang.String.format;
 
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Clazz;
-import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.Resource;
-import aQute.libg.reporter.Reporter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
 import org.apache.felix.ipojo.manipulator.ResourceStore;
 import org.apache.felix.ipojo.manipulator.ResourceVisitor;
 import org.apache.felix.ipojo.manipulator.render.MetadataRenderer;
@@ -34,18 +39,12 @@
 import org.apache.felix.ipojo.manipulator.util.Streams;
 import org.apache.felix.ipojo.metadata.Element;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
+import aQute.bnd.header.Attrs;
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Clazz;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+import aQute.service.reporter.Reporter;
 
 public class BndJarResourceStore implements ResourceStore {
 
@@ -94,7 +93,7 @@
 
             // Iterates over discovered resources
             for (Clazz clazz : classes) {
-                visitor.visit(clazz.getPath());
+                visitor.visit(clazz.getAbsolutePath());
             }
         } catch (Exception e) {
             m_reporter.error("Cannot find iPOJO annotated types: " + e.getMessage());
@@ -106,7 +105,7 @@
         for (Clazz clazz : classes) {
 
             // If it is i the main jar, simply use it
-            if (m_analyzer.getJar().getResource(clazz.getPath()) != null) {
+            if (m_analyzer.getJar().getResource(clazz.getAbsolutePath()) != null) {
                 manipulable.add(clazz);
                 continue;
             }
@@ -114,7 +113,7 @@
             if (m_includeEmbedComponents) {
                 // Otherwise ...
                 // Try to see if it is in an embed dependencies
-                Jar jar = findJar(clazz.getPath());
+                Jar jar = findJar(clazz.getAbsolutePath());
                 if (jar == null) {
                     m_reporter.error("Resource for class %s not found in classpath", clazz.getFQN());
                     continue;
@@ -165,9 +164,10 @@
 
         // Find referred packages and add them into Bnd
         for (String referred : Metadatas.findReferredPackages(metadata)) {
-            if (m_analyzer.getReferred().get(referred) == null) {
+            if (!m_analyzer.getReferred().containsFQN(referred)) {
                 // The given package is not referred ATM
-                m_analyzer.getReferred().put(referred, new HashMap<String, String>());
+                m_analyzer.getReferred().put(m_analyzer.getPackageRef(referred),
+                                             new Attrs());
             }
         }
 
@@ -192,7 +192,7 @@
                     Attributes main = manifest.getMainAttributes();
                     String components = Manifests.getComponents(main);
                     if (components != null) {
-                        m_reporter.progress("Merging components from %s", jar.getName());
+                        m_reporter.trace("Merging components from %s", jar.getName());
                         builder.append(components);
                     }
                 } catch (Exception e) {
@@ -210,24 +210,28 @@
         }
 
         // Add some mandatory imported packages
-        Map<String, String> version = new TreeMap<String, String>();
-        version.put("version", Constants.getPackageImportClause());
+        Attrs version = new Attrs();
+        version.put("version:Version", Constants.getPackageImportClause());
 
-        if (m_analyzer.getReferred().get("org.apache.felix.ipojo") == null) {
-            m_analyzer.getReferred().put("org.apache.felix.ipojo", version);
+        if (!m_analyzer.getReferred().containsFQN("org.apache.felix.ipojo")) {
+            m_analyzer.getReferred().put(m_analyzer.getPackageRef("org.apache.felix.ipojo"),
+                                         version);
         }
-        if (m_analyzer.getReferred().get("org.apache.felix.ipojo.architecture") == null) {
-            m_analyzer.getReferred().put("org.apache.felix.ipojo.architecture", version);
+        if (!m_analyzer.getReferred().containsFQN("org.apache.felix.ipojo.architecture")) {
+            m_analyzer.getReferred().put(m_analyzer.getPackageRef("org.apache.felix.ipojo.architecture"),
+                                         version);
         }
-        if (m_analyzer.getReferred().get("org.osgi.service.cm") == null) {
-            Map<String, String> cm = new TreeMap<String, String>();
-            cm.put("version", "1.2");
-            m_analyzer.getReferred().put("org.osgi.service.cm", cm);
+        if (!m_analyzer.getReferred().containsFQN("org.osgi.service.cm")) {
+            Attrs cm = new Attrs();
+            cm.put("version:Version", "1.2");
+            m_analyzer.getReferred().put(m_analyzer.getPackageRef("org.osgi.service.cm"),
+                                         cm);
         }
-        if (m_analyzer.getReferred().get("org.osgi.service.log") == null) {
-            Map<String, String> log = new TreeMap<String, String>();
-            log.put("version", "1.3");
-            m_analyzer.getReferred().put("org.osgi.service.log", log);
+        if (!m_analyzer.getReferred().containsFQN("org.osgi.service.log")) {
+            Attrs log = new Attrs();
+            log.put("version:Version", "1.3");
+            m_analyzer.getReferred().put(m_analyzer.getPackageRef("org.osgi.service.log"),
+                                         log);
         }
 
 
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java
index 8625853..085d63a 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/BndReporter.java
@@ -22,9 +22,10 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import aQute.libg.reporter.Reporter;
 import org.apache.felix.ipojo.manipulator.reporter.EmptyReporter;
 
+import aQute.service.reporter.Reporter;
+
 /**
  * A {@code BndReporter} knows how to wrap a Bnd Reporter into an iPOJO Reporter.
  *
@@ -47,7 +48,7 @@
      */
     private List<String> m_warnings = new ArrayList<String>();
 
-    public BndReporter(aQute.libg.reporter.Reporter reporter) {
+    public BndReporter(Reporter reporter) {
         m_reporter = reporter;
     }
 
@@ -66,7 +67,7 @@
 
     @Override
     public void info(String message, Object... args) {
-        m_reporter.progress(message, args);
+        m_reporter.trace(message, args);
     }
 
     @Override
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java
index f58c2b3..e2ee7fc 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ByteArrayResource.java
@@ -19,7 +19,8 @@
 
 package org.apache.felix.ipojo.bnd;
 
-import aQute.lib.osgi.AbstractResource;
+
+import aQute.bnd.osgi.AbstractResource;
 
 /**
  * A {@code ByteArrayResource} is ...
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/Manifests.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/Manifests.java
index f3af117..4d267ca 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/Manifests.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/Manifests.java
@@ -19,11 +19,11 @@
 
 package org.apache.felix.ipojo.bnd;
 
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Jar;
-
 import java.util.jar.Attributes;
 
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Jar;
+
 /**
  * A {@code Manifests} is a utility class for extracting data from Bundle's Manifest.
  *
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 a59a8d9..b2ad670 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,11 @@
 
 package org.apache.felix.ipojo.bnd;
 
-import aQute.bnd.service.AnalyzerPlugin;
-import aQute.bnd.service.Plugin;
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Resource;
-import aQute.libg.reporter.Reporter;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.felix.ipojo.manipulator.ManipulationVisitor;
 import org.apache.felix.ipojo.manipulator.Pojoization;
 import org.apache.felix.ipojo.manipulator.ResourceStore;
@@ -35,12 +35,11 @@
 import org.apache.felix.ipojo.manipulator.visitor.writer.ManipulatedResourcesWriter;
 import org.apache.felix.ipojo.metadata.Element;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import static org.apache.felix.ipojo.bnd.Manifests.hasEmbedComponents;
+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;
 
 /**
  * A {@code BndIpojoPlugin} is ...
@@ -108,7 +107,7 @@
 
         int nbComponents = findElements(cache.getMetadatas(), "component").size();
         int nbHandlers = findElements(cache.getMetadatas(), "handler").size();
-        this.m_reporter.progress("iPOJO manipulation performed performed in %s ms (%d components, %d handlers).",
+        this.m_reporter.trace("iPOJO manipulation performed performed in %s ms (%d components, %d handlers).",
                                (System.currentTimeMillis() - start),
                                nbComponents,
                                nbHandlers);
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java
index 948385d..e696b60 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/main/java/org/apache/felix/ipojo/bnd/ResourceMetadataProvider.java
@@ -19,16 +19,17 @@
 
 package org.apache.felix.ipojo.bnd;
 
-import aQute.lib.osgi.Resource;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.felix.ipojo.manipulator.MetadataProvider;
 import org.apache.felix.ipojo.manipulator.Reporter;
 import org.apache.felix.ipojo.manipulator.metadata.StreamMetadataProvider;
 import org.apache.felix.ipojo.metadata.Element;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
+import aQute.bnd.osgi.Resource;
 
 /**
  * A {@code ResourceMetadataProvider} is ...
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/BndJarResourceStoreTestCase.java b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/BndJarResourceStoreTestCase.java
index 2bdb996..100686e 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/BndJarResourceStoreTestCase.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/BndJarResourceStoreTestCase.java
@@ -19,27 +19,28 @@
 
 package org.apache.felix.ipojo.bnd;
 
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Clazz;
-import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.Resource;
-import aQute.lib.osgi.URLResource;
-import aQute.libg.reporter.Reporter;
-import junit.framework.TestCase;
-import org.mockito.Matchers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
 
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Clazz;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+import aQute.bnd.osgi.URLResource;
+import aQute.service.reporter.Reporter;
+import junit.framework.TestCase;
 
 /**
  * Created with IntelliJ IDEA.
@@ -143,7 +144,7 @@
 
         Collection<Clazz> classes = new ArrayList<Clazz>();
         Resource typeResource = new URLResource(getClass().getResource("EmptyComponent.class"));
-        Clazz clazz = new Clazz(path, typeResource);
+        Clazz clazz = new Clazz(analyzer, path, typeResource);
         clazz.parseClassFile();
         classes.add(clazz);
         doReturn(classes).when(analyzer).getClasses(Matchers.<String[]>anyVararg());
diff --git a/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
index 83e5632..97837ad 100644
--- a/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
+++ b/ipojo/manipulator/bnd-ipojo-plugin/src/test/java/org/apache/felix/ipojo/bnd/PojoizationPluginTestCase.java
@@ -19,26 +19,22 @@
 
 package org.apache.felix.ipojo.bnd;
 
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+
 import java.util.HashMap;
 import java.util.Map;
 
-import aQute.lib.osgi.Analyzer;
-import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.Resource;
-import aQute.lib.osgi.URLResource;
-import aQute.libg.reporter.Reporter;
-import junit.framework.TestCase;
-import org.easymock.EasyMock;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.mockito.Spy;
 
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+import aQute.bnd.osgi.URLResource;
+import aQute.service.reporter.Reporter;
+import junit.framework.TestCase;
 
 public class PojoizationPluginTestCase extends TestCase {