ProcessStartInfo StartInfoFrom(ProcessSettings settings)
		{
			var startInfo = new ProcessStartInfo(MonoExecutable, settings.Executable);
			startInfo.WorkingDirectory = settings.Executable.Parent;
			startInfo.WindowStyle = ProcessWindowStyle.Hidden;
			startInfo.UseShellExecute = false;
			foreach (var variable in settings.EnvironmentVariables)
				startInfo.EnvironmentVariables.Add(variable.Key, variable.Value);
			return startInfo;
		}
        /// <summary>
        /// Runs the tool using the specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        public override void Run(CMakeBuildSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (settings.BinaryPath == null)
            {
                throw new ArgumentNullException(nameof(settings.BinaryPath));
            }

            var binaryPath = settings.BinaryPath.MakeAbsolute(_environment);

            // Create the process settings.
            var processSettings = new ProcessSettings
            {
                WorkingDirectory = binaryPath
            };

            this.Run(settings, this.GetArguments(settings), processSettings, null);
        }
        /// <summary>
        /// Runs Git with specified settings.
        /// </summary>
        /// <param name="settings">Settings for running Git.</param>
        /// <returns>Output of command.</returns>
        public IEnumerable <string> RunCommand(GitRunnerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var args = new ProcessArgumentBuilder();

            settings.Evaluate(args);

            var processSettings = new ProcessSettings
            {
                WorkingDirectory       = settings.WorkingDirectory,
                Arguments              = args.Render(),
                RedirectStandardOutput = true,
            };

            var currentEncoding = Console.OutputEncoding;

            Console.OutputEncoding = Encoding.UTF8;
            try
            {
                IEnumerable <string> result = null;
                this.Run(
                    settings,
                    null,
                    processSettings,
                    process =>
                {
                    result = process.GetStandardOutput();
                });
                return(result?.ToList());
            }
            finally
            {
                Console.OutputEncoding = currentEncoding;
            }
        }
Exemple #4
0
    /// <summary>
    /// Runs the specified settings.
    /// </summary>
    /// <param name="settings">The settings.</param>
    /// <exception cref="ArgumentNullException">settings.</exception>
    public void Run(SevenZipSettings settings)
    {
        if (settings == null)
        {
            throw new ArgumentNullException(nameof(settings));
        }

        var procSettings = new ProcessSettings
        {
            RedirectStandardOutput = true,
        };

        void AfterRun(IProcess p)
        {
            if (settings.Command is ICanParseOutput parseOutput)
            {
                parseOutput.SetRawOutput(p.GetStandardOutput());
            }
        }

        Run(settings, GetArguments(settings), procSettings, AfterRun);
    }
