コード例 #1
0
ファイル: MSpecTestRunner.cs プロジェクト: hyrmn/Jubilee
        private IEnumerable<SpecificationResult> ParseResultsFromTest(ProcessOutput output)
        {
            var specificationResults = new List<SpecificationResult>();
            bool startParsingResults = false;

            string context = String.Empty;
            string specification = String.Empty;
            string detail = String.Empty;

            foreach (string line in output.Output.Split(new string[] { Environment.NewLine }, StringSplitOptions.None))
            {
                if (Regex.Match(line, "Contexts:").Success)
                {
                    break;
                }

                if (Regex.Match(line, "Failures:").Success)
                {
                    startParsingResults = true;
                    continue;
                }

                if (startParsingResults == false)
                    continue;

                if (String.IsNullOrEmpty(line))
                {
                    if (!String.IsNullOrEmpty(context))
                    {
                        specificationResults.Add(new SpecificationResult(context, specification, detail));
                    }
                    context = String.Empty;
                    continue;
                }

                if (String.IsNullOrEmpty(context))
                {
                    context = line;
                    continue;
                }

                if (Regex.Match(line, "(FAIL)").Success)
                {
                    specification = line.Replace("(FAIL)", "");
                    continue;
                }

                if (String.IsNullOrEmpty(specification))
                {
                    continue;
                }

                detail += line + Environment.NewLine;
            }
            return specificationResults;
        }
コード例 #2
0
ファイル: AnalyzerTests.cs プロジェクト: iVerb/PTVS
        public async Task GetVEnvDatabasePaths()
        {
            var version = PythonPaths.Python35 ?? PythonPaths.Python35_x64;

            var env = Path.Combine(TestData.GetTempPath(), "env");

            using (var p = ProcessOutput.RunHiddenAndCapture(version.InterpreterPath, "-m", "venv", env)) {
                if ((await p) != 0)
                {
                    Assert.Fail("Could not create venv{0}{1}{0}{2}",
                                Environment.NewLine,
                                string.Join(Environment.NewLine, p.StandardOutputLines),
                                string.Join(Environment.NewLine, p.StandardErrorLines)
                                );
                    return;
                }
            }

            var interpreter = Path.Combine(env, "Scripts", "python.exe");
            var paths       = await PythonTypeDatabase.GetUncachedDatabaseSearchPathsAsync(interpreter);

            AssertUtil.ContainsAtLeast(
                paths.Where(p => p.IsStandardLibrary).Select(p => p.Path),
                new[] {
                Path.Combine(env, "Scripts").ToLowerInvariant(),
                PathUtils.TrimEndSeparator(env.ToLowerInvariant()),
                PathUtils.TrimEndSeparator(version.PrefixPath.ToLowerInvariant()),
                Path.Combine(version.PrefixPath, "Lib").ToLowerInvariant()
            }
                );
            AssertUtil.ContainsAtLeast(
                paths.Where(p => !p.IsStandardLibrary).Select(p => p.Path),
                new[] {
                Path.Combine(env, "Lib", "site-packages").ToLowerInvariant()
            }
                );
            AssertUtil.DoesntContain(
                paths.Select(p => p.Path),
                Path.Combine(version.PrefixPath, "Lib", "site-packages").ToLowerInvariant()
                );
        }
コード例 #3
0
 private void CheckProcessResult(ProcessOutput proc, string expectedError = null)
 {
     Console.WriteLine(String.Join(Environment.NewLine, proc.StandardOutputLines));
     Debug.WriteLine(String.Join(Environment.NewLine, proc.StandardErrorLines));
     if (!string.IsNullOrEmpty(expectedError))
     {
         var matches = proc.StandardErrorLines.Where(err => err.Contains(expectedError));
         if (matches.Count() == 0)
         {
             Assert.Fail(String.Join(Environment.NewLine, proc.StandardErrorLines));
         }
     }
     else
     {
         if (proc.StandardErrorLines.Any())
         {
             Assert.Fail(String.Join(Environment.NewLine, proc.StandardErrorLines));
         }
         Assert.AreEqual(0, proc.ExitCode);
     }
 }
