/// <summary> /// Initializes a new instance of Solution Port, analyzing the solution path using the provided config. /// WARNING: This constructor will rebuild and reanalyze the solution, which will have a performance impact. If you /// have an already analyzed solution, use another constructor /// </summary> /// <param name="solutionFilePath">Path to solution file</param> /// <param name="solutionConfiguration">Configuration for each project in solution to be built</param> public SolutionPort(string solutionFilePath, List<PortCoreConfiguration> solutionConfiguration, ILogger logger = null) { if (logger != null) { LogHelper.Logger = logger; } _portSolutionResult = new PortSolutionResult(solutionFilePath); _solutionPath = solutionFilePath; AnalyzerConfiguration analyzerConfiguration = new AnalyzerConfiguration(LanguageOptions.CSharp); analyzerConfiguration.MetaDataSettings = new MetaDataSettings() { Annotations = true, DeclarationNodes = true, MethodInvocations = true, ReferenceData = true, LoadBuildData = true, InterfaceDeclarations = true }; CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(analyzerConfiguration, LogHelper.Logger); var analyzerResults = analyzer.AnalyzeSolution(solutionFilePath).Result; _context = new MetricsContext(solutionFilePath, analyzerResults); InitSolutionRewriter(analyzerResults, solutionConfiguration); }
public SolutionPort(string solutionFilePath, List<AnalyzerResult> analyzerResults, List<PortCoreConfiguration> solutionConfiguration, ILogger logger = null) { if (logger != null) { LogHelper.Logger = logger; } _portSolutionResult = new PortSolutionResult(solutionFilePath); _solutionPath = solutionFilePath; _context = new MetricsContext(solutionFilePath, analyzerResults); InitSolutionRewriter(analyzerResults, solutionConfiguration); }
public SolutionPort(string solutionFilePath, ILogger logger = null) { if (logger != null) { LogHelper.Logger = logger; } _portSolutionResult = new PortSolutionResult(solutionFilePath); _solutionPath = solutionFilePath; _context = new MetricsContext(solutionFilePath); _solutionAnalysisResult = new SolutionResult(); _solutionRunResult = new SolutionResult(); SkipDownloadFiles = new ConcurrentDictionary <string, bool>(); _projectTypeFeatureResults = new Dictionary <string, FeatureDetectionResult>(); CheckCache(); }
/// <summary> /// Initializes a new instance of Solution Port, analyzing the solution path using the provided config. /// WARNING: This constructor will rebuild and reanalyze the solution, which will have a performance impact. If you /// have an already analyzed solution, use another constructor /// </summary> /// <param name="solutionFilePath">Path to solution file</param> /// <param name="solutionConfiguration">Configuration for each project in solution to be built</param> public SolutionPort(string solutionFilePath, List <PortCoreConfiguration> solutionConfiguration, ILogger logger = null) { if (logger != null) { LogHelper.Logger = logger; } _portSolutionResult = new PortSolutionResult(solutionFilePath); SkipDownloadFiles = new ConcurrentDictionary <string, bool>(); _solutionPath = solutionFilePath; AnalyzerConfiguration analyzerConfiguration = new AnalyzerConfiguration(LanguageOptions.CSharp) { MetaDataSettings = new MetaDataSettings() { Annotations = true, DeclarationNodes = true, MethodInvocations = true, ReferenceData = true, LoadBuildData = true, InterfaceDeclarations = true, MemberAccess = true, ElementAccess = true } }; CodeAnalyzer analyzer = CodeAnalyzerFactory.GetAnalyzer(analyzerConfiguration, LogHelper.Logger); List <AnalyzerResult> analyzerResults = null; //We are building using references if (solutionConfiguration.Any(p => p.MetaReferences?.Any() == true)) { var currentReferences = solutionConfiguration.ToDictionary(s => s.ProjectPath, s => s.MetaReferences); var frameworkReferences = solutionConfiguration.ToDictionary(s => s.ProjectPath, s => s.FrameworkMetaReferences); analyzerResults = analyzer.AnalyzeSolution(solutionFilePath, frameworkReferences, currentReferences).Result; } else { analyzerResults = analyzer.AnalyzeSolution(solutionFilePath).Result; } _context = new MetricsContext(solutionFilePath, analyzerResults); InitSolutionRewriter(analyzerResults, solutionConfiguration); }
internal TestSolutionAnalysis GenerateSolutionResult(string solutionPath, SolutionResult analysisRunResult, PortSolutionResult solutionRunResult) { var result = new TestSolutionAnalysis(); var projectFiles = Utils.GetProjectPaths(solutionPath).ToList(); projectFiles.ForEach(projectFile => { result.ProjectResults.Add(new ProjectResult() { CsProjectPath = projectFile, ProjectDirectory = Directory.GetParent(projectFile).FullName, CsProjectContent = File.ReadAllText(projectFile) }); }); StringBuilder str = new StringBuilder(); foreach (var projectResult in analysisRunResult.ProjectResults) { 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(); result.SolutionRunResult = solutionRunResult; return(result); }
public PortSolutionResultReportGenerator(MetricsContext context, PortSolutionResult portSolutionResult) { Context = context; PortSolutionResult = portSolutionResult; FeatureDetectionResults = new Dictionary <string, FeatureDetectionResult>(); }
private string GeneratePortSolutionResultTextReport() { PortSolutionResultTextReport = PortSolutionResult.ToString(); return(PortSolutionResultTextReport); }
public void Setup() { Directory.CreateDirectory(_tempDir); var solutionPath = $"{_tempDir}/solution.sln"; var projectPath = $"{_tempDir}/project.csproj"; var projectResult = new ProjectWorkspace(projectPath) { ProjectGuid = "1234-5678" }; var analyzerResult = new AnalyzerResult { ProjectResult = projectResult }; var analyzerResults = new List <AnalyzerResult> { analyzerResult }; var context = new MetricsContext(solutionPath, analyzerResults); var buildErrors = new Dictionary <string, Dictionary <string, int> > { { projectPath, new Dictionary <string, int> { { "CS0000: BuildError1", 100 }, { "BuildError2", 200 } } }, { "ProjectFilePath2", new Dictionary <string, int> { { "BuildError3", 300 }, { "BuildError4", 400 } } } }; var references = new HashSet <string> { "System.Web", "System.Web.Mvc" }; var downloadedFiles = new HashSet <string> { "project.all.json" }; var projectResults = new BlockingCollection <Models.ProjectResult> { new Models.ProjectResult { ProjectFile = projectPath, TargetVersions = new List <string>() { Constants.DefaultCoreVersion }, UpgradePackages = new List <PackageAction>() { new PackageAction() { Name = "Newtonsoft.Json", Version = "12.0.0.0" } }, ProjectActions = new ProjectActions() { FileActions = new BlockingCollection <FileActions>() { new FileActions() { FilePath = "FilePath1", AttributeActions = new HashSet <AttributeAction>() { new AttributeAction() { Key = "SampleKey1", Type = "GA1 Type", Name = "GA1 Name", Value = "GA1 Value", }, new AttributeAction() { Key = "SampleKey2", Type = "GA2 Type", Name = "GA2 Name", Value = "GA2 Value", } } } } }, ExecutedActions = new Dictionary <string, List <GenericActionExecution> > { { "FilePath1", new List <GenericActionExecution> { new GenericActionExecution { Type = "GA1 Type", Name = "GA1 Name", Value = "GA1 Value", TimesRun = 2, InvalidExecutions = 1 }, new GenericActionExecution { Type = "GA2 Type", Name = "GA2 Name", Value = "GA2 Value", TimesRun = 3, InvalidExecutions = 0 } } } } } }; var portSolutionResult = new PortSolutionResult(solutionPath) { BuildErrors = buildErrors, References = references, DownloadedFiles = downloadedFiles, ProjectResults = projectResults }; ReportGenerator = new PortSolutionResultReportGenerator(context, portSolutionResult); ReportGenerator.GenerateAndExportReports(); }
public PortSolutionResultReportGenerator(MetricsContext context, PortSolutionResult portSolutionResult) { Context = context; PortSolutionResult = portSolutionResult; }
public void Setup() { Directory.CreateDirectory(_tempDir); var solutionPath = $"{_tempDir}/solution.sln"; var projectPath1 = $"{_tempDir}/project1.csproj"; var projectPath2 = $"{_tempDir}/project2.csproj"; var projectResult1 = new ProjectWorkspace(projectPath1) { ProjectGuid = "1234-5678" }; var projectResult2 = new ProjectWorkspace(projectPath2) { ProjectGuid = "ABCD-EFGH" }; var analyzerResult1 = new AnalyzerResult { ProjectResult = projectResult1 }; var analyzerResult2 = new AnalyzerResult { ProjectResult = projectResult2 }; var analyzerResults = new List <AnalyzerResult> { analyzerResult1, analyzerResult2 }; var context = new MetricsContext(solutionPath, analyzerResults); var buildErrors = new Dictionary <string, Dictionary <string, int> > { { projectPath1, new Dictionary <string, int> { { "CS0000: BuildError1", 100 }, { "BuildError2", 200 } } }, { "ProjectFilePath2", new Dictionary <string, int> { { "BuildError3", 300 }, { "BuildError4", 400 } } } }; var references = new HashSet <string> { "System.Web", "System.Web.Mvc" }; var downloadedFiles = new HashSet <string> { "project.all.json" }; var projectResults = new BlockingCollection <CTA.Rules.Models.ProjectResult> { new CTA.Rules.Models.ProjectResult { ProjectFile = projectPath1, TargetVersions = new List <string>() { Constants.DefaultCoreVersion }, UpgradePackages = new List <PackageAction>() { new PackageAction() { Name = "Newtonsoft.Json", OriginalVersion = "9.0.0", Version = "12.0.0" } }, MissingMetaReferences = new List <string> { @"C://reference1.dll", @"C://reference2.dll" }, ProjectActions = new ProjectActions() { FileActions = new BlockingCollection <FileActions>() { new FileActions() { FilePath = "FilePath1", AttributeActions = new HashSet <AttributeAction>() { new AttributeAction() { Key = "SampleKey1", Type = "GA1 Type", Name = "GA1 Name", Value = "GA1 Value", }, new AttributeAction() { Key = "SampleKey2", Type = "GA2 Type", Name = "GA2 Name", Value = "GA2 Value", } } } } }, ExecutedActions = new Dictionary <string, List <GenericActionExecution> > { { "FilePath1", new List <GenericActionExecution> { new GenericActionExecution { Type = "GA1 Type", Name = "GA1 Name", Value = "GA1 Value", TimesRun = 2, InvalidExecutions = 1 }, new GenericActionExecution { Type = "GA2 Type", Name = "GA2 Name", Value = "GA2 Value", TimesRun = 3, InvalidExecutions = 0 } } } } } }; var portSolutionResult = new PortSolutionResult(solutionPath) { BuildErrors = buildErrors, References = references, DownloadedFiles = downloadedFiles, ProjectResults = projectResults }; var featureDetectionResults = new Dictionary <string, FeatureDetectionResult> { { projectPath1, new FeatureDetectionResult { FeatureStatus = { { "Feature 1", true }, { "Feature 1a", true }, { "Feature 1b", false }, }, ProjectPath = projectPath1 } }, { projectPath2, new FeatureDetectionResult { FeatureStatus = { { "Feature 2", false }, { "Feature 2a", false }, { "Feature 2b", false }, }, ProjectPath = projectPath2 } }, }; ReportGenerator = new PortSolutionResultReportGenerator(context, portSolutionResult); ReportGenerator.GenerateAnalysisReport(); ReportGenerator.GenerateAndExportReports(); ReportGeneratorWithFeatureDetection = new PortSolutionResultReportGenerator(context, portSolutionResult, featureDetectionResults); ReportGeneratorWithFeatureDetection.GenerateAnalysisReport(); }