Exemple #5
0
        /// <summary>
        /// Executes the specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <returns>Returns the <see cref="NodeState"/> of the specified host</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when the settings are null</exception>
        /// <exception cref="CakeException">Required setting HostName not specified.</exception>
        public NodeState Execute(GetNodeStateSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (string.IsNullOrEmpty(settings.HostName))
            {
                throw new CakeException("Required setting HostName not specified.");
            }

            var builder = new ProcessArgumentBuilder();

            builder.Append("GetNodeState");
            builder.Append("--NonInteractive");

            builder.Append("-Hostname");
            builder.Append(settings.HostName);

            var processSettings = new ProcessSettings {
                RedirectStandardOutput = true
            };

            var result = NodeState.Unknown;
            Action <IProcess> postProcessor = process =>
            {
                var lines = process.GetStandardOutput()?.ToList();
                if (lines != null && lines.Any())
                {
                    result = ParseResults(lines);
                }
            };

            this.Run(settings, builder, processSettings, postProcessor);

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// Lists available packages with their versions
        /// </summary>
        /// <param name="packageId">The source package id. If it equals an empty string, it will match all packageIds</param>
        /// <param name="settings">The settings</param>
        /// <returns>A list of available packages</returns>
        public IEnumerable <NuGetListItem> List(string packageId, NuGetListSettings settings)
        {
            if (packageId == null)
            {
                throw new ArgumentNullException(nameof(packageId));
            }
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var processSettings = new ProcessSettings
            {
                RedirectStandardOutput = true
            };

            IEnumerable <string> result = null;

            Run(settings, GetHasArguments(packageId, settings), processSettings,
                process => result = process.GetStandardOutput());

            return(result.Select(line => ConvertToNuGetListItem(line)).ToList());
        }
Exemple #7
0
        /// <summary>
        /// Process the type with the provided settings.
        /// </summary>
        /// <param name="input"> The input to process. </param>
        /// <param name="settings"> The settings to configure the process. </param>
        /// <returns> The result of the type processing. </returns>
        public string Process(string input, ProcessSettings settings)
        {
            switch (settings.Method)
            {
            case ProcessMethod.Trim:
                return(input.Trim());

            case ProcessMethod.TrimLeft:
                return(input.TrimStart());

            case ProcessMethod.TrimRight:
                return(input.TrimEnd());

            case ProcessMethod.LowerCase:
                return(input.ToLower());

            case ProcessMethod.UpperCase:
                return(input.ToUpper());

            default:
                throw new NotImplementedException();
            }
        }
        public static void UnityBuild(this ICakeContext context, Action <BuildSettings> buildSettingsAction)
        {
            var buildSettings = new BuildSettings();

            buildSettingsAction(buildSettings);

            var valid = buildSettings.ValidateArguments(context);

            if (!valid)
            {
                throw new Exception("Invalid build settings");
            }

            var processArguments = buildSettings.GetProcessArguments(context);

            var runner   = new ProcessRunner(context.Environment, context.Log);
            var settings = new ProcessSettings {
                Arguments = processArguments
            };
            var process = runner.Start(buildSettings.Unity, settings);

            process.WaitForExit();
        }
Exemple #9
0
        /// <summary>
        /// Runs the tool using a custom tool path and the specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="toolPath">The tool path to use.</param>
        /// <param name="processSettings">The process settings.</param>
        /// <param name="postAction">If specified called after process exit.</param>
        protected void Run(TSettings settings, ProcessArgumentBuilder arguments, FilePath toolPath,
                           ProcessSettings processSettings, Action <IProcess> postAction)
        {
            if (arguments == null && (processSettings?.Arguments == null))
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            var process = RunProcess(settings, arguments, toolPath, processSettings);

            // Wait for the process to exit.
            process.WaitForExit();

            // Post action specified?
            postAction?.Invoke(process);

            // Did an error occur?
            if (process.GetExitCode() != 0)
            {
                const string message = "{0}: Process returned an error (exit code {1}).";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, GetToolName(), process.GetExitCode()));
            }
        }
Exemple #10
0
        /// <summary>
        /// Execute an assembly using arguments and settings.
        /// </summary>
        /// <param name="projectPath">The target project path.</param>
        /// <param name="command">The command to execute.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="settings">The settings.</param>
        public void Execute(FilePath projectPath, string command, ProcessArgumentBuilder arguments, DotNetCoreToolSettings settings)
        {
            if (projectPath == null)
            {
                throw new ArgumentNullException(nameof(projectPath));
            }

            if (string.IsNullOrWhiteSpace(command))
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            var processSettings = new ProcessSettings();

            processSettings.WorkingDirectory = projectPath.GetDirectory();

            RunCommand(settings, GetArguments(command, arguments, settings), processSettings);
        }
        public ProcessRunnerFixture(bool windows = false)
        {
            var environment = windows
                ? FakeEnvironment.CreateWindowsEnvironment()
                : FakeEnvironment.CreateUnixEnvironment();

            environment.WorkingDirectory = "/Working";

            Environment     = environment;
            FileSystem      = new FakeFileSystem(Environment);
            Log             = Substitute.For <ICakeLog>();
            Tools           = Substitute.For <IToolLocator>();
            Configuration   = Substitute.For <ICakeConfiguration>();
            ProcessFilePath = "/Program Files/Cake.exe";
            ProcessSettings = new ProcessSettings();

            FileSystem.CreateDirectory("/Working");
            FileSystem.CreateDirectory("/Program Files");
            FileSystem.CreateFile("/Program Files/Cake.exe", ClrAssemblyData);
            MonoFile = FileSystem.CreateFile("/Program Files/mono.exe", NonClrAssemblyData);

            Tools.Resolve("mono").Returns(file => MonoFile.Exists ? MonoFile.Path : null);
        }