コード例 #4
0
        public void RunInterpreterError()
        {
            foreach (var fact in Factories)
            {
                using (var output = ProcessOutput.RunHiddenAndCapture(fact.Configuration.InterpreterPath, "-c", "assert False")) {
                    Console.WriteLine(output.Arguments);
                    Assert.IsTrue(output.Wait(TimeSpan.FromSeconds(30)), "Running " + fact.Configuration.Description + " exceeded timeout");

                    foreach (var line in output.StandardOutputLines)
                    {
                        Console.WriteLine(line);
                    }
                    Assert.AreEqual(0, output.StandardOutputLines.Count(), "Expected no standard output");
                    var error = output.StandardErrorLines.ToList();
                    Assert.AreEqual(3, error.Count, "Expected 3 lines on standard error");
                    Assert.AreEqual("Traceback (most recent call last):", error[0]);
                    Assert.AreEqual("  File \"<string>\", line 1, in <module>", error[1]);
                    Assert.AreEqual("AssertionError", error[2]);
                }
            }
        }
コード例 #5
0
        public ProcessOutput ExecuteCcm(string args, int timeout = DefaultCmdTimeout, bool throwOnProcessError = false)
        {
            // right now having a config dir is always a requirement
            var ccmArgs = args + " --config-dir=" + CcmDir.FullName;

            Trace.TraceInformation("Executing cmd line: " + ccmArgs);
            var executable = "/usr/local/bin/ccm";

            if (TestUtils.IsWin)
            {
                executable = "cmd.exe";
                args       = "/c ccm " + args;
            }
            ProcessOutput output = ExecuteProcess(executable, args, timeout);

            if (throwOnProcessError)
            {
                ValidateOutput(output);
            }
            return(output);
        }
コード例 #6
0
        /// <summary>
        /// Starts a new process.
        /// </summary>
        public IMongoDbProcess Start(string binariesDirectory, string dataDirectory, int port, bool doNotKill)
        {
            string fileName  = @"{0}{1}{2}".Formatted(binariesDirectory, System.IO.Path.DirectorySeparatorChar.ToString(), MongoDbDefaults.MongodExecutable);
            string arguments = @"--sslMode disabled --dbpath ""{0}"" --port {1} --nojournal --bind_ip 127.0.0.1".Formatted(dataDirectory, port);

            WrappedProcess wrappedProcess = ProcessControl.ProcessFactory(fileName, arguments);

            wrappedProcess.DoNotKill = doNotKill;

            string windowTitle = "mongod | port: {0}".Formatted(port);

            ProcessOutput output = ProcessControl.StartAndWaitForReady(wrappedProcess, 5, ProcessReadyIdentifier, windowTitle);

            MongoDbProcess mongoDbProcess = new MongoDbProcess(wrappedProcess)
            {
                ErrorOutput    = output.ErrorOutput,
                StandardOutput = output.StandardOutput
            };

            return(mongoDbProcess);
        }
コード例 #7
0
        /// <summary>
        /// Starts a new process.
        /// </summary>
        public IMongoDbProcess Start(string binariesDirectory, string dataDirectory, int port, bool doNotKill)
        {
            string fileName  = @"{0}\{1}".Formatted(binariesDirectory, MongoDbDefaults.MongodExecutable);
            string arguments = @"--dbpath ""{0}"" --port {1} --nohttpinterface --nojournal".Formatted(dataDirectory, port);

            WrappedProcess wrappedProcess = ProcessControl.ProcessFactory(fileName, arguments);

            wrappedProcess.DoNotKill = doNotKill;

            string windowTitle = "mongod | port: {0}".Formatted(port);

            ProcessOutput output = ProcessControl.StartAndWaitForReady(wrappedProcess, 5, ProcessReadyIdentifier, windowTitle);

            MongoDbProcess mongoDbProcess = new MongoDbProcess(wrappedProcess)
            {
                ErrorOutput    = output.ErrorOutput,
                StandardOutput = output.StandardOutput
            };

            return(mongoDbProcess);
        }
コード例 #8
0
        private static string Format(string imageFilePath, ProcessOutput output, bool printStdOut)
        {
            var builder = new StringBuilder();

            builder.AppendFormat("{0} returned {1}", imageFilePath, output.ExitCode);
            if (printStdOut)
            {
                builder.AppendLine();
                if (!string.IsNullOrEmpty(output.StandardOutput))
                {
                    builder.Append(output.StandardOutput);
                }

                if (!string.IsNullOrEmpty(output.StandardError))
                {
                    builder.Append(output.StandardError);
                }
            }

            return(builder.ToString());
        }
