Package javax.tools

Examples of javax.tools.JavaCompiler$CompilationTask


     * @throws Exception
     */
    private void compile(String[] srcFiles) throws Exception {
        String args[] = this.buildCompileJavacArgs(srcFiles);
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if (compiler == null) {
            throw new NullPointerException(
                "ToolProvider.getSystemJavaCompiler() return null,please use JDK replace JRE!");
        }
        int resultCode = compiler.run(null, null, err, args);
        if (resultCode != 0) {
            throw new Exception(err.toString());
        }
    }
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

            String name = psym.getQualifiedName().toString();
            legacyProprietary.remove(name);
            documented.add(name);
        }

        JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
        Location jarLocation = StandardLocation.locationFor(jarName);
        File jarFile = new File(jarName);
        fm.setLocation(jarLocation, List.of(jarFile));
        fm.setLocation(StandardLocation.CLASS_PATH, List.<File>nil());
        fm.setLocation(StandardLocation.SOURCE_PATH, List.<File>nil());
        {
            ArrayList<File> bootClassPath = new ArrayList<File>();
            bootClassPath.add(jarFile);
            for (File path : fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH)) {
                if (!new File(path.getName()).equals(new File("rt.jar")))
                    bootClassPath.add(path);
            }
            System.err.println("Using boot class path = " + bootClassPath);
            fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
        }
        // System.out.println(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH));
        File destDir = new File(destName);
        if (!destDir.exists())
            if (!destDir.mkdirs())
                throw new RuntimeException("Could not create " + destDir);
        fm.setLocation(StandardLocation.CLASS_OUTPUT, List.of(destDir));
        Set<String> hiddenPackages = new HashSet<String>();
        Set<String> crisp = new HashSet<String>();
        List<String> options = List.of("-XDdev");
        // options = options.prepend("-doe");
        // options = options.prepend("-verbose");
        JavacTaskImpl task = (JavacTaskImpl)
            tool.getTask(null, fm, null, options, null, null);
        com.sun.tools.javac.main.JavaCompiler compiler =
            com.sun.tools.javac.main.JavaCompiler.instance(task.getContext());
        ClassWriter writer = ClassWriter.instance(task.getContext());
        Symtab syms = Symtab.instance(task.getContext());
        Names names = Names.instance(task.getContext());
View Full Code Here

  /**
   * Run the annotation processor over one or more classes and verify that the
   * appropriate messages are generated.
   */
  private void testGeneratedMessages(boolean clientOnly, Class<?>... classes) throws IOException {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    if (compiler == null) {
      // This test is being run without a full JDK
      return;
    }

    // Don't spray files in random locations
    File tempFile = File.createTempFile(RfValidatorTest.class.getSimpleName(), ".jar");
    tempFile.deleteOnExit();
    JavaFileManager fileManager =
        new ValidationTool.JarOrDirectoryOutputFileManager(tempFile, compiler
            .getStandardFileManager(null, null, null));

    List<JavaFileObject> files = new ArrayList<JavaFileObject>(classes.length);
    for (Class<?> clazz : classes) {
      JavaFileObject obj = UriJavaFileObject.create(clazz);
      files.add(obj);
    }
    StringWriter errorWriter = new StringWriter();
    RfValidator rfValidator = new RfValidator();
    rfValidator.setForceErrors(true);
    rfValidator.setClientOnly(clientOnly);

    DiagnosticCollector<JavaFileObject> expectedCollector =
        new DiagnosticCollector<JavaFileObject>();
    CompilationTask expectedTask =
        compiler.getTask(errorWriter, fileManager, expectedCollector, Arrays.asList("-proc:only"),
            null, files);
    expectedTask.setProcessors(Arrays.asList(new ExpectCollector()));
    expectedTask.call();

    DiagnosticCollector<JavaFileObject> actualCollector = new DiagnosticCollector<JavaFileObject>();
    CompilationTask actualTask =
        compiler.getTask(errorWriter, fileManager, actualCollector, Arrays.asList("-proc:only"),
            null, files);
    actualTask.setProcessors(Arrays.asList(rfValidator));
    actualTask.call();

    TreeSet<Diagnostic<? extends JavaFileObject>> expected =
View Full Code Here

        out.close();
    }catch(IOException e){
      e.printStackTrace();
    }
   
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    compiler.run(null, null, null, targetFile.getAbsolutePath());
   
  }
View Full Code Here

    } catch (CoreException e) {
      e.printStackTrace();
    }
   
   
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    compiler.run(null, null, null, test+Path.SEPARATOR+"Scanner.java", test+Path.SEPARATOR+"Parser.java");
   
    if(isNew){
      setDefaultPreferences(editorSuffix);
    }
   
View Full Code Here

   
    File proposalProviderWorkspaceFile = new File(folderPath+Path.SEPARATOR+providerPrefix+"_ProposalProvider.java");
   
    generateProposalProvider(proposalProviderWorkspaceFile, packageName, provider, providerPrefix);
   
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    compiler.run(null, null, null, proposalProviderFilePath);
   
   
  }
View Full Code Here

   * @throws Exception in case the compilation fails
   */
  protected 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 );
View Full Code Here

                fileWriter.close();
            }
        }
   
        // Compile source file.
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        compiler.run(null, null, null, sourceFile.getPath());
   
        // Load and instantiate compiled class.
        URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
        Class<?> cls = Class.forName("org.kie.remote.services.rest.jaxb.MyType", true, classLoader);
       
View Full Code Here

            String name = rootDir.getAbsolutePath() + File.separatorChar + srci.className + ".java";
            writeFile(new File(name), srci.srcCode.getBytes());
            args[i++] = name;
        }

        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        compiler.run(null, null, null, args);

        List<ClassInfo> ret = new ArrayList<ClassInfo>();
        addClasses(ret, "", classDir);
        deleteDir(rootDir);
        return ret;
View Full Code Here

TOP

Related Classes of javax.tools.JavaCompiler$CompilationTask

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.