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

import org.terasology.entitySystem.systems.BaseComponentSystem;
import org.terasology.entitySystem.systems.RegisterSystem;
import org.terasology.logic.console.Console;
import org.terasology.logic.console.commandSystem.annotations.Command;
import org.terasology.logic.console.commandSystem.annotations.CommandParam;
import org.terasology.logic.console.commands.ThreadPMDExecution;
import org.terasology.logic.permission.PermissionManager;
import org.terasology.registry.In;

@RegisterSystem
public class PMDCommand extends BaseComponentSystem{
	@In
    private Console console;
	@Command(shortDescription = "PMD coloring.",
            requiredPermission = PermissionManager.NO_PERMISSION)
    public String pmdColoring(@CommandParam(value = "sourcePath",required = true) String sourcePath,@CommandParam(value="rules",required=false) String rules,@CommandParam(value="outPutType",required=false) String outPutType) throws IOException
    {
    	if (rules == null) rules = "basic";
    	if (outPutType == null) outPutType = "text";
    	String inputString = "java -classpath .\\engine\\libs\\pmd\\lib\\* net.sourceforge.pmd.PMD -d "+ sourcePath+" -f "+outPutType+" -R rulesets/java/"+ rules+".xml";
    	//String inputString = "C:\\Users\\Manuel\\Desktop\\pmd-bin-5.3.1\\bin\\pmd.bat -d "+ sourcePath+" -f text -R rulesets/java/"+ rules+".xml";
    	/*
    	System.out.println(inputString);
    	Process process;
		process = Runtime.getRuntime().exec(inputString);
		InputStream is = process.getInputStream();
		 InputStreamReader isr = new InputStreamReader(is);
		 BufferedReader br = new BufferedReader(isr);
			
		 StringBuilder sb = new StringBuilder();
		 String line;
		 while ((line = br.readLine()) != null) 
		 {
			 console.addMessage(line);	
			 System.out.println(line);
		 }
		 */
		 /* 
    	PrintStream out = System.out;
    	System.setOut(new PrintStream(new ConsoleOutputStream(console)));
    	String[] args = {"-d", "C:\\Users\\Manuel\\Documents\\Terasology-develop\\modules\\Core\\src\\main\\java\\org\\terasology\\core\\world\\generator\\facetProviders\\PositionFilters.java", "-f", "text", "-R" ,"rulesets/java/basic.xml"};
			PMD.main(args);
			System.setOut(out);
		*/ 
		
    	Thread t = new Thread(new ThreadPMDExecution(inputString,console));
		 t.start();
		 
    	/*
		 String line = "-d C:\\Users\\Manuel\\workspace\\Tarea2Teoria -f text -R rulesets/java/basic.xml";
	    	String []args1 = line.split(" ");
			 PMD.main(args1);
			 */
		 return "Esperando por resultados del analisis...";
    }
}

class ThreadPMDExecution implements Runnable
{
	String inputString;
	Console console;
	public ThreadPMDExecution(String inputString, Console console) {
		// TODO Auto-generated constructor stub
		this.inputString = inputString;
		this.console = console;
	}

	@Override
	public void run() 
	{
		// TODO Auto-generated method stub
		
		try {
			Process process;
			process = Runtime.getRuntime().exec(inputString);
			InputStream is = process.getInputStream();
			 InputStreamReader isr = new InputStreamReader(is);
			 BufferedReader br = new BufferedReader(isr);
				
			 StringBuilder sb = new StringBuilder();
			 String line;
			 while ((line = br.readLine()) != null) 
			 {
				 console.addMessage(line);	
			 }
			 console.addMessage("Fin del Analisis");
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

} 

@@ -434,73 +434,8 @@
 am;%0A
-import org.terasology.logic.console.commands.ThreadPMDExecution;%0A
 impo
@@ -524,16 +524,17 @@
 ry.In;%0A%0A
+%0A
 @Registe
@@ -1111,84 +1111,25 @@
 g = 
-%22java -classpath .%5C%5Cengine%5C%5Clibs%5C%5Cpmd%5C%5Clib%5C%5C* net.sourceforge.pmd.PMD -d %22+ 
+buildInputString(
 sour
@@ -1138,16 +1138,10 @@
 Path
-+%22 -f %22+
+, 
 outP
@@ -1150,1370 +1150,424 @@
 Type
-+%22 -R rulesets/java/%22+ rules+%22.xml%22;%0A    %09//String inputString = %22C:%5C%5CUsers%5C%5CManuel%5C%5CDesktop%5C%5Cpmd-bin-5.3.1%5C%5Cbin%5C%5Cpmd.bat -d %22+ sourcePath+%22 -f text -R rulesets/java/%22+ rules+%22.xml%22;%0A    %09/*%0A    %09System.out.println(inputString);%0A    %09Process process;%0A%09%09process = Runtime.getRuntime().exec(inputString);%0A%09%09InputStream is = process.getInputStream();%0A%09%09 InputStreamReader isr = new InputStreamReader(is);%0A%09%09 BufferedReader br = new BufferedReader(isr);%0A%09%09%09%0A%09%09
+, rules);%0A    %09%0A    %09Thread t = new Thread(new ThreadPMDExecution(inputString,console));%0A%09%09t.start();%0A%09%09%0A%09%09return %22Esperando por resultados del analisis...%22;%0A    %7D%0A%09private
  String
-B
+ b
 uild
-er sb = new StringBuilder();%0A%09%09 String line;%0A%09%09 while ((line = br.readLine()) != null) %0A%09%09 %7B%0A%09%09%09 console.addMessage(line);%09%0A%09%09%09 System.out.println(line);%0A%09%09 %7D%0A%09%09 */%0A%09%09 /* %0A    %09PrintStream out = System.out;%0A    %09System.setOut(new PrintStream(new ConsoleOutputStream(console)));%0A    %09String%5B%5D args = %7B%22-d%22, %22C:%5C%5CUsers%5C%5CManuel%5C%5CDocuments%5C%5CTerasology-develop%5C%5Cmodules%5C%5CCore%5C%5Csrc%5C%5Cmain%5C%5Cjava%5C%5Corg%5C%5Cterasology%5C%5Ccore%5C%5Cworld%5C%5Cgenerator%5C%5CfacetProviders%5C%5CPositionFilters.java%22, %22-f%22, %22text%22, %22-R%22 ,%22rulesets/java/basic.xml%22%7D;%0A%09%09%09PMD.main(args);%0A%09%09%09System.setOut(out);%0A%09%09*/ %0A%09%09%0A    %09Thread t = new Thread(new ThreadPMDExecution(inputString,console));%0A%09%09 t.start();%0A%09%09 %0A    %09/*%0A%09%09 String line = %22-d C:%5C%5CUsers%5C%5CManuel%5C%5Cworkspace%5C%5CTarea2Teoria -f text -R rulesets/java/basic.xml%22;%0A%09    %09String %5B%5Dargs1 = line.split(%22 %22);%0A%09%09%09 PMD.main(args1);%0A%09%09%09 */%0A%09%09 return %22Esperando por resultados del analisis...%22;%0A    
+InputString(String sourcePath, String outPutType, String rules) %7B%0A%09%09return %22java -classpath .%5C%5Cmodules%5C%5CPMDColoring%5C%5Clibs%5C%5Cpmd%5C%5Clib%5C%5C* net.sourceforge.pmd.PMD -d %22+ sourcePath+%22 -f %22+outPutType+%22 -R rulesets/java/%22+ rules+%22.xml%22;%0A%09
 %7D%0A%7D%0A

Create buildInputString method and fix jar's path