Package javax.tools

Examples of javax.tools.JavaCompiler


        }
    }//GEN-LAST:event_jmniUpdateActionPerformed

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

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

        } catch (Exception ex)
        {
            return false;
        }
View Full Code Here


    // Set up a virtual file system for javac that reads the inputs from memory.
    // Temporary files, are slow, error-prone, and can be a vector for injecting malicious code
    // into running systems when an application uses a temporary directory that is accessible by
    // less privileged users than its process owner.
    JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
    DynamicCompilerJavaFileManager fileManager = new DynamicCompilerJavaFileManager(
        javaCompiler.getStandardFileManager(
            diagnosticListener, Locale.getDefault(), Charsets.UTF_8));

    String className = PACKAGE_FOR_COMPILED_SOY + "." + bundleName;
    ReadableInMemoryJavaFileObject inputFile = new ReadableInMemoryJavaFileObject(
        "/src/" + className.replace('.', '/') + ".java", javaSourceCode);

    fileManager.addInput(inputFile);


    // Invoke the compiler.
    boolean wasSuccessfullyCompiled = javaCompiler.getTask(
        null, fileManager, diagnosticListener,
        ImmutableList.<String>of()// Compiler options
        ImmutableList.<String>of()// Classes,
        ImmutableList.of(inputFile))
        .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);

        } catch (Exception ex)
        {
            return false;
        }
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());
View Full Code Here

    try {
      debugLog("compiledClasses", "dest: " + dest, "src: " + src,
          "classpath: " + classpath, "debug:" + debug);
      del(dest);
      dest.mkdirs();
      JavaCompiler compiler = network.systemJavaCompiler();
      if (compiler == null) {
        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) {
View Full Code Here

    args.add(jarOutDir);

    args.add("-classpath");
    args.add(curClasspath + File.pathSeparator + coreJar + sqoopJar);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (null == compiler) {
      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,
        null, // Compile all classes in the source compilation units
View Full Code Here

        }

        ensureExists(outputDirectory);
        ensureExists(generatedSourcesDirectory);

        JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
       
        if (javac == null) {
            throw new MojoExecutionException("The Java compiler could not be found.  " +
                                             "Make sure to point your Maven build to a full Java development environment.");
        }

        getLog().debug("Exec: javac " + args.toString());
        if (javac.run(null, null, null, args.get()) != 0) {
            throw new MojoExecutionException("Compilation failed");
        }
    }
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()) {
              Output.conerr.println(diag.toString());
            }
View Full Code Here

    args.add(jarOutDir);

    args.add("-classpath");
    args.add(curClasspath + File.pathSeparator + coreJar + sqoopJar);

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (null == compiler) {
      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,
        null, // Compile all classes in the source compilation units
View Full Code Here

        }
        if (options.javacOptions != null) {
            args.addAll(options.getJavacOptions(args, listener));
        }

        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null) {
            out.println(WscompileMessages.WSCOMPILE_CANT_GET_COMPILER(property("java.home"), property("java.version"), property("java.vendor")));
            return false;
        }
        DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
        StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
        JavaCompiler.CompilationTask task = compiler.getTask(
                null,
                fileManager,
                diagnostics,
                args,
                Collections.singleton(endpoint.replaceAll("\\$", ".")),
View Full Code Here

TOP

Related Classes of javax.tools.JavaCompiler

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.