Skip to content
Browse files

first pass of a big simplification. needs more cleanup

  • Loading branch information...
1 parent a4d34d6 commit ad49f40bea04096e0c4a3bcf32a81d30a70b5997 Lucas Meijer committed
View
3 .gitignore
@@ -4,4 +4,5 @@ bin/
bs.5.1.ReSharper.user
bs.suo
obj/
-cake.suo
+cake.suo
+_ReSharper.cake/
View
10 DependencyGraph.cs
@@ -24,14 +24,14 @@ public void RequestTarget(string targetFile)
{
var instructions = _graph[targetFile];
- if (instructions.Settings.InputFiles.Any(inputFile => !File.Exists(inputFile)))
+ if (instructions.InputFiles.Any(inputFile => !File.Exists(inputFile)))
throw new MissingDependencyException();
- if (NeedToGenerate(targetFile, instructions.Settings))
+ if (NeedToGenerate(targetFile, instructions))
Generate(targetFile, instructions);
}
- private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSettings)
+ private bool NeedToGenerate(string targetFile, TargetGenerateInstructions generateSettings)
{
var recordOfLastBuild = _buildHistory.FindRecordFor(targetFile);
@@ -53,9 +53,9 @@ private bool NeedToGenerate(string targetFile, TargetGenerateSettings generateSe
private void Generate(string targetFile, TargetGenerateInstructions instructions)
{
GenerateCallback(targetFile, instructions);
- instructions.Action.Invoke(targetFile, instructions.Settings);
+ instructions.Action.Invoke(targetFile, instructions);
- var record = new GenerationRecord(targetFile, instructions.Settings, "");
+ var record = new GenerationRecord(targetFile, instructions, "");
_buildHistory.AddRecord(record);
}
View
6 FileAssert.cs
@@ -1,8 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
+using System.IO;
using NUnit.Framework;
namespace cake
View
4 GenerationRecord.cs
@@ -7,12 +7,12 @@ namespace cake
public class GenerationRecord
{
public string TargetFile { get; private set; }
- public TargetGenerateSettings Settings { get; private set; }
+ public TargetGenerateInstructions Settings { get; private set; }
public string ActionHash { get; private set; }
private readonly Dictionary<string, DateTime> _modificationDates = new Dictionary<string, DateTime>();
- public GenerationRecord(string targetFile, TargetGenerateSettings settings, string actionHash)
+ public GenerationRecord(string targetFile, TargetGenerateInstructions settings, string actionHash)
{
ActionHash = actionHash;
TargetFile = targetFile;
View
2 ITargetGeneratingAction.cs
@@ -2,7 +2,7 @@
{
public interface ITargetGeneratingAction
{
- void Invoke(string target, TargetGenerateSettings instructions);
+ void Invoke(string target, TargetGenerateInstructions instructions);
string GetActionHash();
}
}
View
46 TargetGenerateInstructions.cs
@@ -1,10 +1,54 @@
using System;
+using System.Collections.Generic;
namespace cake
{
public class TargetGenerateInstructions
{
public ITargetGeneratingAction Action;
- public TargetGenerateSettings Settings;
+ public HashSet<string> InputFiles { get; private set; }
+
+ private string _actionHash;
+
+ public TargetGenerateInstructions(ITargetGeneratingAction action, HashSet<string> inputFiles)
+ {
+ Action = action;
+ _actionHash = action.GetActionHash();
+ InputFiles = inputFiles;
+ }
+
+ //todo: figure out how to write a sane Equals
+ public override bool Equals(object obj)
+ {
+ if (obj == null)
+ return false;
+
+ var other = obj as TargetGenerateInstructions;
+ if (other == null)
+ return false;
+
+ if (ActionHash != other.ActionHash)
+ return false;
+
+ return other.InputFiles.SetEquals(InputFiles);
+ }
+
+ public string ActionHash
+ {
+ get
+ {
+ if (Action != null)
+ return Action.GetActionHash();
+ return _actionHash;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return (InputFiles != null ? InputFiles.GetHashCode() : 0);
+ }
+
+
+
}
}
View
38 TargetGenerateSettings.cs
@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace cake
-{
- public class TargetGenerateSettings
- {
- public HashSet<string> InputFiles { get; private set; }
- public string ActionHash { get; private set; }
-
- public TargetGenerateSettings(HashSet<string> inputFiles, string actionHash)
- {
- InputFiles = inputFiles;
- ActionHash = actionHash;
- }
-
- //todo: figure out how to write a sane Equals
- public override bool Equals(object obj)
- {
- if (obj == null)
- return false;
-
- var other = obj as TargetGenerateSettings;
- if (other == null)
- return false;
-
- if (ActionHash != other.ActionHash)
- return false;
-
- return other.InputFiles.SetEquals(InputFiles);
- }
-
- public override int GetHashCode()
- {
- return (InputFiles != null ? InputFiles.GetHashCode() : 0);
- }
- }
-}
View
6 Tests/DifferentInputFiles.cs
@@ -35,11 +35,7 @@ public void WhenInputFilesChangeTargetGetsRebuilt()
private static TargetGenerateInstructions MakeInstructions(ITargetGeneratingAction action, params string[] inputFiles)
{
- var targetBuildInstructions = new TargetGenerateInstructions();
-
- targetBuildInstructions.Action = action;
- targetBuildInstructions.Settings = new TargetGenerateSettings(new HashSet<string>(inputFiles), action.GetActionHash());
- return targetBuildInstructions;
+ return new TargetGenerateInstructions(action, new HashSet<string>(inputFiles));
}
}
}
View
6 Tests/SimpleAction.cs
@@ -4,16 +4,16 @@ namespace cake.Tests
{
class SimpleAction : ITargetGeneratingAction
{
- private readonly Action<string, TargetGenerateSettings> _invoke;
+ private readonly Action<string, TargetGenerateInstructions> _invoke;
private readonly string _actionHash;
- public SimpleAction(Action<string, TargetGenerateSettings> invoke, string actionHash)
+ public SimpleAction(Action<string, TargetGenerateInstructions> invoke, string actionHash)
{
_invoke = invoke;
_actionHash = actionHash;
}
- public void Invoke(string target, TargetGenerateSettings instructions)
+ public void Invoke(string target, TargetGenerateInstructions instructions)
{
_invoke(target, instructions);
}
View
7 Tests/SimpleCopyDepGraph.cs
@@ -64,11 +64,8 @@ public void WillNotRegeneratesWhenTargetGotManuallyUpdated()
private void SetupSimpleCopyDepGraph()
{
var action = new SimpleAction((target, settings) => File.Copy(settings.InputFiles.Single(), target, true), "hash");
- _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions()
- {
- Action = action,
- Settings = new TargetGenerateSettings(new HashSet<string>(new[]{defaultSourceFile}), action.GetActionHash())
- });
+ _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions(action, new HashSet<string>(new[] {defaultSourceFile})));
+
}
}
}
View
15 Tests/TargetWithoutSources.cs
@@ -46,11 +46,8 @@ public void RegenerateWhenActionHashChanges()
bool invoked = false;
var action = new SimpleAction((t, s) => { invoked=true; }, "hash2");
- _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions()
- {
- Action = action,
- Settings = new TargetGenerateSettings(new HashSet<string>(), action.GetActionHash())
- });
+ _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions(action, new HashSet<string>()));
+
_depGraph.RequestTarget(defaulttargetFile);
Assert.IsTrue(invoked);
}
@@ -61,12 +58,8 @@ public void RegenerateWhenActionHashChanges()
private void SetupGraphWithOneTargetWithoutSources()
{
var simpleAction = new SimpleAction((t,s) => File.WriteAllText(t, "Hello"), "hash1");
-
- _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions()
- {
- Action = simpleAction,
- Settings = new TargetGenerateSettings(new HashSet<string>(),simpleAction.GetActionHash())
- });
+
+ _depGraph.RegisterTarget(defaulttargetFile, new TargetGenerateInstructions(simpleAction, new HashSet<string>()));
}
View
1 cake.csproj
@@ -51,7 +51,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecursiveIncludeScanner.cs" />
<Compile Include="TargetGenerateInstructions.cs" />
- <Compile Include="TargetGenerateSettings.cs" />
<Compile Include="CCompilerTask.cs" />
<Compile Include="Tests\CCompilerTests.cs" />
<Compile Include="Tests\DependencyGraphTests.cs" />

0 comments on commit ad49f40

Please sign in to comment.
Something went wrong with that request. Please try again.