コード例 #9
0
ファイル: Pip.cs プロジェクト: zuokaihuang/PTVS
        /// <summary>
        /// Checks whether a given package is installed and satisfies the
        /// version specification.
        /// </summary>
        /// <param name="package">
        /// Name, and optionally the version of the package to install, in
        /// setuptools format.
        /// </param>
        /// <remarks>
        /// This method requires setuptools to be installed to correctly detect
        /// packages and verify their versions. If setuptools is not available,
        /// the method will always return <c>false</c> for any package name.
        /// </remarks>
        public static async Task <bool> IsInstalled(IPythonInterpreterFactory factory, string package)
        {
            if (!factory.IsRunnable())
            {
                return(false);
            }

            var code = string.Format("import pkg_resources; pkg_resources.require('{0}')", package);

            using (var proc = ProcessOutput.Run(
                       factory.Configuration.InterpreterPath,
                       new[] { "-c", code },
                       factory.Configuration.PrefixPath,
                       UnbufferedEnv,
                       visible: false,
                       redirector: null,
                       quoteArgs: true)
                   ) {
                return(await proc == 0);
            }
        }
コード例 #10
0
        public void AzureClientCertificateX509()
        {
            TestUtilities        utils  = DefaultUtilities();
            ConfigurationOptions config = utils.ConfigurationOptions;

            utils.ConfigurationOptions.Validate();
            DeleteTokenCache();

            ProcessOutput results = utils.ExecuteTest((config) =>
            {
                //config.AzureClientId = "";
                config.AzureClientCertificate = "";
                config.ClientCertificate      = _appCertificate;
                config.AzureKeyVault          = "";
                Assert.IsTrue(config.IsClientIdConfigured(), "test configuration invalid");
                return(config.ValidateAad());
            }, utils.Collector.Config);

            Assert.IsTrue(results.ExitBool);
            Assert.IsTrue(!results.HasErrors(), results.ToString());
        }
コード例 #11
0
        public void AzureClientCertificateKeyVaultUserManagedIdentity()
        {
            TestUtilities        utils  = DefaultUtilities();
            ConfigurationOptions config = utils.ConfigurationOptions;

            utils.ConfigurationOptions.Validate();
            DeleteTokenCache();

            ProcessOutput results = utils.ExecuteTest((config) =>
            {
                //config.AzureClientId = "";
                Assert.IsTrue(config.IsClientIdConfigured(), "test configuration invalid");
                AzureResourceManager arm = new AzureResourceManager(config);

                Assert.IsTrue(arm.ClientIdentity.IsUserManagedIdentity, "arm.IsUserManagedIdentity not detected. test from azure vm with user managed identity enabled.");
                return(config.ValidateAad());
            }, utils.Collector.Config);

            Assert.IsTrue(results.ExitBool);
            Assert.IsTrue(!results.HasErrors(), results.ToString());
        }
コード例 #12
0
ファイル: Git.cs プロジェクト: dekkerb115/Bam.Net
        public Git CloneTo(DirectoryInfo cloneTo, int timeout = 1800000)
        {
            if (string.IsNullOrEmpty(_configStack.UserName))
            {
                throw new UnableToInitializeGitToolsException("Git UserName must be specified");
            }

            if (string.IsNullOrEmpty(_configStack.UserEmail))
            {
                throw new UnableToInitializeGitToolsException("Git UserEmail must be specified");
            }

            if (!EnsureEnvironmentPath())
            {
                throw new UnableToInitializeGitToolsException("Couldn't update environment path");
            }

            bool configured = ConfigGit();

            if (!configured)
            {
                StringBuilder message = new StringBuilder();
                if (_configStack.LastOutput != null)
                {
                    message.AppendLine(_configStack.LastOutput.StandardOutput);
                    message.AppendLine(_configStack.LastOutput.StandardError);
                }
                else
                {
                    message.AppendLine("Unable to configure git");
                }
                throw new UnableToConfigureGitException(message.ToString());
            }
            else
            {
                ProcessOutput output = "git clone {0} \"{1}\""._Format(_configStack.Repository, cloneTo.FullName).Run(timeout);
                _configStack.LastOutput = output;
            }
            return(this);
        }
