Package javax.tools

Examples of javax.tools.StandardJavaFileManager

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

        throw new IwantException(
            "Cannot find system java compiler. Are you running a JRE instead of JDK?");
      }
      DiagnosticListener<? super JavaFileObject> diagnosticListener = null;
      Locale locale = null;
      StandardJavaFileManager fileManager = compiler
          .getStandardFileManager(diagnosticListener, locale,
              encoding);
      Iterable<? extends JavaFileObject> compilationUnits = fileManager
          .getJavaFileObjectsFromFiles(src);
      Writer compilerTaskOut = null;
      Iterable<String> classes = null;

      List<String> options = new ArrayList<String>();
      options.add("-Xlint");
      options.add("-Xlint:-serial");
      if (debug) {
        options.add("-g");
      }
      options.add("-d");
      options.add(dest.getCanonicalPath());
      options.add("-classpath");
      options.add(classpath);

      CompilationTask compilerTask = compiler.getTask(compilerTaskOut,
          fileManager, diagnosticListener, options, classes,
          compilationUnits);
      Boolean compilerTaskResult = compilerTask.call();
      fileManager.close();
      if (!compilerTaskResult) {
        throw new IwantException("Compilation failed.");
      }
      return dest;
    } catch (RuntimeException e) {
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

  private static boolean compileJavaProject() {
    boolean success= false;
    File javaDir= new File(CompilerUtils.DEFAULT_EXPORT_DIRECTORY);
    File[] files= javaDir.listFiles();
    JavaCompiler compiler= ToolProvider.getSystemJavaCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits= fileManager.getJavaFileObjectsFromFiles(Arrays.asList(files));
    DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
        CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, compilationUnits);
        success = task.call();
        if (!success) {
            for (Diagnostic<? extends JavaFileObject> diag : diagnostics.getDiagnostics()) {
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

  private static void createTestJar(OutputStream outStream, String dummyClassName)
      throws URISyntaxException, IOException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    JavaFileObject srcFileObject = new SimpleJavaFileObjectImpl(
        URI.create("string:///" + dummyClassName + Kind.SOURCE.extension), Kind.SOURCE);
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    compiler.getTask(null, fileManager, null, null, null, Collections.singletonList(srcFileObject))
        .call();

    JavaFileObject javaFileObject = fileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
        dummyClassName, Kind.CLASS, null);

    File classFile = new File(dummyClassName + Kind.CLASS.extension);

    JarOutputStream jarOutputStream = new JarOutputStream(outStream);
View Full Code Here

      fw.close();
    }

    // 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");
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

    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

 
  void parseAllFiles() throws Exception {
   
    compiler = ToolProvider.getSystemJavaCompiler();
   
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(
      null, Locale.getDefault(), Charset.forName("utf8"));

    List<JavaFileObject> units = new ArrayList<JavaFileObject>();
    for(String f: filesToParse) {
      units.add(new MyFileObject(new URI(f), javax.tools.JavaFileObject.Kind.SOURCE));
    }
   
    JavacTaskImpl task = (JavacTaskImpl)compiler.getTask(null, fileManager,
      new DiagnosticListener<JavaFileObject>() {
        @Override
        public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
//          System.err.println(diagnostic);
          if(diagnostic.getKind() == Kind.ERROR
            ) {
            throw new RuntimeException(diagnostic.toString());
          }
        }
      },
      null, null, units);

    for(Tree t : task.parse()) {
      currentImports = new ArrayList<String>();
      parse(t);       
    }

    fileManager.close();
    filesToParse.clear();
  }
View Full Code Here

        return internalCompile(list.toArray(new String[list.size()]), idx);
    }

    protected boolean useJava6Compiler(String[] files) {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
        Iterable<? extends JavaFileObject> fileList = fileManager.getJavaFileObjectsFromStrings(Arrays
            .asList(files));

        return internalJava6Compile(compiler, wrapJavaFileManager(fileManager), setupDiagnosticListener(),
                                    fileList);
    }
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.