Exemple #12
0
        /// <summary>
        /// Runs the tool using a custom tool path and the specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="processSettings">The process settings.</param>
        /// <param name="postAction">If specified called after process exit.</param>
        protected void Run(
            TSettings settings,
            ProcessArgumentBuilder arguments,
            ProcessSettings processSettings,
            Action <IProcess> postAction)
        {
            if (arguments == null && (processSettings?.Arguments == null))
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            var process = RunProcess(settings, arguments, processSettings);

            // Wait for the process to exit.
            if (settings.ToolTimeout.HasValue)
            {
                if (!process.WaitForExit((int)settings.ToolTimeout.Value.TotalMilliseconds))
                {
                    const string message = "Tool timeout ({0}): {1}";
                    throw new TimeoutException(string.Format(CultureInfo.InvariantCulture, message, settings.ToolTimeout.Value, GetToolName()));
                }
            }
            else
            {
                process.WaitForExit();
            }

            // Post action specified?
            (postAction ?? settings.PostAction)?.Invoke(process);

            var exitCode = process.GetExitCode();

            if (!settings.HandleExitCode?.Invoke(exitCode) ?? true)
            {
                ProcessExitCode(process.GetExitCode());
            }
        }
        public void Run(TerraformShowSettings settings)
        {
            if (settings.PlanFile == null)
            {
                throw new ArgumentNullException(nameof(settings.PlanFile));
            }

            var arguments = new ProcessArgumentBuilder()
                            .Append("show")
                            .Append(settings.PlanFile.FullPath);

            if (settings.OutputFormat == OutputFormat.PlainText)
            {
                arguments.Append("-no-color");
            }

            var processSettings = new ProcessSettings();

            if (settings.OutFile != null)
            {
                processSettings.RedirectStandardOutput = true;
            }

            Run(settings, arguments, processSettings, x =>
            {
                if (settings.OutFile != null)
                {
                    OutputFormatter formatter;
                    if (!_formatters.TryGetValue(settings.OutputFormat, out formatter))
                    {
                        formatter = _formatters[OutputFormat.PlainText];
                    }

                    File.WriteAllText(settings.OutFile.FullPath, formatter.FormatLines(x.GetStandardOutput()));
                }
            });
        }
        protected T Run <T>(TSettings settings, ProcessArgumentBuilder builder, Func <XDocument, T> deserializer)
        {
            T result           = default(T);
            ProcessSettings ps = new ProcessSettings {
                RedirectStandardOutput = true,
            };

            if (Log.Verbosity != Verbosity.Diagnostic)
            {
                Log.Debug(Verbosity.Verbose, "Calling plastic with parameters: {0}", builder.RenderSafe());
            }
            Run(settings, builder, ps, (process) =>
            {
                var stdout = process.GetStandardOutput().ToList();

                if (settings.ForcePrintingToLog && Log.Verbosity != Verbosity.Diagnostic)
                {
                    PrintToStdout(stdout);
                }
                result = DeserializeXmlResponse(process, stdout, deserializer);
            });

            return(result);
        }
Exemple #15
0
        public List <string> Run(TerraformEnvListSettings settings)
        {
            var builder =
                new ProcessArgumentBuilder()
                .Append("workspace")
                .Append("list");

            var processSettings = new ProcessSettings
            {
                RedirectStandardOutput = true
            };

            var result = new List <string>();

            this.Run(settings, builder, processSettings, x =>
            {
                result = x.GetStandardOutput()
                         .Select(env => env.Replace("*", "").Trim())
                         .Where(env => !string.IsNullOrWhiteSpace(env))
                         .ToList();
            });

            return(result);
        }
Exemple #16
0
            public void Should_Return_Settings_With_Correct_Arguments(string value, string expected)
            {
                var settings = new ProcessSettings().WithArguments(args => { args.Append(value); });

                Assert.Equal(expected, settings.Arguments.Render());
            }
Exemple #17
0
 public MoCSValidationProcess(ProcessSettings settings, IFileSystem fileSystem)
     : base(settings, fileSystem)
 {
     InitializeProcesses();
 }
Exemple #18
0
 /// <summary>
 /// Initializes a new instance of the ContinuousIntegrationClientProcess for testing purposes
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="fileSystem"></param>
 public MoCSValidationProcess(ProcessSettings settings, IFileSystem fileSystem, List <BaseProcess> processes) : base(settings, fileSystem)
 {
     _processes = processes;
     InitializeProcesses();
 }
		public IProcess StartManagedProcess(ProcessSettings settings)
		{
			return new StandardProcess(Process.Start(StartInfoFrom(settings)));
		}
