public Compiler build() { if (sourcePath == null) { throw new IllegalStateException("No null source path"); } if (classOutput == null) { throw new IllegalStateException("No null class output"); } if (sourceOutput == null) { throw new IllegalStateException("No null source output"); } Compiler compiler = new Compiler( javaCompiler.get(), sourcePath, classPaths, sourceOutput, classOutput, config ); if (processor != null) { compiler.addAnnotationProcessor(processor.get()); } return compiler; } }
public void compile() throws IOException, CompilationException { VirtualFileManager fileManager = new VirtualFileManager( javaCompiler.getStandardFileManager(null, null, null), sourcePath, classPaths, sourceOutput, classOutput ); compile(fileManager, getFromSourcePath(fileManager.sourcePath)); }
builder(). sourcePath(sourcePath). sourceOutput(classOutput). classOutput(classOutput). addClassPath(classPath).build(); compiler.addAnnotationProcessor(new MainProcessor()); compiler.compile();
Compiler compiler = Compiler.builder().sourcePath(ramFS).output(output).build(); compiler.compile(); assertEquals(2, output.size(ReadFileSystem.FILE)); Timestamped<Resource> aClass = output.getResource(new String[]{"foo", "A"}); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); bClass = output.getResource(new String[]{"foo", "B"});
void compile() throws IOException, CompilationException { compiler = builder().build(); compiler.compile(); } }
final Compiler.Builder builder() { Compiler.Builder builder = Compiler.builder(); builder.javaCompiler(javaCompiler); builder.processor(processorFactory); builder.addClassPath(classPath); builder.sourcePath(sourcePath); builder.sourceOutput(sourceOutput); builder.classOutput(classOutput); builder.config(config); return builder; }
builder(). sourcePath(sourcePath). sourceOutput(classOutput). classOutput(classOutput). addClassPath(classPath).build(); compiler.addAnnotationProcessor(new MainProcessor()); compiler.compile();
Compiler compiler = Compiler.builder().sourcePath(ramFS).output(output).build(); compiler.compile(); assertEquals(2, output.size(ReadFileSystem.FILE)); Timestamped<Resource> aClass = output.getResource(new String[]{"foo", "A"}); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); bClass = output.getResource(new String[]{"foo", "B"});
void compile() throws IOException, CompilationException { compiler = builder().build(); compiler.compile(); } }
final Compiler.Builder builder() { Compiler.Builder builder = Compiler.builder(); builder.javaCompiler(javaCompiler); builder.processor(processorFactory); builder.addClassPath(classPath); builder.sourcePath(sourcePath); builder.sourceOutput(sourceOutput); builder.classOutput(classOutput); builder.config(config); return builder; }
@Test public void testGetResourceFromSourcePath() throws Exception { DiskFileSystem input = diskFS("compiler.getresource"); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder().javaCompiler(compilerProvider).sourcePath(input).output(output).build(); GetResource processor = new GetResource(StandardLocation.SOURCE_PATH, FileKey.newResourceName("compiler.getresource", "A.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); processor.assertResource("value"); }
public void compile() throws IOException, CompilationException { VirtualFileManager fileManager = new VirtualFileManager( javaCompiler.getStandardFileManager(null, null, null), sourcePath, classPaths, sourceOutput, classOutput ); compile(fileManager, getFromSourcePath(fileManager.sourcePath)); }
public Compiler build() { if (sourcePath == null) { throw new IllegalStateException("No null source path"); } if (classOutput == null) { throw new IllegalStateException("No null class output"); } if (sourceOutput == null) { throw new IllegalStateException("No null source output"); } Compiler compiler = new Compiler( javaCompiler.get(), sourcePath, classPaths, sourceOutput, classOutput, config ); if (processor != null) { compiler.addAnnotationProcessor(processor.get()); } return compiler; } }
compiler.compile(toCompile.toArray(new String[toCompile.size()]));
@Test public void testGetResourceFromSourcePath() throws Exception { DiskFileSystem input = diskFS("compiler.getresource"); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder().javaCompiler(compilerProvider).sourcePath(input).output(output).build(); GetResource processor = new GetResource(StandardLocation.SOURCE_PATH, FileKey.newResourceName("compiler.getresource", "A.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); processor.assertResource("value"); }
public void compile(String... compilationUnits) throws IOException, CompilationException { // Copy anything that is not a java file RAMFileSystem sourcePath1 = new RAMFileSystem(); sourcePath.copy(new Filter() { public boolean acceptDir(Object dir, String name) throws IOException { return true; } public boolean acceptFile(Object file, String name) throws IOException { return !name.endsWith(".java"); } }, sourcePath1); // VirtualFileManager fileManager = new VirtualFileManager( javaCompiler.getStandardFileManager(null, null, null), sourcePath1, classPaths, sourceOutput, classOutput ); // Collection<JavaFileObject> files = getFromSourcePath(sourcePath, compilationUnits); // compile(fileManager, files); }
compiler.compile(toCompile.toArray(new String[toCompile.size()]));
@Test public void testGetResourceFromClassPath() throws Exception { File fic = File.createTempFile("test", ".jar"); fic.deleteOnExit(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addAsResource(new StringAsset("the_resource"), "resource.txt"); jar.as(ZipExporter.class).exportTo(fic, true); JarFileSystem classpath = new JarFileSystem(new JarFile(fic)); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder(). javaCompiler(compilerProvider). config(new CompilerConfig().force(true)). addClassPath(classpath). sourcePath(new RAMFileSystem()). output(output).build(); GetResource processor = new GetResource(StandardLocation.CLASS_PATH, FileKey.newResourceName("", "resource.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); processor.assertResource("the_resource"); }
public void compile(String... compilationUnits) throws IOException, CompilationException { // Copy anything that is not a java file RAMFileSystem sourcePath1 = new RAMFileSystem(); sourcePath.copy(new Filter() { public boolean acceptDir(Object dir, String name) throws IOException { return true; } public boolean acceptFile(Object file, String name) throws IOException { return !name.endsWith(".java"); } }, sourcePath1); // VirtualFileManager fileManager = new VirtualFileManager( javaCompiler.getStandardFileManager(null, null, null), sourcePath1, classPaths, sourceOutput, classOutput ); // Collection<JavaFileObject> files = getFromSourcePath(sourcePath, compilationUnits); // compile(fileManager, files); }
@Test public void testGetResourceFromClassPath() throws Exception { File fic = File.createTempFile("test", ".jar"); fic.deleteOnExit(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addAsResource(new StringAsset("the_resource"), "resource.txt"); jar.as(ZipExporter.class).exportTo(fic, true); JarFileSystem classpath = new JarFileSystem(new JarFile(fic)); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder(). javaCompiler(compilerProvider). config(new CompilerConfig().force(true)). addClassPath(classpath). sourcePath(new RAMFileSystem()). output(output).build(); GetResource processor = new GetResource(StandardLocation.CLASS_PATH, FileKey.newResourceName("", "resource.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); processor.assertResource("the_resource"); }