- Change bundle symbolic name to avoid "org.apache.felix.org.apache.felix.ipojo..."
- Improve error handling in junit4osgi
- Support cobertura in junit4osgi
- Allow enable/disable the log service provided by the host in junit4osgi
- Fix a bug in the manipulation of construtors to support Cobertura. This issue comes the cobertura manipulation injecting code between the method entry and the super constructor call.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@725068 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/arch/pom.xml b/ipojo/arch/pom.xml
index 96364e8..28baaa8 100644
--- a/ipojo/arch/pom.xml
+++ b/ipojo/arch/pom.xml
@@ -56,8 +56,8 @@
 				<extensions>true</extensions>
 				<configuration>
 					<instructions>
-						<Bundle-Name> iPOJO Arch Felix Command </Bundle-Name>
-						<Bundle-SymbolicName> ${pom.artifactId} </Bundle-SymbolicName>
+						<Bundle-Name>Apache Felix iPOJO Arch Command</Bundle-Name>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Vendor> The Apache Software Foundation </Bundle-Vendor>
 						<Bundle-Description> iPOJO Arch command for Felix 
 						</Bundle-Description>
diff --git a/ipojo/composite/pom.xml b/ipojo/composite/pom.xml
index cf4a42f..906434a 100644
--- a/ipojo/composite/pom.xml
+++ b/ipojo/composite/pom.xml
@@ -66,7 +66,8 @@
 				<extensions>true</extensions>
 				<configuration>
 					<instructions>
-						<Bundle-Name>iPOJO Composite</Bundle-Name>
+						<Bundle-Name>Apache Felix iPOJO Composite</Bundle-Name>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Vendor> The Apache Software Foundation </Bundle-Vendor>
 						<Bundle-Description> iPOJO Composititon Framework 
 						</Bundle-Description>
diff --git a/ipojo/core/pom.xml b/ipojo/core/pom.xml
index 7a7421d..3474e20 100644
--- a/ipojo/core/pom.xml
+++ b/ipojo/core/pom.xml
@@ -61,7 +61,7 @@
 				<extensions>true</extensions>
 				<configuration>
 					<instructions>
-						<Bundle-Name>iPOJO</Bundle-Name>
+						<Bundle-Name>Apache Felix iPOJO</Bundle-Name>
 						<Bundle-Vendor> The Apache Software Foundation </Bundle-Vendor>
 						<Bundle-SymbolicName> org.apache.felix.ipojo 
 						</Bundle-SymbolicName>
@@ -76,7 +76,7 @@
 							handler:org.apache.felix.ipojo.HandlerManagerFactory 
 						</IPOJO-Extension>
 						<Import-Package> org.osgi.framework;version=1.3, org.osgi.service.cm,
-							org.osgi.service.log </Import-Package>
+							org.osgi.service.log, !net.sourceforge.cobertura.* </Import-Package>
 						<Private-Package> org.apache.felix.ipojo.handlers.architecture,
 							org.apache.felix.ipojo.handlers.configuration,
 							org.apache.felix.ipojo.handlers.lifecycle.callback,
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
index e53530d..835a291 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/util/DependencyModel.java
@@ -478,7 +478,10 @@
             // The list must confront actual matching services with already get services from the tracker.

 

             int size = m_matchingRefs.size();

-            List usedByTracker = m_tracker.getUsedServiceReferences();

+            List usedByTracker = null;

+            if (m_tracker != null) {

+                usedByTracker = m_tracker.getUsedServiceReferences();

+            }

             if (size == 0 || usedByTracker == null) { return null; }

 

             List list = new ArrayList(1);

diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
index 4e60f93..fa17390 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/pom.xml
@@ -81,6 +81,11 @@
 			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>
 			<version>1.1.0-SNAPSHOT</version>
 		</dependency>
+	    <dependency>
+      		<groupId>net.sourceforge.cobertura</groupId>
+      		<artifactId>cobertura</artifactId>
+      		<version>1.9</version>
+    	</dependency>
 	</dependencies>
 	<build>
 		<plugins>
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
index d98b48a..3519403 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Installer.java
@@ -22,6 +22,7 @@
 import java.net.MalformedURLException;

 import java.net.URL;

 import java.util.List;

