当前位置: 首页>>代码示例>>Java>>正文


Java StandardJavaFileManager.getJavaFileObjectsFromFiles方法代码示例

本文整理汇总了Java中javax.tools.StandardJavaFileManager.getJavaFileObjectsFromFiles方法的典型用法代码示例。如果您正苦于以下问题:Java StandardJavaFileManager.getJavaFileObjectsFromFiles方法的具体用法?Java StandardJavaFileManager.getJavaFileObjectsFromFiles怎么用?Java StandardJavaFileManager.getJavaFileObjectsFromFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.tools.StandardJavaFileManager的用法示例。


在下文中一共展示了StandardJavaFileManager.getJavaFileObjectsFromFiles方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: compileJavaFiles

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
/**
 * 动态编译java文件
 * @param files
 */
private void compileJavaFiles(List<File> files) {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    //获取java文件管理类
    StandardJavaFileManager manager = compiler.getStandardFileManager(null, null, null);
    //获取java文件对象迭代器
    Iterable<? extends JavaFileObject> it = manager.getJavaFileObjectsFromFiles(files);
    //设置编译参数
    ArrayList<String> ops = new ArrayList<>();
    ops.add("-Xlint:unchecked");
    //获取编译任务
    JavaCompiler.CompilationTask task = compiler.getTask(null, manager, null, ops, null, it);
    //执行编译任务
    task.call();
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:20,代码来源:MyBatisGeneratorTool.java

示例2: compile

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public static boolean compile(String[] args, File episode) throws Exception {

            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
            StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
            JavacOptions options = JavacOptions.parse(compiler, fileManager, args);
            List<String> unrecognizedOptions = options.getUnrecognizedOptions();
            if (!unrecognizedOptions.isEmpty())
                Logger.getLogger(SchemaGenerator.class.getName()).log(Level.WARNING, "Unrecognized options found: {0}", unrecognizedOptions);
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(options.getFiles());
            JavaCompiler.CompilationTask task = compiler.getTask(
                    null,
                    fileManager,
                    diagnostics,
                    options.getRecognizedOptions(),
                    options.getClassNames(),
                    compilationUnits);
            com.sun.tools.internal.jxc.ap.SchemaGenerator r = new com.sun.tools.internal.jxc.ap.SchemaGenerator();
            if (episode != null)
                r.setEpisodeFile(episode);
            task.setProcessors(Collections.singleton(r));
            return task.call();
        }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:SchemaGenerator.java

示例3: createCompileTask

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
private JavaCompiler.CompilationTask createCompileTask(JavaCompileSpec spec) {
    List<String> options = new JavaCompilerArgumentsBuilder(spec).build();
    JavaCompiler compiler = javaHomeBasedJavaCompilerFactory.create();
    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);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:9,代码来源:JdkJavaCompiler.java

示例4: compile

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public void compile(JavaCompiler javaCompiler, Writer out, File sourceDirectory, File outputDirectory, List<File> classpath, DiagnosticListener<? super JavaFileObject> diagnosticListener, String targetVersion ) {
    targetVersion = targetVersion == null ? "1.6" : targetVersion;

    StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(null, null, null);

    if (outputDirectory != null) {
        try {
            fileManager.setLocation(StandardLocation.CLASS_OUTPUT,
                    Arrays.asList(outputDirectory));
            fileManager.setLocation(StandardLocation.CLASS_PATH, classpath);
        } catch (IOException e) {
            throw new RuntimeException("could not set output directory", e);
        }
    }

    Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(findAllSourceFiles(sourceDirectory));

    ArrayList<String> options = new ArrayList<String>();
    options.add("-source");
    options.add(targetVersion);
    options.add("-target");
    options.add(targetVersion);
    options.add("-encoding");
    options.add("UTF8");
    options.add("-Xlint:-options");
    options.add("-Xlint:unchecked");
    if (compilationUnits.iterator().hasNext()) {
        Boolean success = javaCompiler.getTask(out, fileManager, diagnosticListener, options, null, compilationUnits).call();
        assertThat("Compilation was not successful, check stdout for errors", success, is(true));
    }

}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:33,代码来源:Compiler.java

示例5: main

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public static void main(String[] args) {
  System.out.println("Sourcepath is " + args[0]);
  // We're interested in scanning all .java files under the sourcepath passed as an argument here.
  List<File> sourceFiles = Arrays.asList(new File(new File(args[0]).getAbsolutePath()).listFiles(f -> f.getName().endsWith(".java")));
  sourceFiles.stream().forEach(System.out::println); // Printing the detected class file paths.
  JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
  Iterable<? extends JavaFileObject> javaFileObjects = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
  JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, null, null, javaFileObjects);
  task.setProcessors(Arrays.asList(new PrivateOnlyAnnotationProcessor(), new JavaBeanAnnotationProcessor()));
  System.out.println(task.call());
}
 
