2015-12-11 03:01:40 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace MultiProjectValidator
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
2015-12-16 02:09:08 +00:00
|
|
|
|
|
|
|
|
|
string rootPath = null;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
rootPath = ParseAndValidateArgs(args);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2015-12-11 03:01:40 +00:00
|
|
|
|
|
|
|
|
|
List<ProjectContext> projects = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
projects = ProjectLoader.Load(rootPath);
|
|
|
|
|
}
|
2016-03-17 18:56:57 +00:00
|
|
|
|
catch(Exception)
|
2015-12-11 03:01:40 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Failed to load projects from path: " + rootPath);
|
2015-12-16 02:09:08 +00:00
|
|
|
|
return 1;
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var analyzer = ProjectAnalyzer.Create(projects);
|
|
|
|
|
var analysisResults = analyzer.DoAnalysis();
|
|
|
|
|
var failed = analysisResults.Where((a) => !a.Passed).Any();
|
|
|
|
|
|
|
|
|
|
PrintAnalysisResults(analysisResults);
|
|
|
|
|
|
|
|
|
|
return failed ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void PrintAnalysisResults(List<AnalysisResult> analysisResults)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Project Validation Results");
|
|
|
|
|
|
|
|
|
|
var failedCount = analysisResults.Where((a) => !a.Passed).Count();
|
|
|
|
|
var passedCount = analysisResults.Where((a) => a.Passed).Count();
|
|
|
|
|
|
2015-12-14 23:08:16 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
2015-12-11 03:01:40 +00:00
|
|
|
|
Console.WriteLine($"{passedCount} Successful Analysis Rules");
|
|
|
|
|
|
2015-12-14 23:08:16 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
|
|
|
Console.WriteLine($"{failedCount} Failed Analysis Rules");
|
|
|
|
|
|
|
|
|
|
if (failedCount != 0)
|
2015-12-11 03:01:40 +00:00
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Failure Messages");
|
|
|
|
|
|
|
|
|
|
foreach(var result in analysisResults)
|
|
|
|
|
{
|
|
|
|
|
if (!result.Passed)
|
|
|
|
|
{
|
|
|
|
|
foreach(var message in result.Messages)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-14 23:08:16 +00:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.White;
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static bool AnyAnalysisFailed(List<AnalysisResult> analysisResults)
|
|
|
|
|
{
|
|
|
|
|
foreach (var result in analysisResults)
|
|
|
|
|
{
|
|
|
|
|
if (!result.Passed)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string ParseAndValidateArgs(string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length != 1)
|
|
|
|
|
{
|
|
|
|
|
PrintHelp();
|
2015-12-16 02:09:08 +00:00
|
|
|
|
throw new Exception();
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string rootPath = args[0];
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(rootPath))
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Root Directory does not exist: " + rootPath);
|
2015-12-16 02:09:08 +00:00
|
|
|
|
throw new Exception();
|
2015-12-11 03:01:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rootPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void PrintHelp()
|
|
|
|
|
{
|
|
|
|
|
var help = @"
|
|
|
|
|
Multi-Project Validator
|
|
|
|
|
|
|
|
|
|
Description:
|
|
|
|
|
This tool recursively searches for project.json's from the given root path.
|
|
|
|
|
It then applies a set of analysis rules, determines whether they pass/fail
|
|
|
|
|
and then sets exit code to reflect.
|
|
|
|
|
|
2015-12-16 22:10:39 +00:00
|
|
|
|
Note:
|
|
|
|
|
Ensure all analyzed project.json have been restored prior to running this tool.
|
|
|
|
|
|
2015-12-11 03:01:40 +00:00
|
|
|
|
Usage:
|
|
|
|
|
pjvalidate [root path of recursive search]";
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(help);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|