+import java.util.jar.JarFile;

 

 import org.apache.maven.artifact.Artifact;

 import org.apache.maven.project.MavenProject;

@@ -152,18 +153,27 @@
         }

 

         File file = m_project.getArtifact().getFile();

-        if (file.exists()) {

-            URL url = null;

-            try {

-                url = file.toURL();

-            } catch (MalformedURLException e) {

-                e.printStackTrace();

+        try {

+            if (file.exists()) {

+                if (file.getName().endsWith("jar")) {

+                    JarFile jar = new JarFile(file);

+                    if (jar.getManifest().getMainAttributes().getValue("Bundle-ManifestVersion") != null) {

+                        Bundle bundle = context.installBundle(file.toURL().toString());

+                        bundle.start();

+                    } else {

+                        System.err.println("The current artifact " + file.getName() + " is not a valid bundle");

+                    }

+                } else {

+                    System.err.println("The current artifact " + file.getName() + " is not a Jar file.");

+                }

+            } else {

+                System.err.println("The current artifact " + file.getName() + " does not exist.");

             }

-            Bundle bundle = context.installBundle(url.toString());

-            bundle.start();

-        } else {

-            throw new BundleException("The current project artifact does not exist (" + file.getAbsolutePath() + ")");

+        } catch (Exception e) {

+            throw new BundleException("The current project artifact cannot be installed (" + e.getMessage() + ")");

         }

+        

+        

     }

 

 

diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
index ce1f378..c064c2b 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/Junit4osgiPlugin.java
@@ -92,7 +92,7 @@
     /**
      * Must the current artifact be deployed?
      * 
-     * @parameter expression="${deployProjectArtifact}" default-value="false"
+     * @parameter expression="${deployProjectArtifact}" default-value="true"
      */
     private boolean m_deployProjectArtifact;
     
@@ -104,6 +104,13 @@
     private ArrayList m_bundles;
     
     /**
+     * Enables / Disables the log service provided by the plugin.
+     * 
+     * @parameter expression="${logService}" default-value="true"
+     */
+    private boolean m_logEnable;
+    
+    /**
      * Number of executed test case.
      */
     private int m_total;
@@ -151,15 +158,23 @@
         
         List activators = new ArrayList();
         m_logService = new LogServiceImpl();
-        activators.add(m_logService);
+        if (m_logEnable) { // Starts the log service if enabled
+            activators.add(m_logService);
+        } else {
+            getLog().info("Log Service disabled");
+        }
         activators.add(new Installer(m_pluginArtifacts, bundles, m_project, m_deployProjectArtifact));
         Map map = new HashMap();
         map.put("felix.systembundle.activators", activators);
         map.put("org.osgi.framework.storage.clean", "onFirstInit");
         map.put("ipojo.log.level", "WARNING");
-        map.put("org.osgi.framework.bootdelegation", "junit.framework, org.osgi.service.log");
+        // Use a boot delagation to share classes between the host and the embedded Felix.
+        // The junit.framework package is boot delegated to execute tests
+        // The log service package is also boot delegated as the host publish a log service
+        // The cobertura package is used during code coverage collection
+        map.put("org.osgi.framework.bootdelegation", "junit.framework, org.osgi.service.log, net.sourceforge.cobertura.coveragedata"); 
+        
         map.put("org.osgi.framework.storage", m_targetDir.getAbsolutePath() + "/felix-cache"); 
-
         
         System.out.println("");
         System.out.println("-------------------------------------------------------");
@@ -305,12 +320,20 @@
             if (Artifact.SCOPE_TEST.equals(artifact.getScope())) { // Select scope=test.
                 File file = artifact.getFile();
                 try {
-                    JarFile jar = new JarFile(file);
-                    if (jar.getManifest().getMainAttributes().getValue("Bundle-ManifestVersion") != null) {
-                        toDeploy.add(file.toURL());
+                    if (file.exists()) {
+                        if (file.getName().endsWith("jar")) {
+                            JarFile jar = new JarFile(file);
+                            if (jar.getManifest().getMainAttributes().getValue("Bundle-ManifestVersion") != null) {
+                                toDeploy.add(file.toURL());
+                            }
+                        } else {
+                            getLog().info("The test artifact " + artifact.getFile().getName() + " is not a Jar file.");
+                        }
+                    } else {
+                        getLog().info("The test artifact " + artifact.getFile().getName() + " does not exist.");
                     }
                 } catch (Exception e) {
-                    getLog().error(e);
+                    getLog().error(file + " is not a valid bundle, this artifact is ignored");
                 }
             }
         }
diff --git a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
index 88e72ec..bc8e6ac 100644
--- a/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
+++ b/ipojo/examples/junit4osgi/maven-junit4osgi-plugin/src/main/java/org/apache/felix/ipojo/junit4osgi/plugin/XMLReport.java
@@ -140,7 +140,9 @@
 
         addOutputStreamElement(err, "system-err", testCase);
 
-        addOutputStreamElement(log, "log-service", testCase);
+        if (log != null) {
+            addOutputStreamElement(log, "log-service", testCase);
+        }
 
         m_results.add(testCase);
     }
