public BaseErrorProneJavaCompiler(ScannerSupplier scannerSupplier) { this(JavacTool.create(), scannerSupplier); }
public ErrorProneJavaCompiler(ScannerSupplier scannerSupplier) { super(JavacTool.create(), scannerSupplier); } }
public ErrorProneJavaCompiler() { this(JavacTool.create()); }
private CompilationTestHelper(ScannerSupplier scannerSupplier, String checkName, Class<?> clazz) { this.fileManager = new ErrorProneInMemoryFileManager(clazz); try { fileManager.setLocation(StandardLocation.SOURCE_PATH, Collections.emptyList()); } catch (IOException e) { throw new UncheckedIOException(e); } this.diagnosticHelper = new DiagnosticTestHelper(checkName); this.outputStream = new ByteArrayOutputStream(); this.compiler = new BaseErrorProneJavaCompiler(JavacTool.create(), scannerSupplier); }
private void checkWellFormed(Iterable<JavaFileObject> sources, List<String> args) { createAndInstallTempFolderForOutput(fileManager); JavaCompiler compiler = JavacTool.create(); OutputStream outputStream = new ByteArrayOutputStream(); List<String> remainingArgs = null; try { remainingArgs = Arrays.asList(ErrorProneOptions.processArgs(args).getRemainingArgs()); } catch (InvalidCommandLineOptionException e) { fail("Exception during argument processing: " + e); } CompilationTask task = compiler.getTask( new PrintWriter( new BufferedWriter(new OutputStreamWriter(outputStream, UTF_8)), /*autoFlush=*/ true), fileManager, null, remainingArgs, null, sources); boolean result = task.call(); assertWithMessage( String.format( "Test program failed to compile with non Error Prone error: %s", outputStream)) .that(result) .isTrue(); } }
private JCCompilationUnit doCompile( final JavaFileObject input, Iterable<JavaFileObject> files, Context context) throws IOException { JavacTool tool = JavacTool.create(); DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>(); ErrorProneOptions errorProneOptions;
JavacTool.create() .getTask( CharStreams.nullWriter(),
public ErrorProneJavaCompiler(ScannerSupplier scannerSupplier) { super(JavacTool.create(), scannerSupplier); } }
public ErrorProneJavaCompiler() { this(JavacTool.create()); }
public BaseErrorProneJavaCompiler(ScannerSupplier scannerSupplier) { this(JavacTool.create(), scannerSupplier); }
private static boolean parseJava(List<CompilationUnitTree> trees, String src) { JavaCompiler compiler = JavacTool.create(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); boolean success = true; ArrayList<JavaStringObject> javaStringObjects = new ArrayList<JavaStringObject>(); javaStringObjects.add(new JavaStringObject(src)); StringWriter errors = new StringWriter(); JavaCompiler.CompilationTask task = compiler.getTask(errors, fileManager, null, null, null, javaStringObjects); JavacTaskImpl javacTask = (JavacTaskImpl) task; try { Iterable<? extends CompilationUnitTree> iterable = javacTask.parse(); for (CompilationUnitTree x : iterable) { trees.add(x); } fileManager.close(); } catch (IOException e) { success = false; } if (!errors.toString().isEmpty()) { success = false; } return success; } }
/** * Creates a configured {@link JavacTask}. */ protected JavacTask configure(DiagnosticListener<? super JavaFileObject> errorListener) throws IOException { JavaCompiler javac = JavacTool.create(); StandardJavaFileManager fileManager = new TabExpandingFileManager( javac.getStandardFileManager(errorListener, locale, encoding),encoding,tabWidth); fileManager.setLocation( StandardLocation.CLASS_PATH, classpath ); // annotation processing appears to cause the source files to be reparsed // (even though I couldn't find exactly where it's done), which causes // Tree symbols created by the original JavacTask.parse() call to be thrown away, // which breaks later processing. // So for now, don't perform annotation processing List<String> options = new ArrayList<>(); options.add("-proc:none"); if (sourceVersion!=null) options.addAll(Arrays.asList("-source",sourceVersion,"-target",sourceVersion)); Iterable<? extends JavaFileObject> files = fileManager.getJavaFileObjectsFromFiles(sourceFiles); CompilationTask task = javac.getTask(null, fileManager, errorListener, options, null, files); return (JavacTask)task; } }
private void init() { if( _javac == null ) { _javac = JavacTool.create(); _fileManager = _javac.getStandardFileManager( null, null, Charset.forName( "UTF-8" ) ); //JavaFileObject compilationUnit = new StringJavaFileObject( fqn, src ); try { IModule globalModule = TypeSystem.getGlobalModule(); if( globalModule != null ) { _fileManager.setLocation( StandardLocation.SOURCE_PATH, globalModule.getSourcePath().stream().map( IResource::toJavaFile ).collect( Collectors.toList() ) ); _fileManager.setLocation( StandardLocation.CLASS_PATH, globalModule.getJavaClassPath().stream().map( IResource::toJavaFile ).collect( Collectors.toList() ) ); } _gfm = new GosuJavaFileManager( _fileManager ); } catch( IOException e ) { throw new RuntimeException( e ); } } }
private void init() { if( _fm != null ) { return; } synchronized( this ) { if( _fm != null ) { return; } _javacTool = JavacTool.create(); StandardJavaFileManager fm = _javacTool.getStandardFileManager( null, null, Charset.forName( "UTF-8" ) ); try { fm.setLocation( StandardLocation.SOURCE_PATH, _module.getCollectiveSourcePath().stream().map( IResource::toJavaFile ).filter( f -> !SourcePathUtil.excludeFromTestPath( f.getAbsolutePath() ) ).collect( Collectors.toList() ) ); fm.setLocation( StandardLocation.CLASS_PATH, _module.getCollectiveJavaClassPath().stream().map( IResource::toJavaFile ).filter( f -> !SourcePathUtil.excludeFromTestPath( f.getAbsolutePath() ) ).collect( Collectors.toList() ) ); _fm = fm; } catch( IOException e ) { throw new RuntimeException( e ); } } }
public void run(File dir) throws Exception { JavaCompiler javac = JavacTool.create(); DiagnosticListener<JavaFileObject> errorListener = createErrorListener();
protected File compileClientSources(File sourceDir) { File compileDir = getCompileDir(); compileDir.mkdirs(); //Compile the java files. if (!isDisableCompile()) { if (!isUpToDateWithSources(compileDir)) { List<File> sources = findJavaFiles(sourceDir); if (sources != null && !sources.isEmpty()) { String classpath = this.enunciate.writeClasspath(enunciate.getClasspath()); JavaCompiler compiler = JavacTool.create(); List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn"); JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources)); if (!task.call()) { throw new EnunciateException("Compile failed of Java client-side classes."); } } else { debug("No Java XML client classes to compile."); } } else { info("Skipping compilation of Java client classes as everything appears up-to-date..."); } } return compileDir; }
protected File compileClientSources(File sourceDir) { File compileDir = getCompileDir(); compileDir.mkdirs(); //Compile the java files. if (!isDisableCompile()) { if (!isUpToDateWithSources(compileDir)) { List<File> sources = findJavaFiles(sourceDir); if (sources != null && !sources.isEmpty()) { String classpath = this.enunciate.writeClasspath(enunciate.getClasspath()); JavaCompiler compiler = JavacTool.create(); List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn"); JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources)); if (!task.call()) { throw new EnunciateException("Compile failed of Java JSON client-side classes."); } } else { debug("No Java JSON client classes to compile."); } } else { info("Skipping compilation of Java JSON client classes as everything appears up-to-date..."); } } return compileDir; }
protected File compileClientSources(File sourceDir) { File compileDir = getCompileDir(); compileDir.mkdirs(); //Compile the java files. if (!isDisableCompile()) { if (!isUpToDateWithSources(compileDir)) { List<File> sources = findJavaFiles(sourceDir); if (sources != null && !sources.isEmpty()) { String classpath = this.enunciate.writeClasspath(enunciate.getClasspath()); JavaCompiler compiler = JavacTool.create(); List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn"); JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources)); if (!task.call()) { throw new EnunciateException("Compile failed of Java client-side classes."); } } else { debug("No Java XML client classes to compile."); } } else { info("Skipping compilation of Java client classes as everything appears up-to-date..."); } } return compileDir; }
protected File compileClientSources(File sourceDir) { File compileDir = getCompileDir(); compileDir.mkdirs(); //Compile the java files. if (!isDisableCompile()) { if (!isUpToDateWithSources(compileDir)) { List<File> sources = findJavaFiles(sourceDir); if (sources != null && !sources.isEmpty()) { String classpath = this.enunciate.writeClasspath(enunciate.getClasspath()); JavaCompiler compiler = JavacTool.create(); List<String> options = Arrays.asList("-source", getJavacSource(), "-target", getJavacTarget(), "-encoding", "UTF-8", "-cp", classpath, "-d", compileDir.getAbsolutePath(), "-nowarn"); JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, options, null, compiler.getStandardFileManager(null, null, null).getJavaFileObjectsFromFiles(sources)); if (!task.call()) { throw new EnunciateException("Compile failed of Java JSON client-side classes."); } } else { debug("No Java JSON client classes to compile."); } } else { info("Skipping compilation of Java JSON client classes as everything appears up-to-date..."); } } return compileDir; }
/** * Prepare the compiler thread for use. It is not yet started. * It will be started by the executor service. */ public synchronized void use() { assert(!inUse); inUse = true; compiler = com.sun.tools.javac.api.JavacTool.create(); fileManager = compiler.getStandardFileManager(null, null, null); fileManagerBase = (BaseFileManager)fileManager; smartFileManager = new SmartFileManager(fileManager); context = new Context(); context.put(JavaFileManager.class, smartFileManager); ResolveWithDeps.preRegister(context); JavaCompilerWithDeps.preRegister(context, this); subTasks = new ArrayList<Future<?>>(); }