Exemple #1
0
        public bool TryWriteProperties(PropertiesWriter writer, out IEnumerable <ProjectData> allProjects)
        {
            var projects = ProjectLoader.LoadFrom(analysisConfig.SonarOutputDir);

            if (!projects.Any())
            {
                logger.LogError(Resources.ERR_NoProjectInfoFilesFound, SonarProduct.GetSonarProductToLog(analysisConfig.SonarQubeHostUrl));
                allProjects = Enumerable.Empty <ProjectData>();
                return(false);
            }

            var projectsWithoutGuid = projects.Where(p => p.ProjectGuid == Guid.Empty).ToList();

            if (projectsWithoutGuid.Count > 0)
            {
                logger.LogWarning(Resources.WARN_EmptyProjectGuids, string.Join(", ", projectsWithoutGuid.Select(p => p.FullPath)));
            }

            var projectDirectories = projects.Select(p => p.GetDirectory()).ToList();
            var analysisProperties = analysisConfig.ToAnalysisProperties(logger);

            FixSarifAndEncoding(projects, analysisProperties);

            allProjects = projects.GroupBy(p => p.ProjectGuid).Select(ToProjectData).ToList();
            var validProjects = allProjects.Where(p => p.Status == ProjectInfoValidity.Valid).ToList();

            if (validProjects.Count == 0)
            {
                logger.LogError(Resources.ERR_NoValidProjectInfoFiles, SonarProduct.GetSonarProductToLog(analysisConfig.SonarQubeHostUrl));
                return(false);
            }

            var rootProjectBaseDir = ComputeRootProjectBaseDir(projectDirectories);

            if (rootProjectBaseDir == null ||
                !rootProjectBaseDir.Exists)
            {
                logger.LogError(Resources.ERR_ProjectBaseDirDoesNotExist);
                return(false);
            }

            var rootModuleFiles = PutFilesToRightModuleOrRoot(validProjects, rootProjectBaseDir);

            PostProcessProjectStatus(validProjects);

            if (rootModuleFiles.Count == 0 &&
                validProjects.All(p => p.Status == ProjectInfoValidity.NoFilesToAnalyze))
            {
                logger.LogError(Resources.ERR_NoValidProjectInfoFiles, SonarProduct.GetSonarProductToLog(analysisConfig.SonarQubeHostUrl));
                return(false);
            }

            writer.WriteSonarProjectInfo(rootProjectBaseDir);
            writer.WriteSharedFiles(rootModuleFiles);
            validProjects.ForEach(writer.WriteSettingsForProject);
            // Handle global settings
            writer.WriteGlobalSettings(analysisProperties);
            return(true);
        }
Exemple #2
0
        public bool TryWriteProperties(PropertiesWriter writer, out IEnumerable <ProjectData> allProjects)
        {
            var projects = ProjectLoader.LoadFrom(analysisConfig.SonarOutputDir);

            if (projects == null || !projects.Any())
            {
                logger.LogError(Resources.ERR_NoProjectInfoFilesFound);
                allProjects = Enumerable.Empty <ProjectData>();
                return(false);
            }

            var projectPaths = projects.Select(p => p.GetProjectDirectory()).ToList();

            var analysisProperties = analysisConfig.ToAnalysisProperties(logger);

            FixSarifAndEncoding(projects, analysisProperties);

            allProjects = projects
                          .GroupBy(p => p.ProjectGuid)
                          .Select(ToProjectData)
                          .ToList();

            var validProjects = allProjects
                                .Where(d => d.Status == ProjectInfoValidity.Valid)
                                .ToList();

            if (validProjects.Count == 0)
            {
                logger.LogError(Resources.ERR_NoValidProjectInfoFiles);
                return(false);
            }

            var rootProjectBaseDir = ComputeRootProjectBaseDir(projectPaths);

            if (rootProjectBaseDir == null ||
                !Directory.Exists(rootProjectBaseDir))
            {
                logger.LogError(Resources.ERR_ProjectBaseDirDoesNotExist);
                return(false);
            }

            var rootModuleFiles = PutFilesToRightModuleOrRoot(validProjects, rootProjectBaseDir);

            PostProcessProjectStatus(validProjects);

            if (rootModuleFiles.Count == 0 && validProjects.All(p => p.Status == ProjectInfoValidity.NoFilesToAnalyze))
            {
                logger.LogError(Resources.ERR_NoValidProjectInfoFiles);
                return(false);
            }

            writer.WriteSonarProjectInfo(rootProjectBaseDir);
            writer.WriteSharedFiles(rootModuleFiles);
            validProjects.ForEach(p => writer.WriteSettingsForProject(p, p.CoverageAnalysisExists(logger)
                ? p.VisualStudioCoverageLocation : null));

            // Handle global settings
            writer.WriteGlobalSettings(analysisProperties);

            return(true);
        }