diff --git a/ipojo/handler/eventadmin/pom.xml b/ipojo/handler/eventadmin/pom.xml
index 4d67d3e..bf6c959 100644
--- a/ipojo/handler/eventadmin/pom.xml
+++ b/ipojo/handler/eventadmin/pom.xml
@@ -63,8 +63,7 @@
 						<Export-Package>org.apache.felix.ipojo.handlers.event.*;
 							version="0.9.0"</Export-Package>
 						<Bundle-Name>${pom.name}</Bundle-Name>
-						<Bundle-SymbolicName> org.apache.felix.ipojo.handler.eventadmin 
-						</Bundle-SymbolicName>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Description> iPOJO Event Admin Handlers 
 						</Bundle-Description>
 						<Bundle-DocURL>
diff --git a/ipojo/handler/extender/pom.xml b/ipojo/handler/extender/pom.xml
index 46fbe9d..8981289 100644
--- a/ipojo/handler/extender/pom.xml
+++ b/ipojo/handler/extender/pom.xml
@@ -68,10 +68,8 @@
 						</Bundle-DocURL>
 						<Private-Package> org.apache.felix.ipojo.handler.extender 
 						</Private-Package>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Name>${pom.name}</Bundle-Name>
-						<Bundle-SymbolicName>
-							org.apache.felix.ipojo.handler.extender.pattern 
-						</Bundle-SymbolicName>
 						<Include-Resource> META-INF/LICENCE=LICENSE,
 							META-INF/NOTICE=NOTICE </Include-Resource>
 					</instructions>
diff --git a/ipojo/handler/jmx/pom.xml b/ipojo/handler/jmx/pom.xml
index da1f1f0..86f85df 100644
--- a/ipojo/handler/jmx/pom.xml
+++ b/ipojo/handler/jmx/pom.xml
@@ -63,8 +63,7 @@
 						<Private-Package> org.apache.felix.ipojo.handlers.jmx 
 						</Private-Package>
 						<Bundle-Name>${pom.name}</Bundle-Name>
-						<Bundle-SymbolicName> org.apache.felix.ipojo.handler.jmx 
-						</Bundle-SymbolicName>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
 						<Bundle-Description> iPOJO JMX Handler </Bundle-Description>
 						<Bundle-DocURL>
diff --git a/ipojo/handler/temporal/pom.xml b/ipojo/handler/temporal/pom.xml
index 3bc6726..be0773b 100644
--- a/ipojo/handler/temporal/pom.xml
+++ b/ipojo/handler/temporal/pom.xml
@@ -64,8 +64,7 @@
 						<Private-Package> org.apache.felix.ipojo.handler.temporal 
 						</Private-Package>
 						<Bundle-Name>${pom.name}</Bundle-Name>
-						<Bundle-SymbolicName> org.apache.felix.ipojo.handler.temporal 
-						</Bundle-SymbolicName>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Vendor> The Apache Software Foundation </Bundle-Vendor>
 						<Bundle-Description> iPOJO Temporal Dependency Handler 
 						</Bundle-Description>
