public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { try { var executionList = Setup(defaultTargetExpression); return(new ExecutionListRunner().Run(executionList)); } catch (AggregateException exception) { foreach (var innerException in exception.Flatten().InnerExceptions) { OutputSink.Error(innerException.Message, innerException.StackTrace); } return(-exception.Message.GetHashCode()); } catch (TargetInvocationException exception) { var innerException = exception.InnerException.NotNull(); OutputSink.Error(innerException.Message, innerException.StackTrace); return(-exception.Message.GetHashCode()); } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); return(-exception.Message.GetHashCode()); } }
public async Task ProjectReferences_Graph() { var graph = new TestProjectGraph(_tempDir); graph.OnCreate(p => p.WithTargetFrameworks("net45")); var matches = Regex.Matches(@" A->B B->C C->D D->E B->E A->F F->G G->E F->E W->U Y->Z Y->B Y->F", @"(\w)->(\w)"); Assert.Equal(13, matches.Count); foreach (Match m in matches) { var target = graph.GetOrCreate(m.Groups[2].Value); graph.GetOrCreate(m.Groups[1].Value).WithProjectReference(target); } var a = graph.Find("A"); Assert.NotNull(a); a !.WithProjectReference(graph.Find("W"), watch: false); var output = new OutputSink(); var filesetFactory = new MsBuildFileSetFactory(_reporter, DotNetWatchOptions.Default, graph.GetOrCreate("A").Path, output, trace: true); var fileset = await GetFileSet(filesetFactory); _reporter.Output(string.Join( Environment.NewLine, output.Current.Lines.Select(l => "Sink output: " + l))); var includedProjects = new[] { "A", "B", "C", "D", "E", "F", "G" }; AssertEx.EqualFileList( _tempDir.Root, includedProjects .Select(p => $"{p}/{p}.csproj"), fileset ); // ensure unreachable projects exist but where not included Assert.NotNull(graph.Find("W")); Assert.NotNull(graph.Find("U")); Assert.NotNull(graph.Find("Y")); Assert.NotNull(graph.Find("Z")); // ensure each project is only visited once for collecting watch items Assert.All(includedProjects, projectName => Assert.Single(output.Current.Lines, line => line.Contains($"Collecting watch items from '{projectName}'")) ); }
/// <summary> /// Create a REPL-ready interpreter using a given /// module object, interior scope, and sink. /// </summary> /// <param name="obj"> /// Module object /// </param> /// <param name="localScope"> /// Interior scope which holds (at least) "self". /// </param> /// <param name="sink"> /// Output sink for this interpreter. /// </param> public static Interpreter CreateInterpreter(UserObject obj, LocalScope localScope, OutputSink sink) { var interp = new Interpreter(sink); configureInterpreter(interp, obj, localScope); return(interp); }
private static IReadOnlyCollection <TargetDefinition> Setup <T> (Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { var build = (T)FormatterServices.GetUninitializedObject(typeof(T)); NukeBuild.Instance = build; var constructors = typeof(T).GetConstructors(); ControlFlow.Assert(constructors.Length == 1 && constructors.Single().GetParameters().Length == 0, $"Type '{typeof(T).Name}' must declare a single parameterless constructor."); constructors.Single().Invoke(build, new object[0]); PrintLogo(); InjectionService.InjectValues(build); OutputSink.Instance = OutputSink.GetOutputSink(build.Host); Logger.Log(); //{ // Console.WriteLine($"Target: {build.Target.Join(", ")}"); // Console.WriteLine($"Verbosity: {build.Verbosity}"); // Console.WriteLine($"LogLevel: {build.LogLevel}"); // Console.WriteLine($"NoDependencies: {build.NoDependencies}"); // Console.WriteLine($"Configuration: {build.Configuration}"); //} var defaultTargetFactory = defaultTargetExpression.Compile().Invoke(build); if (build.Help != null) { if (build.Help.Length == 0 || build.Help.Any(x => "targets".StartsWithOrdinalIgnoreCase(x))) { Logger.Log(GetTargetsText(build, defaultTargetFactory)); } if (build.Help.Length == 0 || build.Help.Any(x => "parameters".StartsWithOrdinalIgnoreCase(x))) { Logger.Log(GetParametersText(build, defaultTargetFactory)); } } if (build.Graph) { ShowGraph(build, defaultTargetFactory); } if (build.Help != null || build.Graph) { Environment.Exit(exitCode: 0); } var executionList = TargetDefinitionLoader.GetExecutionList(build, defaultTargetFactory); RequirementService.ValidateRequirements(executionList, build); return(executionList); }
/// <summary>A default interpreter</summary> public Interpreter() { sink = new StdoutOutputSinkWrapper(); ErrorReporting.SetSink(new StderrOutputSinkWrapper()); if (JSIL) { ErrorReporting.SetSink(sink); } initialise(); }
public async Task <bool> DumpLogcatToFile(string filePath) { var runner = CreateAdbRunner(); runner.AddArgument("logcat"); runner.AddArgument("-d"); using (var outputSink = new OutputSink(filePath)) { runner.AddStandardOutputSink(outputSink); return(await RunAdb(runner, setupOutputSink : false)); } }
static void Main(string[] args) { var customer1 = new Customer(); var customer2 = new Customer(); var customer1OutputSink = new OutputSink(); var customer2OutputSink = new OutputSink(); using (var bindingManager = new BindingManager()) { var useFluentInterface = false; if (!useFluentInterface) { //add various bindings to the binding manager AddSimpleBinding(customer1, customer2, bindingManager); AddSimpleTypedBinding(customer1, customer2, bindingManager); AddComplexBinding(customer1, customer2, bindingManager); AddComplexTypedBinding(customer1, customer2, bindingManager); AddSimpleMultiBinding(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBinding(customer2, customer2OutputSink, bindingManager); } else { //add various bindings to the binding manager using the fluent interface AddSimpleBindingFluent(customer1, customer2, bindingManager); AddSimpleTypedBindingFluent(customer1, customer2, bindingManager); AddComplexBindingFluent(customer1, customer2, bindingManager); AddComplexTypedBindingFluent(customer1, customer2, bindingManager); AddSimpleMultiBindingFluent(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBindingFluent(customer2, customer2OutputSink, bindingManager); } //make some property changes customer1.Name = "Kent"; customer2.Gender = Gender.Male; customer2.Address.Line1 = "12 Somewhere Lodge"; customer2.Address.Line2 = "Northwich"; } //output the details of each Customer object OutputCustomer("Customer 1", customer1); OutputCustomer("Customer 2", customer2); //output the details of each output sink Console.WriteLine("Customer 1 Output Sink: {0}", customer1OutputSink.Output); Console.WriteLine("Customer 2 Output Sink: {0}", customer2OutputSink.Output); Console.WriteLine("Any key to exit"); Console.ReadKey(); }
static void Main(string[] args) { var customer1 = new Customer(); var customer2 = new Customer(); var customer1OutputSink = new OutputSink(); var customer2OutputSink = new OutputSink(); using (var bindingManager = new BindingManager()) { var useFluentInterface = false; if (!useFluentInterface) { //add various bindings to the binding manager AddSimpleBinding(customer1, customer2, bindingManager); AddSimpleTypedBinding(customer1, customer2, bindingManager); AddComplexBinding(customer1, customer2, bindingManager); AddComplexTypedBinding(customer1, customer2, bindingManager); AddSimpleMultiBinding(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBinding(customer2, customer2OutputSink, bindingManager); } else { //add various bindings to the binding manager using the fluent interface AddSimpleBindingFluent(customer1, customer2, bindingManager); AddSimpleTypedBindingFluent(customer1, customer2, bindingManager); AddComplexBindingFluent(customer1, customer2, bindingManager); AddComplexTypedBindingFluent(customer1, customer2, bindingManager); AddSimpleMultiBindingFluent(customer1, customer1OutputSink, bindingManager); AddSimpleTypedMultiBindingFluent(customer2, customer2OutputSink, bindingManager); } //make some property changes customer1.Name = "Kent"; customer2.Gender = Gender.Male; customer2.Address.Line1 = "12 Somewhere Lodge"; customer2.Address.Line2 = "Northwich"; } //output the details of each Customer object OutputCustomer("Customer 1", customer1); OutputCustomer("Customer 2", customer2); //output the details of each output sink Console.WriteLine("Customer 1 Output Sink: {0}", customer1OutputSink.Output); Console.WriteLine("Customer 2 Output Sink: {0}", customer2OutputSink.Output); Console.WriteLine("Any key to exit"); Console.ReadKey(); }
public static int Execute <T> (Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { try { var executionList = Setup(defaultTargetExpression); return(new ExecutionListRunner().Run(executionList)); } catch (Exception ex) { OutputSink.Fail(ex.Message, ex.StackTrace); return(-ex.Message.GetHashCode()); } }
public static int Execute <T>(Expression <Func <T, Target> > defaultTargetExpression) where T : NukeBuild { Logger.Log(FigletTransform.GetText("NUKE")); Logger.Log($"Version: {typeof(BuildExecutor).GetTypeInfo().Assembly.GetVersionText()}"); Logger.Log($"Host: {EnvironmentInfo.HostType}"); Logger.Log(); var executionList = default(IReadOnlyCollection <TargetDefinition>); try { var build = CreateBuildInstance(defaultTargetExpression); InjectionService.InjectValues(build); HandleEarlyExits(build); executionList = TargetDefinitionLoader.GetExecutingTargets(build); RequirementService.ValidateRequirements(executionList, build); Execute(executionList); return(0); } catch (AggregateException exception) { foreach (var innerException in exception.Flatten().InnerExceptions) { OutputSink.Error(innerException.Message, innerException.StackTrace); } return(-exception.Message.GetHashCode()); } catch (TargetInvocationException exception) { var innerException = exception.InnerException.NotNull(); OutputSink.Error(innerException.Message, innerException.StackTrace); return(-exception.Message.GetHashCode()); } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); return(-exception.Message.GetHashCode()); } finally { if (executionList != null) { OutputSink.WriteSummary(executionList); } } }
public void TestOutputOverwritingWithoutClobber() { this.TestFiles.AddEmptyFile("output.txt"); var sink = new OutputSink( this.BuildLogger <OutputSink>(), new EmuGlobalOptions() { Output = "output.txt", }, this.TestFiles); var action = () => sink.Create(); action.Should().Throw <InvalidOperationException>() .WithMessage("File exists and clobber not specified"); }
public void TestOutput() { this.TestFiles.AddDirectory("/abc"); this.TestFiles.Directory.SetCurrentDirectory(this.ResolvePath("/abc")); var sink = new OutputSink( this.BuildLogger <OutputSink>(), new EmuGlobalOptions() { Output = "output.txt", }, this.TestFiles); sink.Create(); // relative paths should resolve to the current working directory this.TestFiles.FileExists("/abc/output.txt").Should().BeTrue(); }
public int Run(IReadOnlyCollection <TargetDefinition> executionList) { foreach (var target in executionList) { if (target.Factory == null) { target.Status = ExecutionStatus.Absent; continue; } if (target.Conditions.Any(x => !x())) { target.Status = ExecutionStatus.Skipped; continue; } using (Logger.Block(target.Name)) { var stopwatch = Stopwatch.StartNew(); try { target.Actions.ForEach(x => x()); target.Duration = stopwatch.Elapsed; target.Status = ExecutionStatus.Executed; } catch (Exception exception) { OutputSink.Error(exception.Message, exception.StackTrace); target.Status = ExecutionStatus.Failed; break; } finally { target.Duration = stopwatch.Elapsed; } } } OutputSink.WriteSummary(executionList); return(-executionList.Count(x => x.Status == ExecutionStatus.Failed)); }
private static void AddSimpleMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent MultiBinding bindingManager.MultiBind(outputSink, "Output") .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, "Name") .AndTo(customer, "Gender") .AndTo(customer, "BirthDate") .AndTo(customer, "Address.Line1") .AndTo(customer, "Address.Line2") .AndTo(customer, "Address.Line3") .AndTo(customer, "Address.Line4") .AndTo(customer, "Address.PostCode") .Activate(); #endregion }
private static void AddSimpleTypedMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent TypedMultiBinding bindingManager.MultiBind(outputSink, o => o.Output) .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, c => c.Name) .AndTo(customer, c => c.Gender) .AndTo(customer, c => c.BirthDate) .AndTo(customer, c => c.Address.Line1) .AndTo(customer, c => c.Address.Line2) .AndTo(customer, c => c.Address.Line3) .AndTo(customer, c => c.Address.Line4) .AndTo(customer, c => c.Address.PostCode) .Activate(); #endregion }
public async Task ProjectReferences_Graph() { // A->B,F,W(Watch=False) // B->C,E // C->D // D->E // F->E,G // G->E // W->U // Y->B,F,Z var testDirectory = _testAssets.CopyTestAsset("ProjectReferences_Graph") .WithSource() .Path; var projectA = Path.Combine(testDirectory, "A", "A.csproj"); var output = new OutputSink(); var options = GetWatchOptions(); var filesetFactory = new MsBuildFileSetFactory(options, _reporter, projectA, output, waitOnError: false, trace: true); var fileset = await GetFileSet(filesetFactory); Assert.NotNull(fileset); _reporter.Output(string.Join( Environment.NewLine, output.Current.Lines.Select(l => "Sink output: " + l))); var includedProjects = new[] { "A", "B", "C", "D", "E", "F", "G" }; AssertEx.EqualFileList( testDirectory, includedProjects .Select(p => $"{p}/{p}.csproj"), fileset ); // ensure each project is only visited once for collecting watch items Assert.All(includedProjects, projectName => Assert.Single(output.Current.Lines, line => line.Contains($"Collecting watch items from '{projectName}'")) ); }
private static void AddSimpleMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple MultiBinding var binding = new MultiBinding(outputSink, "Output"); binding.Sources.Add(new Binding(null, null, customer, "Name")); binding.Sources.Add(new Binding(null, null, customer, "Gender")); binding.Sources.Add(new Binding(null, null, customer, "BirthDate")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line1")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line2")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line3")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line4")); binding.Sources.Add(new Binding(null, null, customer, "Address.PostCode")); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }
public void TestOutputOverwriting() { this.TestFiles.AddEmptyFile("output.txt"); var sink = new OutputSink( this.BuildLogger <OutputSink>(), new EmuGlobalOptions() { Output = "output.txt", Clobber = true, }, this.TestFiles); sink.Create(); this.TestFiles.FileExists("/output.txt").Should().BeTrue(); var expectedPath = this.ResolvePath("/output.txt"); this.Loggers.Single().Entries.Single().Message.Should().Be($"Overwriting {expectedPath} because --clobber was specified"); }
private static void AddSimpleTypedMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple TypedMultiBinding var binding = new TypedMultiBinding <OutputSink>(outputSink, o => o.Output); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Name)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Gender)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.BirthDate)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Address.Line1)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Address.Line2)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Address.Line3)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Address.Line4)); binding.Sources.Add(new TypedBinding <object, Customer>(null, null, customer, c => c.Address.PostCode)); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }
public void TestOutputIntermediateDirectoryCreation() { var sink = new OutputSink( this.BuildLogger <OutputSink>(), new EmuGlobalOptions() { Output = "/subdir/anotherdir/output.txt", }, this.TestFiles); var beforeDirs = this.TestFiles.AllDirectories; sink.Create(); var afterDirs = beforeDirs.Concat(new[] { "/subdir", "/subdir/anotherdir", }).Select(this.ResolvePath); this.TestFiles.AllDirectories.Should().Equal(afterDirs); }
private static void AddSimpleTypedMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent TypedMultiBinding bindingManager.MultiBind(outputSink, o => o.Output) .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, c => c.Name) .AndTo(customer, c => c.Gender) .AndTo(customer, c => c.BirthDate) .AndTo(customer, c => c.Address.Line1) .AndTo(customer, c => c.Address.Line2) .AndTo(customer, c => c.Address.Line3) .AndTo(customer, c => c.Address.Line4) .AndTo(customer, c => c.Address.PostCode) .Activate(); #endregion }
/// <summary> /// Logs a message as Success. /// </summary> public static void Success(string text = null) { OutputSink.Success(text ?? string.Empty); }
/// <summary> /// Logs a message unconditionally. /// </summary> public static void Log(string text = null) { OutputSink.Write(text ?? string.Empty); }
/// <summary> /// Logs a message as trace if <see cref="NukeBuild.LogLevel"/> is greater or equal to <see cref="LogLevel.Trace"/>. /// </summary> public static void Trace(string text = null) { OutputSink.Trace(text ?? string.Empty); }
/// <summary> /// Logs a message as error. /// </summary> public static void Error(string text = null) { OutputSink.Error(text ?? string.Empty); }
/// <summary> /// Provides a logging block for better readability. The actual output is dependent on the executing environment. /// <ul> /// <li><b>Console:</b> logs message with figlet font <em>cybermedium</em></li> /// <li><b>TeamCity:</b> calls <see cref="TeamCity.OpenBlock"/> and <see cref="TeamCity.CloseBlock"/></li> /// <li><b>Bitrise:</b> logs message with figlet font <em>ansi-shadow</em></li> /// </ul> /// </summary> /// <returns> /// Returns an <see cref="IDisposable"/> which will automatically end the block. /// </returns> public static IDisposable Block(string text) { return(OutputSink.WriteBlock(text)); }
/// <summary> /// Logs a message as information if <see cref="NukeBuild.LogLevel"/> is greater or equal to <see cref="LogLevel.Information"/>. /// </summary> public static void Info(string text = null) { OutputSink.Info(text ?? string.Empty); }
/// <summary> /// Logs a message as warning if <see cref="NukeBuild.LogLevel"/> is greater or equal to <see cref="LogLevel.Warning"/>. /// </summary> public static void Warn(string text = null) { OutputSink.Warn(text ?? string.Empty); }
private static void AddSimpleTypedMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple TypedMultiBinding var binding = new TypedMultiBinding<OutputSink>(outputSink, o => o.Output); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Name)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Gender)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.BirthDate)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line1)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line2)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line3)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.Line4)); binding.Sources.Add(new TypedBinding<object, Customer>(null, null, customer, c => c.Address.PostCode)); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }
/// <summary> /// Set the sink where error messages will be written. /// </summary> /// <param name="s">Destination for error messages</param> public static void SetSink(OutputSink s) { sink = s; }
private static void AddSimpleMultiBindingFluent(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple Fluent MultiBinding bindingManager.MultiBind(outputSink, "Output") .WithConverter(new OutputConverter()) .OneWayToTarget() .To(customer, "Name") .AndTo(customer, "Gender") .AndTo(customer, "BirthDate") .AndTo(customer, "Address.Line1") .AndTo(customer, "Address.Line2") .AndTo(customer, "Address.Line3") .AndTo(customer, "Address.Line4") .AndTo(customer, "Address.PostCode") .Activate(); #endregion }
/// <param name="s">Destination for error messages</param> public Interpreter(OutputSink s) { sink = s; ErrorReporting.SetSink(s); initialise(); }
private static void AddSimpleMultiBinding(Customer customer, OutputSink outputSink, BindingManager bindingManager) { #region Simple MultiBinding var binding = new MultiBinding(outputSink, "Output"); binding.Sources.Add(new Binding(null, null, customer, "Name")); binding.Sources.Add(new Binding(null, null, customer, "Gender")); binding.Sources.Add(new Binding(null, null, customer, "BirthDate")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line1")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line2")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line3")); binding.Sources.Add(new Binding(null, null, customer, "Address.Line4")); binding.Sources.Add(new Binding(null, null, customer, "Address.PostCode")); binding.Mode = BindingMode.OneWayToTarget; binding.Converter = new OutputConverter(); bindingManager.Bindings.Add(binding); #endregion }