+ public boolean compile() throws IOException {
+ List<String> args = new ArrayList<>();
+ args.add("javac");
+ args.add("-d");
+ args.add(outdir.toString());
+ for(Path p : infiles)
+ args.add(p.toString());
+ ProcessBuilder cmd = new ProcessBuilder(args);
+ cmd.redirectErrorStream(true);
+ cmd.redirectOutput(ProcessBuilder.Redirect.PIPE);
+ Process proc = cmd.start();
+ List<String> output = new ArrayList<>();
+ BufferedReader fp = new BufferedReader(new InputStreamReader(proc.getInputStream(), Utils.UTF8));
+ while(true) {
+ String ln = fp.readLine();
+ if(ln == null)
+ break;
+ output.add(ln);
+ }
+ int status;
+ try {
+ status = proc.waitFor();
+ } catch(InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw(new IOException("compilation interrupted"));
+ }
+ this.output = output;
+ return(status == 0);
+ }
+
+ public List<String> output() {
+ if(output == null)
+ throw(new IllegalStateException());
+ return(output);
+ }
+
+ public Collection<ClassOutput> classes() throws IOException {
+ Collection<ClassOutput> ret = new ArrayList<>();
+ for(Path p : (Iterable<Path>)Files.walk(outdir)::iterator) {
+ Path rel = outdir.relativize(p);
+ String fn = rel.getName(rel.getNameCount() - 1).toString();
+ if(!Files.isRegularFile(p) || !fn.endsWith(".class"))
+ continue;
+ StringBuilder clnm = new StringBuilder();
+ for(int i = 0; i < rel.getNameCount() - 1; i++) {
+ clnm.append(rel.getName(i));
+ clnm.append('.');
+ }
+ clnm.append(fn.substring(0, fn.length() - 6));
+ ClassOutput cls = new ClassOutput(clnm.toString());
+ Files.copy(p, cls.buf);
+ ret.add(cls);
+ }
+ return(ret);