Skip to content

Commit 8baeea1

Browse files
committed
CCNET-1921: Implement a task for FAKE - F# Make
* set default properties * apply integration properties * execute fake.exe and merge xml result file
1 parent 489c533 commit 8baeea1

2 files changed

Lines changed: 80 additions & 2 deletions

File tree

project/UnitTests/Core/Tasks/FakeTaskTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,19 @@ public void PopulateFromReflector()
3838
Assert.AreEqual("mybuild.fx", task.BuildFile);
3939
Assert.AreEqual("Test description", task.Description);
4040
}
41+
42+
[Test]
43+
public void PopulateFromConfigurationUsingOnlyRequiredElementsAndCheckDefaultValues()
44+
{
45+
46+
var task = new FakeTask();
47+
const string xml = "<fake />";
48+
49+
NetReflector.Read(xml, task);
50+
Assert.AreEqual(FakeTask.defaultExecutable, task.Executable);
51+
Assert.AreEqual(string.Empty, task.ConfiguredBaseDirectory);
52+
Assert.AreEqual(string.Empty, task.BuildFile);
53+
Assert.AreEqual(null, task.Description);
54+
}
4155
}
4256
}

project/core/tasks/FakeTask.cs

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Diagnostics;
5+
using System.IO;
46
using System.Linq;
57
using System.Text;
68
using Exortech.NetReflector;
9+
using ThoughtWorks.CruiseControl.Core.Util;
710

811
namespace ThoughtWorks.CruiseControl.Core.Tasks
912
{
@@ -45,6 +48,8 @@ public class FakeTask : BaseExecutableTask
4548
public readonly Guid LogFileId = Guid.NewGuid();
4649
public const ProcessPriorityClass DefaultPriority = ProcessPriorityClass.Normal;
4750

51+
private readonly IFileDirectoryDeleter fileDirectoryDeleter = new IoService();
52+
4853
/// <summary>
4954
/// The location of the FAKE executable.
5055
/// </summary>
@@ -86,6 +91,19 @@ public class FakeTask : BaseExecutableTask
8691
[ReflectorProperty("buildFile", Required = false)]
8792
public string BuildFile { get; set; }
8893

94+
public FakeTask():
95+
this(new ProcessExecutor()){}
96+
97+
public FakeTask(ProcessExecutor executor)
98+
{
99+
this.executor = executor;
100+
Executable = defaultExecutable;
101+
ConfiguredBaseDirectory = string.Empty;
102+
Priority = DefaultPriority;
103+
BuildTimeoutSeconds = DefaultBuildTimeout;
104+
BuildFile = string.Empty;
105+
}
106+
89107
#region Overrides of TaskBase
90108

91109
/// <summary>
@@ -95,7 +113,25 @@ public class FakeTask : BaseExecutableTask
95113
/// <returns><c>true</c> if the task was successful; <c>false</c> otherwise.</returns>
96114
protected override bool Execute(IIntegrationResult result)
97115
{
98-
throw new NotImplementedException();
116+
var fakeOutputFile = GetFakeOutputFile(result);
117+
118+
//delete old nant output logfile, if exist
119+
fileDirectoryDeleter.DeleteIncludingReadOnlyObjects(fakeOutputFile);
120+
121+
result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description :
122+
string.Format("Executing FAKE - {0}", ToString()));
123+
124+
var processResult = TryToRun(CreateProcessInfo(result), result);
125+
126+
if (File.Exists(fakeOutputFile))
127+
result.AddTaskResult(new FileTaskResult(fakeOutputFile));
128+
129+
result.AddTaskResult(new ProcessTaskResult(processResult, true));
130+
131+
if (processResult.TimedOut)
132+
throw new BuilderException(this, string.Concat("FAKE process timed out (after ", BuildTimeoutSeconds, " seconds)"));
133+
134+
return !processResult.Failed;
99135
}
100136

101137
#endregion
@@ -109,7 +145,11 @@ protected override string GetProcessFilename()
109145

110146
protected override string GetProcessArguments(IIntegrationResult result)
111147
{
112-
throw new NotImplementedException();
148+
var buffer = new ProcessArgumentBuilder();
149+
buffer.AppendArgument(StringUtil.AutoDoubleQuoteString(BuildFile));
150+
buffer.AppendArgument("logfile={0}", StringUtil.AutoDoubleQuoteString(GetFakeOutputFile(result)));
151+
AppendIntegrationResultProperties(buffer, result);
152+
return buffer.ToString();
113153
}
114154

115155
protected override string GetProcessBaseDirectory(IIntegrationResult result)
@@ -128,5 +168,29 @@ protected override int GetProcessTimeout()
128168
}
129169

130170
#endregion
171+
172+
private static void AppendIntegrationResultProperties(ProcessArgumentBuilder buffer, IIntegrationResult result)
173+
{
174+
// We have to sort this alphabetically, else the unit tests
175+
// that expect args in a certain order are unpredictable
176+
IDictionary properties = result.IntegrationProperties;
177+
foreach (string key in properties.Keys)
178+
{
179+
object value = result.IntegrationProperties[key];
180+
if (value != null)
181+
buffer.AppendArgument(string.Format("{0}={1}", key, StringUtil.AutoDoubleQuoteString(StringUtil.RemoveTrailingPathDelimeter(StringUtil.IntegrationPropertyToString(value)))));
182+
}
183+
}
184+
185+
public override string ToString()
186+
{
187+
string baseDirectory = ConfiguredBaseDirectory ?? string.Empty;
188+
return string.Format(@" BaseDirectory: {0}, Executable: {1}, BuildFile: {2}", baseDirectory, Executable, BuildFile);
189+
}
190+
191+
private string GetFakeOutputFile(IIntegrationResult result)
192+
{
193+
return Path.Combine(result.ArtifactDirectory, string.Format(logFilename, LogFileId));
194+
}
131195
}
132196
}

0 commit comments

Comments
 (0)