Emma has been disabled for the past few months, and inevitably, the code
that does the instrumentation does not work. Can the person who wrote the
following method please explain how it works?

public synchronized static 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) {
                    System.out.println(temp);
                }
            } catch (IOException ignored) {
            }
            FileUtils.copyFileToDirectory(new File(carbonHome +
File.separator + "coverage.em"),
                    emmaOutput);
        } finally {
            System.setProperty("user.dir", workingDir);
        }
    }

-- 
*Afkham Azeez*
Director of Architecture; WSO2, Inc.; http://wso2.com
Member; Apache Software Foundation; http://www.apache.org/
* <http://www.apache.org/>**
email: **[email protected]* <[email protected]>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to