Package javax.tools.JavaCompiler

Examples of javax.tools.JavaCompiler.CompilationTask


    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(null, null, null);
   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
View Full Code Here


    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(null, null, null);
   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
View Full Code Here

    StaticFileManager staticFileManager = new StaticFileManager(fileManager, outDir);

    List<String> options = new ArrayList<String>();
    options.add(includeDebugInfo ? "-g" : "-g:none");
    options.addAll(COMMON_ARGS);
    CompilationTask task = compiler.getTask(null, staticFileManager, null, options, null, compilationUnits);
    Boolean result = task.call();
    fileManager.close();
    if (Boolean.TRUE.equals(result)) {
      return staticFileManager.outputFiles();
    }
    return Collections.emptyList();
View Full Code Here

    fileManager = new ClassFileManager(compiler.getStandardFileManager(null, null, null));

    List<JavaFileObject> jFiles = new ArrayList<JavaFileObject>(1);
    jFiles.add(new CharSequenceJavaFileObject(fullName, code));

    CompilationTask compilerTask = compiler.getTask(null, fileManager, null, null, null, jFiles);
    return Boolean.TRUE.equals(compilerTask.call());
  }
View Full Code Here

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager =
      compiler.getStandardFileManager(null, null, null);
   
    CompilationTask cTask = compiler.getTask(null, fileManager, null, null,
        null,
        fileManager.getJavaFileObjects(
            javaFiles.toArray(new File[javaFiles.size()])));
    assertTrue(cTask.call());
  }
View Full Code Here

      throws CompileException, IOException, ClassNotFoundException {
    try {
      // Create one Java source file in memory, which will be compiled later.
      DrillJavaFileObject compilationUnit = new DrillJavaFileObject(className.dot, sourceCode);

      CompilationTask task = compiler.getTask(null, fileManager, listener, compilerOptions, null, Collections.singleton(compilationUnit));

      // Run the compiler.
      if(!task.call()) {
        throw new CompileException("Compilation failed", null);
      } else if (!compilationUnit.isCompiled()) {
        throw new ClassNotFoundException(className + ": Class file not created by compilation.");
      }
      // all good
View Full Code Here

    //otherwise classes are written to current directory
    String[] options = new String[] { "-d", "target/classes" };
    List<String> compileOptions = Arrays.asList(options);

    CompilationTask task = compiler.getTask(null, fileManager, diagnosticListener, compileOptions, null,
        compilationUnits);
    Boolean result = task.call();
    /*
    List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticListener.getDiagnostics();
    for (Diagnostic<? extends JavaFileObject> diagnosticItem : diagnostics) {
      System.out.format("Error in %s", diagnosticItem);
    }
View Full Code Here

      /*
       * Create a compilation task from compiler by passing in the required
       * input objects prepared above
       */
      CompilationTask compilerTask = compiler.getTask( null, stdFileManager, diagnostics, compilationOptionss, null, compilationUnits );

      // Perform the compilation by calling the call method on compilerTask
      // object.
      boolean status = compilerTask.call();

      Object instance = null;
      if( !status ) {// If compilation error occurs
        /* Iterate through each compilation problem and print it */
        for(Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
View Full Code Here

 
  public static Class<?> compileSource(String completeClassName, String source) throws Throwable {
    boolean result = false;
    JavaFileManager fileManager = CompilerUtils.getStringSourceJavaFileManager(compiler, null, null, Charset.forName("UTF-8"));
    try {
      CompilationTask task = compiler.getTask(null, fileManager, null, null, null,Arrays.asList(new JavaSourceFromString(completeClassName, source)));
      result = task.call();
    } finally {
      fileManager.close();
    }
   
    if(!result)
View Full Code Here

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileManager fileManager = CompilerUtils.getStringSourceJavaFileManager(compiler, null, null, Charset.forName("UTF-8"));
    boolean result = false;
    try {
      CompilationTask task = compiler.getTask(null, fileManager, null, null, null,Arrays.asList(new JavaSourceFromString("com.test.Say", source)));
      result = task.call();
    } finally {
      fileManager.close();
    }

    if (!result)
View Full Code Here

TOP

Related Classes of javax.tools.JavaCompiler.CompilationTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.