Index: tests/pom.xml
===================================================================
--- tests/pom.xml	(revision 122938)
+++ tests/pom.xml	(working copy)
@@ -135,30 +135,32 @@
                     </includes>
                     <testFailureIgnore>false</testFailureIgnore>
                     <skip>false</skip>
-                    <!--<systemProperties>
-                        <property>
-                            <name>maven.test.haltafterfailure</name>
-                            <value>false</value>
-                        </property>
-                        <property>
-                            <name>carbon.zip</name>
-                            <value>
-                                ${basedir}/../../kernel/target/wso2carbon-core-${project.version}.zip
-                            </value>
-                        </property>
-                        <property>
-                            <name>sec.verifier.dir</name>
-                            <value>${basedir}/../security-verifier/</value>
-                        </property>
-                    </systemProperties>-->
                     <systemPropertyVariables>
                         <sec.verifier.dir>${basedir}/../security-verifier/</sec.verifier.dir>
                         <carbon.zip>${basedir}/../../kernel/target/wso2carbon-core-${project.version}.zip</carbon.zip>
+                        <emma.home>${basedir}/target/lib</emma.home>
+                        <emma.output>${basedir}/../target/emma</emma.output>
                     </systemPropertyVariables>
                     <workingDirectory>${basedir}/target</workingDirectory>
                 </configuration>
             </plugin>
             <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                            <includeTypes>jar</includeTypes>
+                            <includeArtifactIds>emma,org.wso2.carbon.integration.framework</includeArtifactIds>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
                 <executions>
Index: core/pom.xml
===================================================================
--- core/pom.xml	(revision 122938)
+++ core/pom.xml	(working copy)
@@ -105,7 +105,7 @@
                 <configuration>
                     <testFailureIgnore>false</testFailureIgnore>
                     <skipTests>false</skipTests>
