예제 #1
0
 public static IProcess StartShell(
     string command,
     string workingDirectory = null,
     IReadOnlyDictionary <string, string> environmentVariables = null,
     int?timeout        = null,
     bool?logOutput     = null,
     bool?logInvocation = null,
     bool?logTimestamp  = null,
     string logFile     = null,
     Action <OutputType, string> customLogger = null,
     Func <string, string> outputFilter       = null)
 {
     return(StartProcess(
                toolPath: ToolPathResolver.GetPathExecutable(EnvironmentInfo.IsWin ? "cmd" : "bash"),
                arguments: $"{(EnvironmentInfo.IsWin ? "/c" : "-c")} {command.DoubleQuote()}",
                workingDirectory,
                environmentVariables,
                timeout,
                logOutput,
                logInvocation,
                logTimestamp,
                logFile,
                customLogger,
                outputFilter));
 }
예제 #2
0
        public virtual IProcess StartProcess(ToolSettings toolSettings)
        {
            var toolPath              = toolSettings.ToolPath;
            var arguments             = toolSettings.GetArguments();
            var argumentsForExecution = arguments.RenderForExecution();
            var argumentsForOutput    = arguments.RenderForOutput();

#if NETCORE
            if (EnvironmentInfo.IsUnix && toolPath.EndsWithOrdinalIgnoreCase(".exe"))
            {
                argumentsForExecution = $"{toolPath.DoubleQuoteIfNeeded()} {argumentsForExecution}".TrimEnd();
                argumentsForOutput    = $"{toolPath.DoubleQuoteIfNeeded()} {argumentsForOutput}".TrimEnd();
                toolPath = ToolPathResolver.GetPathExecutable("mono");
            }
#endif

            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {argumentsForOutput}");

            return(StartProcessInternal(
                       toolPath,
                       argumentsForExecution,
                       toolSettings.WorkingDirectory,
                       toolSettings.EnvironmentVariables,
                       toolSettings.ExecutionTimeout,
                       toolSettings.LogOutput,
                       toolSettings.LogLevelParser,
                       arguments.Filter));
        }
예제 #3
0
        public override object GetValue(MemberInfo member, object instance)
        {
            var toolPath = ToolPathResolver.TryGetEnvironmentExecutable($"{member.Name.ToUpperInvariant()}_EXE") ??
                           ToolPathResolver.GetPackageExecutable(_packageId, _packageExecutable, Framework);

            return(new Tool(new ToolExecutor(toolPath).Execute));
        }
예제 #4
0
        public virtual IProcess StartProcess(
            string toolPath,
            string arguments        = null,
            string workingDirectory = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout         = null,
            bool redirectOutput = false,
            Func <string, string> outputFilter = null)
        {
            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {arguments}");

            return(StartProcessInternal(toolPath,
                                        arguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        redirectOutput,
                                        outputFilter ?? (x => x)));
        }
예제 #5
0
        public override object GetValue(MemberInfo member, object instance)
        {
            var name     = _name ?? member.Name;
            var toolPath = ToolPathResolver.TryGetEnvironmentExecutable($"{name.ToUpperInvariant()}_EXE") ??
                           ToolPathResolver.GetPathExecutable(name);

            return(new Tool(new ToolExecutor(toolPath).Execute));
        }
예제 #6
0
        public static Tool TryGetEnvironmentTool(string name)
        {
            var toolPath = ToolPathResolver.TryGetEnvironmentExecutable($"{name.ToUpperInvariant()}_EXE");

            if (toolPath == null)
            {
                return(null);
            }

            return(new ToolExecutor(toolPath).Execute);
        }
예제 #7
0
        public virtual IProcess StartProcess(
            string toolPath,
            string executionArguments = null,
            string outputArguments    = null,
            string workingDirectory   = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout    = null,
            bool logOutput = true,
            Func <string, LogLevel> logLevelParser = null,
            Func <string, string> outputFilter     = null)
        {
            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

#if NETCORE
            string toolPathOverride = null;
            if (toolPath.EndsWith(".dll"))
            {
                toolPathOverride = ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE") ??
                                   ToolPathResolver.GetPathExecutable("dotnet");
            }
            else if (EnvironmentInfo.IsUnix && toolPath.EndsWithOrdinalIgnoreCase(".exe"))
            {
                toolPathOverride = ToolPathResolver.GetPathExecutable("mono");
            }

            if (!string.IsNullOrEmpty(toolPathOverride))
            {
                executionArguments = $"{toolPath.DoubleQuoteIfNeeded()} {executionArguments}".TrimEnd();
                outputArguments    = $"{toolPath.DoubleQuoteIfNeeded()} {outputArguments}".TrimEnd();
                toolPath           = toolPathOverride;
            }
#endif

            outputArguments = outputArguments ?? (outputFilter == null ? executionArguments : outputFilter(executionArguments));
            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {outputArguments}");

            return(StartProcessInternal(toolPath,
                                        executionArguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        logOutput,
                                        logLevelParser,
                                        outputFilter ?? (x => x)));
        }
