Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tweaks to allow replaceable writer.

  • Loading branch information...
commit 46c731bca5205132afc9fb16fae726662642795c 1 parent badf9ee
@JeremySkinner authored
View
19 src/Phantom.Core/BuildRunner.cs
@@ -27,10 +27,20 @@ namespace Phantom.Core {
[Export]
public class BuildRunner {
readonly IEnumerable<IDslFactory> dslFactories;
+ readonly Func<TextWriter> log;
- [ImportingConstructor]
- public BuildRunner([ImportMany] IEnumerable<IDslFactory> dslFactories) {
+ protected TextWriter Log {
+ get { return log(); }
+ }
+
+ public BuildRunner(IEnumerable<IDslFactory> dslFactories, Func<TextWriter> log) {
this.dslFactories = dslFactories;
+ this.log = log;
+ }
+
+
+ [ImportingConstructor]
+ public BuildRunner([ImportMany] IEnumerable<IDslFactory> dslFactories) : this(dslFactories, ()=>Console.Out) {
}
public static BuildRunner Create() {
@@ -58,11 +68,12 @@ public class BuildRunner {
}
var script = GenerateBuildScript(options.File);
+ script.Log = Log;
script.ExecuteTargets(options.TargetNames.ToArray());
}
public void OutputTargets(PhantomOptions options) {
- Console.WriteLine("Targets in {0}: ", options.File);
+ Log.WriteLine("Targets in {0}: ", options.File);
var script = GenerateBuildScript(options.File);
var allTargets = script.OrderBy(x => x.Name).ToList();
@@ -76,7 +87,7 @@ public class BuildRunner {
description = description.Substring(0, 47) + "...";
}
- Console.WriteLine(name + description);
+ Log.WriteLine(name + description);
}
}
}
View
9 src/Phantom.Core/PhantomOptions.cs
@@ -17,6 +17,7 @@
namespace Phantom.Core {
using System;
using System.Collections.Generic;
+ using System.IO;
using Mono.Options;
[Serializable]
@@ -75,10 +76,10 @@ public class PhantomOptions {
}
}
- public void PrintHelp() {
- Console.WriteLine("phantom [-f <filename>] [-t] [-h] [-a:<name>=<value>] targets");
- Console.WriteLine();
- parser.WriteOptionDescriptions(Console.Out);
+ public void PrintHelp(TextWriter writer) {
+ writer.WriteLine("phantom [-f <filename>] [-t] [-h] [-a:<name>=<value>] targets");
+ writer.WriteLine();
+ parser.WriteOptionDescriptions(writer);
}
public void Parse(string[] args) {
View
15 src/Phantom.Core/ScriptModel.cs
@@ -18,9 +18,17 @@ namespace Phantom.Core {
using System;
using System.Collections;
using System.Collections.Generic;
+ using System.IO;
public class ScriptModel : IEnumerable<Target> {
public const string DefaultTargetName = "default";
+
+ Func<TextWriter> log = () => Console.Out;
+
+ public TextWriter Log {
+ get { return log(); }
+ set { log = () => value; }
+ }
readonly Dictionary<string, Target> targets = new Dictionary<string, Target>();
@@ -67,14 +75,13 @@ public class ScriptModel : IEnumerable<Target> {
try {
foreach (var target in targetsToExecute) {
- Console.WriteLine(target.Name + ":");
+ Log.WriteLine(target.Name + ":");
target.Execute();
- Console.WriteLine();
+ Log.WriteLine();
}
}
catch (PhantomException e) {
- Console.WriteLine(
- string.Format("Target failed: {0}", e.Message));
+ Log.WriteLine(string.Format("Target failed: {0}", e.Message));
Environment.ExitCode = 1;
}
}
View
5 src/Phantom.Tests/ScriptTest.cs
@@ -29,14 +29,15 @@ public abstract class ScriptTest {
[SetUp]
public void BaseSetup() {
+ Writer = new StringWriter();
+ Console.SetOut(Writer);
+
if (Runner == null) {
var container = new CompositionContainer(new DirectoryCatalog(Directory.GetCurrentDirectory()));
Runner = container.GetExportedValue<BuildRunner>();
}
Options = new PhantomOptions();
- Writer = new StringWriter();
- Console.SetOut(Writer);
Setup();
}
View
4 src/Phantom/Program.cs
@@ -37,12 +37,12 @@ internal class Program {
}
catch (CommandLineException exception) {
Console.WriteLine(exception.Message);
- options.PrintHelp();
+ options.PrintHelp(Console.Out);
return;
}
if (options.Help) {
- options.PrintHelp();
+ options.PrintHelp(Console.Out);
return;
}
Please sign in to comment.
Something went wrong with that request. Please try again.