Exemple #20
0
        /// <summary><p>ReportGenerator converts XML reports generated by OpenCover, PartCover, dotCover, Visual Studio, NCover or Cobertura into human readable reports in various formats.</p><p>The reports do not only show the coverage quota, but also include the source code and visualize which lines have been covered.</p><p>ReportGenerator supports merging several reports into one. It is also possible to pass one XML file containing several reports to ReportGenerator (e.g. a build log file).</p><p>The following <a href="https://github.com/danielpalme/ReportGenerator/wiki/Output-formats">output formats</a> are supported by ReportGenerator:<ul><li>HTML, HTMLSummary, HTMLInline, HTMLChart, <a href="https://en.wikipedia.org/wiki/MHTML">MHTML</a></li><li>XML, XMLSummary</li><li>Latex, LatexSummary</li><li>TextSummary</li><li>CsvSummary</li><li>PngChart</li><li>Badges</li><li><a href="https://github.com/danielpalme/ReportGenerator/wiki/Custom-reports">Custom reports</a></li></ul></p><p>Compatibility:<ul><li><a href="https://github.com/OpenCover/opencover">OpenCover</a></li><li><a href="https://github.com/sawilde/partcover.net4">PartCover 4.0</a></li><li><a href="http://sourceforge.net/projects/partcover">PartCover 2.2, 2.3</a></li><li><a href="https://www.jetbrains.com/dotcover/help/dotCover__Console_Runner_Commands.html">dotCover</a> (/ReportType=DetailedXML)</li><li>Visual Studio (<a href="https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#vstestconsoleexe">vstest.console.exe</a>, <a href="https://github.com/danielpalme/ReportGenerator/wiki/Visual-Studio-Coverage-Tools#codecoverageexe">CodeCoverage.exe</a>)</li><li><a href="http://www.ncover.com/download/current">NCover</a> (tested version 1.5.8, other versions may not work)</li><li><a href="https://github.com/cobertura/cobertura">Cobertura</a></li><li>Mono (<a href="http://www.mono-project.com/docs/debug+profile/profile/profiler/#analyzing-the-profile-data">mprof-report</a>)</li></ul></p><p>For more details, visit the <a href="https://github.com/danielpalme/ReportGenerator">official website</a>.</p></summary>
        public static void ReportGenerator(Configure <ReportGeneratorSettings> configurator = null, ProcessSettings processSettings = null)
        {
            var toolSettings = configurator.InvokeSafe(new ReportGeneratorSettings());

            PreProcess(toolSettings);
            var process = ProcessTasks.StartProcess(toolSettings, processSettings);

            process.AssertZeroExitCode();
            PostProcess(toolSettings);
        }
