Package javax.tools

Examples of javax.tools.StandardJavaFileManager

Whereas these are not (reason in parentheses): @author Peter von der Ahé @since 1.6

        boolean haveSourcePath = fileManager.hasLocation(SOURCE_PATH);

        if (verbose && verbosePath) {
            if (fileManager instanceof StandardJavaFileManager) {
                StandardJavaFileManager fm = (StandardJavaFileManager)fileManager;
                if (haveSourcePath && wantSourceFiles) {
                    List<File> path = List.nil();
                    for (File file : fm.getLocation(SOURCE_PATH)) {
                        path = path.prepend(file);
                    }
                    printVerbose("sourcepath", path.reverse().toString());
                } else if (wantSourceFiles) {
                    List<File> path = List.nil();
                    for (File file : fm.getLocation(CLASS_PATH)) {
                        path = path.prepend(file);
                    }
                    printVerbose("sourcepath", path.reverse().toString());
                }
                if (wantClassFiles) {
                    List<File> path = List.nil();
                    for (File file : fm.getLocation(PLATFORM_CLASS_PATH)) {
                        path = path.prepend(file);
                    }
                    for (File file : fm.getLocation(CLASS_PATH)) {
                        path = path.prepend(file);
                    }
                    printVerbose("classpath",  path.reverse().toString());
                }
            }
View Full Code Here


    private static  boolean compiler(String encoding,String jars,String filePath, String distDir, DiagnosticCollector<JavaFileObject> diagnostics){   
        // 获取编译器实例  
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();  

        // 获取标准文件管理器实例  
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);  
         
        //编译文件
        if (StringUtil.IsNullOrEmpty(filePath)) {  
          log.info("待编译的文件或目录不存在");
            return false;  
        }
        //输出目录
        if (!FileUtil.createDictory(distDir)) {  
          log.info("输出目录创建失败");
            return false;  
        }

        // 得到filePath目录下的所有java源文件  
        File sourceFile = new File(filePath);  
        List<File> sourceFileList = new ArrayList<File>();  
        sourceFileList = getSourceFiles(sourceFile);  

        // 没有java文件,直接返回  
        if (sourceFileList.size() == 0) {  
          log.info(filePath + "目录下查找不到任何java文件");
            return false;  
        }  
           
        // 获取要编译的编译单元  
        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());
    }
        return res;
View Full Code Here

  @Override
  protected JavaFileManager getJavaFileManager(
    JavaFileManager javaFileManager) {

    if (javaFileManager instanceof StandardJavaFileManager) {
      StandardJavaFileManager standardJavaFileManager =
        (StandardJavaFileManager)javaFileManager;

      try {
        standardJavaFileManager.setLocation(
          StandardLocation.CLASS_PATH, _classPath);

        BundleJavaManager bundleJavaManager = new BundleJavaManager(
          _bundle, standardJavaFileManager, options, true);
View Full Code Here

    private static List<File> compile(File[] javaFiles) {
        LOG.info("Compiling: " + Arrays.asList(javaFiles));

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

        List<File> classFiles = Lists.newArrayList();
View Full Code Here

    //Get an instance of java compiler
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

    //Get a new instance of the standard file manager implementation
    StandardJavaFileManager fileManager = compiler.
        getStandardFileManager(null, null, null);

    // Get the list of java file objects, in this case we have only
    // one file, TestClass.java

    System.out.println(">>> DETECTING SOURCES");
    fileManager.setLocation(StandardLocation.SOURCE_PATH, singleton(searchDir.getAbsoluteFile()));
    Iterable<JavaFileObject> sources = fileManager.list(
        StandardLocation.SOURCE_PATH //locationFor("src/test/java")
        , ""
        , singleton(JavaFileObject.Kind.SOURCE)
        , true);
View Full Code Here

      LOG.error("It seems as though you are running sqoop with a JRE.");
      LOG.error("Sqoop requires a JDK that can compile Java code.");
      LOG.error("Please install a JDK and set $JAVA_HOME to use it.");
      throw new IOException("Could not start Java compiler.");
    }
    StandardJavaFileManager fileManager =
        compiler.getStandardFileManager(null, null, null);

    ArrayList<String> srcFileNames = new ArrayList<String>();
    for (String srcfile : sources) {
      srcFileNames.add(jarOutDir + srcfile);
      LOG.debug("Adding source file: " + jarOutDir + srcfile);
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("Invoking javac with args:");
      for (String arg : args) {
        LOG.debug("  " + arg);
      }
    }

    Iterable<? extends JavaFileObject> srcFileObjs =
        fileManager.getJavaFileObjectsFromStrings(srcFileNames);
    JavaCompiler.CompilationTask task = compiler.getTask(
        null, // Write to stderr
        fileManager,
        null, // No special diagnostic handling
        args,
View Full Code Here

    for (OutputFile o : outputs) {
      javaFiles.add(o.writeToDestination(null, dstDir));
    }

    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

    for (OutputFile o : outputs) {
      javaFiles.add(o.writeToDestination(null, dstDir));
    }

    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

  private static final List<String> COMMON_ARGS = Arrays.asList("-source 1.6 -target 1.6".split(" "));

  public static List<File> compile(List<File> files, File outDir, boolean includeDebugInfo) throws IOException {

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files);

    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

                return new CompilerResult( false, Collections.singletonList( message ) );
            }
            final String sourceEncoding = config.getSourceEncoding();
            final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
            final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<JavaFileObject>();
            final StandardJavaFileManager standardFileManager =
                compiler.getStandardFileManager( collector, null, sourceCharset );

            final Iterable<? extends JavaFileObject> fileObjects =
                standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) );
            final JavaCompiler.CompilationTask task =

                                         /*(Writer out,
                                         JavaFileManager fileManager,
                                         DiagnosticListener<? super JavaFileObject> diagnosticListener,
View Full Code Here

TOP

Related Classes of javax.tools.StandardJavaFileManager

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.