Skip to content

Commit

Permalink
evolve ActionScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmeijer committed Apr 15, 2012
1 parent 721d110 commit 4df7360
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
16 changes: 13 additions & 3 deletions ActionScheduler.cs
@@ -1,15 +1,16 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;


namespace cake namespace cake
{ {
public class ActionScheduler public class ActionScheduler
{ {
private Dictionary<TargetGenerateSettings, List<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, List<string>>(); private readonly Dictionary<TargetGenerateSettings, HashSet<string>> _scheduledActions = new Dictionary<TargetGenerateSettings, HashSet<string>>();


public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs) public void Add(IEnumerable<string> dependenciesRequiringRegeneration, TargetGenerateSettings tgs)
{ {
_scheduledActions.Add(tgs, new List<string>(dependenciesRequiringRegeneration)); _scheduledActions.Add(tgs, new HashSet<string>(dependenciesRequiringRegeneration));
} }


public TargetGenerateSettings FindJobToRun() public TargetGenerateSettings FindJobToRun()
Expand All @@ -19,5 +20,14 @@ public TargetGenerateSettings FindJobToRun()
_scheduledActions.Remove(findJobToRun); _scheduledActions.Remove(findJobToRun);
return findJobToRun; return findJobToRun;
} }

public void JobFinished(TargetGenerateSettings finishedJob)
{
foreach(var outputFile in finishedJob.OutputFiles)
{
foreach (var deps in _scheduledActions.Values)
deps.Remove(outputFile);
}
}
} }
} }
14 changes: 14 additions & 0 deletions Tests/ActionSchedulerTest.cs
Expand Up @@ -48,5 +48,19 @@ public void SingleActionWithDependenciesRequiringGenerationCannotBeRun()
Assert.IsNull(_scheduler.FindJobToRun()); Assert.IsNull(_scheduler.FindJobToRun());
} }


[Test]
public void ActionWithDependenciesRequiringGenerationCanBeRanWhenDependencyIsGenerated()
{
var tgs = new TargetGenerateSettings(_action, new[] { "input" }, "output");
_scheduler.Add(new[] { "input" }, tgs);

Assert.IsNull(_scheduler.FindJobToRun());

var inputGenerator = new TargetGenerateSettings(_action, new string[0], "input");
_scheduler.JobFinished(inputGenerator);

Assert.AreEqual(tgs,_scheduler.FindJobToRun());
}

} }
} }

0 comments on commit 4df7360

Please sign in to comment.