コード例 #13
0
        public void DetectLocalEnvOutsideWorkspace()
        {
            var python = PythonPaths.Python37_x64 ?? PythonPaths.Python37;

            var tempFolder      = TestData.GetTempPath();
            var workspaceFolder = Path.Combine(tempFolder, "workspace");
            var envFolder       = Path.Combine(tempFolder, "outside");

            Directory.CreateDirectory(workspaceFolder);
            File.WriteAllText(Path.Combine(workspaceFolder, "app.py"), string.Empty);

            // Create virtual env outside the workspace folder
            using (var p = ProcessOutput.RunHiddenAndCapture(python.InterpreterPath, "-m", "venv", envFolder))
            {
                Console.WriteLine(p.Arguments);
                p.Wait();
                Console.WriteLine(string.Join(Environment.NewLine, p.StandardOutputLines.Concat(p.StandardErrorLines)));
                Assert.AreEqual(0, p.ExitCode);
            }

            // Normally a local virtual environment outside the workspace
            // wouldn't be detected, but it is when it's referenced from
            // the workspace python settings.
            WorkspaceTestHelper.MockWorkspace                workspace                = new WorkspaceTestHelper.MockWorkspace(workspaceFolder);
            WorkspaceTestHelper.MockWorkspaceContext         workspaceContext         = new WorkspaceTestHelper.MockWorkspaceContext(workspace, @"..\outside\scripts\python.exe");
            WorkspaceTestHelper.MockWorkspaceContextProvider workspaceContextProvider = new WorkspaceTestHelper.MockWorkspaceContextProvider(workspaceContext);

            using (var factoryProvider = new WorkspaceInterpreterFactoryProvider(workspaceContextProvider))
            {
                workspaceContextProvider.SimulateChangeWorkspace(workspaceContext);
                var configs = factoryProvider.GetInterpreterConfigurations().ToArray();

                Assert.AreEqual(1, configs.Length);
                Assert.IsTrue(PathUtils.IsSamePath(
                                  Path.Combine(envFolder, "scripts", "python.exe"),
                                  configs[0].InterpreterPath
                                  ));
                Assert.AreEqual("Workspace|Workspace|outside", configs[0].Id);
            }
        }
コード例 #14
0
        public async Task Run()
        {
            var service = _project.Site.GetComponentModel().GetService <IInterpreterRegistryService>();

            var factory = await _project.CreateOrAddVirtualEnvironment(
                service,
                _create,
                _virtualEnvPath,
                _baseInterpreter,
                _useVEnv
                );

            if (factory == null)
            {
                return;
            }

            var txt = PathUtils.GetAbsoluteFilePath(_project.ProjectHome, "requirements.txt");

            if (!_installRequirements || !File.Exists(txt))
            {
                return;
            }

            WriteOutput(Strings.RequirementsTxtInstalling.FormatUI(txt));
            if (await Pip.Install(
                    _project.Site,
                    factory,
                    "-r " + ProcessOutput.QuoteSingleArgument(txt),
                    false, // never elevate for a virtual environment
                    _output
                    ))
            {
                WriteOutput(Strings.PackageInstallSucceeded.FormatUI(Path.GetFileName(txt)));
            }
            else
            {
                WriteOutput(Strings.PackageInstallFailed.FormatUI(Path.GetFileName(txt)));
            }
        }
コード例 #15
0
        public void NC_IOTerminal_Execute()
        {
            // Arrange
            var           systemInformation = container.Resolve <NetStandard.SystemInformation.ISystemInformation>();
            ProcessOutput result            = null;

            if (systemInformation.GetOSInfo().Platform == SystemInformation.OSPlatformType.Windows)
            {
                // Act
                IIOTerminal iOTerminal = this.CreateIOTerminal();
                result = iOTerminal.Execute(new ProcessInput
                {
                    Command   = "Get-WmiObject Win32_BaseBoard | Format-Wide -Property SerialNumber",
                    ShellName = "powershell",
                    Arguments = "-OutputFormat Text -InputFormat Text -File -"
                });
                result.StandardOutput =
                    result.StandardOutput.Skip(1).SkipLast(1)
                    .Where(o => o?.Trim()?.Equals("") != true).ToArray();
                // Assert
            }
            else if (systemInformation.GetOSInfo().Platform == SystemInformation.OSPlatformType.Linux)
            {
                // Act
                IIOTerminal iOTerminal = this.CreateIOTerminal();
                result = iOTerminal.Execute(new ProcessInput
                {
                    Command   = "/sys/devices/virtual/dmi/id/board_serial",
                    ShellName = "/bin/bash",
                    Arguments = ""
                });
                result.StandardOutput =
                    result.StandardOutput.Skip(1).SkipLast(1)
                    .Where(o => o?.Trim()?.Equals("") != true).ToArray();
                // Assert
            }

            Console.WriteLine(string.Join(",", result.StandardOutput));
            Assert.AreNotEqual(result.StandardOutput, 0);
        }
