public Target Parse(XElement element, BuildProject buildProject) { var target = new Target(); target.Name = GetNameOfTarget(element.Attribute("name").Value); target.Body = element.ToString(); if (element.Attribute("depends") != null) { foreach (var name in Regex.Split(element.Attribute("depends").Value, "[ ,]")) { if (name.Trim().Length > 0 && name != ",") target.DependsOn.Add(_targetRepository.Resolve(name)); } } foreach (var childNode in element.Elements()) { var parser = _resolver.Resolve(childNode.Name.ToString()); parser.Parse(childNode, buildProject); target.Tasks.Add(parser); } _targetRepository.Register(target); return target; }
public void SetUp() { TargetRepository.ClearKnownTargets(); _subject = new TargetRepository(); var target = new Target { Name = "test" }; _subject.Register(target); }
public void TestSimpleDependancy() { var defaultTarget = new Target() { Name="BuildAll"}; var cleanTarget = new Target() { Name="Clean"}; defaultTarget.DependsOn.Add(cleanTarget); var targets = TargetTreeBuilder.CreateTree(defaultTarget); Assert.That(targets[0], Is.EqualTo(cleanTarget)); Assert.That(targets[1], Is.EqualTo(defaultTarget)); }
public void NestedDepencanciesShouldWork() { //default needs compile which needs clean var defaultTarget = new Target() { Name = "BuildAll" }; var compileTarget = new Target() { Name = "Compile" }; var cleanTarget = new Target() { Name = "Clean" }; compileTarget.DependsOn.Add(cleanTarget); defaultTarget.DependsOn.Add(compileTarget); var targets = TargetTreeBuilder.CreateTree(defaultTarget); Assert.That(targets[0], Is.EqualTo(cleanTarget)); Assert.That(targets[1], Is.EqualTo(compileTarget)); Assert.That(targets[2], Is.EqualTo(defaultTarget)); }
public static void RegisterTarget(Target target) { //check each previously registered targets dependancies //if it depends on the target we are registering then //ensure that the dependancy is updated (from unregisteredTarget to an actual Target) //foreach (var knownTarget in _knownTargets.Values) //{ // for (var index = 0; index < knownTarget.DependsOn.Count; index++) // { // if (knownTarget.DependsOn[index].Name == target.Name) // { // knownTarget.DependsOn[index] = target; // } // } //} _knownTargets.Add(target.Name, target); }
public void TwoDepencanciesOnCleanShouldWork() { //default needs clean and compile //compile also needs clean var defaultTarget = new Target() { Name = "BuildAll" }; var compileTarget = new Target() {Name = "Compile"}; var cleanTarget = new Target() { Name = "Clean" }; compileTarget.DependsOn.Add(cleanTarget); defaultTarget.DependsOn.Add(cleanTarget); defaultTarget.DependsOn.Add(compileTarget); var targets = TargetTreeBuilder.CreateTree(defaultTarget); Assert.That(targets[0].Name, Is.EqualTo(cleanTarget.Name)); Assert.That(targets[1].Name, Is.EqualTo(compileTarget.Name)); Assert.That(targets[2].Name, Is.EqualTo(defaultTarget.Name)); }
public void ShouldHaveUnregisteredDependancyThenShouldHaveRegisteredDepenancy() { //create a "compile" target that depends on a "clean" target that has yet to be parsed var compileTarget = new Target() {Name ="compile"}; compileTarget.DependsOn.Add(_subject.Resolve("clean")); _subject.Register(compileTarget); //ensure that we get a proxy to unregisteredTarget Assert.That(compileTarget.DependsOn[0], Is.TypeOf<UnregisteredTarget>()); Assert.That(compileTarget.DependsOn[0].Name, Is.EqualTo("clean")); //ensure that when the actual target gets added that the target will now be the actual target //(instead of the proxy) var cleanTarget = new Target() {Name = "clean"}; _subject.Register(cleanTarget); //Assert.That(compileTarget.DependsOn[0], Is.TypeOf<Target>()); Assert.That(compileTarget.DependsOn[0].Name, Is.EqualTo("clean")); Assert.That(compileTarget.DependsOn[0].Body, Is.Null); }
public void Register(Target target) { TargetRepository.RegisterTarget(target); }