package com.blubi.branchmaster.commandline;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.LogOutputStream;
import org.apache.commons.exec.PumpStreamHandler;

import com.blubi.branchmaster.Main;

public abstract class AbstractCommandLineRunner {

	private static long stat_total_ms = 0;
	private static long stat_total_calls = 0;
	
	File homedir = null;
		
	public AbstractCommandLineRunner(File homedir) {
		this.homedir = homedir;
	}

	public int run(String command) {
		try {
			LogOutputStream outStrm = new LogOutputStream() {
			    @Override protected void processLine(String line, int level) {
			    	System.out.println("out: "+line+"; "+level);
		        handle(line);
		      }			
			};
			
			LogOutputStream errStrm = new LogOutputStream() {
			    @Override protected void processLine(String line, int level) {
			    	System.out.println("err: "+line+"; "+level);
		        handleErr(line);
		      }
			};

		    PumpStreamHandler psh = new PumpStreamHandler(outStrm,errStrm);
		    CommandLine cl = CommandLine.parse(command);
		    DefaultExecutor exec = new DefaultExecutor();
		    exec.setWorkingDirectory(this.homedir);
		    exec.setExitValues(new int[] {0,1});
		    exec.setStreamHandler(psh);
		    
		    int exitValue = exec.execute(cl);
		    return exitValue;	    	
		} catch (Exception e)  {
			return handleException(e);			
		}
	}
	
	protected void handle(String line) {
        System.out.println(line);
	}
	
	protected void handleErr(String line) {
        System.out.println("ERROR: "+ line);		
	}
	
	protected int handleException(Throwable e) {
		throw new RuntimeException(e);		
	}
	
	public static void output_stat() {
		System.out.println("\n-- Stats --");
		System.out.println("Total time in commands: "+stat_total_ms+"ms");
		System.out.println("Total commands: "+stat_total_calls);
		
	}
}
@@ -57,105 +57,12 @@
 .io.
-BufferedReader;%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader
+File
 ;%0A%0Ai
@@ -255,45 +255,8 @@
 r;%0A%0A
-import com.blubi.branchmaster.Main;%0A%0A
 publ

Remove unused imports