Examples of JavaCompiler


Examples of javax.tools.JavaCompiler

    }
  }

  private String bind(String className, String exprString, JavaFileObject fileObject)
      throws IOException {
    JavaCompiler javaCompiler = JavacTool.create();
    JavacTaskImpl task = (JavacTaskImpl) javaCompiler.getTask(new PrintWriter(System.err, true),
        fileManager, null, Collections.<String>emptyList(), null, Arrays.asList(fileObject));
    Iterable<? extends CompilationUnitTree> compilationUnits = task.parse();
    task.analyze();
    for (CompilationUnitTree compilationUnit : compilationUnits) {
      FindClass finder = new FindClass();
View Full Code Here

Examples of javax.tools.JavaCompiler

    context.put(JavaFileManager.class, fileManager);
    return compiler.compile(args, context, asJavacList(sources), null);
  }

  private void checkWellFormed(Iterable<JavaFileObject> sources, String[] args) {
    JavaCompiler compiler = JavacTool.create();
    OutputStream outputStream = new ByteArrayOutputStream();
    CompilationTask task = compiler.getTask(
        new PrintWriter(outputStream, /*autoFlush=*/true),
        fileManager,
        null,
        buildArguments(Arrays.asList(ErrorProneOptions.processArgs(args).getRemainingArgs())),
        null,
View Full Code Here

Examples of javax.tools.JavaCompiler

  @Rule public TemporaryFolder tempDir = new TemporaryFolder();

  @Test
  public void testIsSupportedOption() {
    JavaCompiler mockCompiler = mock(JavaCompiler.class);
    ErrorProneJavaCompiler compiler = new ErrorProneJavaCompiler(mockCompiler);

    // javac options should be passed through
    compiler.isSupportedOption("-source");
    verify(mockCompiler).isSupportedOption("-source");
View Full Code Here

Examples of javax.tools.JavaCompiler

  interface JavaFileObjectDiagnosticListener extends DiagnosticListener<JavaFileObject> {}

  @Test
  public void testGetStandardJavaFileManager() {
    JavaCompiler mockCompiler = mock(JavaCompiler.class);
    ErrorProneJavaCompiler compiler = new ErrorProneJavaCompiler(mockCompiler);

    JavaFileObjectDiagnosticListener listener = mock(JavaFileObjectDiagnosticListener.class);
    Locale locale = Locale.CANADA;
View Full Code Here

Examples of javax.tools.JavaCompiler

    verify(mockCompiler).getStandardFileManager(listener, locale, null);
  }

  @Test
  public void testRun() {
    JavaCompiler mockCompiler = mock(JavaCompiler.class);
    ErrorProneJavaCompiler compiler = new ErrorProneJavaCompiler(mockCompiler);

    InputStream in = mock(InputStream.class);
    OutputStream out = mock(OutputStream.class);
    OutputStream err = mock(OutputStream.class);
View Full Code Here

Examples of javax.tools.JavaCompiler

    

public  boolean compileFile( String sourceFile) {
      boolean compilationResult = true// no errors
   
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    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");
View Full Code Here

Examples of javax.tools.JavaCompiler

    BufferedWriter bw = new BufferedWriter(new FileWriter(sourceCodeFile));
    bw.write(javaCode);
    bw.close();

    // 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();
    String classpath = currentDir + File.separator + "target"+ File.separator
      + "classes" + System.getProperty("path.separator")
      + System.getProperty("java.class.path") + System.getProperty("path.separator")
      + System.getProperty("surefire.test.class.path");
    options.add(classpath);
    LOG.debug("Setting classpath to: " + classpath);

    JavaCompiler.CompilationTask task = compiler.getTask(null, fm, null,
      options, null, cu);
    assertTrue("Compile file " + sourceCodeFile + " failed.", task.call());

    // build a jar file by the classes files
    String jarFileName = className + ".jar";
View Full Code Here

Examples of javax.tools.JavaCompiler

        assertEquals("abc123XYZ", messages.get(0));
    }

    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) {
View Full Code Here

Examples of javax.tools.JavaCompiler

    try {
      File inFile = new File(sourcePath + File.separator + className + ".java");
      File outFile = new File(sourcePath + File.separator + className + ".class");

      ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

      if (compiler == null) {
        throw new RuntimeException("Could not locate a compiler. You may be running in a JRE and not a JDK. " +
                "For the purpose of development mode Errai requires the use of a JDK so it may produce server " +
                "marshalling code on-the-fly.");
      }

      /**
       * Attempt to run the compiler without any classpath specified.
       */
      if (compiler.run(null, null, errorOutputStream, inFile.getAbsolutePath()) != 0) {
        errorOutputStream.reset();

        /**
         * That didn't work. Let's try and figure out the classpath.
         */
        StringBuilder sb = new StringBuilder();

        List<URL> configUrls = MetaDataScanner.getConfigUrls();
        List<File> classpathElements = new ArrayList<File>(configUrls.size());

        for (URL url : configUrls) {
          File file = getFileIfExists(url.getFile());
          if (file != null) {
            classpathElements.add(file);
          }
        }

        for (File file : classpathElements)
          sb.append(file.getAbsolutePath()).append(File.pathSeparator);

        sb.append(System.getProperty("java.class.path"));
        sb.append(findAllJarsByManifest());

        if (compiler.run(null, null, errorOutputStream, "-cp", sb.toString(), inFile.getAbsolutePath()) != 0) {
          System.out.println("*** FAILED TO COMPILE MARSHALLER CLASS ***");
          System.out.println("*** Classpath Used: " + sb.toString());


          for (byte b : errorOutputStream.toByteArray()) {
View Full Code Here

Examples of javax.tools.JavaCompiler

    try {
      File inFile = new File(sourcePath + File.separator + className + ".java");
      //  File outFile = new File(sourcePath + File.separator + className + ".class");

      ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      CompilerAdapter adapter;

      if (compiler == null) {
        adapter = new JDTCompiler();
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.