예제 #1
0
        private void ConvertProject(Report report, Options options)
        {
            var projectFileInfo = new FileInfo(options.Project);

            if (!projectFileInfo.Exists)
            {
                throw new FileNotFoundException("Project not found.", options.Project);
            }

            var projectName = projectFileInfo.Name;
            var projectNameWithoutExtension = Path.GetFileNameWithoutExtension(projectName);
            var sonarReports = SonarReportGeneratorFactory.GetGenerator(options.OutputFormat).Generate(report);

            var projectToWrite = sonarReports.FirstOrDefault(
                r => string.Equals(projectName, projectFileInfo.Name, StringComparison.OrdinalIgnoreCase));

            if (projectToWrite == null)
            {
                Logger.Information("Project " + options.Project + " contains no issues.");
            }
            else
            {
                var outputFile = string.IsNullOrEmpty(options.Directory)
                    ? GetOutputPath(projectFileInfo.DirectoryName, options.Output, projectNameWithoutExtension)
                    : GetOutputPath(options.Directory, options.Output, projectNameWithoutExtension);

                WriteReport(outputFile, projectToWrite);
            }
        }
예제 #2
0
        private void ConvertSolution(Report report, Options options)
        {
            if (Path.IsPathRooted(options.Output))
            {
                throw new ArgumentException("Absolute paths are not allowed with -output, when converting a sln.");
            }

            var solution = SolutionParser.Parse(report.Information.Solution);

            ValidateSolution(solution);

            var baseDir = string.IsNullOrEmpty(options.Directory)
                ? Path.GetDirectoryName(report.Information.Solution) : options.Directory;
            var sonarReports = SonarReportGeneratorFactory.GetGenerator(options.OutputFormat).Generate(report);

            if (options.OutputFormat == SonarOutputFormat.Generic)
            {
                // We need to write dummy report because SonarQube MSBuild reads a report from the root
                WriteReport(
                    GetOutputPath(baseDir, options.Output, string.Empty),
                    SonarGenericReport.Empty);
            }

            foreach (var sonarReport in sonarReports)
            {
                var filePath = GetOutputPath(
                    baseDir,
                    Path.Combine(GetProjectFolder(solution, sonarReport.ProjectName), options.Output),
                    sonarReport.ProjectName);
                WriteReport(filePath, sonarReport);
            }

            TryWriteMissingReports(solution, baseDir, options, sonarReports);
        }