コード例 #16
0
ファイル: PipExtensionProvider.cs プロジェクト: krus/PTVS
        public async Task InstallPip()
        {
            AbortOnInvalidConfiguration();

            using (await WaitAndLockPip()) {
                OnOperationStarted(Resources.InstallingPipStarted);
                using (var output = ProcessOutput.Run(
                           _factory.Configuration.InterpreterPath,
                           new[] { PythonToolsInstallPath.GetFile("pip_downloader.py") },
                           _factory.Configuration.PrefixPath,
                           UnbufferedEnv,
                           false,
                           _output,
                           elevate: ShouldElevate
                           )) {
                    bool success = true;
                    try {
                        var exitCode = await output;
                        if (exitCode != 0)
                        {
                            success = false;
                            throw new PipException(Resources.InstallationFailed);
                        }
                    } catch (OperationCanceledException) {
                        success = false;
                    } catch (Exception ex) {
                        success = false;
                        if (ex.IsCriticalException())
                        {
                            throw;
                        }
                        ToolWindow.UnhandledException.Execute(ExceptionDispatchInfo.Capture(ex), WpfObject);
                    } finally {
                        OnOperationFinished(
                            success ? Resources.InstallingPipSuccess : Resources.InstallingPipFailed
                            );
                    }
                }
            }
        }
コード例 #17
0
        private static void RunProfiler(SessionNode session, LaunchConfiguration config, bool openReport)
        {
            var process = new ProfiledProcess(
                (PythonToolsService)session._serviceProvider.GetService(typeof(PythonToolsService)),
                config.GetInterpreterPath(),
                string.Join(" ", ProcessOutput.QuoteSingleArgument(config.ScriptName), config.ScriptArguments),
                config.WorkingDirectory,
                session._serviceProvider.GetPythonToolsService().GetFullEnvironment(config)
                );

            string baseName = Path.GetFileNameWithoutExtension(session.Filename);
            string date     = DateTime.Now.ToString("yyyyMMdd");
            string outPath  = Path.Combine(Path.GetTempPath(), baseName + "_" + date + ".vsp");

            int count = 1;

            while (File.Exists(outPath))
            {
                outPath = Path.Combine(Path.GetTempPath(), baseName + "_" + date + "(" + count + ").vsp");
                count++;
            }

            process.ProcessExited += (sender, args) => {
                var dte = (EnvDTE.DTE)session._serviceProvider.GetService(typeof(EnvDTE.DTE));
                _profilingProcess     = null;
                _stopCommand.Enabled  = false;
                _startCommand.Enabled = true;
                if (openReport && File.Exists(outPath))
                {
                    dte.ItemOperations.OpenFile(outPath);
                }
            };

            session.AddProfile(outPath);

            process.StartProfiling(outPath);
            _profilingProcess     = process;
            _stopCommand.Enabled  = true;
            _startCommand.Enabled = false;
        }
コード例 #18
0
        public void AzureClientCertificateX509withPassword()
        {
            TestUtilities        utils  = DefaultUtilities();
            ConfigurationOptions config = utils.ConfigurationOptions;

            utils.ConfigurationOptions.Validate();
            DeleteTokenCache();

            ProcessOutput results = utils.ExecuteTest((config) =>
            {
                CertificateUtilities certificateUtilities = new CertificateUtilities();
                certificateUtilities.SetSecurePassword(TestUtilities.TestProperties.testAdminPassword);

                config.ClientCertificate = certificateUtilities.GetClientCertificate(TestUtilities.TestProperties.AzureClientCertificate);// _appCertificate;
                config.AzureKeyVault     = "";
                Assert.IsTrue(config.IsClientIdConfigured(), "test configuration invalid");
                return(config.ValidateAad());
            }, utils.Collector.Config);

            Assert.IsTrue(results.ExitBool);
            Assert.IsTrue(!results.HasErrors(), results.ToString());
        }
コード例 #19
0
ファイル: TestFramework.cs プロジェクト: zjherp/nodejstools
        private string EvaluateJavaScript(string nodeExePath, string testFile, string discoverResultFile, IMessageLogger logger, string workingDirectory)
        {
            workingDirectory = workingDirectory.TrimEnd(new char['\\']);
#if DEBUG
            var arguments = $"{WrapWithQuotes(this.findTestsScriptFile)} {this.Name} {WrapWithQuotes(testFile)} {WrapWithQuotes(discoverResultFile)} {WrapWithQuotes(workingDirectory)}";
            logger.SendMessage(TestMessageLevel.Informational, "Arguments: " + arguments);
#endif

            var stdout = string.Empty;
            try
            {
                var process = ProcessOutput.Run(nodeExePath, new[] { this.findTestsScriptFile, this.Name, testFile, discoverResultFile, workingDirectory }, workingDirectory, env: null, visible: false, redirector: new DiscoveryRedirector(logger));

                process.Wait();
            }
            catch (FileNotFoundException e)
            {
                logger.SendMessage(TestMessageLevel.Error, $"Error starting node.exe.{Environment.NewLine}{e}");
            }

            return(stdout);
        }
