public /* for test purposes */ static bool ExecuteProcessorRunner(AnalysisConfig config, ILogger logger, string exeFileName, IEnumerable <string> userCmdLineArguments, string propertiesFileName, IProcessRunner runner)
        {
            Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName);
            Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName);

            logger.LogInfo(Resources.MSG_TFSProcessorCalling);

            Debug.Assert(!string.IsNullOrWhiteSpace(config.SonarScannerWorkingDirectory), "The working dir should have been set in the analysis config");
            Debug.Assert(Directory.Exists(config.SonarScannerWorkingDirectory), "The working dir should exist");

            var converterArgs = new ProcessRunnerArguments(exeFileName, !PlatformHelper.IsWindows())
            {
                CmdLineArgs      = userCmdLineArguments,
                WorkingDirectory = config.SonarScannerWorkingDirectory,
            };

            var success = runner.Execute(converterArgs);

            if (success)
            {
                logger.LogInfo(Resources.MSG_TFSProcessorCompleted);
            }
            else
            {
                logger.LogError(Resources.ERR_TFSProcessorExecutionFailed);
            }
            return(success);
        }
Ejemplo n.º 2
0
        public void Execute(IScript script)
        {
            var sqlPlusScript = new SqlPlusScript(script);

            var arguments = "{0}/{1}@\"{2}\" @{3}".FormatWith(_username, _password, _connectionString, sqlPlusScript.Path);

            var exitCode = _processRunner.Execute(_sqlPlusConfiguration.RunnerPath, arguments);

            if (exitCode > 0)
            {
                Output.Error("sqlplus encountered an error running script '{0}'.".FormatWith(script.Name));
                throw new SqlPlusException();
            }
        }
        internal /* for testing */ static void CallClangAnalyzer(Action <Message> handleMessage, Request request, IProcessRunner runner, ILogger logger, CancellationToken cancellationToken)
        {
            if (analyzerExeFilePath == null)
            {
                logger.WriteLine("Unable to locate the CFamily analyzer exe");
                return;
            }

            const string communicateViaStreaming = "-"; // signal the subprocess we want to communicate via standard IO streams.

            var args = new ProcessRunnerArguments(analyzerExeFilePath, false)
            {
                CmdLineArgs       = new[] { communicateViaStreaming },
                CancellationToken = cancellationToken,
                WorkingDirectory  = WorkingDirectory,
                HandleInputStream = writer =>
                {
                    using (var binaryWriter = new BinaryWriter(writer.BaseStream))
                    {
                        Protocol.Write(binaryWriter, request);
                    }
                },
                HandleOutputStream = reader =>
                {
                    if ((request.Flags & Request.CreateReproducer) != 0)
                    {
                        reader.ReadToEnd();
                        logger.WriteLine(CFamilyStrings.MSG_ReproducerSaved, ReproducerFilePath);
                    }
                    else if ((request.Flags & Request.BuildPreamble) != 0)
                    {
                        reader.ReadToEnd();
                        logger.WriteLine(CFamilyStrings.MSG_PchSaved, request.File, request.PchFile);
                    }
                    else
                    {
                        using (var binaryReader = new BinaryReader(reader.BaseStream))
                        {
                            Protocol.Read(binaryReader, handleMessage, request.File);
                        }
                    }
                }
            };

            runner.Execute(args);
        }
        private static bool ExecuteAnalysis(IProcessRunner runner, string fileName, ILogger logger)
        {
            if (analyzerExeFilePath == null)
            {
                logger.WriteLine("Unable to locate the CFamily analyzer exe");
                return(false);
            }

            ProcessRunnerArguments args = new ProcessRunnerArguments(analyzerExeFilePath, false);

            args.CmdLineArgs           = new string[] { fileName };
            args.TimeoutInMilliseconds = GetTimeoutInMs();

            bool success = runner.Execute(args);

            return(success);
        }
