Package javax.tools.JavaCompiler

Examples of javax.tools.JavaCompiler.CompilationTask


        File srcdir = new File(tmpdir, "src");
        File destdir = new File(tmpdir, "dest");
        write(srcdir, "pkg/X.java", "package pkg; class X {}");
        destdir.mkdirs();

        CompilationTask task = javac.getTask(null, null, null,
                Arrays.asList("-sourcepath", srcdir.toString(), "-d", destdir.toString()),
                Collections.singleton("pkg.X"), null);
        task.setProcessors(Collections.singleton(new AnnoProc()));
        boolean result = task.call();
        System.err.println("javac result when missing resource: " + result);
        expect(result, false);

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
View Full Code Here


        List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
        for(String name : fileNames){
            qualifiedNames.add("../ceylon-sdk/source/" + name);
        }
        Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
        CompilationTask task = compiler.getTask(null, null, null, options, null, fileObjects);
        Boolean ret = task.call();
        Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
       
        // now we need to zip it up
        makeCarFromClassFiles(dir, fileNames, "ceylon.net", Versions.CEYLON_VERSION_NUMBER);
        makeCarFromClassFiles(dir, fileNames, "ceylon.interop.java", Versions.CEYLON_VERSION_NUMBER);
View Full Code Here

            String msg = "Harnesses cannot be reused.";
            throw new IllegalStateException(msg);
        }

        try {
            CompilationTask task;
            SourceInputFileMockup in = new SourceInputFileMockup(fqResourcePath);
            classes.add(in);
            task = compiler.getTask(null, filer, diag, options, null, classes);
            task.setProcessors(processors);

            if (task.call() && !diag.hasErrors()) {
                Location loc = StandardLocation.CLASS_OUTPUT;
                String ext = Kind.SOURCE.extension;
                ClassLoader loader = filer.getClassLoader(loc);
                String path = in.toUri().getPath();
                String data = in.getCharContent(true).toString();
View Full Code Here

        }  
        // 获取要编译的编译单元  
        Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(sourceFileList);  
        //编译选项,在编译java文件时,编译程序会自动的去寻找java文件引用的其他的java源文件或者class。 -classpath选项就是定义class文件的查找目录。 
        Iterable<String> options = Arrays.asList("-encoding",encoding,"-classpath",jars,"-d", distDir);  
        CompilationTask compilationTask = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);  

        // 运行编译任务  
        boolean res= compilationTask.call();
        try {
      fileManager.close();
    } catch (IOException e) {
      log.error("关闭文件管理器失败");
      log.error(e.getMessage());
View Full Code Here

    // compiling it
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjects(javaFile);
    CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits1);
    task.call();

    // here is the compiled file
    File classFile = new File(javaFile.getParentFile(), className+".class");
    Assert.assertTrue(classFile.exists());
View Full Code Here

    for (int i = 6; i < 600000; i*=10) {
      String klass =  createClass(cName, i);
      JavaMemoryFileObject file = new JavaMemoryFileObject(cName, klass);
      MemoryFileManager mfm = new MemoryFileManager(comp.getStandardFileManager(diags, null, null), file);
      CompilationTask task = comp.getTask(null, mfm, diags, null, null, Arrays.asList(file));

      if (task.call()) {
        try {
          MemoryClassLoader mcl = new MemoryClassLoader(file);
          long start = System.nanoTime();
          Class<? extends Object> c = Class.forName(cName, true, mcl);
          long end = System.nanoTime();
View Full Code Here

        // set up output location
        StandardJavaFileManager fm = compiler.getStandardFileManager( null, null, null);
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File[] { new File(binDirRoot) }));
       
        // compile the file
        CompilationTask task = compiler.getTask(null, fm, null, null, null, fm.getJavaFileObjects(source));
        boolean success = task.call().booleanValue();

        // instantiate, config and return
        if (success) {
          // create instance
          ClassLoader cl = new ClassLoader() {
View Full Code Here

    }
    catch ( IOException e ) {
      throw new RuntimeException( e );
    }

    CompilationTask task = compiler.getTask( null, fileManager, diagnostics, options, null, compilationUnits );
    task.setProcessors( Arrays.asList( annotationProcessor ) );

    return task.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

                default:
                    break;
                }  
            }
        };
        CompilationTask task = compiler.getTask(null, fileManager, listener , args, null, fileList);
        Boolean ret = task.call();
        try {
            fileManager.close();
        } catch (IOException e) {
            System.err.print("[ERROR] IOException during compiling.");
            e.printStackTrace();
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.