Exemple #1
0
        public ProjectInfoAnalysisResult Execute(AnalysisConfig config, IEnumerable <string> userCmdLineArguments)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (userCmdLineArguments == null)
            {
                throw new ArgumentNullException(nameof(userCmdLineArguments));
            }

            var result = new PropertiesFileGenerator(config, logger).GenerateFile();

            Debug.Assert(result != null, "Not expecting the file generator to return null");
            result.RanToCompletion = false;

            SonarProjectPropertiesValidator.Validate(
                config.SonarScannerWorkingDirectory,
                result.Projects,
                onValid: () =>
            {
                ProjectInfoReportBuilder.WriteSummaryReport(config, result, logger);

                result.RanToCompletion = InternalExecute(config, userCmdLineArguments, logger, result.FullPropertiesFilePath);
            },
                onInvalid: (invalidFolders) =>
            {
                // LOG error message
                logger.LogError(Resources.ERR_ConflictingSonarProjectProperties, string.Join(", ", invalidFolders));
            });

            return(result);
        }
Exemple #2
0
        public void WriteSettingsForProject(ProjectData projectData)
        {
            if (FinishedWriting)
            {
                throw new InvalidOperationException();
            }

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

            Debug.Assert(projectData.ReferencedFiles.Count > 0, "Expecting a project to have files to analyze");
            Debug.Assert(projectData.SonarQubeModuleFiles.All(f => f.Exists), "Expecting all of the specified files to exist");

            var guid = projectData.Project.GetProjectGuidAsString();

            AppendKeyValue(guid, SonarProperties.ProjectKey, config.SonarProjectKey + ":" + guid);
            AppendKeyValue(guid, SonarProperties.ProjectName, projectData.Project.ProjectName);
            AppendKeyValue(guid, SonarProperties.ProjectBaseDir, projectData.Project.GetDirectory().FullName);

            if (!string.IsNullOrWhiteSpace(projectData.Project.Encoding))
            {
                AppendKeyValue(guid, SonarProperties.SourceEncoding, projectData.Project.Encoding.ToLowerInvariant());
            }

            string property;

            if (projectData.Project.ProjectType == ProjectType.Product)
            {
                property = "sonar.sources";
            }
            else
            {
                AppendKeyValue(guid, "sonar.sources", "");
                property = "sonar.tests";
            }
            AppendKeyValue(guid, property, projectData.SonarQubeModuleFiles);
            sb.AppendLine();

            if (projectData.Project.AnalysisSettings != null && projectData.Project.AnalysisSettings.Any())
            {
                foreach (var setting in projectData.Project.AnalysisSettings.Where(x => !PropertiesFileGenerator.IsProjectOutPaths(x.Id) && !PropertiesFileGenerator.IsReportFilePaths(x.Id)))
                {
                    sb.AppendFormat("{0}.{1}={2}", guid, setting.Id, Escape(setting.Value));
                    sb.AppendLine();
                }

                WriteAnalyzerOutputPaths(projectData);
                WriteRoslynReportPaths(projectData);

                sb.AppendLine();
            }

            // Store the project guid so that we can write all module keys in the end
            moduleKeys.Add(projectData.Guid);

            var moduleWorkdir = Path.Combine(config.SonarOutputDir, ".sonar", $"mod{moduleKeys.Count - 1}"); // zero-based index of projectData.Guid

            AppendKeyValue(projectData.Guid, SonarProperties.WorkingDirectory, moduleWorkdir);
        }