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);
                    }
                    log.printVerbose("sourcepath", path.reverse().toString());
                } else if (wantSourceFiles) {
                    List<File> path = List.nil();
                    for (File file : fm.getLocation(CLASS_PATH)) {
                        path = path.prepend(file);
                    }
                    log.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);
                    }
                    log.printVerbose("classpath",  path.reverse().toString());
                }
            }
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

        mkdir(sourceDirectory);
        mkdir(classDirectory);

        DiagnosticCollector<JavaFileObject> diagnostics =
            new DiagnosticCollector<JavaFileObject>();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(
                diagnostics,
                Locale.getDefault(),
                CHARSET);
        try {
            List<String> arguments = Lists.create();
            Collections.addAll(arguments, "-source", "1.6");
            Collections.addAll(arguments, "-target", "1.6");
            Collections.addAll(arguments, "-encoding", CHARSET.name());
            Collections.addAll(arguments,
                    "-sourcepath",
                    sourceDirectory.getCanonicalFile().toString());
            Collections.addAll(arguments,
                    "-d",
                    classDirectory.getCanonicalFile().toString());
            Collections.addAll(arguments, "-proc:none");
            Collections.addAll(arguments, "-Xlint:all");
            Collections.addAll(arguments, "-Xlint:-options");

            StringWriter errors = new StringWriter();
            PrintWriter pw = new PrintWriter(errors);

            LOG.debug("コンパイルオプション: {}", arguments);
            CompilationTask task = compiler.getTask(
                    pw,
                    fileManager,
                    diagnostics,
                    arguments,
                    Collections.<String>emptyList(),
                    fileManager.getJavaFileObjectsFromFiles(sources));

            Boolean succeeded = task.call();
            pw.close();
            for (Diagnostic<?> diagnostic : diagnostics.getDiagnostics()) {
                switch (diagnostic.getKind()) {
                case ERROR:
                case MANDATORY_WARNING:
                    getEnvironment().error(diagnostic.getMessage(null));
                    break;
                case WARNING:
                    LOG.warn(diagnostic.getMessage(null));
                    break;
                default:
                    LOG.info(diagnostic.getMessage(null));
                    break;
                }
            }
            if (Boolean.TRUE.equals(succeeded) == false) {
                throw new IOException(MessageFormat.format(
                        "{0}のコンパイルに失敗しました: {1}",
                        getEnvironment().getTargetId(),
                        errors.toString()));
            }
        } finally {
            fileManager.close();
        }
    }
View Full Code Here

        }
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null) {
            throw new IOException("Failed to create a compiler");
        }
        StandardJavaFileManager files = compiler.getStandardFileManager(null, null, encoding);
        try {
            CompilationTask task = compiler.getTask(
                    null,
                    files,
                    null,
                    arguments,
                    Collections.<String>emptyList(),
                    files.getJavaFileObjectsFromFiles(sourceFiles));
            if (task.call() == false) {
                LOG.error("Compilation Failed");
            }
        } finally {
            files.close();
        }
        LOG.info("Completed");
    }
View Full Code Here

    if (compiler == null)  {  // Sterg-SOS why not loaded?
        System.out.println("ToolProvider.getSystemJavaCompiler: no compiler provided. Unable to compile");
    }
    DiagnosticCollector<JavaFileObject> diagnostics =
             new DiagnosticCollector<JavaFileObject>();
    StandardJavaFileManager fileManager =
            compiler.getStandardFileManager(diagnostics, null, null);
   
    StringWriter  compileWriter = new StringWriter();
   
    List <File> sourceFileList = new ArrayList<File>();
    sourceFileList.add(new File(sourceFile));
    Iterable<? extends JavaFileObject> compilationUnits =
            fileManager.getJavaFileObjectsFromFiles(sourceFileList);
  
    String pathOfFile = sourceFile.substring(0, sourceFile.lastIndexOf(File.separatorChar));
    String classpath =GlobalValues.jarFilePath+File.pathSeparatorChar+pathOfFile+File.pathSeparatorChar+".";
    Iterable <String> options = Arrays.asList("-cp", classpath);
   
    CompilationTask task = compiler.getTask(compileWriter, fileManager, null, options, null, compilationUnits);
  
    boolean compileResult = task.call();
    if (compileResult == false) {
        compilationResult = false// compilation errors
        JFrame compResultsFrame = new JFrame("Compilation Results");
        String diagnString = compileWriter.toString();
        JTextArea compResultsArea = new JTextArea(diagnString);
        compResultsArea.setFont(new Font("Arial", Font.BOLD, 16));
        JPanel  compResultsPanel = new JPanel();
        compResultsPanel.add(compResultsArea);
        compResultsFrame.add(compResultsPanel);
        compResultsFrame.setSize(800, 200);
        compResultsFrame.setLocation(100, 200);
        compResultsFrame.setVisible(true);
        int response = JOptionPane.showOptionDialog(null, "File "+sourceFile+" has compilation errors ""Edit File? ",
                JOptionPane.YES_NO_OPTION,  JOptionPane.QUESTION_MESSAGE, null, null, null);
        if (response == JOptionPane.YES_OPTION)   {   // edit it with scalalabEditor
            new scalalabEdit.EditorPaneEdit(sourceFile);
        }
       
     }      
 
    try {
        fileManager.close();
    }
    catch (IOException e) { }
   
   
    return compilationResult;
View Full Code Here

    // compile it by JavaCompiler
    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();
View Full Code Here

    private void compile(File f) throws IOException {
        // set up compiler
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(f));

        // compile generated source
        compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();

        // check we don't have any compilation errors
        List<String> errors = new ArrayList<String>();
        for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
            if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
                errors.add(String.format("Compile error: %s%n", diagnostic.getMessage(Locale.getDefault())));
            }
        }
        fileManager.close();
        assertTrue(errors.toString(), errors.isEmpty());
    }
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();
//    DiagnosticCollector<JavaFileObject> diagnostics =
//      new DiagnosticCollector<JavaFileObject>();

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

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

    Iterable<String> compileOptions =
      Arrays.asList("-g", "-source", "1.6", "-target", "1.6", "-implicit:class", "-Xlint:-options", "-d", tmpdir, "-cp", tmpdir+pathSep+CLASSPATH);

    JavaCompiler.CompilationTask task =
      compiler.getTask(null, fileManager, null, compileOptions, null,
               compilationUnits);
    boolean ok = task.call();

    try {
      fileManager.close();
    }
    catch (IOException ioe) {
      ioe.printStackTrace(System.err);
    }
View Full Code Here

    List<File> files = new ArrayList<File>();
    files.add(new File(workingDirName, fileName));

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

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

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

    Iterable<String> compileOptions =
      Arrays.asList("-g", "-source", "1.6", "-target", "1.6", "-implicit:class", "-Xlint:-options", "-d", workingDirName, "-cp", workingDirName+pathSep+CLASSPATH);

    JavaCompiler.CompilationTask task =
      compiler.getTask(null, fileManager, null, compileOptions, null,
               compilationUnits);
    boolean ok = task.call();

    try {
      fileManager.close();
    }
    catch (IOException ioe) {
      ioe.printStackTrace(System.err);
    }
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.