Skip to content

Commit

Permalink
extend-analyzehandler (#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
xueningl-az authored Oct 13, 2023
1 parent c03a97f commit 391d9ee
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
32 changes: 28 additions & 4 deletions src/PortingAssistant.Client.Analysis/AnalysisHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,30 @@ public async Task<Dictionary<string, ProjectAnalysisResult>> AnalyzeSolution(
TraceEvent.End(_logger, $"Compatibility assessment of solution without generator: {solutionFilename}");
CommonUtils.RunGarbageCollection(_logger, "PortingAssistantAnalysisHandler.AnalyzeSolution");
}
}

public async Task<Dictionary<string, ProjectAnalysisResult>> AnalyzeSolution(
string solutionFilename,
List<string> projects,
List<AnalyzerResult> analyzerResults,
string targetFramework = DEFAULT_TARGET,
AssessmentType assessmentType = AssessmentType.FullAssessment)
{
try
{
TraceEvent.Start(_logger, $"Compatibility assessment of solution with AnalysisResult: {solutionFilename}");

return GetSolutionAnalysisResult(solutionFilename, projects, analyzerResults, targetFramework, assessmentType: assessmentType);
}
catch (OutOfMemoryException e)
{
_logger.LogError("Analyze solution {0} with error {1}", solutionFilename, e);
throw e;
}
finally
{
TraceEvent.End(_logger, $"Compatibility assessment of solution with AnalysisResult: {solutionFilename}");
}
}

public async IAsyncEnumerable<ProjectAnalysisResult> AnalyzeSolutionGeneratorAsync(
Expand Down Expand Up @@ -388,7 +411,7 @@ private List<ProjectResult> AnalyzeActions(
var analyzedProjects = projects.Where(p =>
{
var project = analyzerResults.Find((a) => a.ProjectResult?.ProjectFilePath != null &&
a.ProjectResult.ProjectFilePath.Equals(p));
a.ProjectResult.ProjectFilePath.Equals(p, StringComparison.InvariantCultureIgnoreCase));
return project != null;
}).ToList();

Expand Down Expand Up @@ -474,12 +497,12 @@ private ProjectAnalysisResult AnalyzeProject(
TraceEvent.Start(_logger, $"Compatibility assessment of project {project}");

var analyzer = analyzers.Find((a) => a.ProjectResult?.ProjectFilePath != null &&
a.ProjectResult.ProjectFilePath.Equals(project));
a.ProjectResult.ProjectFilePath.Equals(project, StringComparison.InvariantCultureIgnoreCase));

var projectFeatureType = analysisActions.Find((a) => a.ProjectFile != null &&
a.ProjectFile.Equals(project))?.FeatureType.ToString();
a.ProjectFile.Equals(project, StringComparison.InvariantCultureIgnoreCase))?.FeatureType.ToString();

var projectActions = analysisActions.FirstOrDefault(p => p.ProjectFile == project)?.ProjectActions ?? new ProjectActions();
var projectActions = analysisActions.FirstOrDefault(p => p.ProjectFile.Equals(project, StringComparison.InvariantCultureIgnoreCase))?.ProjectActions ?? new ProjectActions();

