# # patch "contrib/monotree/Monotone.java" # from [9a979d5d0fcd116294f3a2c38e18962849403d71] # to [635d14051fad2e14b1a3bbf0072233c1f4376908] # --- contrib/monotree/Monotone.java +++ contrib/monotree/Monotone.java @@ -27,6 +27,7 @@ import javax.xml.transform.URIResolver; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; +import java.util.Arrays; /** * Interface class to control an inferior Monotone process and return information from it @@ -60,8 +61,8 @@ * * @return the base monotone command */ - public String getBaseCommand() { - return "monotone \"--db="+database+"\" "; + public String[] getBaseCommand() { + return new String[] { "monotone","--db="+database }; } /** @@ -70,7 +71,7 @@ * @return a list of strings which enumerates the branches in the current monotone database */ public List listBranches() throws IOException { - List result=runMonotone("list branches"); + List result=runMonotone(new String[] { "list", "branches"}); return result; } @@ -81,7 +82,7 @@ * @return a list of strings which enumerates the heads of the specified branch in the current monotone database */ public List listHeads(String branch) throws IOException { - Listresult=runMonotone("heads --branch \""+branch+"\""); + Listresult=runMonotone(new String[] { "heads", "--branch",branch}); return result; } @@ -113,6 +114,19 @@ BRANCHES }; + /** + * Return the full command by composing the base command and the sub-command + * @param subCommand an array of strings representing the sub-command + * @return an array of strings containing the full command + */ + private String[] getCommand(String[] subCommand) { + String[] base=getBaseCommand(); + ArrayList fullCommand=new ArrayList(); + fullCommand.addAll(Arrays.asList(base)); + fullCommand.addAll(Arrays.asList(subCommand)); + return fullCommand.toArray(new String[0]); + } + /** * Run monotone and get an SVG stream from a log * @@ -121,12 +135,12 @@ * @return a stream from which an SVG format graph may be read */ public InputStream getSVGLog(final String id,final HighlightTypes highlight) throws IOException { - final String command="log --revision "+id; + final String[] command=new String[] { "log","--revision",id }; // Start the inferior processes - final Process monotone=Runtime.getRuntime().exec(getBaseCommand()+command); + final Process monotone=Runtime.getRuntime().exec(getCommand(command)); new ErrorReader("monotone",monotone.getErrorStream()); - final Process dot2svg=Runtime.getRuntime().exec("dot -Tsvg"); + final Process dot2svg=Runtime.getRuntime().exec(new String[] { "dot","-Tsvg" }); new ErrorReader("dot2svg",dot2svg.getErrorStream()); final PipedOutputStream gxl2dotSourceOutputStream=new PipedOutputStream(); @@ -171,11 +185,11 @@ * @param command the monotone sub-command to execute, e.g. "list branches" * @return a string list containing the output lines from monotone's stdout */ - public List runMonotone(String command) throws IOException { + public List runMonotone(String[] command) throws IOException { List results=new ArrayList(); LineNumberReader source=null; try { - Process monotone=Runtime.getRuntime().exec(getBaseCommand()+command); + Process monotone=Runtime.getRuntime().exec(getCommand(command)); new ErrorReader("monotone",monotone.getErrorStream()); source=new LineNumberReader(new InputStreamReader(monotone.getInputStream()));