private Dictionary <string, ProjectActions> AnalyzeActions(List <string> projects, string targetFramework, List <AnalyzerResult> analyzerResults, string pathToSolution) { List <PortCoreConfiguration> configs = new List <PortCoreConfiguration>(); var anaylyzedProjects = projects.Where(p => { var project = analyzerResults.Find((a) => a.ProjectResult?.ProjectFilePath != null && a.ProjectResult.ProjectFilePath.Equals(p)); return(project != null); }).ToList(); foreach (var proj in anaylyzedProjects) { PortCoreConfiguration projectConfiguration = new PortCoreConfiguration() { ProjectPath = proj, UseDefaultRules = true, TargetVersions = new List <string> { targetFramework }, }; configs.Add(projectConfiguration); } var solutionPort = new SolutionPort(pathToSolution, analyzerResults, configs, _logger); return(solutionPort.AnalysisRun().ToDictionary(cd => cd.Key, cd => cd.Value)); }
public TestSolutionAnalysis AnalyzeSolution( string solutionPath, string version, Dictionary <string, List <string> > metaReferences = null, bool skipCopy = false, bool portCode = true, bool portProject = true) { TestSolutionAnalysis result = new TestSolutionAnalysis(); if (solutionPath != null && solutionPath.Length > 0) { List <PortCoreConfiguration> solutionPortConfiguration = new List <PortCoreConfiguration>(); IEnumerable <string> projectFiles = Utils.GetProjectPaths(solutionPath); if (projectFiles != null && projectFiles.Count() > 0) { foreach (string projectFile in projectFiles) { Dictionary <string, Tuple <string, string> > packages = new Dictionary <string, Tuple <string, string> > { { "Newtonsoft.Json", new Tuple <string, string>("9.0.0", "*") } }; PortCoreConfiguration projectConfiguration = new PortCoreConfiguration() { SolutionPath = solutionPath, ProjectPath = projectFile, UseDefaultRules = true, TargetVersions = new List <string> { version }, PackageReferences = packages, PortCode = portCode, PortProject = portProject }; if (metaReferences != null) { projectConfiguration.MetaReferences = metaReferences.ContainsKey(projectFile) ? metaReferences[projectFile] : null; } solutionPortConfiguration.Add(projectConfiguration); result.ProjectResults.Add(new ProjectResult() { CsProjectPath = projectFile, ProjectDirectory = Directory.GetParent(projectFile).FullName }); } // SolutionPort should remove this extra config because it does not have a matching analyzer result. // Otherwise will hit KeyNotFoundException solutionPortConfiguration.Add(new PortCoreConfiguration { SolutionPath = solutionPath, ProjectPath = "fakeproject.csproj", UseDefaultRules = true, }); SolutionPort solutionPort = new SolutionPort(solutionPath, solutionPortConfiguration); CopyTestRules(); var analysisRunResult = solutionPort.AnalysisRun(); StringBuilder str = new StringBuilder(); foreach (var projectResult in analysisRunResult.ProjectResults) { Assert.IsTrue(projectResult.ProjectActions.ToSummaryString()?.Length > 0); StringBuilder projectResults = new StringBuilder(); projectResults.AppendLine(projectResult.ProjectFile); projectResults.AppendLine(projectResult.ProjectActions.ToString()); result.ProjectResults.Where(p => p.CsProjectPath == projectResult.ProjectFile).FirstOrDefault().ProjectAnalysisResult = projectResults.ToString(); str.Append(projectResults); } result.SolutionAnalysisResult = str.ToString(); var runResult = solutionPort.Run(); foreach (var projectFile in result.ProjectResults) { projectFile.CsProjectContent = File.ReadAllText(projectFile.CsProjectPath); } result.SolutionRunResult = runResult; } } return(result); }
public TestSolutionAnalysis AnalyzeSolution( string solutionPath, string version, Dictionary <string, List <string> > metaReferences = null, bool skipCopy = false, bool portCode = true, bool portProject = true) { TestSolutionAnalysis result = new TestSolutionAnalysis(); var solutionDir = Directory.GetParent(solutionPath).FullName; if (solutionPath != null && solutionPath.Length > 0) { List <PortCoreConfiguration> solutionPortConfiguration = new List <PortCoreConfiguration>(); IEnumerable <string> projectFiles = Directory.EnumerateFiles(solutionDir, "*.csproj", SearchOption.AllDirectories); if (projectFiles != null && projectFiles.Count() > 0) { foreach (string projectFile in projectFiles) { Dictionary <string, Tuple <string, string> > packages = new Dictionary <string, Tuple <string, string> > { { "Newtonsoft.Json", new Tuple <string, string>("9.0.0", "*") } }; PortCoreConfiguration projectConfiguration = new PortCoreConfiguration() { ProjectPath = projectFile, UseDefaultRules = true, TargetVersions = new List <string> { version }, PackageReferences = packages, PortCode = portCode, PortProject = portProject }; if (metaReferences != null) { projectConfiguration.MetaReferences = metaReferences.ContainsKey(projectFile) ? metaReferences[projectFile] : null; } solutionPortConfiguration.Add(projectConfiguration); } // SolutionPort should remove this extra config because it does not have a matching analyzer result. // Otherwise will hit KeyNotFoundException solutionPortConfiguration.Add(new PortCoreConfiguration { ProjectPath = "fakeproject.csproj", UseDefaultRules = true, }); SolutionPort solutionPort = new SolutionPort(solutionPath, solutionPortConfiguration); CopyTestRules(); var analysisRunResult = solutionPort.AnalysisRun(); foreach (var projectResult in analysisRunResult.ProjectResults) { Assert.IsTrue(projectResult.ProjectActions.ToSummaryString()?.Length > 0); } var runResult = solutionPort.Run(); result = GenerateSolutionResult(solutionDir, analysisRunResult, runResult); } } return(result); }
public TestSolutionAnalysis AnalyzeSolution(string solutionName, string tempDir, string downloadLocation, string version, bool skipCopy = false) { TestSolutionAnalysis result = new TestSolutionAnalysis(); var sourceDir = Directory.GetParent(Directory.EnumerateFiles(downloadLocation, solutionName, SearchOption.AllDirectories).FirstOrDefault()); var solutionDir = Path.Combine(tempDir, version); if (!skipCopy) { CopyDirectory(sourceDir, new DirectoryInfo(solutionDir)); } else { solutionDir = tempDir; } string solutionPath = Directory.EnumerateFiles(solutionDir, solutionName, SearchOption.AllDirectories).FirstOrDefault(); if (solutionPath != null && solutionPath.Length > 0) { List <PortCoreConfiguration> solutionPortConfiguration = new List <PortCoreConfiguration>(); IEnumerable <string> projectFiles = Directory.EnumerateFiles(solutionDir, "*.csproj", SearchOption.AllDirectories); if (projectFiles != null && projectFiles.Count() > 0) { foreach (string projectFile in projectFiles) { ProjectResult project = new ProjectResult(); Dictionary <string, string> packages = new Dictionary <string, string>(); packages.Add("Newtonsoft.Json", "*"); PortCoreConfiguration projectConfiguration = new PortCoreConfiguration() { ProjectPath = projectFile, UseDefaultRules = true, TargetVersions = new List <string> { version }, PackageReferences = packages }; //project.CsProjectContent = File.ReadAllText(projectFile); project.ProjectDirectory = Directory.GetParent(projectFile).FullName; project.CsProjectPath = projectFile; result.ProjectResults.Add(project); solutionPortConfiguration.Add(projectConfiguration); } SolutionPort solutionPort = new SolutionPort(solutionPath, solutionPortConfiguration); var analysisRunResult = solutionPort.AnalysisRun(); foreach (var projectAction in analysisRunResult.Values) { Assert.IsTrue(projectAction.ToSummaryString()?.Length > 0); } StringBuilder str = new StringBuilder(); foreach (var k in analysisRunResult.Keys) { StringBuilder projectResults = new StringBuilder(); projectResults.AppendLine(k); projectResults.AppendLine(analysisRunResult[k].ToString()); result.ProjectResults.Where(p => p.CsProjectPath == k).FirstOrDefault().ProjectAnalysisResult = projectResults.ToString(); str.Append(projectResults); } result.SolutionAnalysisResult = str.ToString(); var runResult = solutionPort.Run(); result.SolutionRunResult = runResult; foreach (var project in result.ProjectResults) { project.CsProjectContent = File.ReadAllText(project.CsProjectPath); } } } return(result); }