-		    <skip>false</skip>
+                    <skip>false</skip>
                     <argLine>-Xms512m -Xmx1024m -XX:MaxPermSize=256m</argLine>
                     <excludes>
                         <exclude>**/*Abstract*.java</exclude>
@@ -129,15 +129,43 @@
                                 ${basedir}/../../kernel/target/wso2carbon-core-${project.version}.zip
                             </value>
                         </property>
-			            <property>
+                        <property>
                             <name>sec.verifier.dir</name>
                             <value>${basedir}/../security-verifier/</value>
                         </property>
+                        <property>
+                            <name>emma.home</name>
+                            <value>${basedir}/target/lib</value>
+                        </property>
+                        <property>
+                            <name>jar.list</name>
+                            <value>${basedir}/../src/test/resources/jarlist.txt</value>
+                        </property>
+                        <property>
+                            <name>emma.output</name>
+                            <value>${basedir}/../target/emma</value>
+                        </property>
                     </systemProperties>
                     <workingDirectory>${basedir}/target</workingDirectory>
                 </configuration>
             </plugin>
             <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>compile</phase>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
+                            <includeTypes>jar</includeTypes>
+                            <includeArtifactIds>emma,org.wso2.carbon.integration.core</includeArtifactIds>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>
                 <executions>
@@ -145,9 +173,9 @@
                         <goals>
                             <goal>test-jar</goal>
                         </goals>
-			<configuration>
-				<skip>false</skip>
-			</configuration>
+                        <configuration>
+                            <skip>false</skip>
+                        </configuration>
                     </execution>
                 </executions>
             </plugin>
@@ -171,20 +199,20 @@
                 </executions>
             </plugin>
             <plugin>
-        	<groupId>org.apache.maven.plugins</groupId>
-        	<artifactId>maven-compiler-plugin</artifactId>
-        	<version>2.3.2</version>
-        	<configuration>
-          		<skip>false</skip>
-        	</configuration>
-      	    </plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <skip>false</skip>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
-  <properties>
-    <skipTests>false</skipTests>
-    <skip>false</skip>
-    <maven.test.skip>false</maven.test.skip>
-  </properties>
+    <properties>
+        <skipTests>false</skipTests>
+        <skip>false</skip>
+        <maven.test.skip>false</maven.test.skip>
+    </properties>
 
 </project>
Index: framework/src/main/java/org/wso2/carbon/integration/framework/utils/EmmaUtils.java
===================================================================
--- framework/src/main/java/org/wso2/carbon/integration/framework/utils/EmmaUtils.java	(revision 0)
+++ framework/src/main/java/org/wso2/carbon/integration/framework/utils/EmmaUtils.java	(revision 0)
@@ -0,0 +1,226 @@
+/*
+*  Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+*  WSO2 Inc. licenses this file to you under the Apache License,
+*  Version 2.0 (the "License"); you may not use this file except
+*  in compliance with the License.
+*  You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.wso2.carbon.integration.framework.utils;
+
+import com.vladium.emma.Command;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.utils.ArchiveManipulator;
+import org.wso2.carbon.utils.FileManipulator;
+import org.wso2.carbon.utils.ServerConstants;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.io.Writer;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * TODO: class description
+ */
+public class EmmaUtils {
+
+    private static final Log log = LogFactory.getLog(EmmaUtils.class);
+
+    public static void exportCoverage() {
+        if (System.getProperty("emma.home") == null) {
+            return;
+        }
+        String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
+        String emmaOutput = System.getProperty("emma.output");
+        File current = new File(carbonHome + File.separator + "coverage.ec");
+        File saved = new File(emmaOutput + File.separator + "coverage.ec");
+        if (current.exists() && new File(emmaOutput).exists()) {
+            try {
+                FileUtils.copyFile(current, saved);
+            } catch (IOException ignored) {
+            }
+        }
+    }
+
+    public static void importCoverage() {
+        if (System.getProperty("emma.home") == null) {
+            return;
+        }
+        String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
+        String emmaOutput = System.getProperty("emma.output");
+        File current = new File(carbonHome + File.separator + "coverage.ec");
+        File saved = new File(emmaOutput + File.separator + "coverage.ec");
+        if (saved.exists() && new File(carbonHome).exists()) {
+            try {
+                FileUtils.copyFile(saved, current);
+            } catch (IOException ignored) {
+            }
+        }
+    }
+
+    public static void instrument(String carbonHome) {
+        String workingDir = System.getProperty("user.dir");
+        try {
+            System.setProperty("user.dir", carbonHome);
+            String emmaHome = System.getProperty("emma.home");
+            if (emmaHome == null) {
+                return;
+            } else if (!emmaHome.endsWith(File.separator)) {
+                emmaHome += File.separator;
+            }
+            File emmaOutput = new File(System.getProperty("emma.output"));
+            if (!emmaOutput.exists()) {
+                FileUtils.forceMkdir(emmaOutput);
+            }
+            String emmaJarName = null;
+            for (File file : new File(emmaHome).listFiles()) {
+                if (file.getName().startsWith("org.wso2.carbon.integration.framework")) {
+                    ArchiveManipulator archiveManipulator = new ArchiveManipulator();
+                    archiveManipulator.extract(file.getAbsolutePath(), emmaHome);
+                } else if (file.getName().startsWith("emma")) {
+                    emmaJarName = file.getName();
+                }
+            }
+
+            if (emmaJarName == null) {
+                return;
+            }
+
+            //TODO: Uncomment following code when Sameera fixes the dropins issue
+           /* FileUtils.copyFile(new File(emmaHome + emmaJarName),
+                               new File(carbonHome + File.separator + "repository" +
+                                        File.separator + "components" + File.separator + "plugins" +
+                                        File.separator + "emma.jar"));
+            FileUtils.copyFile(new File(emmaHome + emmaJarName),
+                               new File(carbonHome + File.separator + "repository" +
+                                        File.separator + "components" + File.separator + "lib" +
+                                        File.separator + "emma.jar"));
+            FileUtils.copyFile(new File(emmaHome + emmaJarName),
+                               new File(carbonHome + File.separator + "lib" +
+                                        File.separator + "emma.jar"));
+            for (File dir : new File[]{new File(carbonHome), emmaOutput}) {
+                FileUtils.copyFileToDirectory(new File(carbonHome + File.separator + "lib" +
+                                                       File.separator + "emma.jar"), dir);
+            }*/
+
+            File plugins = new File(carbonHome + File.separator + "repository" + File.separator +
+                                    "components" + File.separator + "plugins");
+            for (File file : plugins.listFiles()) {
+                if (file.isFile() && file.getName().startsWith("org.wso2.")) {
+                    addEmmaDynamicImportPackage(file.getAbsolutePath());
+                    //TODO: Uncomment the following code when Sameera fixes the dropins issue
+                    /*Command cmd = Command.create("instr", "emmarun",
+                                                 new String[]{"-m", "overwrite", "-ip", file.getAbsolutePath()});
+                    cmd.run();*/
+                    log.info("Instrumented " + file.getAbsolutePath());
+                }
+            }
+
+            FileUtils.copyFileToDirectory(new File(System.getProperty("basedir") + File.separator + "" +
+                                                   "target" + File.separator + "coverage.em"),
+                                          emmaOutput);
+        } catch (IOException e) {
+            log.error("Cannot instrument jars", e);
+        } finally {
+            System.setProperty("user.dir", workingDir);
+        }
+    }
+
+    public static void main(String[] args) throws IOException {
+        String jarFile = "/Users/azeez/.m2/repository/org/wso2/carbon/org.wso2.carbon.utils/4.0.0-SNAPSHOT/org.wso2.carbon.utils-4.0.0-SNAPSHOT.jar";
+//        addEmmaDynamicImportPackage(jarFile);
+        Command cmd = Command.create("instr", "emmarun",
+                                     new String[]{"-m", "overwrite", "-ip", jarFile});
+        cmd.run();
+    }
+
+    private synchronized static void addEmmaDynamicImportPackage(String jarFile) throws IOException {
+        String fileSeparator = (File.separatorChar == '\\') ? "\\" : File.separator;
+        String jarFileName = jarFile;
+        if (jarFile.lastIndexOf(fileSeparator) != -1) {
+            jarFileName = jarFile.substring(jarFile.lastIndexOf(fileSeparator) + 1);
+        }
+        ZipFile zipFile = new ZipFile(jarFile);
+        ZipEntry manifestEntry = zipFile.getEntry("META-INF/MANIFEST.MF");
+        if (manifestEntry != null) {
+            ArchiveManipulator archiveManipulator;
+            String tempExtractedDir;
+            try {
+                archiveManipulator = new ArchiveManipulator();
+                tempExtractedDir = System.getProperty("basedir") + File.separator + "target" +
+                                   File.separator + jarFileName.substring(0, jarFileName.lastIndexOf("."));
+                archiveManipulator.extract(jarFile, tempExtractedDir);
+            } finally {
+                zipFile.close();
+            }
+            File origManifest = new File(tempExtractedDir + File.separator + "META-INF" +
+                                         File.separator + "MANIFEST.MF");
+            RandomAccessFile rf = new RandomAccessFile(origManifest, "r");
+            File newManifest;
+            StringBuilder output;
+            boolean isDynamicImportPackageFound;
+            try {
+                newManifest = new File(System.getProperty("basedir") + File.separator + "target" +
+                                       File.separator + "MANIFEST.MF");
+                if (newManifest.exists()) {
+                    if (!newManifest.delete()) {
+                        log.warn("Could not delete temp MANIFEST.MF file");
+                    }
+                }
+                if (!newManifest.createNewFile()) {
+                    log.warn("Could not create a new temp MANIFEST.MF file");
+                }
+                newManifest.deleteOnExit();
+
+                String line;
+                output = new StringBuilder();
+                isDynamicImportPackageFound = false;
+                while ((line = rf.readLine()) != null) {
+                    if (line.contains("DynamicImport-Package")) {
+                        output.append(line).append(",com.vladium.*").append("\n");
+                        isDynamicImportPackageFound = true;
+                    } else {
+                        output.append(line).append("\n");
+                    }
+                }
+            } finally {
+                rf.close();
+            }
+            if (!isDynamicImportPackageFound) {
+                output.append("DynamicImport-Package: com.vladium.*\n");
+            }
+            Writer out = null;
+            try {
+                out = new BufferedWriter(new FileWriter(newManifest));
+                out.write(output.toString());
+            } catch (IOException e) {
+                log.error("Could not write content to new MANIFEST.MF file", e);
+            } finally {
+                if (out != null) {
+                    out.close();
+                }
+            }
+            FileManipulator.copyFile(newManifest, origManifest);
+            if (!new File(jarFile).delete()) {
+                log.warn("Could not delete original jar file " + jarFile);
+            }
+            archiveManipulator.archiveDir(jarFile, tempExtractedDir);
+            FileManipulator.deleteDir(tempExtractedDir);
+        }
+    }
+}
Index: framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java
===================================================================
--- framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java	(revision 122938)
+++ framework/src/main/java/org/wso2/carbon/integration/framework/utils/ServerUtils.java	(working copy)
@@ -16,7 +16,6 @@
 
 package org.wso2.carbon.integration.framework.utils;
 
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.carbon.integration.framework.ClientConnectionUtil;
@@ -26,10 +25,8 @@
 import org.wso2.carbon.utils.FileManipulator;
 import org.wso2.carbon.utils.ServerConstants;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStreamReader;
 
 /**
  * A set of utility methods such as starting & stopping a Carbon server.
@@ -52,20 +49,18 @@
         }
         Process tempProcess;
         try {
-            instrumentJarsForEmma(carbonHome);
+            EmmaUtils.instrument(carbonHome);
             FrameworkSettings.init();
             defaultHttpsPort = Integer.parseInt(FrameworkSettings.HTTPS_PORT);
             int defaultHttpPort = Integer.parseInt(FrameworkSettings.HTTP_PORT);
             System.setProperty(ServerConstants.CARBON_HOME, carbonHome);
             originalUserDir = System.getProperty("user.dir");
             System.setProperty("user.dir", carbonHome);
-            log.info("Importing Code Coverage Details...");
-            importEmmaCoverage();
+            EmmaUtils.importCoverage();
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException ignored) {
             }
-            log.info("Imported Code Coverage Details.");
             File commandDir = new File(carbonHome);
             if (System.getProperty("os.name").toLowerCase().contains("windows")) {
                 commandDir = new File(carbonHome + File.separator + "bin");
@@ -133,109 +128,6 @@
                 extractedCarbonDir;
     }
 
-    private void exportEmmaCoverage() {
-        if (System.getProperty("emma.home") == null) {
-            return;
-        }
-        String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
-        String emmaOutput = System.getProperty("emma.output");
-        File current = new File(carbonHome + File.separator + "coverage.ec");
-        File saved = new File(emmaOutput + File.separator + "coverage.ec");
-        if (current.exists() && new File(emmaOutput).exists()) {
-            try {
-                FileUtils.copyFile(current, saved);
-            } catch (IOException ignored) {
-            }
-        }
-    }
-
-    private void importEmmaCoverage() {
-        if (System.getProperty("emma.home") == null) {
-            return;
-        }
-        String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
-        String emmaOutput = System.getProperty("emma.output");
-        File current = new File(carbonHome + File.separator + "coverage.ec");
-        File saved = new File(emmaOutput + File.separator + "coverage.ec");
-        if (saved.exists() && new File(carbonHome).exists()) {
-            try {
-                FileUtils.copyFile(saved, current);
-            } catch (IOException ignored) {
-            }
-        }
-    }
-
-    private void instrumentJarsForEmma(String carbonHome) throws IOException {
-        String workingDir = System.getProperty("user.dir");
-        try {
-            System.setProperty("user.dir", carbonHome);
-            String emmaHome = System.getProperty("emma.home");
-            if (emmaHome == null) {
-                return;
-            } else if (!emmaHome.endsWith(File.separator)) {
-                emmaHome += File.separator;
-            }
-            File emmaOutput = new File(System.getProperty("emma.output"));
-            if (!emmaOutput.exists()) {
-                FileUtils.forceMkdir(emmaOutput);
-            }
-            String emmaJarName = null;
-            for (File file : new File(emmaHome).listFiles()) {
-                if (file.getName().startsWith("org.wso2.carbon.integration.core")) {
-                    ArchiveManipulator archiveManipulator = new ArchiveManipulator();
-                    archiveManipulator.extract(file.getAbsolutePath(), emmaHome);
-                } else if (file.getName().startsWith("emma")) {
-                    emmaJarName = file.getName();
-                }
-            }
-
-            if (emmaJarName == null) {
-                return;
-            }
-
-            String jarList = System.getProperty("jar.list");
-
-
-            FileUtils.copyFile(new File(emmaHome + emmaJarName),
-                               new File(carbonHome + File.separator + "repository" +
-                                        File.separator + "components" + File.separator + "plugins" +
-                                        File.separator + "emma.jar"));
-            FileUtils.copyFile(new File(emmaHome + emmaJarName),
-                               new File(carbonHome + File.separator + "repository" +
-                                        File.separator + "components" + File.separator + "lib" +
-                                        File.separator + "emma.jar"));
-            FileUtils.copyFile(new File(emmaHome + emmaJarName),
-                               new File(carbonHome + File.separator + "lib" +
-                                        File.separator + "emma.jar"));
-            for (File file : new File[]{new File(carbonHome), emmaOutput}) {
-                FileUtils.copyFileToDirectory(new File(carbonHome + File.separator + "lib" +
-                                                       File.separator + "emma.jar"), file);
-                FileUtils.copyFileToDirectory(new File(emmaHome + "gen_emma_coverage.rb"), file);
-                FileUtils.copyFileToDirectory(new File(jarList), file);
-            }
-
-            String temp;
-            Process process = Runtime.getRuntime().exec(new String[]{"ruby",
-                                                                     "gen_emma_coverage.rb",
-                                                                     "instrument",
-                                                                     System.getenv("JAVA_HOME")},
-                                                        null,
-                                                        new File(carbonHome));
-            BufferedReader reader = new BufferedReader(
-                    new InputStreamReader(process.getInputStream()));
-            try {
-                while ((temp = reader.readLine()) != null) {
-                    log.info(temp);
-                }
-            } catch (IOException ignored) {
-            }
-            FileUtils.copyFileToDirectory(new File(carbonHome + File.separator + "coverage.em"),
-                                          emmaOutput);
-        } finally {
-            System.setProperty("user.dir", workingDir);
-        }
-    }
-
     public synchronized void shutdown(int portOffset) throws Exception {
         if (process != null) {
             if (ClientConnectionUtil.isPortOpen(defaultHttpsPort + portOffset)) {
@@ -250,7 +142,7 @@
             process.destroy();
             process = null;
             log.info("Saving Code Coverage Details...");
-            exportEmmaCoverage();
+            EmmaUtils.exportCoverage();
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException ignored) {