예제 #8
0
        public static IProcess StartProcess(
            string toolPath,
            string arguments        = null,
            string workingDirectory = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout        = null,
            bool?logOutput     = null,
            bool?logInvocation = null,
            bool?logTimestamp  = null,
            string logFile     = null,
            Action <OutputType, string> customLogger = null,
            Func <string, string> outputFilter       = null)
        {
            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

            var toolPathOverride = GetToolPathOverride(toolPath);

            if (!string.IsNullOrEmpty(toolPathOverride))
            {
                arguments = $"{toolPath.DoubleQuoteIfNeeded()} {arguments}".TrimEnd();
                toolPath  = toolPathOverride;
            }

            outputFilter ??= x => x;
            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            if (logInvocation ?? DefaultLogInvocation)
            {
                Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {outputFilter(arguments)}");
                if (LogWorkingDirectory && workingDirectory != null)
                {
                    Logger.Info($"@ {workingDirectory}");
                }
            }

            return(StartProcessInternal(toolPath,
                                        arguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        logTimestamp ?? DefaultLogTimestamp,
                                        logFile,
                                        logOutput ?? DefaultLogOutput
                    ? customLogger ?? DefaultLogger
                    : null,
                                        outputFilter));
        }
예제 #9
0
        public static IProcess StartProcess(
            string toolPath,
            string arguments        = null,
            string workingDirectory = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout        = null,
            bool?logOutput     = null,
            bool?logInvocation = null,
            Action <OutputType, string> customLogger = null,
            Func <string, string> outputFilter       = null)
        {
            Assert.True(toolPath != null);
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

            var toolPathOverride = GetToolPathOverride(toolPath);

            if (!string.IsNullOrEmpty(toolPathOverride))
            {
                arguments = $"{toolPath.DoubleQuoteIfNeeded()} {arguments}".TrimEnd();
                toolPath  = toolPathOverride;
            }

            outputFilter ??= x => x;
            Assert.FileExists(toolPath);
            if (logInvocation ?? DefaultLogInvocation)
            {
                // TODO: logging additional
                Log.Information("> {ToolPath} {Arguments}", Path.GetFullPath(toolPath).DoubleQuoteIfNeeded(), outputFilter(arguments));
                if (LogWorkingDirectory && workingDirectory != null)
                {
                    Log.Information("@ {WorkingDirectory}", workingDirectory);
                }
            }

            return(StartProcessInternal(toolPath,
                                        arguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        logOutput ?? DefaultLogOutput
                    ? customLogger ?? DefaultLogger
                    : null,
                                        outputFilter));
        }
예제 #10
0
        private static string GetToolPathOverride(string toolPath)
        {
            if (toolPath.EndsWithOrdinalIgnoreCase(".dll"))
            {
                return(ToolPathResolver.TryGetEnvironmentExecutable("DOTNET_EXE") ??
                       ToolPathResolver.GetPathExecutable("dotnet"));
            }

#if NETCORE
            if (EnvironmentInfo.IsUnix && toolPath.EndsWithOrdinalIgnoreCase(".exe"))
            {
                return(ToolPathResolver.GetPathExecutable("mono"));
            }
#endif

            return(null);
        }
예제 #11
0
        public virtual IProcess StartProcess(
            string toolPath,
            string executionArguments = null,
            string outputArguments    = null,
            string workingDirectory   = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout    = null,
            bool logOutput = true,
            Func <string, LogLevel> logLevelParser = null,
            Func <string, string> outputFilter     = null)
        {
            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

            var toolPathOverride = GetToolPathOverride(toolPath);

            if (!string.IsNullOrEmpty(toolPathOverride))
            {
                executionArguments = $"{toolPath.DoubleQuoteIfNeeded()} {executionArguments}".TrimEnd();
                outputArguments    = $"{toolPath.DoubleQuoteIfNeeded()} {outputArguments}".TrimEnd();
                toolPath           = toolPathOverride;
            }

            outputArguments = outputArguments ?? (outputFilter == null ? executionArguments : outputFilter(executionArguments));
            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {outputArguments}");

            return(StartProcessInternal(toolPath,
                                        executionArguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        logOutput,
                                        logLevelParser,
                                        outputFilter ?? (x => x)));
        }
예제 #12
0
        public virtual IProcess StartProcess(
            string toolPath,
            string arguments        = null,
            string workingDirectory = null,
            IReadOnlyDictionary <string, string> environmentVariables = null,
            int?timeout    = null,
            bool logOutput = true,
            Func <string, LogLevel> logLevelParser = null,
            Func <string, string> outputFilter     = null)
        {
            ControlFlow.Assert(toolPath != null, "ToolPath was not set.");
            if (!Path.IsPathRooted(toolPath) && !toolPath.Contains(Path.DirectorySeparatorChar))
            {
                toolPath = ToolPathResolver.GetPathExecutable(toolPath);
            }

#if NETCORE
            if (EnvironmentInfo.IsUnix && toolPath.EndsWithOrdinalIgnoreCase(".exe"))
            {
                arguments = $"{toolPath.DoubleQuoteIfNeeded()} {arguments}".TrimEnd();
                toolPath  = ToolPathResolver.GetPathExecutable("mono");
            }
#endif

            ControlFlow.Assert(File.Exists(toolPath), $"ToolPath '{toolPath}' does not exist.");
            Logger.Info($"> {Path.GetFullPath(toolPath).DoubleQuoteIfNeeded()} {arguments}");

            return(StartProcessInternal(toolPath,
                                        arguments,
                                        workingDirectory,
                                        environmentVariables,
                                        timeout,
                                        logOutput,
                                        logLevelParser,
                                        outputFilter ?? (x => x)));
        }
예제 #13
0
        public static Tool GetPathTool(string name)
        {
            var toolPath = ToolPathResolver.GetPathExecutable(name);

            return(new ToolExecutor(toolPath).Execute);
        }
예제 #14
0
        public static Tool GetPackageTool(string packageId, string packageExecutable, string version = null, string framework = null)
        {
            var toolPath = ToolPathResolver.GetPackageExecutable(packageId, packageExecutable, version, framework);

            return(new ToolExecutor(toolPath).Execute);
        }