private IEnumerable <AnalyzerPlugin> FetchAnalyzerPlugins(string language, IEnumerable <SonarRule> activeRules)
        {
            var            partialRepoKeys = ActiveRulesPartialRepoKeys(activeRules);
            IList <Plugin> plugins         = new List <Plugin>();

            foreach (var partialRepoKey in partialRepoKeys)
            {
                if (!sonarProperties.TryGetValue($"{partialRepoKey}.pluginKey", out var pluginkey) ||
                    !sonarProperties.TryGetValue($"{partialRepoKey}.pluginVersion", out var pluginVersion) ||
                    !sonarProperties.TryGetValue($"{partialRepoKey}.staticResourceName", out var staticResourceName))
                {
                    if (!partialRepoKey.StartsWith(SONARANALYZER_PARTIAL_REPO_KEY_PREFIX))
                    {
                        this.logger.LogInfo(Resources.RAP_NoAssembliesForRepo, partialRepoKey, language);
                    }
                    continue;
                }

                plugins.Add(new Plugin(pluginkey, pluginVersion, staticResourceName));
            }

            if (plugins.Count == 0)
            {
                this.logger.LogInfo(Resources.RAP_NoAnalyzerPluginsSpecified, language);
                return(Enumerable.Empty <AnalyzerPlugin>());
            }
            else
            {
                this.logger.LogInfo(Resources.RAP_ProvisioningAnalyzerAssemblies, language);
                return(this.analyzerInstaller.InstallAssemblies(plugins));
            }
        }
Example #2
0
        public ProcessedArgs(string key, string name, string version, bool installLoaderTargets, IAnalysisPropertyProvider cmdLineProperties,
                             IAnalysisPropertyProvider globalFileProperties, IAnalysisPropertyProvider scannerEnvProperties)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }
            if (cmdLineProperties == null)
            {
                throw new ArgumentNullException("cmdLineProperties");
            }
            if (globalFileProperties == null)
            {
                throw new ArgumentNullException("globalFileProperties");
            }
            if (scannerEnvProperties == null)
            {
                throw new ArgumentNullException("scannerEnvProperties");
            }

            this.projectKey     = key;
            this.projectName    = name;
            this.projectVersion = version;

            this.cmdLineProperties    = cmdLineProperties;
            this.globalFileProperties = globalFileProperties;
            this.scannerEnvProperties = scannerEnvProperties;
            this.InstallLoaderTargets = installLoaderTargets;

            this.aggProperties = new AggregatePropertiesProvider(cmdLineProperties, globalFileProperties, scannerEnvProperties);
            if (!aggProperties.TryGetValue(SonarProperties.HostUrl, out this.sonarQubeUrl))
            {
                this.sonarQubeUrl = "http://localhost:9000";
            }
        }
        /// <summary>
        /// Computes verbosity based on the available properties.
        /// </summary>
        /// <remarks>If no verbosity setting is present, the default verbosity (info) is used</remarks>
        public static LoggerVerbosity ComputeVerbosity(IAnalysisPropertyProvider properties, ILogger logger)
        {
            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            properties.TryGetValue(SonarProperties.Verbose, out string sonarVerboseValue);

            properties.TryGetValue(SonarProperties.LogLevel, out string sonarLogLevelValue);

            return(ComputeVerbosity(sonarVerboseValue, sonarLogLevelValue, logger));
        }
        private static string FindBranch(AnalysisConfig config)
        {
            IAnalysisPropertyProvider localSettings = config.GetAnalysisSettings(includeServerSettings: false);

            Debug.Assert(localSettings != null);

            localSettings.TryGetValue(SonarProperties.ProjectBranch, out string branch);

            return(branch);
        }
        /// <summary>
        /// Computes verbosity based on the available properties. 
        /// </summary>
        /// <remarks>If no verbosity setting is present, the default verbosity (info) is used</remarks>
        public static LoggerVerbosity ComputeVerbosity(IAnalysisPropertyProvider properties, ILogger logger)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            string sonarVerboseValue;
            properties.TryGetValue(SonarProperties.Verbose, out sonarVerboseValue);

            string sonarLogLevelValue;
            properties.TryGetValue(SonarProperties.LogLevel, out sonarLogLevelValue);

            return ComputeVerbosity(sonarVerboseValue, sonarLogLevelValue, logger);
        }
        private static string TryGetHostUrl(IAnalysisPropertyProvider properties, ILogger logger)
        {
            string url;

            if (properties.TryGetValue(SonarProperties.HostUrl, out url))
            {
                return(url);
            }

            logger.LogError(Resources.ERROR_Args_UrlRequired);
            return(null);
        }
        private static string TryGetHostUrl(IAnalysisPropertyProvider properties, ILogger logger)
        {
            string url;
            if (properties.TryGetValue(SonarProperties.HostUrl, out url))
            {
                return url;
            }

            logger.LogError(Resources.ERROR_Args_UrlRequired);
            return null;
        }