ExecScript implements Script, StreamConsumer { public Commandline buildCommandline() throws CruiseControlException { Commandline cmdLine = new Commandline(); if (execCommand != null) { cmdLine.setExecutable(execCommand); } else { throw new CruiseControlException("no command to be executed"); } if (execArgs != null) { cmdLine.addArguments(Commandline.translateCommandline(execArgs)); } if (LOG.isDebugEnabled()) { final StringBuilder sb = new StringBuilder(); sb.append("Executing Command: "); final String[] args = cmdLine.getCommandline(); for (final String arg : args) { sb.append(arg); sb.append(" "); } LOG.debug(sb.toString()); } return cmdLine; }  Commandline buildCommandline(); synchronized void consumeLine(final String line); Element setBuildLogHeader(Element buildLogElement); void setExecArgs(String execArgs); void setExecCommand(String execCommand); int getExitCode(); void setExitCode(int exitCode); void setErrorStr(String errStr); void setBuildLogElement(Element buildLogElement); void setProgress(final Progress progress); boolean wasError();  }
@Test public void testGetCommandLineArgsWin() throws CruiseControlException { String testExecCmd = "dir"; String[] simpleCmd = { testExecCmd }; ExecScript script = createExecScript(testExecCmd, null); TestUtil.assertArray("simpleCmd", simpleCmd, script.buildCommandline().getCommandline()); String testExecArgs = "C:\\temp"; script = createExecScript(testExecCmd, testExecArgs); String[] detailedCmd = { testExecCmd, testExecArgs }; TestUtil.assertArray("detailedCmd", detailedCmd, script.buildCommandline().getCommandline()); }
@Test public void testGetCommandLineArgsUnix() throws CruiseControlException { String testExecCmd = "/bin/sh"; String testExecArg1 = "rm"; String testExecArg2 = "rm -rf *"; String testExecArgs = testExecArg1 + space + quote + testExecArg2 + quote; testExecCmd = testExecCmd.replace('/', File.separatorChar); String[] testExecArr = { testExecCmd, testExecArg1, testExecArg2 }; ExecScript script = createExecScript(testExecCmd, testExecArgs); TestUtil.assertArray("detailedCmd", testExecArr, script.buildCommandline().getCommandline()); }
@Test public void testGetCommandLineArgsURL() throws CruiseControlException { String testExecCmd = "/bin/sh"; String testExecArg1 = "svn"; String testExecArg2 = "checkout"; String testExecArg3 = "https: String testExecArgs = testExecArg1 + space + testExecArg2 + space + quote + testExecArg3 + quote; testExecCmd = testExecCmd.replace('/', File.separatorChar); String[] testExecArr = { testExecCmd, testExecArg1, testExecArg2, testExecArg3 }; ExecScript script = createExecScript(testExecCmd, testExecArgs); TestUtil.assertArray("detailedCmd", testExecArr, script.buildCommandline().getCommandline()); }