public override bool Execute() { ProjectInfo pi = new ProjectInfo(); pi.ProjectType = this.IsTest ? ProjectType.Test : ProjectType.Product; pi.IsExcluded = this.IsExcluded; pi.ProjectName = this.ProjectName; pi.FullPath = this.FullProjectPath; pi.ProjectLanguage = this.ProjectLanguage; Guid projectId; if (Guid.TryParse(this.ProjectGuid, out projectId)) { pi.ProjectGuid = projectId; pi.AnalysisResults = TryCreateAnalysisResults(this.AnalysisResults); pi.AnalysisSettings = TryCreateAnalysisSettings(this.AnalysisSettings); string outputFileName = Path.Combine(this.OutputFolder, FileConstants.ProjectInfoFileName); pi.Save(outputFileName); } else { this.Log.LogWarning(Resources.WPIF_MissingOrInvalidProjectGuid, this.FullProjectPath); } return true; }
/// <summary> /// Creates a new project info file in a new subdirectory. /// </summary> private static string CreateProjectInfoInSubDir(string parentDir, string projectName, Guid projectGuid, ProjectType projectType, bool isExcluded, string fullProjectPath) { string newDir = Path.Combine(parentDir, Guid.NewGuid().ToString()); Directory.CreateDirectory(newDir); // ensure the directory exists ProjectInfo project = new ProjectInfo() { FullPath = fullProjectPath, ProjectName = projectName, ProjectGuid = projectGuid, ProjectType = projectType, IsExcluded = isExcluded, }; string filePath = Path.Combine(newDir, FileConstants.ProjectInfoFileName); project.Save(filePath); return filePath; }
public void FileGen_MissingFilesAreSkipped() { // Create project info with a managed file list and a content file list. // Each list refers to a file that does not exist on disk. // The missing files should not appear in the generated properties file. // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); string projectBaseDir = TestUtils.CreateTestSpecificFolder(TestContext, "Project1"); string projectFullPath = CreateEmptyFile(projectBaseDir, "project1.proj"); string existingManagedFile = CreateEmptyFile(projectBaseDir, "File1.cs"); string existingContentFile = CreateEmptyFile(projectBaseDir, "Content1.txt"); string missingManagedFile = Path.Combine(projectBaseDir, "MissingFile1.cs"); string missingContentFile = Path.Combine(projectBaseDir, "MissingContent1.txt"); ProjectInfo projectInfo = new ProjectInfo() { FullPath = projectFullPath, AnalysisResults = new List<AnalysisResult>(), IsExcluded = false, ProjectGuid = Guid.NewGuid(), ProjectName = "project1.proj", ProjectType = ProjectType.Product }; string analysisFileList = CreateFileList(projectBaseDir, "filesToAnalyze.txt", existingManagedFile, missingManagedFile, existingContentFile, missingContentFile); projectInfo.AddAnalyzerResult(AnalysisType.FilesToAnalyze, analysisFileList); string projectInfoDir = TestUtils.CreateTestSpecificFolder(this.TestContext, "ProjectInfo1Dir"); string projectInfoFilePath = Path.Combine(projectInfoDir, FileConstants.ProjectInfoFileName); projectInfo.Save(projectInfoFilePath); TestLogger logger = new TestLogger(); AnalysisConfig config = new AnalysisConfig() { SonarProjectKey = "my_project_key", SonarProjectName = "my_project_name", SonarProjectVersion = "1.0", SonarOutputDir = testDir }; // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger); string actual = File.ReadAllText(result.FullPropertiesFilePath); // Assert AssertFileIsReferenced(existingContentFile, actual); AssertFileIsReferenced(existingManagedFile, actual); AssertFileIsNotReferenced(missingContentFile, actual); AssertFileIsNotReferenced(missingManagedFile, actual); logger.AssertSingleWarningExists(missingManagedFile); logger.AssertSingleWarningExists(missingContentFile); }