ScriptRunner { public boolean runScript(final File workingDir, final Script script, final long timeout) throws CruiseControlException { return runScript(workingDir, script, timeout, null, null); }  boolean runScript(final File workingDir, final Script script, final long timeout); boolean runScript(final File workingDir, final Script script, final long timeout,
                             final BuildOutputLogger buildOutputConsumer); boolean runScript(final File workingDir, final Script script, final long timeout,
                             final InputStream scriptInputProvider, final BuildOutputLogger buildOutputConsumer); boolean runScript(Script script, long timeout, BuildOutputLogger logger); static final long NO_TIMEOUT; }
@Test public void testDoNotCreateAntOutputLoggerFile() throws Exception { final MockCommandline mockCommandline = new MockCommandline(); mockCommandline.setAssertCorrectCommandline(false); mockCommandline.setProcessInputStream( new ByteArrayInputStream("some stuff\nmore stuff\n".getBytes())); mockCommandline.setProcessErrorStream(new ByteArrayInputStream("".getBytes())); final Script dummyScript = new Script() { public Commandline buildCommandline() throws CruiseControlException { return mockCommandline; } public void setExitCode(int result) { } public int getExitCode() { return 0; } }; final ScriptRunner sr = new ScriptRunner(); sr.runScript(TestUtil.getTargetDir(), dummyScript, ScriptRunner.NO_TIMEOUT); final File expectedAntBuilderLog = new File(TestUtil.getTargetDir(), AntOutputLogger.DEFAULT_OUTFILE_NAME); assertFalse("Generic ScriptRunner should not have created AntOuputLogger file: " + expectedAntBuilderLog.getAbsolutePath(), expectedAntBuilderLog.exists()); }
@Test public void testClearOutputLoggerFileAtEndOfScript() throws Exception { final String logFilename = "logFilename-" + getName(); final File outputLog = new File(TestUtil.getTargetDir(), logFilename); assertFalse(outputLog.exists()); final MockCommandline mockCommandline = new MockCommandline(); mockCommandline.setAssertCorrectCommandline(false); mockCommandline.setProcessInputStream( new ByteArrayInputStream("some stuff\nmore stuff\n".getBytes())); mockCommandline.setProcessErrorStream(new ByteArrayInputStream("".getBytes())); final Script dummyScript = new Script() { public Commandline buildCommandline() throws CruiseControlException { return mockCommandline; } public void setExitCode(int result) { } public int getExitCode() { return 0; } }; final ScriptRunner sr = new ScriptRunner(); final TestBuilder builder = new TestBuilder(); final String projectName = "testProjectName"; final BuildOutputLogger buildOutputLogger = builder.getBuildOutputConsumer(projectName, outputLog.getParentFile(), outputLog.getName()); final String origId = buildOutputLogger.getID(); sr.runScript(TestUtil.getTargetDir(), dummyScript, ScriptRunner.NO_TIMEOUT, buildOutputLogger); assertFalse("LiveOutput log should be cleared at end of script run: " + outputLog.getAbsolutePath(), outputLog.exists()); final String currentId = buildOutputLogger.getID(); assertTrue("buildOutputLogger id should change due to clear() at end of script run. origId: " + origId + "; current Id: " + currentId, currentId.startsWith(origId) && (currentId.length() > origId.length())); }