langtools/test/tools/javac/T6358166.java
changeset 26264 a09fedde76be
parent 24897 655b72d7b96e
child 30730 d3ce7619db2c
--- a/langtools/test/tools/javac/T6358166.java	Fri Aug 22 12:25:01 2014 +0200
+++ b/langtools/test/tools/javac/T6358166.java	Fri Aug 22 16:28:16 2014 -0700
@@ -29,13 +29,15 @@
 
 import java.io.*;
 import java.util.*;
+
 import javax.annotation.processing.*;
 import javax.lang.model.element.*;
 import javax.tools.*;
-import com.sun.tools.javac.file.*;
-import com.sun.tools.javac.file.JavacFileManager; // disambiguate
+
+import com.sun.tools.javac.api.JavacTaskImpl;
+import com.sun.tools.javac.api.JavacTool;
+import com.sun.tools.javac.file.JavacFileManager;
 import com.sun.tools.javac.main.JavaCompiler;
-import com.sun.tools.javac.main.*;
 import com.sun.tools.javac.util.*;
 import com.sun.tools.javac.util.List; // disambiguate
 
@@ -58,12 +60,11 @@
     static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
         Context context = new Context();
 
-        Main compilerMain = initCompilerMain(context, fm, args);
+        JavacTool tool = JavacTool.create();
+        JavacTaskImpl task = (JavacTaskImpl) tool.getTask(null, fm, null, Arrays.asList(args), null, List.of(f), context);
+        task.call();
 
         JavaCompiler c = JavaCompiler.instance(context);
-
-        c.compile(List.of(f));
-
         if (c.errorCount() != 0)
             throw new AssertionError("compilation failed");
 
@@ -72,19 +73,6 @@
             throw new AssertionError("elapsed time is suspect: " + msec);
     }
 
-    static Main initCompilerMain(Context context, JavacFileManager fm, String... args) {
-        fm.setContext(context);
-        context.put(JavaFileManager.class, fm);
-
-        Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
-        compilerMain.setOptions(Options.instance(context));
-        compilerMain.filenames = new LinkedHashSet<File>();
-        compilerMain.deferredFileManagerOptions = new LinkedHashMap<>();
-        compilerMain.processArgs(args);
-        fm.handleOptions(compilerMain.deferredFileManagerOptions);
-        return compilerMain;
-    }
-
     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
         return true;
     }