MultiProjectValidator Fixes
Ignore desktop frameworks (if specified)
This commit is contained in:
parent
2d70ffc508
commit
d8b04851e6
7 changed files with 40 additions and 18 deletions
|
@ -5,16 +5,16 @@ namespace MultiProjectValidator
|
|||
public class AnalysisResult
|
||||
{
|
||||
|
||||
private List<string> _messages;
|
||||
private IEnumerable<string> _messages;
|
||||
private bool _passed;
|
||||
|
||||
public AnalysisResult(List<string> messages, bool passed)
|
||||
public AnalysisResult(IEnumerable<string> messages, bool passed)
|
||||
{
|
||||
_messages = messages;
|
||||
_passed = passed;
|
||||
}
|
||||
|
||||
public List<string> Messages
|
||||
public IEnumerable<string> Messages
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ProjectSanity.AnalysisRules.DependencyMismatch
|
||||
namespace MultiProjectValidator.AnalysisRules.DependencyMismatch
|
||||
{
|
||||
internal class DependencyGroup
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.DotNet.ProjectModel;
|
||||
|
||||
namespace ProjectSanity.AnalysisRules.DependencyMismatch
|
||||
namespace MultiProjectValidator.AnalysisRules.DependencyMismatch
|
||||
{
|
||||
internal class DependencyInfo
|
||||
{
|
||||
|
|
|
@ -3,24 +3,30 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using System.Text;
|
||||
using ProjectSanity.AnalysisRules.DependencyMismatch;
|
||||
using MultiProjectValidator.AnalysisRules.DependencyMismatch;
|
||||
|
||||
namespace MultiProjectValidator.AnalysisRules
|
||||
{
|
||||
public class DependencyMismatchRule : IAnalysisRule
|
||||
{
|
||||
public AnalysisResult Evaluate(List<ProjectContext> projectContexts)
|
||||
public AnalysisResult Evaluate(IEnumerable<ProjectContext> projectContexts)
|
||||
{
|
||||
var targetGroupedContexts = GroupContextsByTarget(projectContexts);
|
||||
var filteredContexts = FilterContextList(projectContexts);
|
||||
var targetGroupedContexts = GroupContextsByTarget(filteredContexts);
|
||||
|
||||
var failureMessages = EvaluateProjectContextTargetGroups(targetGroupedContexts);
|
||||
var pass = failureMessages.Count == 0;
|
||||
var pass = failureMessages.Count() == 0;
|
||||
|
||||
var result = new AnalysisResult(failureMessages, pass);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<string> EvaluateProjectContextTargetGroups(Dictionary<string, List<ProjectContext>> targetGroupedProjectContexts)
|
||||
private IEnumerable<ProjectContext> FilterContextList(IEnumerable<ProjectContext> projectContexts)
|
||||
{
|
||||
return projectContexts.Where(context=> !context.TargetIsDesktop());
|
||||
}
|
||||
|
||||
private IEnumerable<string> EvaluateProjectContextTargetGroups(Dictionary<string, List<ProjectContext>> targetGroupedProjectContexts)
|
||||
{
|
||||
var failureMessages = new List<string>();
|
||||
|
||||
|
@ -42,13 +48,12 @@ namespace MultiProjectValidator.AnalysisRules
|
|||
return failureMessages;
|
||||
}
|
||||
|
||||
private List<string> EvaluateProjectContextTargetGroup(List<ProjectContext> targetProjectContextGroup)
|
||||
private List<string> EvaluateProjectContextTargetGroup(IEnumerable<ProjectContext> targetProjectContextGroup)
|
||||
{
|
||||
var failedMessages = new List<string>();
|
||||
|
||||
var dependencyGroups = CreateDependencyGroups(targetProjectContextGroup);
|
||||
|
||||
|
||||
foreach (var dependencyGroup in dependencyGroups)
|
||||
{
|
||||
if(dependencyGroup.HasConflict)
|
||||
|
@ -80,7 +85,7 @@ namespace MultiProjectValidator.AnalysisRules
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
private Dictionary<string, List<ProjectContext>> GroupContextsByTarget(List<ProjectContext> projectContexts)
|
||||
private Dictionary<string, List<ProjectContext>> GroupContextsByTarget(IEnumerable<ProjectContext> projectContexts)
|
||||
{
|
||||
var targetContextMap = new Dictionary<string, List<ProjectContext>>();
|
||||
foreach (var context in projectContexts)
|
||||
|
@ -103,7 +108,7 @@ namespace MultiProjectValidator.AnalysisRules
|
|||
return targetContextMap;
|
||||
}
|
||||
|
||||
private List<DependencyGroup> CreateDependencyGroups(List<ProjectContext> projectContexts)
|
||||
private List<DependencyGroup> CreateDependencyGroups(IEnumerable<ProjectContext> projectContexts)
|
||||
{
|
||||
var libraryNameDependencyGroupMap = new Dictionary<string, DependencyGroup>();
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ namespace MultiProjectValidator
|
|||
{
|
||||
public interface IAnalysisRule
|
||||
{
|
||||
AnalysisResult Evaluate(List<ProjectContext> projectContexts);
|
||||
AnalysisResult Evaluate(IEnumerable<ProjectContext> projectContexts);
|
||||
}
|
||||
}
|
||||
|
|
17
tools/MultiProjectValidator/ProjectContextExtensions.cs
Normal file
17
tools/MultiProjectValidator/ProjectContextExtensions.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
|
||||
namespace MultiProjectValidator
|
||||
{
|
||||
public static class ProjectContextExtensions
|
||||
{
|
||||
private static readonly string s_desktopTfmPrefix = ".NETFramework";
|
||||
public static bool TargetIsDesktop(this ProjectContext context)
|
||||
{
|
||||
var targetFramework = context.TargetFramework.ToString();
|
||||
|
||||
return targetFramework.StartsWith(s_desktopTfmPrefix);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ namespace MultiProjectValidator
|
|||
{
|
||||
public class ProjectLoader
|
||||
{
|
||||
private static readonly string PROJECT_FILENAME = "project.json";
|
||||
private static readonly string s_projectFileName = "project.json";
|
||||
|
||||
public static List<ProjectContext> Load(string rootPath, bool recursive=true)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace MultiProjectValidator
|
|||
|
||||
private static string[] DiscoverProjectFiles(string rootPath)
|
||||
{
|
||||
return Directory.GetFiles(rootPath, PROJECT_FILENAME, SearchOption.AllDirectories);
|
||||
return Directory.GetFiles(rootPath, s_projectFileName, SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
private static List<ProjectContext> LoadProjectContexts(string[] projectFiles)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue