コード例 #1
0
        /// <summary>
        /// Attempts to process the supplied command line arguments and
        /// reports any errors using the logger.
        /// Returns false if any parsing errors were encountered.
        /// </summary>
        public static bool TryProcessArgs(string[] commandLineArgs, ILogger logger, out IBootstrapperSettings settings)
        {
            if (commandLineArgs == null)
            {
                throw new ArgumentNullException("commandLineArgs");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            settings = null;

            IEnumerable<ArgumentInstance> arguments;

            // This call will fail if there are duplicate or missing arguments
            CommandLineParser parser = new CommandLineParser(Descriptors, true /* allow unrecognized arguments*/);
            bool parsedOk = parser.ParseArguments(commandLineArgs, logger, out arguments);

            // Handler for command line analysis properties
            IAnalysisPropertyProvider cmdLineProperties;
            parsedOk &= CmdLineArgPropertyProvider.TryCreateProvider(arguments, logger, out cmdLineProperties);

            // Handler for property file
            IAnalysisPropertyProvider globalFileProperties;
            string asmPath = Path.GetDirectoryName(typeof(Bootstrapper.ArgumentProcessor).Assembly.Location);
            parsedOk &= FilePropertyProvider.TryCreateProvider(arguments, asmPath, logger, out globalFileProperties);

            AnalysisPhase phase;
            parsedOk &= TryGetPhase(commandLineArgs.Length, arguments, logger, out phase);

            Debug.Assert(!parsedOk || cmdLineProperties != null);
            Debug.Assert(!parsedOk || globalFileProperties != null);

            if (parsedOk)
            {
                Debug.Assert(cmdLineProperties != null);
                Debug.Assert(globalFileProperties != null);
                IAnalysisPropertyProvider properties = new AggregatePropertiesProvider(cmdLineProperties, globalFileProperties);

                IList<string> baseChildArgs = RemoveBootstrapperArgs(commandLineArgs);

                if (phase == AnalysisPhase.PreProcessing)
                {
                    settings = CreatePreProcessorSettings(baseChildArgs, properties, globalFileProperties, logger);
                }
                else
                {
                    settings = CreatePostProcessorSettings(baseChildArgs, properties, logger);
                }
            }

            return settings != null;
        }
コード例 #2
0
        private static int PreProcess(IBuildAgentUpdater updater, IBootstrapperSettings settings, ILogger logger)
        {
            string downloadBinPath = settings.DownloadDirectory;

            logger.LogInfo(Resources.MSG_PreparingDirectories);
            if (!Utilities.TryEnsureEmptyDirectories(logger,
                settings.TempDirectory,
                downloadBinPath))
            {
                return ErrorCode;
            }

            string server = settings.SonarQubeUrl;
            Debug.Assert(!string.IsNullOrWhiteSpace(server), "Not expecting the server url to be null/empty");
            logger.LogDebug(Resources.MSG_ServerUrl, server);

            logger.LogInfo(Resources.MSG_CheckingForUpdates);
            if (!updater.TryUpdate(server, downloadBinPath, logger))
            {
                logger.LogError(Resources.ERROR_FailedToUpdateRunnerBinaries);
                return ErrorCode;
            }

            if (!updater.CheckBootstrapperApiVersion(settings.SupportedBootstrapperVersionsFilePath, settings.BootstrapperVersion))
            {
                logger.LogError(Resources.ERROR_VersionMismatch);
                return ErrorCode;
            }

            var preprocessorFilePath = settings.PreProcessorFilePath;

            ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(preprocessorFilePath, logger)
            {
                CmdLineArgs = settings.ChildCmdLineArgs,
                WorkingDirectory = settings.TempDirectory,
            };
            ProcessRunner runner = new ProcessRunner();
            runner.Execute(runnerArgs);

            return runner.ExitCode;
        }
コード例 #3
0
        private static int PostProcess(IBootstrapperSettings settings, ILogger logger)
        {

            if (!File.Exists(settings.PostProcessorFilePath))
            {
                logger.LogError(Resources.ERROR_PostProcessExeNotFound, settings.PostProcessorFilePath);
                return ErrorCode;
            }

            ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(settings.PostProcessorFilePath, logger)
            {
                CmdLineArgs = settings.ChildCmdLineArgs,
                WorkingDirectory = settings.TempDirectory
            };

            ProcessRunner runner = new ProcessRunner();
            runner.Execute(runnerArgs);

            return runner.ExitCode;
        }
コード例 #4
0
 private static void AssertExpectedDownloadDir(string expected, IBootstrapperSettings settings)
 {
     string actual = settings.DownloadDirectory;
     Assert.AreEqual(expected, actual, "Unexpected download dir", true /* ignore case */);
 }
コード例 #5
0
 private static void AssertExpectedServerUrl(string expected, IBootstrapperSettings settings)
 {
     string actual = settings.SonarQubeUrl;
     Assert.AreEqual(expected, actual, true /* ignore case */, "Unexpected server url");
 }
コード例 #6
0
 private static void AssertExpectedPhase(AnalysisPhase expected, IBootstrapperSettings settings)
 {
     Assert.AreEqual(expected, settings.Phase, "Unexpected analysis phase");
 }
コード例 #7
0
 private static void AssertExpectedPhase(AnalysisPhase expected, IBootstrapperSettings settings)
 {
     Assert.AreEqual(expected, settings.Phase, "Unexpected analysis phase");
 }
コード例 #8
0
        private static void AssertUrlAndChildCmdLineArgs(IBootstrapperSettings settings, string expectedUrl, params string[] expectedCmdLineArgs)
        {
            Assert.AreEqual(expectedUrl, settings.SonarQubeUrl, "Unexpected SonarQube URL");

            CollectionAssert.AreEqual(expectedCmdLineArgs, settings.ChildCmdLineArgs.ToList(), "Unexpected child command line arguments");
        }
コード例 #9
0
 private static void AssertExpectedPhase(AnalysisPhase expected, IBootstrapperSettings settings)
 {
     settings.Phase.Should().Be(expected, "Unexpected analysis phase");
 }
コード例 #10
0
 public BootstrapperClass(IProcessorFactory processorFactory, IBootstrapperSettings bootstrapSettings, ILogger logger)
     : this(processorFactory, bootstrapSettings, logger, assemblyPath => AssemblyName.GetAssemblyName(assemblyPath).Version)
 {
 }
コード例 #11
0
        private static void AssertExpectedDownloadDir(string expected, IBootstrapperSettings settings)
        {
            string actual = settings.DownloadDirectory;

            Assert.AreEqual(expected, actual, "Unexpected download dir", true /* ignore case */);
        }
コード例 #12
0
        private static void AssertExpectedServerUrl(string expected, IBootstrapperSettings settings)
        {
            string actual = settings.SonarQubeUrl;

            Assert.AreEqual(expected, actual, true /* ignore case */, "Unexpected server url");
        }
コード例 #13
0
        private static void AssertExpectedPostProcessPath(string expected, IBootstrapperSettings settings)
        {
            string actual = settings.PostProcessorFilePath;

            Assert.AreEqual(expected, actual, true /* ignore case */, "Unexpected PostProcessFilePath");
        }
コード例 #14
0
 private static void AssertExpectedChildArguments(IBootstrapperSettings actualSettings, params string[] expected)
 {
     CollectionAssert.AreEqual(expected, actualSettings.ChildCmdLineArgs.ToList(), "Unexpected child command line arguments");
 }
コード例 #15
0
        private static int PostProcess(IBootstrapperSettings settings, ILogger logger)
        {
            ProcessRunnerArguments runnerArgs = new ProcessRunnerArguments(settings.PostProcessorFilePath, logger)
            {
                CmdLineArgs = settings.ChildCmdLineArgs,
                WorkingDirectory = settings.TempDirectory
            };

            ProcessRunner runner = new ProcessRunner();
            runner.Execute(runnerArgs);

            return runner.ExitCode;
        }
コード例 #16
0
 private static void AssertExpectedChildArguments(IBootstrapperSettings actualSettings, params string[] expected)
 {
     actualSettings.ChildCmdLineArgs.Should().BeEquivalentTo(expected, "Unexpected child command line arguments");
 }
コード例 #17
0
 private static void AssertUrlAndChildCmdLineArgs(IBootstrapperSettings settings, params string[] expectedCmdLineArgs)
 {
     settings.ChildCmdLineArgs.Should().BeEquivalentTo(expectedCmdLineArgs, "Unexpected child command line arguments");
 }
コード例 #18
0
 private static void AssertUrl(IBootstrapperSettings settings, string expectedUrl)
 {
     Assert.AreEqual(expectedUrl, settings.SonarQubeUrl, "Unexpected SonarQube URL");
 }
コード例 #19
0
 private static void AssertExpectedPostProcessPath(string expected, IBootstrapperSettings settings)
 {
     string actual = settings.PostProcessorFilePath;
     Assert.AreEqual(expected, actual, true /* ignore case */, "Unexpected PostProcessFilePath");
 }
コード例 #20
0
 private static void AssertExpectedChildArguments(IBootstrapperSettings actualSettings, params string[] expected)
 {
     CollectionAssert.AreEqual(expected, actualSettings.ChildCmdLineArgs.ToList(), "Unexpected child command line arguments");
 }
コード例 #21
0
 private static void AssertUrlAndChildCmdLineArgs(IBootstrapperSettings settings, string expectedUrl, params string[] expectedCmdLineArgs)
 {
     CollectionAssert.AreEqual(expectedCmdLineArgs, settings.ChildCmdLineArgs.ToList(), "Unexpected child command line arguments");
 }