@Override public String inferBinaryName(Location loc, JavaFileObject file) { if (file instanceof JavaFileObjectImpl) { return file.getName(); } return super.inferBinaryName(loc, file); }
public void processors( JavaCompiler.CompilationTask task ) { task.setProcessors( processors ); }
@Before public void setUp() throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); File output = new File("target/externals"); output.mkdirs(); fileManager.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singletonList( output)); Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(Collections.singletonList( new File("src/test/externals/MyVerticle.java"))); compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call(); }
public static List<File> compile(List<File> files, File outDir, boolean includeDebugInfo) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files); StaticFileManager staticFileManager = new StaticFileManager(fileManager, outDir); List<String> options = new ArrayList<>(); options.add(includeDebugInfo ? "-g" : "-g:none"); options.addAll(COMMON_ARGS); CompilationTask task = compiler.getTask(null, staticFileManager, null, options, null, compilationUnits); Boolean result = task.call(); fileManager.close(); if (Boolean.TRUE.equals(result)) { return staticFileManager.outputFiles(); } return Collections.emptyList(); }
InMemFileManager() { super( ToolProvider.getSystemJavaCompiler().getStandardFileManager( null, null, null ) ); }
private static int compileClass(File sourceFile) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); return compiler.run(null, null, null, "-proc:none", sourceFile.getPath()); }
public TestCompiler(JavaCompiler compiler, TemporaryFolder temporaryFolder) throws IOException { this.compiler = compiler; this.fileManager = compiler.getStandardFileManager(null, null, null); this.outputLocation = temporaryFolder.newFolder(); Iterable<? extends File> temp = Collections.singletonList(this.outputLocation); this.fileManager.setLocation(StandardLocation.CLASS_OUTPUT, temp); this.fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, temp); }
public void call(Processor... processors) { this.task.setProcessors(Arrays.asList(processors)); if (!this.task.call()) { throw new IllegalStateException("Compilation failed"); } } }
public TestCompiler(TemporaryFolder temporaryFolder) throws IOException { this(ToolProvider.getSystemJavaCompiler(), temporaryFolder); }
private TestCompilationTask getTask(Iterable<? extends JavaFileObject> javaFileObjects) { return new TestCompilationTask( this.compiler.getTask(null, this.fileManager, null, null, null, javaFileObjects)); }
public CandidateComponentsMetadata readMetadata() { try { return readMetadata(getMetadataResource().openInputStream()); } catch (IOException ex) { // Failed to read metadata -> ignore. return null; } }
private URI uri(Location location, String packageName, String relativeName) { return ClassUtils.toURI(location.getName() + '/' + packageName + '/' + relativeName); }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileObject o = fileObjects.get(uri(location, packageName, relativeName)); if (o != null) { return o; } return super.getFileForInput(location, packageName, relativeName); }
private Iterable<? extends JavaFileObject> getJavaFileObjects(String... types) { File[] files = new File[types.length]; for (int i = 0; i < types.length; i++) { files[i] = getFile(types[i]); } return this.fileManager.getJavaFileObjects(files); }
private ClassLoader getClassLoader() { return fileManager.getClassLoader(null); }
private static int compileClass(File sourceFile) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); return compiler.run(null, null, null, "-proc:none", sourceFile.getPath()); }
@Override public String inferBinaryName(Location loc, JavaFileObject file) { if (file instanceof JavaFileObjectImpl) { return file.getName(); } return super.inferBinaryName(loc, file); }
private URI uri(Location location, String packageName, String relativeName) { return ClassUtils.toURI(location.getName() + '/' + packageName + '/' + relativeName); }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileObject o = fileObjects.get(uri(location, packageName, relativeName)); if (o != null) { return o; } return super.getFileForInput(location, packageName, relativeName); }