コード例 #20
0
        private async Task <bool> ExecuteTypingsTool(IEnumerable <string> arguments, Redirector redirector)
        {
            string typingsTool = await EnsureTypingsToolInstalled();

            if (string.IsNullOrEmpty(typingsTool))
            {
                redirector?.WriteErrorLine(SR.GetString(SR.TypingsToolNotInstalledError));
                return(false);
            }

            using (var process = ProcessOutput.Run(
                       typingsTool,
                       arguments,
                       _pathToRootProjectDirectory,
                       null,
                       false,
                       redirector,
                       quoteArgs: true)) {
                if (!process.IsStarted)
                {
                    // Process failed to start, and any exception message has
                    // already been sent through the redirector
                    redirector?.WriteErrorLine("could not start 'typings'");
                    return(false);
                }
                var i = await process;
                if (i == 0)
                {
                    redirector?.WriteLine(SR.GetString(SR.TypingsToolInstallCompleted));
                    return(true);
                }
                else
                {
                    process.Kill();
                    redirector?.WriteErrorLine(SR.GetString(SR.TypingsToolInstallErrorOccurred));
                    return(false);
                }
            }
        }
コード例 #21
0
        private async void RunInOutput(IPythonProject project, CommandStartInfo startInfo)
        {
            Redirector redirector = OutputWindowRedirector.GetGeneral(project.Site);

            if (startInfo.ErrorRegex != null || startInfo.WarningRegex != null)
            {
                redirector = new TeeRedirector(redirector, new ErrorListRedirector(_project.Site, project as IVsHierarchy, startInfo.WorkingDirectory, _errorListProvider, startInfo.ErrorRegex, startInfo.WarningRegex));
            }
            redirector.ShowAndActivate();

            using (var process = ProcessOutput.Run(
                       startInfo.Filename,
                       new[] { startInfo.Arguments },
                       startInfo.WorkingDirectory,
                       startInfo.EnvironmentVariables,
                       false,
                       redirector,
                       quoteArgs: false
                       )) {
                await process;
            }
        }
コード例 #22
0
        private async Task <int> WaitAndKillOnCancelAsync(ProcessOutput processOutput, CancellationToken ct)
        {
            var tcs = new TaskCompletionSource <int>();

            processOutput.Exited += (o, e) => tcs.TrySetResult(0);
            try {
                if (processOutput.ExitCode == null)
                {
                    tcs.RegisterForCancellation(ct).UnregisterOnCompletion(tcs.Task);
                    await tcs.Task;
                }
                return((int)processOutput.ExitCode);
            } catch (OperationCanceledException) when(ct.IsCancellationRequested)
            {
                try {
                    processOutput.Kill();
                } catch (InvalidOperationException) {
                    // Must have exited just as we were about to kill it
                }
                throw;
            }
        }
コード例 #23
0
        public static HashSet <GitLog> BetweenCommits(string gitRepoPath, string commitIdentifier, string toCommit = "HEAD")
        {
            string startDirectory = Environment.CurrentDirectory;

            Environment.CurrentDirectory = gitRepoPath;
            string           command = $"git --no-pager log --pretty=format:{GetPrettyFormatArg()} {commitIdentifier}..{toCommit}";
            ProcessOutput    output  = null;
            HashSet <GitLog> results = new HashSet <GitLog>();
            AutoResetEvent   wait    = new AutoResetEvent(false);

            output = command.Run((o, a) =>
            {
                Environment.CurrentDirectory = startDirectory;
                output.StandardOutput.DelimitSplit("\r", "\n").Each(log =>
                {
                    results.Add(log.FromJson <GitLog>());
                });
                wait.Set();
            });
            wait.WaitOne();
            return(results);
        }
コード例 #24
0
        public bool AttachToProcess(ProcessOutput processOutput, EnvDTE.Process process, Guid[] engines = null)
        {
            // Retry the attach itself 3 times before displaying a Retry/Cancel
            // dialog to the user.
            var dte = GetDTE();

            dte.SuppressUI = true;
            try {
                try {
                    if (engines == null)
                    {
                        process.Attach();
                    }
                    else
                    {
                        var process3 = process as EnvDTE90.Process3;
                        if (process3 == null)
                        {
                            return(false);
                        }
                        process3.Attach2(engines.Select(engine => engine.ToString("B")).ToArray());
                    }
                    return(true);
                } catch (COMException) {
                    if (processOutput.Wait(TimeSpan.FromMilliseconds(500)))
                    {
                        // Process exited while we were trying
                        return(false);
                    }
                }
            } finally {
                dte.SuppressUI = false;
            }

            // Another attempt, but display UI.
            process.Attach();
            return(true);
        }
