/// <summary> /// Returns all of the valid files that can be analyzed. Logs warnings/info about /// files that cannot be analyzed. /// </summary> private static IEnumerable<string> GetFilesToAnalyze(ProjectInfo projectInfo, ILogger logger) { // We're only interested in files that exist and that are under the project root var result = new List<string>(); var baseDir = projectInfo.GetProjectDirectory(); foreach (string file in projectInfo.GetAllAnalysisFiles()) { if (File.Exists(file)) { if (IsInFolder(file, baseDir)) { result.Add(file); } else { logger.LogWarning(Resources.WARN_FileIsOutsideProjectDirectory, file, projectInfo.FullPath); } } else { logger.LogWarning(Resources.WARN_FileDoesNotExist, file); } } return result; }
public void WriteSettingsForProject(ProjectInfo project, IEnumerable<string> files, string fxCopReportFilePath, string codeCoverageFilePath) { if (this.FinishedWriting) { throw new InvalidOperationException(); } if (project == null) { throw new ArgumentNullException("project"); } if (files == null) { throw new ArgumentNullException("files"); } Debug.Assert(files.Any(), "Expecting a project to have files to analyze"); Debug.Assert(files.All(f => File.Exists(f)), "Expecting all of the specified files to exist"); this.projects.Add(project); string guid = project.GetProjectGuidAsString(); AppendKeyValue(sb, guid, "sonar.projectKey", this.config.SonarProjectKey + ":" + guid); AppendKeyValue(sb, guid, "sonar.projectName", project.ProjectName); AppendKeyValue(sb, guid, "sonar.projectBaseDir", project.GetProjectDirectory()); if (fxCopReportFilePath != null) { string property = null; if (ProjectLanguages.IsCSharpProject(project.ProjectLanguage)) { property = "sonar.cs.fxcop.reportPath"; } else if (ProjectLanguages.IsVbProject(project.ProjectLanguage)) { property = "sonar.vbnet.fxcop.reportPath"; } Debug.Assert(property != null, "FxCopReportFilePath is set but the language is unrecognised. Language: " + project.ProjectLanguage); if (property != null) { AppendKeyValue(sb, guid, property, fxCopReportFilePath); } } if (codeCoverageFilePath != null) { AppendKeyValue(sb, guid, "sonar.cs.vscoveragexml.reportsPaths", codeCoverageFilePath); } if (project.ProjectType == ProjectType.Product) { sb.AppendLine(guid + @".sonar.sources=\"); } else { AppendKeyValue(sb, guid, "sonar.sources", ""); sb.AppendLine(guid + @".sonar.tests=\"); } IEnumerable<string> escapedFiles = files.Select(f => Escape(f)); sb.AppendLine(string.Join(@",\" + Environment.NewLine, escapedFiles)); sb.AppendLine(); if (project.AnalysisSettings != null && project.AnalysisSettings.Any()) { foreach(Property setting in project.AnalysisSettings) { sb.AppendFormat("{0}.{1}={2}", guid, setting.Id, Escape(setting.Value)); sb.AppendLine(); } sb.AppendLine(); } }