if (analyzer == null || analyzer.ProjectResult == null)
{
Expand Down Expand Up @@ -789,6 +812,7 @@ private Dictionary<string, ProjectAnalysisResult> GetSolutionAnalysisResult(
AssessmentType assessmentType = AssessmentType.FullAssessment
)
{

var analysisActions = AnalyzeActions(projects, targetFramework, analyzerResults, solutionFilename);

var solutionAnalysisResult = AnalyzeProjects(
Expand Down
7 changes: 7 additions & 0 deletions src/PortingAssistant.Client.Analysis/IAnalysisHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public interface IPortingAssistantAnalysisHandler
Task<Dictionary<string, ProjectAnalysisResult>> AnalyzeSolution(string solutionFilename, List<string> projects, string targetFramework = "net6.0", AnalyzerSettings settings = null,
AssessmentType assessmentType = AssessmentType.FullAssessment);

Task<Dictionary<string, ProjectAnalysisResult>> AnalyzeSolution(
string solutionFilename,
List<string> projects,
List<AnalyzerResult> analyzerResults,
string targetFramework,
AssessmentType assessmentType = AssessmentType.FullAssessment);

Task<Dictionary<string, ProjectAnalysisResult>> AnalyzeSolutionIncremental(string solutionFilename, List<string> projects,
string targetFramework = "net6.0", AnalyzerSettings settings = null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public SolutionAnalysisResult GetCompatibilityResults(string solutionFilePath, A
}
}

private SolutionAnalysisResult GenerateSolutionAnalysisResult(string solutionFilePath, Dictionary<string, ProjectAnalysisResult> projectAnalysisResultsDict, List<string> projects)
public SolutionAnalysisResult GenerateSolutionAnalysisResult(string solutionFilePath, Dictionary<string, ProjectAnalysisResult> projectAnalysisResultsDict, List<string> projects)
{
var failedProjects = new List<string>();
var projectAnalysisResults = projects.Select(p =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace PortingAssistant.Client.Client.Reports
public interface IReportExporter
{
bool GenerateJsonReport(List<PortingResult> portingResults, string SolutionName, string outputFolder);
bool GenerateJsonReport(SolutionAnalysisResult solutionAnalysisResult, string outputFolder);
bool GenerateJsonReport(SolutionAnalysisResult solutionAnalysisResult, string outputFolder, bool separateApiAnalyzeByEachCodeFile = false);
}
}
23 changes: 18 additions & 5 deletions src/PortingAssistant.Client.Client/Reports/ReportExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using PortingAssistant.Client.Model;
using System.Collections.Immutable;

namespace PortingAssistant.Client.Client.Reports
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public bool GenerateJsonReport(

public bool GenerateJsonReport(
SolutionAnalysisResult solutionAnalysisResult,
string outputFolder)
string outputFolder, bool separateApiAnalyzeByEachCodeFile = false)
{
try
{
Expand All @@ -66,9 +67,8 @@ public bool GenerateJsonReport(
Directory.CreateDirectory(FileDir);
List<PackageAnalysisResult> packageAnalysisResults = new List<PackageAnalysisResult>();
Dictionary<PackageVersionPair, string> packageAnalysisResultErrors = new Dictionary<PackageVersionPair, string>();

projectAnalysResult.PackageAnalysisResults.ToList()
.ForEach(p =>
var sorted = projectAnalysResult.PackageAnalysisResults.OrderBy(c=>c.Key.PackageId).ToList();
sorted.ForEach(p =>
{
if (p.Value.IsCompletedSuccessfully)
{
Expand All @@ -82,6 +82,8 @@ public bool GenerateJsonReport(

//project apis analsis result
string ApiAnalyzeFileName = ProjectName + "-api-analysis.json";
projectAnalysResult.SourceFileAnalysisResults.Sort(
(r1, r2) => string.Compare(r1.SourceFileName, r2.SourceFileName, StringComparison.OrdinalIgnoreCase));
var projectApiAnalysisResult = projectAnalysResult.IsBuildFailed ? new ProjectApiAnalysisResult
{
Errors = new List<string> { $"Errors during compilation in {projectAnalysResult.ProjectName}." },
Expand All @@ -102,8 +104,19 @@ public bool GenerateJsonReport(
ProjectFile = ProjectName,
SourceFileAnalysisResults = projectAnalysResult.SourceFileAnalysisResults
};
writeToFiles.Add(WriteReportToFileAsync(projectApiAnalysisResult, Path.Combine(FileDir, ApiAnalyzeFileName)));

if (separateApiAnalyzeByEachCodeFile && projectApiAnalysisResult!= null && projectApiAnalysisResult.SourceFileAnalysisResults!= null)
{
projectApiAnalysisResult.SourceFileAnalysisResults?.ForEach(source =>
{
var fileApiAnalyzeName = ProjectName + "-" + Path.GetFileNameWithoutExtension(source.SourceFilePath) + "-api-analysis.json";
writeToFiles.Add(WriteReportToFileAsync(source, Path.Combine(FileDir, fileApiAnalyzeName)));
});
}
else
{
writeToFiles.Add(WriteReportToFileAsync(projectApiAnalysisResult, Path.Combine(FileDir, ApiAnalyzeFileName)));
}
//project packages analsis result
string PackageAnalyzeFileName = ProjectName + "-package-analysis.json";
writeToFiles.Add(WriteReportToFileAsync(packageAnalysisResults, Path.Combine(FileDir, PackageAnalyzeFileName)));
Expand Down

0 comments on commit 391d9ee

Please sign in to comment.