diff --git a/ipojo/handler/whiteboard/pom.xml b/ipojo/handler/whiteboard/pom.xml
index 4c2f892..cc4865c 100644
--- a/ipojo/handler/whiteboard/pom.xml
+++ b/ipojo/handler/whiteboard/pom.xml
@@ -61,8 +61,7 @@
 				<configuration>
 					<instructions>
 						<Bundle-Name>${pom.name}</Bundle-Name>
-						<Bundle-SymbolicName> org.apache.felix.ipojo.handler.whiteboard 
-						</Bundle-SymbolicName>
+						<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
 						<Bundle-Vendor> The Apache Software Foundation </Bundle-Vendor>
 						<Bundle-Description> iPOJO White-Board Pattern Handler 
 						</Bundle-Description>
diff --git a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
index 1b5327f..dc046e2 100644
--- a/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
+++ b/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ConstructorCodeAdapter.java
@@ -136,9 +136,8 @@
      */

     public void visitMethodInsn(int opcode, String owner, String name, String desc) {

         

-        

         // A method call is detected, check if it is the super call :

-        if (!m_superDetected) {

+        if (!m_superDetected && name.equals("<init>")) {

             m_superDetected = true; 

             // The first invocation is the super call

             // 1) Visit the super constructor :

diff --git a/ipojo/tests/integration-tests/pom.xml b/ipojo/tests/integration-tests/pom.xml
index f1fb35c..194132d 100644
--- a/ipojo/tests/integration-tests/pom.xml
+++ b/ipojo/tests/integration-tests/pom.xml
@@ -22,12 +22,14 @@
 						<goals>
 							<goal>test</goal>
 						</goals>
-						<configuration>
-							<deployProjectArtifact>false</deployProjectArtifact>
-						</configuration>
 					</execution>
 				</executions>
 			</plugin>
+			
+		</plugins>
+	</build>
+	<reporting>
+		<plugins>
 			<plugin>
 				<groupId>org.apache.maven.plugins</groupId>
 				<artifactId>maven-surefire-report-plugin 
@@ -40,8 +42,13 @@
 					</reportsDirectories>
 				</configuration>
 			</plugin>
+			<plugin>
+				<groupId>org.codehaus.mojo</groupId>
+				<artifactId>cobertura-maven-plugin</artifactId>
+			</plugin>
 		</plugins>
-	</build>
+	</reporting>
+	
 	<dependencies>
    <!-- Manipulation -->
 		<dependency>
@@ -95,12 +102,6 @@
 		</dependency>
 		<dependency>
 			<groupId>ipojo.tests</groupId>
-			<artifactId>tests.core.configadmin</artifactId>
-			<version>${ipojo.version}</version>
-			<scope>test</scope>
-		</dependency>
-		<dependency>
-			<groupId>ipojo.tests</groupId>
 			<artifactId>tests.core.configuration 
 			</artifactId>
 			<version>${ipojo.version}</version>
@@ -115,6 +116,12 @@
 		</dependency>
 		<dependency>
 			<groupId>ipojo.tests</groupId>
+			<artifactId>tests.core.configadmin</artifactId>
+			<version>${ipojo.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>ipojo.tests</groupId>
 			<artifactId>tests.core.factories</artifactId>
 			<version>${ipojo.version}</version>
 			<scope>test</scope>
@@ -173,7 +180,7 @@
 			</artifactId>
 			<version>${ipojo.version}</version>
 			<scope>test</scope>
-		</dependency>
+		</dependency> 
     
    		<!-- Composite -->
 		<dependency>
@@ -203,7 +210,7 @@
 			<version>${ipojo.version}</version>
 			<scope>test</scope>
 		</dependency>
-	
+
 	<!--  External handlers -->
 		<dependency>
 			<groupId>ipojo.tests</groupId>
@@ -224,7 +231,6 @@
 			<version>${ipojo.version}</version>
 			<scope>test</scope>
 		</dependency>
-	
 	<!--  Utility bundles -->
 		<dependency>
 			<groupId>org.apache.felix</groupId>