Package javax.tools

Examples of javax.tools.StandardJavaFileManager

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

    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 void compile(List<File> sourceFiles) throws Exception {
    List<String> options = createJavaOptions();

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

    compileSources( options, compiler, diagnostics, fileManager, compilationUnits );
    compilationDiagnostics.addAll( diagnostics.getDiagnostics() );
    fileManager.close();
  }
View Full Code Here

      options.addAll(cop.getOptions());
    }
    logger.info("Compiler options: "+options.toString());
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (compiler == null) throw new NullPointerException("No java compiler available! Did you start from a JDK? JRE will not work.");
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    final Map<String,File> files = new HashMap<String,File>();
    try {
      final StringWriter sw = new StringWriter();
      sw.append("Compilation failed!\n");
      for (String dir : sourceDirs) {
        files.putAll(findFiles(new File(dir), ".java"));
      }
      files.putAll(findFiles(additionalSourcesDir,".java"));
      if (files.size() > 0) {
        final Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(files.values());
        final CompilationTask task = compiler.getTask(sw, fileManager, null, options, null, compilationUnits1);
        if (!task.call()) {
          logger.error(sw.toString());
          throw new CopperRuntimeException("Compilation failed, see logfile for details");
        }
      }
    }
    finally {
      fileManager.close();
    }
    return files;
  }
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

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (compiler == null) {
      throw new RuntimeException(
          "Cannot get the System Java Compiler. Please use a JDK, not a JRE.");
    }
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);

    ArrayList<File> files = new ArrayList<File>();
    for (File f : new FileIterator(jspClassDir)) {
      if (f.getPath().toLowerCase().endsWith(".java")) {
        files.add(f);
      }
    }
    if (files.isEmpty()) {
      return;
    }
    List<String> optionList = new ArrayList<String>();
    optionList.addAll(Arrays.asList("-classpath", classpath.toString()));
    optionList.addAll(Arrays.asList("-d", jspClassDir.getPath()));
    optionList.addAll(Arrays.asList("-encoding", opts.getCompileEncoding()));

    Iterable<? extends JavaFileObject> compilationUnits =
        fileManager.getJavaFileObjectsFromFiles(files);
    boolean success = compiler.getTask(
        null, fileManager, null, optionList, null, compilationUnits).call();
    fileManager.close();

    if (!success) {
      throw new JspCompilationException("Failed to compile the generated JSP java files.",
          JspCompilationException.Source.JSPC);
    }
View Full Code Here

    protected void generateClass(String[] smap) {
      if (compiler == null) {
        throw new RuntimeException(
            "Cannot get the System Java Compiler. Please use a JDK, not a JRE.");
      }
      StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
      ArrayList<File> files = new ArrayList<File>();
      files.add(new File(ctxt.getServletJavaFileName()));
      List<String> optionList = new ArrayList<String>();
      optionList.addAll(Arrays.asList("-classpath", System.getProperty("java.class.path")));
      optionList.addAll(Arrays.asList("-encoding", ctxt.getOptions().getJavaEncoding()));
      Iterable<? extends JavaFileObject> compilationUnits =
          fileManager.getJavaFileObjectsFromFiles(files);
      compiler.getTask(null, fileManager, null, optionList, null, compilationUnits).call();
    }
View Full Code Here

    }//GEN-LAST:event_jmniUpdateActionPerformed

    private boolean isInJDKMode()
    {
        JavaCompiler jc = null;
        StandardJavaFileManager sjfm = null;
        try
        {

            jc = ToolProvider.getSystemJavaCompiler();
            sjfm = jc.getStandardFileManager(null, null, null);
View Full Code Here

    }//GEN-LAST:event_jmniUpdateActionPerformed

    private boolean isInJDKMode()
    {
        JavaCompiler jc = null;
        StandardJavaFileManager sjfm = null;
        try
        {

            jc = ToolProvider.getSystemJavaCompiler();
            sjfm = jc.getStandardFileManager(null, null, null);
View Full Code Here

    public static boolean compileFile(String elementPath, String srcFile, String destPath, String classpath)
    {

        JavaCompiler jc = null;
        StandardJavaFileManager sjfm = null;
        try
        {

            jc = ToolProvider.getSystemJavaCompiler();
            sjfm = jc.getStandardFileManager(null, null, null);

        }
        catch (Exception ex)
        {
            showMessage("To compile you need Java JDK 1.6 or higher.\nPlease start with JDK.");
            return false;
        }

        try
        {
            File javaFile = new File(srcFile);
            // getJavaFileObjects' param is a vararg
            Iterable fileObjects = sjfm.getJavaFileObjects(javaFile);

            ArrayList<String> options = new ArrayList<String>();
            options.add("-d");
            options.add(destPath + "/bin");
            options.add("-cp");
            options.add(destPath + "/src" + ";.;" + elementPath + ";" + destPath + "/" + classpath);


            StringWriter out = new StringWriter();
            jc.getTask(out, sjfm, null, options, null, fileObjects).call();


            if (!out.toString().trim().equals(""))
            {
                System.err.println(out.toString());
            }
            else
            {
                System.err.println("File \"" + new File(srcFile).getName() + "\" compiled.\n");
            }
            out.close();


            // Add more compilation tasks
            sjfm.close();
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
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.