开发者ID:asgs,项目名称:annotation-processor-demo,代码行数:13,代码来源:Main.java

示例6: compile

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public static boolean compile(String[] args, File episode) throws Exception {

            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
            DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
            StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
            JavacOptions options = JavacOptions.parse(compiler, fileManager, args);
            List<String> unrecognizedOptions = options.getUnrecognizedOptions();
            if (!unrecognizedOptions.isEmpty()) {
                LOGGER.log(Level.WARNING, "Unrecognized options found: {0}", unrecognizedOptions);
            }
            Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(options.getFiles());
            JavaCompiler.CompilationTask task = compiler.getTask(
                    null,
                    fileManager,
                    diagnostics,
                    options.getRecognizedOptions(),
                    options.getClassNames(),
                    compilationUnits);
            com.sun.tools.internal.jxc.ap.SchemaGenerator r = new com.sun.tools.internal.jxc.ap.SchemaGenerator();
            if (episode != null)
                r.setEpisodeFile(episode);
            task.setProcessors(Collections.singleton(r));
            boolean res = task.call();
            //Print compiler generated messages
            for( Diagnostic<? extends JavaFileObject> d : diagnostics.getDiagnostics() ) {
                 System.err.println(d.toString());
            }
            return res;
        }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:SchemaGenerator.java

示例7: compileToPath

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
public void compileToPath(File[] files, String path, String target, String classPath) throws ClassNotFoundException
{
        // create a diagnostic collector to collect eventually errors
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
        // create a standard manager for the Java file objects
        StandardJavaFileManager fileMan = compiler.getStandardFileManager(diagnostics, null, null);

        // create the iterable from the list
        Iterable<? extends JavaFileObject> compilationUnits = fileMan.getJavaFileObjectsFromFiles(Arrays.asList(files));

        // create a store for the compiled code
        Map<String, JavaFileObject> store = new HashMap<String, JavaFileObject>();

        // set compileroptions for target JVM
        //System.err.println(path+"bin/");
        String[] options = new String[]{"-d",path};
        Iterable<String> myOptions = null;
        if(target!=null) 
         {
            options = new String[]{"-d",path,"-source", target,"-target", target, "-cp", classPath,"-Xlint:unchecked"};
        }
        myOptions = Arrays.asList(options);
        //for(int i=0;i<options.length;i++) System.err.print(options[i]+" // ");
        // compile the file
        CompilationTask task = compiler.getTask(null, fileMan, diagnostics, myOptions , null, compilationUnits);

        boolean success = task.call();
        String error = new String();
        for (Diagnostic diagnostic : diagnostics.getDiagnostics())
        {
            error+=diagnostic.getMessage(null)+"\n";
        }
        //System.out.println("Success: " + success);
        if(success==true)
        {
            // debug
            //System.out.println("Loading: "+this.getShortName());
            // create the class loader
            classLoader = new ByteClassLoader(store,rootDirectory);
            //interpreter.setClassLoader(classLoader);
            // load the specified class
            //Class<?> cl = classLoader.loadClass(this.getShortName());
            
        }
        else
        {
            error=error.replaceAll("string:///", "");
            //error=error.replaceAll("\\.java", "");
            throw new ClassNotFoundException(error.trim());
        }
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:52,代码来源:Runtime6.java

示例8: run

import javax.tools.StandardJavaFileManager; //导入方法依赖的package包/类
@Override
boolean run(PrintWriter out, Set<String> keys, boolean raw, List<String> opts, List<File> files) {
    if (out != null && keys != null)
        throw new IllegalArgumentException();

    if (verbose)
        System.err.println("run_jsr199: " + opts + " " + files);

    DiagnosticCollector<JavaFileObject> dc = null;
    if (keys != null)
        dc = new DiagnosticCollector<JavaFileObject>();

    if (raw) {
        List<String> newOpts = new ArrayList<String>();
        newOpts.add("-XDrawDiagnostics");
        newOpts.addAll(opts);
        opts = newOpts;
    }

    JavaCompiler c = ToolProvider.getSystemJavaCompiler();

    StandardJavaFileManager fm = c.getStandardFileManager(dc, null, null);
    try {
        if (fmOpts != null)
            fm = new FileManager(fm, fmOpts);

        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

        CompilationTask t = c.getTask(out, fm, dc, opts, null, fos);
        Boolean ok = t.call();

        if (keys != null) {
            for (Diagnostic<? extends JavaFileObject> d: dc.getDiagnostics()) {
                scanForKeys(unwrap(d), keys);
            }
        }

        return ok;
    } finally {
        close(fm);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:Example.java


注:本文中的javax.tools.StandardJavaFileManager.getJavaFileObjectsFromFiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。