Java 8 StandardJavaFileManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 StandardJavaFileManager class.

This code example shows how to use the following methods:getJavaFileObjects
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    ArrayList<String> srcFileNames = new ArrayList<String>();
    srcFileNames.add(sourceCodeFile.toString());
    StandardJavaFileManager fm = compiler.getStandardFileManager(null, null,
      null); 
    Iterable<? extends JavaFileObject> cu =
      fm.getJavaFileObjects(sourceCodeFile);
    List<String> options = new ArrayList<String>();
    options.add("-classpath");
    // only add hbase classes to classpath. This is a little bit tricky: assume 
    // the classpath is {hbaseSrc}/target/classes. 
    String currentDir = new File(".").getAbsolutePath();
    String classpath = currentDir + File.separator + "target"+ File.separator
      + "classes" + System.getProperty("path.separator")
      + System.getProperty("java.class.path") + System.getProperty("path.separator")
      + System.getProperty("surefire.test.class.path");
 
    options.add(classpath);
    LOG.debug("Setting classpath to: " + classpath);
 

6
CodeRank
This code example shows how to use the following methods:close, inferBinaryName, list, setLocation
6
CodeRank
This code example shows how to use the following methods:getJavaFileObjectsFromFiles
        if(compiler==null){
            throw new RuntimeException("Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.");
        } 
        CompileOptions compileOptions = spec.getCompileOptions();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, compileOptions.getEncoding() != null ? Charset.forName(compileOptions.getEncoding()) : null);
        Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(spec.getSource());
        return compiler.getTask(null, null, null, options, null, compilationUnits);
    } 
 
    private static JavaCompiler findCompiler() {
        File realJavaHome = Jvm.current().getJavaHome();
        File javaHomeFromToolProvidersPointOfView = new File(System.getProperty("java.home"));
        if (realJavaHome.equals(javaHomeFromToolProvidersPointOfView)) {
            return ToolProvider.getSystemJavaCompiler();
        } 
 
        System.setProperty("java.home", realJavaHome.getAbsolutePath());
        try { 
            return ToolProvider.getSystemJavaCompiler();
        } finally { 
6
CodeRank
This code example shows how to use the following methods:close, getJavaFileObjects
        generator.generate( request );
 
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager( null, null, null );
 
        Iterable<? extends JavaFileObject> compilationUnits1 =
            fileManager.getJavaFileObjects( new File( files, "net/flexmojos/oss/compiler" ).listFiles() );
        assertTrue( compiler.getTask( null, fileManager, null, null, null, compilationUnits1 ).call(),
                    "Problems compiling files" ); 
 
        fileManager.close();
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getJavaFileObjectsFromFiles, setLocation
        String testSrc = System.getProperty("test.src", ".");
        String testClasses = System.getProperty("test.classes", ".");
        JavacTool tool = JavacTool.create();
        MyDiagListener dl = new MyDiagListener();
        StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null);
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
        Iterable<? extends JavaFileObject> files =
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
        JavacTask task = tool.getTask(null, fm, dl, null, null, files);
        task.parse();
        task.analyze();
        task.generate();
 
        // expect 2 notes: 
        // Note: T6410706.java uses or overrides a deprecated API. 
        // Note: Recompile with -Xlint:deprecation for details. 
 
        if (dl.notes != 2)
            throw new AssertionError(dl.notes + " notes given");
    } 
6
CodeRank
This code example shows how to use the following methods:getJavaFileObjects
 
        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
 
        File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
        JavacTask task = tool.getTask(null, fm, null, null, null, fos);
        Iterable<? extends CompilationUnitTree> cus = task.parse();
 
        TestScanner s = new TestScanner();
        s.scan(cus, task);
 
        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    } 
 
    void error(String msg) {
        System.err.println("Error: " + msg);
        errors++;
    } 
6
CodeRank
This code example shows how to use the following methods:setLocation
 
    int run(JavaCompiler comp, StandardJavaFileManager fm) throws IOException {
        System.err.println("test: ck:" + ck + " gk:" + gk + " sk:" + sk);
        File testDir = new File(ck + "-" + gk + "-" + sk);
        testDir.mkdirs();
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(testDir));
 
        JavaSource js = new JavaSource();
        System.err.println(js.getCharContent(false));
        CompilationTask t = comp.getTask(null, fm, null, null, null, Arrays.asList(js));
        if (!t.call())
            throw new Error("compilation failed");
 
        File testClass = new File(testDir, "Test.class");
        String out = javap(testClass);
 
        // Extract class sig from first line of Java source 
        String expect = js.source.replaceAll("(?s)^(.* Test[^{]+?) *\\{.*", "$1");
 
        // Extract class sig from line from javap output 
5
CodeRank
This code example shows how to use the following methods:close, getJavaFileObjectsFromFiles
This code example shows how to use the following methods:close, getJavaFileObjectsFromFiles
This code example shows how to use the following methods:getJavaFileObjects
 
        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
 
        File f = new File(testSrc, T6993305.class.getSimpleName() + ".java");
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f);
        JavacTask task = tool.getTask(null, fm, null, null, null, fos);
        Iterable<? extends CompilationUnitTree> cus = task.parse();
 
        TestScanner s = new TestScanner();
        s.scan(cus, task);
 
        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    } 
 
    void error(String msg) {
        System.err.println("Error: " + msg);
        errors++;
    } 
5
CodeRank
See Code Examples for Java 8 StandardJavaFileManager Methods: