package org.springframework.ldap.odm.test.utils;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;

public class CompilerInterface {
    // Compile the given file - when we can drop Java 5 we'll use the Java 6 compiler API
    public static void compile(String directory, String file) throws Exception {

        ProcessBuilder pb = new ProcessBuilder(
                new String[] { "javac", 
                               "-cp", "."+File.pathSeparatorChar+"target"+File.separatorChar+"classes"+
                                  File.pathSeparatorChar+System.getProperty("java.class.path"),
                                  directory+File.separatorChar+file });

        pb.redirectErrorStream(true);
        Process proc = pb.start();
        InputStream is = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);

        char[] buf = new char[1024];
        int count;
        StringBuilder builder = new StringBuilder();
        while ((count = isr.read(buf)) > 0) {
            builder.append(buf, 0, count);
        }
        
        boolean ok = proc.waitFor() == 0;

        if (!ok) {
            throw new RuntimeException(builder.toString());
        }
    }
}

@@ -83,54 +83,167 @@
 ava.
-io.InputStream;%0D%0Aimport java.io.InputStreamRea
+util.Arrays;%0D%0A%0D%0Aimport javax.tools.JavaCompiler;%0D%0Aimport javax.tools.JavaFileObject;%0D%0Aimport javax.tools.StandardJavaFileManager;%0D%0Aimport javax.tools.ToolProvi
 der;
@@ -453,26 +453,24 @@
 tion %7B%0D%0A
-%0D%0A
         
 ProcessB
@@ -465,492 +465,224 @@
     
-ProcessBuilder pb = new ProcessBuilder(%0D%0A                new String%5B%5D %7B %22javac%22, %0D%0A                               %22-cp%22, %22.%22+File.pathSeparatorChar+%22target%22+File.separatorChar+%22classes%22+%0D%0A                                  File.pathSeparatorChar+System.getProperty(%22java.class.path%22),%0D%0A                                  directory+File.separatorChar+file %7D);%0D%0A%0D%0A        pb.redirectErrorStream(true);%0D%0A        Process proc = pb.start();%0D%0A        InputStream is = proc.getInputStream(
+File toCompile = new File(directory, file);%0D%0A        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();%0D%0A        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null
 );%0D%0A
+%0D%0A
     
@@ -690,420 +690,259 @@
    I
-nputStreamReader isr = new InputStreamReader(is);%0D%0A%0D%0A        char%5B%5D buf = new char%5B1024%5D;%0D%0A        int count;%0D%0A        StringBuilder builder = new StringBuilder();%0D%0A        while ((count = isr.read(buf)) %3E 0) %7B%0D%0A            builder.append(buf, 0, count);%0D%0A        %7D%0D%0A        %0D%0A        boolean ok = proc.waitFor() == 0;%0D%0A%0D%0A        if (!ok) %7B%0D%0A            throw new RuntimeException(builder.toString());%0D%0A        %7D
+terable%3C? extends JavaFileObject%3E javaFileObjects =%0D%0A            fileManager.getJavaFileObjectsFromFiles(Arrays.asList(toCompile));%0D%0A        compiler.getTask(null, fileManager, null, null, null, javaFileObjects).call();%0D%0A%0D%0A        fileManager.close();
 %0D%0A  

Use JavaCompiler in tests isntead of manually finding "javac"