198 lines
No EOL
8.1 KiB
C#
198 lines
No EOL
8.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.ComponentModel;
|
|
using System.Diagnostics;
|
|
|
|
using TeaBox.Macros;
|
|
|
|
namespace TeaBox.Code
|
|
{
|
|
[Module(Icon = "check")]
|
|
[Category(@"Robot\Code")]
|
|
[AvailableOn(TeaBoxFlavor.Code)]
|
|
public class CodeQualityMacros
|
|
{
|
|
[DisplayName("Check violations in dependencies")]
|
|
[Macro(Icon = "check.png")]
|
|
public static void CheckDependencies(IExecutionContext context, string outputFile)
|
|
{
|
|
if (File.Exists(outputFile))
|
|
{
|
|
File.Delete(outputFile);
|
|
}
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(outputFile));
|
|
|
|
context.AddStep("Search violations", stepcontext =>
|
|
{
|
|
var process = new ForbiddenStringsProcess(outputFile);
|
|
process.Execute(stepcontext);
|
|
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(outputFile);
|
|
});
|
|
}
|
|
|
|
public class ForbiddenStringsProcess : ProcessTask
|
|
{
|
|
private readonly string _outputFile;
|
|
|
|
public ForbiddenStringsProcess(string outputFile)
|
|
{
|
|
_outputFile = outputFile;
|
|
}
|
|
|
|
public string ForbiddenStringsFolder
|
|
{
|
|
get { return Path.Combine(RootFolder.Value, @"tools\qa\forbiddenstrings\"); }
|
|
}
|
|
|
|
protected override string CommandName
|
|
{
|
|
get { return Path.Combine(ForbiddenStringsFolder, "ForbiddenStringsApplication.exe"); }
|
|
}
|
|
|
|
protected override string GetArguments()
|
|
{
|
|
return Path.Combine(ForbiddenStringsFolder, "ConfigFiles") + " " +
|
|
Path.Combine(ForbiddenStringsFolder, "DirectoriesToBeChecked.xml") + " " +
|
|
RootFolder.Value + @"\ " +
|
|
_outputFile;
|
|
}
|
|
}
|
|
|
|
[DisplayName("Compare violations in dependencies")]
|
|
[Macro(ThreadAffinity.ExecuteAsync, Icon = "check.png")]
|
|
public static void CompareDependenciesViolations(IExecutionContext context, RelativeFileName oldViolationsFile, RelativeFileName newViolationsFile)
|
|
{
|
|
var process = new ForbiddenStringsDiffProcess(oldViolationsFile, newViolationsFile);
|
|
process.Execute(context);
|
|
context.AddStep("Find new violations", stepcontext =>
|
|
{
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(Path.Combine(process.ForbiddenStringsDiffFolder, "newErrors.txt"));
|
|
});
|
|
|
|
context.AddStep("Find fixed violations", stepcontext =>
|
|
{
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(Path.Combine(process.ForbiddenStringsDiffFolder, "fixedErrors.txt"));
|
|
});
|
|
}
|
|
|
|
public class ForbiddenStringsDiffProcess : ProcessTask
|
|
{
|
|
private readonly string _oldViolationsFile;
|
|
private readonly string _newViolationsFile;
|
|
|
|
public ForbiddenStringsDiffProcess(RelativeFileName oldViolationsFile, RelativeFileName newViolationsFile)
|
|
{
|
|
_oldViolationsFile = oldViolationsFile.FullPath;
|
|
_newViolationsFile = newViolationsFile.FullPath;
|
|
}
|
|
|
|
public string ForbiddenStringsDiffFolder
|
|
{
|
|
get { return Path.Combine(RootFolder.Value, @"tools\qa\forbiddenstrings\"); }
|
|
}
|
|
|
|
protected override string CommandName
|
|
{
|
|
get { return Path.Combine(ForbiddenStringsDiffFolder, "ForbiddenStringsDiff.exe"); }
|
|
}
|
|
|
|
protected override string GetArguments()
|
|
{
|
|
return _oldViolationsFile + " " +
|
|
_newViolationsFile + " " +
|
|
ForbiddenStringsDiffFolder;
|
|
}
|
|
}
|
|
|
|
[DisplayName("Create metrics reports")]
|
|
[Macro(ThreadAffinity.ExecuteAsync, Icon = "check.png")]
|
|
public static void CreateMetricsReports(IExecutionContext context, string outputDirectory)
|
|
{
|
|
string sln = UAFConstants.GetEngineSolutionFile(VisualStudioVersion.vs2015);
|
|
string configuration = "\"Release|Win32\"";
|
|
|
|
CreateMetricsReportsInternal(context, sln, configuration, outputDirectory);
|
|
}
|
|
|
|
private static void CreateMetricsReportsInternal(IExecutionContext context, string sln, string configuration, string outputDirectory)
|
|
{
|
|
// Application used
|
|
string und_exe = @"C:\Program Files\SciTools\bin\pc-win64\und.exe";
|
|
string uperl_exe = @"C:\Program Files\SciTools\bin\pc-win64\uperl.exe";
|
|
string scripts_path = Path.Combine(RootFolder.Value, @"tools\qa\Understand\Metrics\");
|
|
|
|
if (!File.Exists(und_exe))
|
|
{
|
|
context.LogError("Understand is not installed on your computer");
|
|
return;
|
|
}
|
|
|
|
// Extract input data
|
|
string projectFile = Path.GetFileName(sln);
|
|
|
|
// Compute output files names
|
|
string udb = Path.ChangeExtension(Path.Combine(outputDirectory, projectFile), ".udb");
|
|
string reportFiles = Path.ChangeExtension(Path.Combine(outputDirectory, projectFile), ".files.txt");
|
|
string reportFunctions = Path.ChangeExtension(Path.Combine(outputDirectory, projectFile), ".functions.txt");
|
|
string reportTypes = Path.ChangeExtension(Path.Combine(outputDirectory, projectFile), ".types.txt");
|
|
|
|
// Prepare output directory
|
|
if (System.IO.Directory.Exists(outputDirectory))
|
|
{
|
|
// remove old files
|
|
File.Delete(udb);
|
|
File.Delete(reportFiles);
|
|
File.Delete(reportFunctions);
|
|
File.Delete(reportTypes);
|
|
}
|
|
else
|
|
{
|
|
// Create directory
|
|
Directory.CreateDirectory(outputDirectory);
|
|
}
|
|
|
|
// Create udb file
|
|
context.AddStep("Create", new GenericCommand(und_exe, "create -languages c++ " + udb).Execute);
|
|
context.AddStep("Set configuration", new GenericCommand(und_exe, "add " + configuration + " " + sln + " " + udb).Execute);
|
|
context.AddStep("Set settings", new GenericCommand(und_exe, "settings -c++TreatSystemIncludesAsUser off " + udb).Execute);
|
|
|
|
// Analyze project
|
|
context.AddStep("Analyze", new GenericCommand(und_exe, "-db " + udb + " -quiet analyze -all").Execute);
|
|
|
|
// Generate reports
|
|
string commonParameters = " -db " + udb + " -root_path " + Path.Combine(RootFolder.Value, "src");
|
|
|
|
context.AddStep("Metrics for files", stepcontext =>
|
|
{
|
|
var command = new GenericCommand(uperl_exe, Path.Combine(scripts_path, "c_highestMetrics_files.pl") + commonParameters + " -output_file " + reportFiles);
|
|
|
|
command.Execute(stepcontext);
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(reportFiles);
|
|
});
|
|
|
|
context.AddStep("Metrics for functions", stepcontext =>
|
|
{
|
|
var command = new GenericCommand(uperl_exe, Path.Combine(scripts_path, "c_highestMetrics_functions.pl") + commonParameters + " -output_file " + reportFunctions);
|
|
|
|
command.Execute(stepcontext);
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(reportFunctions);
|
|
});
|
|
|
|
context.AddStep("Metrics for types (~10 mn)", stepcontext =>
|
|
{
|
|
var command = new GenericCommand(uperl_exe, Path.Combine(scripts_path, "c_highestMetrics_types.pl") + commonParameters + " -output_file " + reportTypes);
|
|
|
|
command.Execute(stepcontext);
|
|
stepcontext.Name += " (double click for details)";
|
|
stepcontext.ActivateAction = () => Process.Start(reportTypes);
|
|
});
|
|
}
|
|
}
|
|
} |