Skip to content

Commit

Permalink
fix all module issue
Browse files Browse the repository at this point in the history
  • Loading branch information
wyunchi-ms committed Jan 27, 2021
1 parent 34b199c commit 49aa722
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
48 changes: 23 additions & 25 deletions tools/StaticAnalysis/IssueChecker/IssueChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ namespace StaticAnalysis.IssueChecker
{
public class IssueChecker : IStaticAnalyzer
{
private readonly List<(string, string)> exceptionLogInfoList = new List<(string, string)>()
{
("BreakingChangeIssues.csv", "BreakingChangeIssues"),
("AssemblyVersionConflict.csv", "AssemblyVersionConflict"),
("SharedAssemblyConflict.csv", "SharedAssemblyConflict"),
("MissingAssemblies.csv", "MissingAssembly"),
("ExtraAssemblies.csv", "ExtraAssembly"),
};
public AnalysisLogger Logger { get; set; }

public string Name { get; private set; }
Expand Down Expand Up @@ -40,25 +48,20 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
string reportsDirectory = scopes.First();

bool hasCriticalIssue = false;
if (IsSingleExceptionFileHasCriticalIssue<BreakingChangeIssue>(reportsDirectory, "BreakingChangeIssues.csv"))
{
hasCriticalIssue = true;
}
if (IsSingleExceptionFileHasCriticalIssue<AssemblyVersionConflict>(reportsDirectory, "AssemblyVersionConflict.csv"))
{
hasCriticalIssue = true;
}
if (IsSingleExceptionFileHasCriticalIssue<SharedAssemblyConflict>(reportsDirectory, "SharedAssemblyConflict.csv"))
{
hasCriticalIssue = true;
}
if (IsSingleExceptionFileHasCriticalIssue<MissingAssembly>(reportsDirectory, "MissingAssemblies.csv"))
{
hasCriticalIssue = true;
}
if (IsSingleExceptionFileHasCriticalIssue<ExtraAssembly>(reportsDirectory, "ExtraAssemblies.csv"))
foreach ((string, string) item in exceptionLogInfoList)
{
hasCriticalIssue = true;
string exceptionFileName = item.Item1;
string recordTypeName = item.Item2;

string exceptionFilePath = Path.Combine(reportsDirectory, exceptionFileName);
if (!File.Exists(exceptionFilePath))
{
continue;
}
if (IsSingleExceptionFileHasCriticalIssue(exceptionFilePath, recordTypeName))
{
hasCriticalIssue = true;
}
}
if (hasCriticalIssue)
{
Expand All @@ -68,13 +71,8 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
}
}

private bool IsSingleExceptionFileHasCriticalIssue<T>(string reportsDirectory, string exceptionFileName) where T : IReportRecord
private bool IsSingleExceptionFileHasCriticalIssue(string exceptionFilePath, string reportRecordTypeName)
{
string exceptionFilePath = Path.Combine(reportsDirectory, exceptionFileName);
if (!File.Exists(exceptionFilePath))
{
return false;
}
bool hasError = false;
using (var reader = new StreamReader(exceptionFilePath))
{
Expand All @@ -83,7 +81,7 @@ private bool IsSingleExceptionFileHasCriticalIssue<T>(string reportsDirectory, s
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
IReportRecord newRecord = (T)Activator.CreateInstance(typeof(T));
IReportRecord newRecord = ReportRecordFactory.Create(reportRecordTypeName);
recordList.Add(newRecord.Parse(line));
}
var errorText = new StringBuilder();
Expand Down
40 changes: 40 additions & 0 deletions tools/StaticAnalysis/ReportRecordFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using StaticAnalysis.BreakingChangeAnalyzer;
using StaticAnalysis.DependencyAnalyzer;

using System;
using System.Collections.Generic;
using System.Text;

using Tools.Common.Issues;

namespace StaticAnalysis
{
public static class ReportRecordFactory
{
public static IReportRecord Create(string type)
{
if (type.Equals("BreakingChangeIssue"))
{
return new BreakingChangeIssue();
}
if (type.Equals("AssemblyVersionConflict"))
{
return new AssemblyVersionConflict();
}
if (type.Equals("SharedAssemblyConflict"))
{
return new SharedAssemblyConflict();
}
if (type.Equals("MissingAssembly"))
{
return new MissingAssembly();
}
if (type.Equals("ExtraAssembly"))
{
return new ExtraAssembly();
}

return null;
}
}
}

0 comments on commit 49aa722

Please sign in to comment.