Ejemplo n.º 5
0
        private static bool ExecuteAnalysis(IProcessRunner runner, string fileName, string workingDirectory, ILogger logger, CancellationToken cancellationToken)
        {
            if (analyzerExeFilePath == null)
            {
                logger.WriteLine("Unable to locate the CFamily analyzer exe");
                return(false);
            }

            var args = new ProcessRunnerArguments(analyzerExeFilePath, false)
            {
                CmdLineArgs           = new[] { fileName },
                TimeoutInMilliseconds = GetTimeoutInMs(),
                CancellationToken     = cancellationToken,
                WorkingDirectory      = workingDirectory
            };

            var success = runner.Execute(args);

            return(success);
        }
        public /* for test purposes */ static bool ExecuteJavaRunner(AnalysisConfig config, IEnumerable <string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName, IProcessRunner runner)
        {
            Debug.Assert(File.Exists(exeFileName), "The specified exe file does not exist: " + exeFileName);
            Debug.Assert(File.Exists(propertiesFileName), "The specified properties file does not exist: " + propertiesFileName);

            IgnoreSonarScannerHome(logger);

            var allCmdLineArgs = GetAllCmdLineArgs(propertiesFileName, userCmdLineArguments, config, logger);

            var envVarsDictionary = GetAdditionalEnvVariables(logger);

            Debug.Assert(envVarsDictionary != null);

            logger.LogInfo(Resources.MSG_SonarScannerCalling);

            Debug.Assert(!string.IsNullOrWhiteSpace(config.SonarScannerWorkingDirectory), "The working dir should have been set in the analysis config");
            Debug.Assert(Directory.Exists(config.SonarScannerWorkingDirectory), "The working dir should exist");

            var scannerArgs = new ProcessRunnerArguments(exeFileName, PlatformHelper.IsWindows())
            {
                CmdLineArgs          = allCmdLineArgs,
                WorkingDirectory     = config.SonarScannerWorkingDirectory,
                EnvironmentVariables = envVarsDictionary
            };

            // SONARMSBRU-202 Note that the Sonar Scanner may write warnings to stderr so
            // we should only rely on the exit code when deciding if it ran successfully
            var success = runner.Execute(scannerArgs);

            if (success)
            {
                logger.LogInfo(Resources.MSG_SonarScannerCompleted);
            }
            else
            {
                logger.LogError(Resources.ERR_SonarScannerExecutionFailed);
            }
            return(success);
        }
Ejemplo n.º 7
0
        protected override void RunInternal()
        {
            // Get the immutable repository information.

            IRepositoryData repositoryData = _loader.LoadFrom(_repositoryDir.FullName);

            // Pick the remote to work on.
            IRemote remoteToUse = _remoteHelper.PickRemote(repositoryData, Options.RemoteToUse);

            // Create the tree.
            IBranchingStrategy strategy = _strategyProvider.GetStrategy(Options.LesserBranchesRegex);

            IBranch[]          allBranches       = repositoryData.Branches.GetFor(remoteToUse).ToArray();
            IBranchesKnowledge branchesKnowledge = strategy.CreateKnowledge(allBranches);

            // Options for building the tree.
            ITagPickingOptions tagPickingOptions = TagPickingOptions.Set(
                Options.TagPickingMode,
                Options.TagCount,
                Options.IncludeOrphanedTags);
            IBranchPickingOptions branchPickingOptions = BranchPickingOptions.Set(
                Options.IncludeBranchesRegices,
                Options.ExcludeBranchesRegices);

            ITree tree = _treeBuilder.Build(
                repositoryData,
                remoteToUse,
                branchesKnowledge,
                branchPickingOptions,
                tagPickingOptions);

            SimplifyTree(tree);

            string tempPath = _fileSystem.Path.GetTempFileName();

            tempPath = _fileSystem.Path.ChangeExtension(tempPath, "gv");

            // Rendering options.
            TreeRenderingOptions renderingOptions = TreeRenderingOptions.Default;

            renderingOptions.ForceTreatAsGitHub = Options.ForceTreatAsGitHub;

            // ReSharper disable once AssignNullToNotNullAttribute
            using (IFileStream fileStream = _fileSystem.File.OpenWrite(tempPath))
            {
                using (IStreamWriter textWriter = _textWriterFactory.CreateStreamWriter(fileStream))
                {
                    IGraphVizWriter graphVizWriter = _graphVizFactory.CreateGraphVizWriter(textWriter);

                    ITreeRenderer treeRenderer = _treeRendererFactory.CreateRenderer(graphVizWriter);
                    treeRenderer.Render(tree, remoteToUse, branchesKnowledge, renderingOptions);
                }
            }

            string targetPath = PrepareTargetPath();

            string graphVizCommand = _appPathProvider.GetProperAppPath(ExternalApp.GraphViz);
            string graphVizArgs    = $@"""{tempPath}"" -T{_outputFormat} -o""{targetPath}""";

            Log.Debug($"Starting GraphViz with arguments: [{graphVizArgs}].");
            int code = _processRunner.Execute(graphVizCommand, graphVizArgs);

            if (code != 0)
            {
                Log.Fatal("GraphViz execution failed.");
            }
            else
            {
                Log.Info("GraphViz execution succeeded.");
                Log.Info($"Saved to {targetPath}.");
            }
        }