Exemple #21
0
        /// <summary>
        /// Runs the tool using a custom tool path and the specified settings.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="processSettings">The process settings.</param>
        /// <returns>The process that the tool is running under.</returns>
        protected IProcess RunProcess(
            TSettings settings,
            ProcessArgumentBuilder arguments,
            ProcessSettings processSettings)
        {
            if (arguments == null && (processSettings?.Arguments == null))
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            // Should we customize the arguments?
            if (settings.ArgumentCustomization != null)
            {
                arguments = settings.ArgumentCustomization(arguments);
            }

            // Get the tool name.
            var toolName = GetToolName();

            // Get the tool path.
            var toolPath = GetToolPath(settings);

            if (toolPath == null || !_fileSystem.Exist(toolPath))
            {
                const string message = "{0}: Could not locate executable.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }

            // Get the working directory.
            var workingDirectory = GetWorkingDirectory(settings);

            if (workingDirectory == null)
            {
                const string message = "{0}: Could not resolve working directory.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }

            // Create the process start info.
            var info = processSettings ?? new ProcessSettings();

            if (info.Arguments == null)
            {
                info.Arguments = arguments;
            }
            if (info.WorkingDirectory == null)
            {
                info.WorkingDirectory = workingDirectory.MakeAbsolute(_environment).FullPath;
            }
            if (info.EnvironmentVariables == null)
            {
                info.EnvironmentVariables = GetEnvironmentVariables(settings);
            }

            // Want to opt out of using a working directory?
            info.NoWorkingDirectory = settings.NoWorkingDirectory;

            // Configure process settings
            settings.SetupProcessSettings?.Invoke(info);

            // Run the process.
            var process = _processRunner.Start(toolPath, info);

            if (process == null)
            {
                const string message = "{0}: Process was not started.";
                throw new CakeException(string.Format(CultureInfo.InvariantCulture, message, toolName));
            }

            return(process);
        }
        /// <summary><p>One of ReSharper's most notable features, code inspection, is available even without opening Visual Studio. InspectCode, a free command line tool requires a minimum of one parameter- your solution file- to apply all of ReSharper's inspections.</p><p>For more details, visit the <a href="https://www.jetbrains.com/help/resharper/InspectCode.html/">official website</a>.</p></summary>
        public static void InspectCode(Configure <InspectCodeSettings> configurator = null, ProcessSettings processSettings = null)
        {
            var toolSettings = configurator.InvokeSafe(new InspectCodeSettings());

            PreProcess(toolSettings);
            var process = StartProcess(toolSettings, processSettings);

            process.AssertZeroExitCode();
            PostProcess(toolSettings);
        }
Exemple #23
0
            public void Should_Return_Settings_With_Correct_Timeout(int value, int expected)
            {
                var settings = new ProcessSettings().SetTimeout(value);

                Assert.Equal(expected, settings.Timeout);
            }
Exemple #24
0
            public void Should_Return_Settings_With_Correct_Directory(string value, string expected)
            {
                var settings = new ProcessSettings().UseWorkingDirectory(value);

                Assert.Equal(expected, settings.WorkingDirectory.FullPath);
            }
 /// <summary><p>One of ReSharper's most notable features, code inspection, is available even without opening Visual Studio. InspectCode, a free command line tool requires a minimum of one parameter- your solution file- to apply all of ReSharper's inspections.</p><p>For more details, visit the <a href="https://www.jetbrains.com/help/resharper/InspectCode.html/">official website</a>.</p></summary>
 public static void InspectCode(string targetPath, string output, Configure <InspectCodeSettings> configurator = null, ProcessSettings processSettings = null)
 {
     configurator = configurator ?? (x => x);
     InspectCode(targetPath, x => configurator(x).SetOutput(output));
 }
Exemple #26
0
            public void Should_Return_Settings_With_Correct_Output(bool value, bool expected)
            {
                var settings = new ProcessSettings().SetRedirectStandardOutput(value);

                Assert.Equal(expected, settings.RedirectStandardOutput);
            }
Exemple #27
0
 /// <summary>
 /// Process the type with the provided settings.
 /// </summary>
 /// <param name="input"> The input to process. </param>
 /// <param name="settings"> The settings to configure the process. </param>
 /// <returns> The result of the type processing. </returns>
 public TimeSpan Process(TimeSpan input, ProcessSettings settings)
 {
     return(input);
 }
Exemple #28
0
        /// <summary>
        /// Runs the dotnet cli command using the specified settings and arguments.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="arguments">The arguments.</param>
        /// <param name="processSettings">The processSettings.</param>
        protected void RunCommand(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings)
        {
            // add arguments common to all commands last
            AppendCommonArguments(arguments, settings);

            Run(settings, arguments, processSettings, null);
        }
Exemple #29
0
 public DateTime Process(DateTime input, ProcessSettings settings)
 {
     return(input);
 }
 /// <summary><p>One of ReSharper's most notable features, code inspection, is available even without opening Visual Studio. InspectCode, a free command line tool requires a minimum of one parameter- your solution file- to apply all of ReSharper's inspections.</p><p>For more details, visit the <a href="https://www.jetbrains.com/help/resharper/InspectCode.html/">official website</a>.</p></summary>
 public static void InspectCode(string targetPath, Configure <InspectCodeSettings> configurator = null, ProcessSettings processSettings = null)
 {
     configurator = configurator ?? (x => x);
     InspectCode(x => configurator(x).SetTargetPath(targetPath));
 }
 public ToolFixtureResult(FilePath toolPath, ProcessSettings process)
 {
     _toolPath = toolPath;
     _args = process.Arguments.Render();
     _process = process;
 }
Exemple #32
0
 protected override ToolFixtureResult CreateResult(FilePath path, ProcessSettings process)
 {
     return(new ToolFixtureResult(path, process));
 }
Exemple #33
0
        /// <summary><p>GitVersion is a tool to help you achieve Semantic Versioning on your project.</p><p>For more details, visit the <a href="http://gitversion.readthedocs.io/en/stable/">official website</a>.</p></summary>
        public static GitVersion GitVersion(Configure <GitVersionSettings> configurator = null, ProcessSettings processSettings = null)
        {
            var toolSettings = configurator.InvokeSafe(new GitVersionSettings());

            PreProcess(toolSettings);
            var process = ProcessTasks.StartProcess(toolSettings, processSettings);

            process.AssertZeroExitCode();
            PostProcess(toolSettings);
            return(GetResult(process, toolSettings, processSettings));
        }