List of usage examples for org.apache.commons.jci.compilers JavaCompiler compile
CompilationResult compile(final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore);
From source file:me.jaimegarza.syntax.test.AbstractGenerationBase.java
protected CompilationResult compileJavaFile(File source, File sourceDir) { JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse"); String sources[] = new String[1]; sources[0] = source.getName();/* w ww . j ava 2 s . c o m*/ CompilationResult result = compiler.compile(sources, new FileResourceReader(sourceDir), new FileResourceStore(sourceDir)); return result; }
From source file:org.vafer.drift.generator.JavaGeneratorTestCase.java
private CompilationResult compile(final InputStream input) throws IOException { final Schema schema = Schema.build(input); final JavaGenerator javaGenerator = new JavaGenerator("org.vafer.drift.generator.generated"); final MemoryCodeWriter writer = new MemoryCodeWriter(); javaGenerator.generate(schema, writer); final ResourceStore store = new MemoryResourceStore(); final ResourceReader reader = writer; final JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse"); assertNotNull(compiler);// www .j a v a 2 s . c o m final CompilationResult result = compiler.compile(writer.getNames(), reader, store); final CompilationProblem[] errors = result.getErrors(); final Set<String> fileNames = new HashSet<String>(); for (int i = 0; i < errors.length; i++) { System.out.println(errors[i]); fileNames.add(errors[i].getFileName()); } final CompilationProblem[] warnings = result.getWarnings(); for (int i = 0; i < warnings.length; i++) { System.out.println(warnings[i]); fileNames.add(warnings[i].getFileName()); } if (fileNames.size() > 0) { System.out.println("Writing out files with problems"); for (Iterator<String> it = fileNames.iterator(); it.hasNext();) { final String name = it.next(); final String content = new String(reader.getBytes(name)); final File fullPath = new File(dir, name); fullPath.getParentFile().mkdirs(); System.out.println(" writing " + fullPath.getAbsolutePath()); FileUtils.writeStringToFile(fullPath, content); } } return result; }