private void FetchSonarQubeProperties(AnalysisConfig config, SonarWebService ws)
        {
            var properties = this.propertiesFetcher.FetchProperties(ws, config.SonarProjectKey);

            foreach (var property in properties)
            {
                config.SetValue(property.Key, property.Value);
            }
        }
Пример #2
0
        public void Generate(SonarWebService ws, string requiredPluginKey, string language, string fxcopRepositoryKey, string sonarProjectKey, string outputFilePath)
        {
            if (ws == null)
            {
                throw new ArgumentNullException("ws");
            }
            if (string.IsNullOrWhiteSpace(requiredPluginKey))
            {
                throw new ArgumentNullException("requiredPluginKey");
            }
            if (string.IsNullOrWhiteSpace(language))
            {
                throw new ArgumentNullException("language");
            }
            if (string.IsNullOrWhiteSpace(fxcopRepositoryKey))
            {
                throw new ArgumentNullException("fxcopRepositoryKey");
            }
            if (string.IsNullOrWhiteSpace(sonarProjectKey))
            {
                throw new ArgumentNullException("sonarProjectKey");
            }
            if (string.IsNullOrWhiteSpace(outputFilePath))
            {
                throw new ArgumentNullException("outputFilePath");
            }

            IEnumerable <string> activeRuleKeys = Enumerable.Empty <string>();

            if (ws.GetInstalledPlugins().Contains(requiredPluginKey))
            {
                string qualityProfile;
                if (ws.TryGetQualityProfile(sonarProjectKey, language, out qualityProfile))
                {
                    activeRuleKeys = ws.GetActiveRuleKeys(qualityProfile, language, fxcopRepositoryKey);
                }
            }

            if (activeRuleKeys.Any())
            {
                var internalKeys = ws.GetInternalKeys(fxcopRepositoryKey);
                var ids          = activeRuleKeys.Select(
                    k =>
                {
                    var fullKey = fxcopRepositoryKey + ':' + k;
                    return(internalKeys.ContainsKey(fullKey) ? internalKeys[fullKey] : k);
                });

                File.WriteAllText(outputFilePath, RulesetWriter.ToString(ids));
            }
            else
            {
                File.Delete(outputFilePath);
            }
        }
        public void Generate(SonarWebService ws, string requiredPluginKey, string language, string fxcopRepositoryKey, string sonarProjectKey, string outputFilePath)
        {
            if (ws == null)
            {
                throw new ArgumentNullException("ws");
            }
            if (string.IsNullOrWhiteSpace(requiredPluginKey))
            {
                throw new ArgumentNullException("requiredPluginKey");
            }
            if (string.IsNullOrWhiteSpace(language))
            {
                throw new ArgumentNullException("language");
            }
            if (string.IsNullOrWhiteSpace(fxcopRepositoryKey))
            {
                throw new ArgumentNullException("fxcopRepositoryKey");
            }
            if (string.IsNullOrWhiteSpace(sonarProjectKey))
            {
                throw new ArgumentNullException("sonarProjectKey");
            }
            if (string.IsNullOrWhiteSpace(outputFilePath))
            {
                throw new ArgumentNullException("outputFilePath");
            }

            IEnumerable<string> activeRuleKeys = Enumerable.Empty<string>();
            if (ws.GetInstalledPlugins().Contains(requiredPluginKey))
            {
                string qualityProfile;
                if (ws.TryGetQualityProfile(sonarProjectKey, language, out qualityProfile))
                {
                    activeRuleKeys = ws.GetActiveRuleKeys(qualityProfile, language, fxcopRepositoryKey);
                }
            }

            if (activeRuleKeys.Any())
            {
                var internalKeys = ws.GetInternalKeys(fxcopRepositoryKey);
                var ids = activeRuleKeys.Select(
                    k =>
                    {
                        var fullKey = fxcopRepositoryKey + ':' + k;
                        return internalKeys.ContainsKey(fullKey) ? internalKeys[fullKey] : k;
                    });

                File.WriteAllText(outputFilePath, RulesetWriter.ToString(ids));
            }
            else
            {
                File.Delete(outputFilePath);
            }
        }
        public IDictionary <string, string> FetchProperties(SonarWebService ws, string sonarProjectKey)
        {
            if (ws == null)
            {
                throw new ArgumentNullException("ws");
            }
            if (string.IsNullOrWhiteSpace(sonarProjectKey))
            {
                throw new ArgumentNullException("sonarProjectKey");
            }

            return(ws.GetProperties(sonarProjectKey));
        }
        public IDictionary<string, string> FetchProperties(SonarWebService ws, string sonarProjectKey, ILogger logger)
        {
            if (ws == null)
            {
                throw new ArgumentNullException("ws");
            }
            if (string.IsNullOrWhiteSpace(sonarProjectKey))
            {
                throw new ArgumentNullException("sonarProjectKey");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            return ws.GetProperties(sonarProjectKey, logger);
        }
Пример #6
0
 private void GenerateFxCopRuleset(SonarWebService ws, string projectKey, string requiredPluginKey, string language, string repository, string path, ILogger logger)
 {
     logger.LogDebug(Resources.MSG_GeneratingRuleset, path);
     this.rulesetGenerator.Generate(ws, requiredPluginKey, language, repository, projectKey, path);
 }
        public bool Execute(ILogger logger, string projectKey, string projectName, string projectVersion, string propertiesPath)
        {
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (string.IsNullOrWhiteSpace(projectKey))
            {
                throw new ArgumentNullException("projectKey");
            }
            if (string.IsNullOrWhiteSpace(projectName))
            {
                throw new ArgumentNullException("projectName");
            }
            if (string.IsNullOrWhiteSpace(projectVersion))
            {
                throw new ArgumentNullException("projectVersion");
            }
            if (string.IsNullOrWhiteSpace(propertiesPath))
            {
                throw new ArgumentNullException("propertiesPath");
            }

            AnalysisConfig config = new AnalysisConfig();

            config.SonarProjectKey           = projectKey;
            config.SonarProjectName          = projectName;
            config.SonarProjectVersion       = projectVersion;
            config.SonarRunnerPropertiesPath = propertiesPath;

            TeamBuildSettings teamBuildSettings = TeamBuildSettings.GetSettingsFromEnvironment(logger);

            // We're checking the args and environment variables so we can report all
            // config errors to the user at once
            if (teamBuildSettings == null)
            {
                logger.LogError(Resources.ERROR_CannotPerformProcessing);
                return(false);
            }

            config.SetBuildUri(teamBuildSettings.BuildUri);
            config.SetTfsUri(teamBuildSettings.TfsUri);
            config.SonarConfigDir = teamBuildSettings.SonarConfigDirectory;
            config.SonarOutputDir = teamBuildSettings.SonarOutputDirectory;

            // Create the directories
            logger.LogMessage(Resources.DIAG_CreatingFolders);
            EnsureEmptyDirectory(logger, config.SonarConfigDir);
            EnsureEmptyDirectory(logger, config.SonarOutputDir);

            using (SonarWebService ws = GetSonarWebService(config))
            {
                // Fetch the SonarQube project properties
                FetchSonarQubeProperties(config, ws);

                // Generate the FxCop ruleset
                GenerateFxCopRuleset(config, ws, logger);
            }

            // Save the config file
            logger.LogMessage(Resources.DIAG_SavingConfigFile, teamBuildSettings.AnalysisConfigFilePath);
            config.Save(teamBuildSettings.AnalysisConfigFilePath);

            return(true);
        }
 private void GenerateFxCopRuleset(AnalysisConfig config, SonarWebService ws, ILogger logger)
 {
     logger.LogMessage(Resources.DIAG_GeneratingRuleset);
     this.rulesetGenerator.Generate(ws, config.SonarProjectKey, Path.Combine(config.SonarConfigDir, FxCopRulesetFileName));
 }