コード例 #25
0
ファイル: GlobalToolsManager.cs プロジェクト: shaun-h/gti
        private void WriteOuput(ProcessOutput output)
        {
            var originalColour = Console.ForegroundColor;

            if (output.ExitCode == 0)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                foreach (var line in output.StandardOutLines)
                {
                    Console.WriteLine(line);
                }

                Console.ForegroundColor = originalColour;
            }
            else
            {
                if (output.StandardError.ToLowerInvariant().Contains("is already installed"))
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    foreach (var line in output.StandardErrorLines)
                    {
                        Console.WriteLine(line);
                    }

                    Console.ForegroundColor = originalColour;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    foreach (var line in output.StandardErrorLines)
                    {
                        Console.WriteLine(line);
                    }

                    Console.ForegroundColor = originalColour;
                }
            }
        }
コード例 #26
0
ファイル: GitClient.cs プロジェクト: valsun2016/PTVS
        public async Task <Tuple <string, ProcessOutputResult> > CloneAsync(string repoUrl, string targetParentFolderPath)
        {
            Directory.CreateDirectory(targetParentFolderPath);

            string localTemplateFolder = GetClonedFolder(repoUrl, targetParentFolderPath);

            if (Directory.Exists(localTemplateFolder))
            {
                ShellUtils.DeleteDirectory(localTemplateFolder);
            }

            var arguments = new string[] { "clone", repoUrl };
            var output    = ProcessOutput.Run(_gitExeFilePath, arguments, targetParentFolderPath, null, false, null);

            using (output) {
                await output;

                var r = new ProcessOutputResult()
                {
                    ExeFileName         = _gitExeFilePath,
                    ExitCode            = output.ExitCode,
                    StandardOutputLines = output.StandardOutputLines.ToArray(),
                    StandardErrorLines  = output.StandardErrorLines.ToArray(),
                };

                if (r.ExitCode < 0)
                {
                    throw new ProcessException(r);
                }

                if (!Directory.Exists(localTemplateFolder))
                {
                    throw new ProcessException(r);
                }

                return(Tuple.Create(localTemplateFolder, r));
            }
        }
コード例 #27
0
ファイル: ProcessExecute.cs プロジェクト: PeezoSlug/PTVS
 static internal string RunWithTimeout(
     string filename,
     Dictionary <string, string> env,
     IEnumerable <string> arguments,
     string workingDirectory,
     string pathEnv,
     int timeoutInSeconds
     )
 {
     using (var outputStream = new MemoryStream())
         using (var reader = new StreamReader(outputStream, Encoding.UTF8, false, 4096, leaveOpen: true))
             using (var writer = new StreamWriter(outputStream, Encoding.UTF8, 4096, leaveOpen: true))
                 using (var proc = ProcessOutput.Run(
                            filename,
                            arguments,
                            workingDirectory,
                            env,
                            visible: false,
                            new StreamRedirector(writer)
                            )) {
                     if (!proc.ExitCode.HasValue)
                     {
                         if (!proc.Wait(TimeSpan.FromSeconds(timeoutInSeconds)))
                         {
                             try {
                                 proc.Kill();
                             } catch (InvalidOperationException) {
                                 // Process has already exited
                             }
                             throw new TimeoutException();
                         }
                     }
                     writer.Flush();
                     outputStream.Seek(0, SeekOrigin.Begin);
                     string data = reader.ReadToEnd();
                     return(data);
                 }
 }
コード例 #28
0
ファイル: CondaUtils.cs プロジェクト: serg32m/PTVS
        private static PackageVersion GetCondaVersion(string exePath)
        {
            using (var output = ProcessOutput.RunHiddenAndCapture(exePath, "-V")) {
                output.Wait();
                if (output.ExitCode == 0)
                {
                    // Version is currently being printed to stderr, and nothing in stdout
                    foreach (var line in output.StandardErrorLines.Union(output.StandardOutputLines))
                    {
                        if (!string.IsNullOrEmpty(line) && line.StartsWith("conda "))
                        {
                            var version = line.Substring("conda ".Length);
                            if (PackageVersion.TryParse(version, out PackageVersion ver))
                            {
                                return(ver);
                            }
                        }
                    }
                }
            }

            return(PackageVersion.Empty);
        }
コード例 #29
0
        public static HashSet <GitLog> BetweenCommits(string gitRepoPath, string commitIdentifier, string toCommit = "HEAD")
        {
            string startDirectory = Environment.CurrentDirectory;

            Environment.CurrentDirectory = gitRepoPath;
            string           command = $"git --no-pager log --pretty=format:{GetPrettyFormatArg()} {commitIdentifier}..{toCommit}";
            HashSet <GitLog> results = new HashSet <GitLog>();
            ProcessOutput    output  = command.Run();
            int num = 0;

            output.StandardOutput.DelimitSplit("\r", "\n").Each(log =>
            {
                Dictionary <string, string> replacements = new Dictionary <string, string>()
                {
                    { "\"", "\'" }, { "\\", "\\\\" }
                };
                string line = log.DelimitedReplace(replacements);
                LineReader(++num, line);
                results.Add(line.FromJson <GitLog>());
            });

            return(results);
        }
