/// <summary>
        /// Returns a provider containing the analysis settings coming from all providers (analysis config file, environment, settings file).
        /// Optionally includes settings downloaded from the SonarQube server.
        /// </summary>
        /// <remarks>This could include settings imported from a settings file</remarks>
        public static IAnalysisPropertyProvider GetAnalysisSettings(this AnalysisConfig config, bool includeServerSettings)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            var providers = new List <IAnalysisPropertyProvider>();

            // Note: the order in which the providers are added determines the precedence
            // Add local settings
            if (config.LocalSettings != null)
            {
                providers.Add(new ListPropertiesProvider(config.LocalSettings));
            }

            // Add file settings
            var settingsFilePath = config.GetSettingsFilePath();

            if (settingsFilePath != null)
            {
                var fileProvider = new ListPropertiesProvider(AnalysisProperties.Load(settingsFilePath));
                providers.Add(fileProvider);
            }

            // Add scanner environment settings
            if (EnvScannerPropertiesProvider.TryCreateProvider(null, out var envProvider))
            {
                providers.Add(envProvider);
            }

            // Add server settings
            if (includeServerSettings && config.ServerSettings != null)
            {
                providers.Add(new ListPropertiesProvider(config.ServerSettings));
            }

            IAnalysisPropertyProvider provider;

            switch (providers.Count)
            {
            case 0:
                provider = EmptyPropertyProvider.Instance;
                break;

            case 1:
                provider = providers[0];
                break;

            default:
                provider = new AggregatePropertiesProvider(providers.ToArray());
                break;
            }

            return(provider);
        }
 public static bool TryCreateProvider(ILogger logger, out IAnalysisPropertyProvider provider)
 {
     provider = null;
     try
     {
         provider = new EnvScannerPropertiesProvider(Environment.GetEnvironmentVariable(ENV_VAR_KEY));
         return(true);
     }
     catch (Exception)
     {
         logger?.LogError(Resources.ERROR_FailedParsePropertiesEnvVar, ENV_VAR_KEY);
     }
     return(false);
 }