public /* for test */ static ProjectInfoAnalysisResult GenerateFile(AnalysisConfig config, ILogger logger, IRoslynV1SarifFixer fixer)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            string fileName = Path.Combine(config.SonarOutputDir, ProjectPropertiesFileName);

            logger.LogDebug(Resources.MSG_GeneratingProjectProperties, fileName);

            IEnumerable <ProjectInfo> projects = ProjectLoader.LoadFrom(config.SonarOutputDir);

            if (projects == null || !projects.Any())
            {
                logger.LogError(Resources.ERR_NoProjectInfoFilesFound);
                return(new ProjectInfoAnalysisResult());
            }

            TryFixSarifReports(logger, projects, fixer);

            string projectBaseDir = ComputeProjectBaseDir(config, projects);

            PropertiesWriter writer = new PropertiesWriter(config);

            ProjectInfoAnalysisResult result = ProcessProjectInfoFiles(projects, writer, logger, projectBaseDir);

            writer.WriteSonarProjectInfo(projectBaseDir, result.SharedFiles);

            IEnumerable <ProjectInfo> validProjects = result.GetProjectsByStatus(ProjectInfoValidity.Valid);

            if (validProjects.Any() || result.SharedFiles.Any())
            {
                // Handle global settings
                AnalysisProperties properties = GetAnalysisPropertiesToWrite(config, logger);
                writer.WriteGlobalSettings(properties);

                string contents = writer.Flush();

                result.FullPropertiesFilePath = fileName;
                File.WriteAllText(result.FullPropertiesFilePath, contents, Encoding.ASCII);
            }
            else
            {
                // if the user tries to build multiple configurations at once there will be duplicate projects
                if (result.GetProjectsByStatus(ProjectInfoValidity.DuplicateGuid).Any())
                {
                    logger.LogError(Resources.ERR_NoValidButDuplicateProjects);
                }
                else
                {
                    logger.LogError(Resources.ERR_NoValidProjectInfoFiles);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private void Generate()
        {
            IEnumerable <ProjectInfo> validProjects = analysisResult.GetProjectsByStatus(ProjectInfoValidity.Valid);

            WriteTitle(Resources.REPORT_ProductProjectsTitle);
            WriteFileList(validProjects.Where(p => p.ProjectType == ProjectType.Product));
            WriteGroupSpacer();

            WriteTitle(Resources.REPORT_TestProjectsTitle);
            WriteFileList(validProjects.Where(p => p.ProjectType == ProjectType.Test));
            WriteGroupSpacer();

            WriteTitle(Resources.REPORT_InvalidProjectsTitle);
            WriteFilesByStatus(ProjectInfoValidity.InvalidGuid);
            WriteGroupSpacer();

            WriteTitle(Resources.REPORT_SkippedProjectsTitle);
            WriteFilesByStatus(ProjectInfoValidity.NoFilesToAnalyze);
            WriteGroupSpacer();

            WriteTitle(Resources.REPORT_ExcludedProjectsTitle);
            WriteFilesByStatus(ProjectInfoValidity.ExcludeFlagSet);
            WriteGroupSpacer();

            var reportFileName = Path.Combine(config.SonarOutputDir, ReportFileName);

            logger.LogDebug(Resources.MSG_WritingSummary, reportFileName);
            File.WriteAllText(reportFileName, sb.ToString());
        }