コード例 #30
0
        public void CheckNativePortOpen(ProcessOutput output, string ip)
        {
            using (var ccmConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                using (var cts = new CancellationTokenSource(5 * 60 * 1000))
                {
                    while (!cts.IsCancellationRequested)
                    {
                        try
                        {
                            ccmConnection.Connect(ip, 9042);
                            return;
                        }
                        catch
                        {
                            Thread.Sleep(5000);
                        }
                    }
                }
            }

            throw new TestInfrastructureException("Native Port check timed out. Output: " + Environment.NewLine + output.ToString());
        }
コード例 #31
0
        public override void Edit(Action <string> output = null, Action <string> error = null)
        {
            try
            {
                JobProviderArguments providerArguments = GetProviderArguments(true, true) as JobProviderArguments;
                JobConf    jobConf    = GetJobConf(providerArguments.JobName);
                WorkerConf workerConf = jobConf.GetWorkerConf(providerArguments.WorkerName, true);
                if (workerConf == null)
                {
                    Message.PrintLine("specified worker was not found: {0}", providerArguments.WorkerName);
                    Exit(1);
                }

                ProcessOutput processOutput = ShellSettings.Current.Editor.Start(workerConf.LoadedFrom);
                jobConf.Save();
                Exit(0);
            }
            catch (Exception ex)
            {
                Message.PrintLine("error editing worker: {0}", ConsoleColor.Magenta, ex.Message);
                Exit(1);
            }
        }
コード例 #32
0
        public override bool Execute() {
            var compilerPath = CompilerPath ?? "tsc";
            var compilerOptions = CompilerOptions ?? string.Empty;
            var inputFiles = ReferenceOrderer.OrderFiles(InputFiles ?? new ITaskItem[0]);
            var outputFiles = inputFiles
                .SelectMany(item => new[] {
                    TaskItemWithNewExtension(item, ".js"),
                    TaskItemWithNewExtension(item, ".js.map")
                })
                .ToArray();
            var success = true;

            var singleOutputFile = GetSingleOutputFile(compilerOptions);
            if (singleOutputFile != null)
                outputFiles = new ITaskItem[] {
                    new TaskItem(singleOutputFile),
                    new TaskItem(singleOutputFile + ".map")
                };

            if (OverwriteReadOnlyFiles) {
                var readOnlyFiles =
                    from item in outputFiles
                    let file = new FileInfo(item.ItemSpec)
                    where file.Exists && file.IsReadOnly
                    select file;

                foreach (var file in readOnlyFiles) {
                    file.IsReadOnly = false;
                }
            }

            if (outputFiles.Length > 0) {
                var startInfo =
                    new ProcessStartInfo {
                        FileName = compilerPath,
                        Arguments = string.Join(" ", new[] {compilerOptions}.Concat(inputFiles.Select(item => Quote(item.ItemSpec)))),
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                    };

                var process = Process.Start(startInfo);
                if (process == null) {
                    Log.LogError("TypeScript process failed to start.");
                    return false;
                }

                var processOutput = new ProcessOutput(process);

                if (!process.WaitForExit(ChildProcessTimeout)) {
                    Log.LogError("Timeout waiting for child process to finish.");
                    success = false;
                }

                if (success && process.ExitCode != 0) {
                    success = false;

                    foreach (var line in processOutput.Lines) {
                        var errorLineMatch = errorLineMatcher.Match(line);

                        if (errorLineMatch.Success) {
                            var file = new FileInfo(errorLineMatch.Groups["file"].Value).FullName;
                            var lineNumber = int.Parse(errorLineMatch.Groups["lineNumber"].Value);
                            var columnNumber = int.Parse(errorLineMatch.Groups["columnNumber"].Value) + 1;
                            var message = errorLineMatch.Groups["message"].Value;

                            Log.LogError(null, null, null, file, lineNumber, columnNumber, 0, 0, message);
                        }
                        else
                            Log.LogWarning(line);
                    }

                    Log.LogError("Typescript compiler exited with code " + process.ExitCode);
                }
            }

            OutputFiles = outputFiles.Where(item => File.Exists(item.ItemSpec)).ToArray();
            return success;
        }