hotspot/test/testlibrary/jdk/test/lib/InMemoryJavaCompiler.java
changeset 36508 5f9eee6b383b
parent 31993 f4f6fec4906e
equal deleted inserted replaced
36507:c80f6ecb0bb3 36508:5f9eee6b383b
   126     /**
   126     /**
   127      * Compiles the class with the given name and source code.
   127      * Compiles the class with the given name and source code.
   128      *
   128      *
   129      * @param className The name of the class
   129      * @param className The name of the class
   130      * @param sourceCode The source code for the class with name {@code className}
   130      * @param sourceCode The source code for the class with name {@code className}
       
   131      * @param options additional command line options
   131      * @throws RuntimeException if the compilation did not succeed
   132      * @throws RuntimeException if the compilation did not succeed
   132      * @return The resulting byte code from the compilation
   133      * @return The resulting byte code from the compilation
   133      */
   134      */
   134     public static byte[] compile(String className, CharSequence sourceCode) {
   135     public static byte[] compile(String className, CharSequence sourceCode, String... options) {
   135         MemoryJavaFileObject file = new MemoryJavaFileObject(className, sourceCode);
   136         MemoryJavaFileObject file = new MemoryJavaFileObject(className, sourceCode);
   136         CompilationTask task = getCompilationTask(file);
   137         CompilationTask task = getCompilationTask(file, options);
   137 
   138 
   138         if(!task.call()) {
   139         if(!task.call()) {
   139             throw new RuntimeException("Could not compile " + className + " with source code " + sourceCode);
   140             throw new RuntimeException("Could not compile " + className + " with source code " + sourceCode);
   140         }
   141         }
   141 
   142 
   144 
   145 
   145     private static JavaCompiler getCompiler() {
   146     private static JavaCompiler getCompiler() {
   146         return ToolProvider.getSystemJavaCompiler();
   147         return ToolProvider.getSystemJavaCompiler();
   147     }
   148     }
   148 
   149 
   149     private static CompilationTask getCompilationTask(MemoryJavaFileObject file) {
   150     private static CompilationTask getCompilationTask(MemoryJavaFileObject file, String... options) {
   150         return getCompiler().getTask(null, new FileManagerWrapper(file), null, null, null, Arrays.asList(file));
   151         return getCompiler().getTask(null, new FileManagerWrapper(file), null, Arrays.asList(options), null, Arrays.asList(file));
   151     }
   152     }
   152 }
   153 }