예제 #1
0
        public override bool Execute()
        {
            if (TaskUtilities.TryGetConfig(AnalysisConfigDir, new MSBuildLoggerAdapter(Log)) is AnalysisConfig config)
            {
                if (config.GetAnalysisSettings(true).TryGetValue(TestRegExSettingId, out var regEx) && !string.IsNullOrWhiteSpace(regEx))
                {
                    Log.LogMessage(MessageImportance.Low, Resources.IsTest_UsingRegExFromConfig, regEx);
                    try
                    {
                        // Let's use a case sensitive regex (default behavior)
                        IsTest = Regex.IsMatch(FullFilePath, regEx);
                    }
                    catch (ArgumentException ex) // thrown for invalid regular expressions
                    {
                        Log.LogError(Resources.IsTest_InvalidRegularExpression, regEx, ex.Message, TestRegExSettingId);
                    }
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, Resources.IsTest_NameNotChecked);
                }
            }

            return(!Log.HasLoggedErrors);
        }
        public override bool Execute()
        {
            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, new MSBuildLoggerAdapter(Log));

            ExecuteAnalysis(config);

            return(!Log.HasLoggedErrors);
        }
예제 #3
0
        public override bool Execute()
        {
            var logger = new MSBuildLoggerAdapter(Log);
            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, logger);

            var languageSettings = GetLanguageSpecificSettings(config);

            if (languageSettings == null)
            {
                // Early-out: we don't have any settings for the current language.
                // Preserve the default existing behaviour of only preserving the original list of additional files but clearing the analyzers.
                RuleSetFilePath     = null;
                AdditionalFilePaths = OriginalAdditionalFiles;
                return(!Log.HasLoggedErrors);
            }

            TaskOutputs outputs;

            // We analyze test projects since MMF-2297 / SQ 8.9. C#/VB.NET plugin <= 8.20 bundled with SQ <= 8.8 would ignore results on test projects anyway.
            if (IsTestProject && (ExcludeTestProjects() || !IsTestAnalysisSupported()))
            {
                // Special case: to provide colorization etc for code in test projects, we need to run only the SonarC#/VB analyzers, with all of the non-utility rules turned off
                // See [MMF-486]: https://jira.sonarsource.com/browse/MMF-486
                Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_ConfiguringTestProjectAnalysis);
                outputs = CreateDeactivatedProjectSettings(languageSettings);
            }
            else
            {
                if (ShouldMergeAnalysisSettings(Language, config, logger))
                {
                    Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_MergingSettings);
                    outputs = CreateMergedAnalyzerSettings(languageSettings);
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_OverwritingSettings);
                    outputs = CreateLegacyProductProjectSettings(languageSettings);
                }
            }

            ApplyTaskOutput(outputs);

            return(!Log.HasLoggedErrors);

            bool ExcludeTestProjects() =>
            config.GetAnalysisSettings(false).TryGetValue(ExcludeTestProjectsSettingId, out var excludeTestProjects) &&
            excludeTestProjects.Equals("true", StringComparison.OrdinalIgnoreCase);

            bool IsTestAnalysisSupported()
            {
                var version = config.FindServerVersion();

                return(SonarProduct.IsSonarCloud(config.SonarQubeHostUrl, version) || version >= new Version(8, 9));
            }
        }
예제 #4
0
        public override bool Execute()
        {
            var logger = new MSBuildLoggerAdapter(Log);
            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, logger);

            if (ShouldMergeAnalysisSettings(this.Language, config, logger))
            {
                MergeAnalysisSettings(config);
            }
            else
            {
                OverrideAnalysisSettings(config);
            }

            return(!Log.HasLoggedErrors);
        }
        public override bool Execute()
        {
            var logger = new MSBuildLoggerAdapter(Log);
            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, logger);

            var languageSettings = GetLanguageSpecificSettings(config);

            if (languageSettings == null)
            {
                // Early-out: we don't have any settings for the current language.
                // Preserve the default existing behaviour of only preserving the original list of additional files
                // but clearing the analyzers.
                RuleSetFilePath     = null;
                AdditionalFilePaths = OriginalAdditionalFiles;
                return(!Log.HasLoggedErrors);
            }

            TaskOutputs outputs = null;

            if (IsTestProject)
            {
                // Special case: to provide colorization etc for code in test projects, we need
                // to run only the SonarC#/VB analyzers, with all of the non-utility rules turned off
                // See [MMF-486]: https://jira.sonarsource.com/browse/MMF-486
                Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_ConfiguringTestProjectAnalysis);
                outputs = CreateTestProjectSettings(languageSettings);
            }
            else
            {
                if (ShouldMergeAnalysisSettings(Language, config, logger))
                {
                    Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_MergingSettings);
                    outputs = CreateMergedAnalyzerSettings(languageSettings);
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, Resources.AnalyzerSettings_OverwritingSettings);
                    outputs = CreateLegacyProductProjectSettings(languageSettings);
                }
            }

            ApplyTaskOutput(outputs);

            return(!Log.HasLoggedErrors);
        }
예제 #6
0
        public override bool Execute()
        {
            var taskSuccess = true;

            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, new MSBuildLoggerAdapter(Log));

            if (config != null)
            {
                var regEx = TryGetRegularExpression(config);

                try
                {
                    IsTest = !string.IsNullOrEmpty(regEx) && Regex.IsMatch(FullFilePath, regEx, RegexOptions.IgnoreCase);
                }
                catch (ArgumentException ex) // thrown for invalid regular expressions
                {
                    taskSuccess = false;
                    Log.LogError(Resources.IsTest_InvalidRegularExpression, regEx, ex.Message, TestRegExSettingId);
                }
            }

            return(!Log.HasLoggedErrors && taskSuccess);
        }
예제 #7
0
        public override bool Execute()
        {
            var taskSuccess = true;

            var config = TaskUtilities.TryGetConfig(AnalysisConfigDir, new MSBuildLoggerAdapter(Log));

            if (config != null)
            {
                var regEx = TryGetRegularExpression(config);

                try
                {
                    // Let's use a case sensitive regex (default behavior)
                    IsTest = Regex.IsMatch(FullFilePath, regEx);
                }
                catch (ArgumentException ex) // thrown for invalid regular expressions
                {
                    taskSuccess = false;
                    Log.LogError(Resources.IsTest_InvalidRegularExpression, regEx, ex.Message, TestRegExSettingId);
                }
            }

            return(!Log.HasLoggedErrors && taskSuccess);
        }