From 4f496fdc4374e286f03ca8dc13af1456df89d73b Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 28 Nov 2023 14:38:25 -0500 Subject: [PATCH 1/5] checkpoint before refactoring --- CodeQLToolkit.sln | 12 +- .../CodeQLToolkit.Core.csproj | 1 + src/CodeQLToolkit.Core/Main.cs | 7 +- .../CodeQLToolkit.Features.Validation.csproj | 13 ++ .../Targets/ValidateUnitTestsCommand.cs | 138 ++++++++++++++++++ .../Commands/ValidationCommandFeature.cs | 60 ++++++++ .../Common.cs | 7 + .../Models/CodeQLCliResponseModel.cs | 33 +++++ .../ValidationFeatureMain.cs | 38 +++++ 9 files changed, 306 insertions(+), 3 deletions(-) create mode 100644 src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj create mode 100644 src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs create mode 100644 src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs create mode 100644 src/CodeQLToolkit.Features.Validation/Common.cs create mode 100644 src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs create mode 100644 src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs diff --git a/CodeQLToolkit.sln b/CodeQLToolkit.sln index df253a8..d5c0778 100644 --- a/CodeQLToolkit.sln +++ b/CodeQLToolkit.sln @@ -41,7 +41,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Code EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Pack", "CodeQLToolkit.Features.Pack", "{DB21251D-9281-44FA-99CD-BFEE2571C340}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQLToolkit.Features.Pack", "src\CodeQLToolkit.Features.Pack\CodeQLToolkit.Features.Pack.csproj", "{48CF8986-5E37-43DB-8045-5F64C25076E7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Pack", "src\CodeQLToolkit.Features.Pack\CodeQLToolkit.Features.Pack.csproj", "{48CF8986-5E37-43DB-8045-5F64C25076E7}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Validation", "CodeQLToolkit.Features.Validation", "{6B355B68-9342-4B76-BCA6-B9F47185A9DC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQLToolkit.Features.Validation", "src\CodeQLToolkit.Features.Validation\CodeQLToolkit.Features.Validation.csproj", "{87226A6E-AF29-4616-86D0-63311CA9FD38}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -81,6 +85,10 @@ Global {48CF8986-5E37-43DB-8045-5F64C25076E7}.Debug|Any CPU.Build.0 = Debug|Any CPU {48CF8986-5E37-43DB-8045-5F64C25076E7}.Release|Any CPU.ActiveCfg = Release|Any CPU {48CF8986-5E37-43DB-8045-5F64C25076E7}.Release|Any CPU.Build.0 = Release|Any CPU + {87226A6E-AF29-4616-86D0-63311CA9FD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {87226A6E-AF29-4616-86D0-63311CA9FD38}.Debug|Any CPU.Build.0 = Debug|Any CPU + {87226A6E-AF29-4616-86D0-63311CA9FD38}.Release|Any CPU.ActiveCfg = Release|Any CPU + {87226A6E-AF29-4616-86D0-63311CA9FD38}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -98,6 +106,8 @@ Global {FCC3A25B-29D4-4626-816A-B4BD62D14992} = {47F5F5EF-C1F9-4932-878C-2D00C17411F4} {DB21251D-9281-44FA-99CD-BFEE2571C340} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} {48CF8986-5E37-43DB-8045-5F64C25076E7} = {DB21251D-9281-44FA-99CD-BFEE2571C340} + {6B355B68-9342-4B76-BCA6-B9F47185A9DC} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} + {87226A6E-AF29-4616-86D0-63311CA9FD38} = {6B355B68-9342-4B76-BCA6-B9F47185A9DC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BF8F3B81-F4DC-4608-A41C-F00F3E5A05CA} diff --git a/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj b/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj index 5243799..8f0422a 100644 --- a/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj +++ b/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj @@ -26,6 +26,7 @@ + diff --git a/src/CodeQLToolkit.Core/Main.cs b/src/CodeQLToolkit.Core/Main.cs index 040514a..d847037 100644 --- a/src/CodeQLToolkit.Core/Main.cs +++ b/src/CodeQLToolkit.Core/Main.cs @@ -9,6 +9,7 @@ using CodeQLToolkit.Features.CodeQL; using CodeQLToolkit.Features.Test; using CodeQLToolkit.Features.Pack; +using CodeQLToolkit.Features.Validation; namespace CodeQLDevelopmentLifecycleToolkit.Core { @@ -44,8 +45,10 @@ public static async Task Main(string[] args) // Register the `Test` feature TestFeatureMain.Instance.Register(rootCommand); // Register the `Pack` feature - PackFeatureMain.Instance.Register(rootCommand); - + PackFeatureMain.Instance.Register(rootCommand); + // Register the `Validation` feature + ValidationFeatureMain.Instance.Register(rootCommand); + await rootCommand.InvokeAsync(args); return 0; diff --git a/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj b/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj new file mode 100644 index 0000000..6133b9c --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs new file mode 100644 index 0000000..2fc347b --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets +{ + + + public class UnitTestResult + { + public string test { get; set; } + public bool pass { get; set; } + public string failureStage { get; set; } + public string failureDescription { get; set; } + public object[] messages { get; set; } + public int compilationMs { get; set; } + public int evaluationMs { get; set; } + public string expected { get; set; } + public string actual { get; set; } + public string[] diff { get; set; } + } + + public class ValidateUnitTestsCommand : CommandTarget + { + public string ResultsDirectory { get; set; } + + public bool PrettyPrint { get; set; } + + public override void Run() + { + Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); + + string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); + + List unitTestResults = new List(); + + foreach (string result in results) + { + using (StreamReader r = new StreamReader(result)) + { + string json = r.ReadToEnd(); + List items = JsonConvert.DeserializeObject>(json); + + foreach(var item in items) + { + unitTestResults.Add(item); + } + } + } + + + int totalCases = unitTestResults.Count; + int currentCase = 0; + + foreach (var item in unitTestResults) + { + currentCase++; + + if (item.pass) + { + if(PrettyPrint) + { + Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : PASSED "); + Log.G().LogError($"+----------------------------------------------+"); + } + } + else + { + if (PrettyPrint) + { + Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + if (item.failureStage == "RESULT") + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : RESULT"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST DIFFERENCES |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + + + foreach (var diff in item.diff) + { + Log.G().LogError($"| {diff}"); + } + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FAILURE DESCRIPTION |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + Log.G().LogError($"| {item.failureDescription}"); + + + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + } + } + } + + var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); + + if (failedTests.Length > 0 && !PrettyPrint) + { + DieWithError("One or more failures during run unit tests."); + } + } + } +} diff --git a/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs b/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs new file mode 100644 index 0000000..2e8db6d --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs @@ -0,0 +1,60 @@ +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public class ValidationCommandFeature : FeatureBase, IToolkitLifecycleFeature + { + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; } + + public ValidationCommandFeature() + { + FeatureName = "Validation"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining running validation commands."); + parentCommand.Add(runCommand); + + var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); + + var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; + getMatrixTestCommand.Add(matrixOSVersion); + + runCommand.Add(getMatrixTestCommand); + + + getMatrixTestCommand.SetHandler(() => + { + Log.G().LogInformation("Executing validate-unit-tests command..."); + + //new ValidateUnitTestsCommand() + //{ + // ResultsDirectory = resultsDirectory, + // PrettyPrint = prettyPrint + //}.Run(); + + + }); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features.Validation/Common.cs b/src/CodeQLToolkit.Features.Validation/Common.cs new file mode 100644 index 0000000..279d9e9 --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/Common.cs @@ -0,0 +1,7 @@ +global using CodeQLToolkit.Shared.Target; +global using CodeQLToolkit.Shared.Logging; +global using Microsoft.Extensions.Logging; +global using CodeQLToolkit.Shared.Feature; +global using CodeQLToolkit.Shared.Options; +global using CodeQLToolkit.Shared.Types; + diff --git a/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs b/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs new file mode 100644 index 0000000..30aad10 --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Models +{ + public class CodeQLCliResponseModel + { + public string query { get; set; } + public string relativeName { get; set; } + public bool success { get; set; } + public Message[] messages { get; set; } + } + + public class Message + { + public string severity { get; set; } + public string message { get; set; } + public Position position { get; set; } + } + + public class Position + { + public string fileName { get; set; } + public int line { get; set; } + public int column { get; set; } + public int endLine { get; set; } + public int endColumn { get; set; } + } + +} diff --git a/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs b/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs new file mode 100644 index 0000000..1f8367f --- /dev/null +++ b/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs @@ -0,0 +1,38 @@ +using CodeQLToolkit.Features.Test.Commands; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Validation +{ + public class ValidationFeatureMain : IToolkitFeature + + { + readonly ValidationCommandFeature commandFeature; + readonly static ValidationFeatureMain instance; + + static ValidationFeatureMain() + { + instance = new ValidationFeatureMain(); + } + + private ValidationFeatureMain() + { + commandFeature = new ValidationCommandFeature(); + } + public static ValidationFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var validationCommand = new Command("validation", "Features related to the validation of CodeQL Development Repositories."); + parentCommand.Add(validationCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(validationCommand); + + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file From 357b88a609b131690a0d883074e4b8638008a6f8 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 28 Nov 2023 15:01:09 -0500 Subject: [PATCH 2/5] big refactor --- CodeQLToolkit.sln | 62 +---- .../CodeQLToolkit.Core.csproj | 6 +- .../CodeQL}/CodeQLFeatureMain.cs | 0 .../Lifecycle}/CodeQLLifecycleFeature.cs | 0 .../Targets/GetVersionLifecycleTarget.cs | 0 .../Targets/SetVersionLifecycleTarget.cs | 0 .../CodeQLToolkit.Features.csproj | 77 ++++++ .../Common.cs | 0 .../Pack}/Commands/PackCommandFeature.cs | 0 .../Targets/HelloJeongsooCommandTarget.cs | 0 .../Pack}/PackFeatureMain.cs | 0 .../Query}/Commands/QueryCommandFeature.cs | 0 .../Targets/InstallQueryPacksCommandTarget.cs | 0 .../Query}/Lifecycle/QueryLifecycleFeature.cs | 0 .../Lifecycle/Targets/InitLifecycleTarget.cs | 0 .../Query}/QueryFeatureMain.cs | 0 .../Scaffolding/QueryScaffoldFeature.cs | 0 .../Targets/NewQueryScaffoldTarget.cs | 0 .../Templates/Query/codeql-workspace.liquid | 0 .../Templates/Query/cpp/expected.liquid | 0 .../Query/cpp/new-dataflow-query.liquid | 0 .../Templates/Query/cpp/new-query.liquid | 0 .../Templates/Query/cpp/qlpack-query.liquid | 0 .../Templates/Query/cpp/qlpack-test.liquid | 0 .../Templates/Query/cpp/test.liquid | 0 .../Templates/Query/cpp/testref.liquid | 0 .../Query/javascript/expected.liquid | 0 .../javascript/new-dataflow-query.liquid | 0 .../Query/javascript/new-query.liquid | 0 .../Query/javascript/qlpack-query.liquid | 0 .../Query/javascript/qlpack-test.liquid | 0 .../Templates/Query/javascript/test.liquid | 0 .../Templates/Query/javascript/testref.liquid | 0 .../Test/Actions/install-codeql.liquid | 0 .../Templates/Test/Actions/install-qlt.liquid | 0 .../Test/Actions/run-unit-tests.liquid | 0 .../BaseExecuteUnitTestsCommandTarget.cs | 0 .../Commands/BaseGetMatrixCommandTarget.cs | 0 .../Actions/ExecuteUnitTestsCommandTarget.cs | 0 .../Targets/Actions/GetMatrixCommandTarget.cs | 0 .../Targets/ValidateUnitTestsCommand.cs | 0 .../Test}/Commands/TestCommandFeature.cs | 0 .../Test}/Lifecycle/BaseLifecycleTarget.cs | 0 .../Test}/Lifecycle/Models/TestReport.cs | 0 .../Targets/Actions/InitLifecycleTarget.cs | 0 .../Test}/Lifecycle/TestLifecycleFeature.cs | 0 .../Test/TestFeatureMain.cs | 45 ++++ .../Commands/ValidationCommandFeature.cs | 0 .../Models/CodeQLCliResponseModel.cs | 0 .../Validation}/ValidationFeatureMain.cs | 0 .../CodeQLToolkit.Core.csproj | 39 +++ src_backup/src/CodeQLToolkit.Core/Main.cs | 57 +++++ src_backup/src/CodeQLToolkit.Core/NLog.config | 14 + .../Properties/launchSettings.json | 8 + src_backup/src/CodeQLToolkit.Core/ver.txt | 1 + .../CodeQLLifecycleFeature.cs | 76 ++++++ ...QLToolkit.Features.CodeQL.Lifecycle.csproj | 0 .../Common.cs | 0 .../Targets/GetVersionLifecycleTarget.cs | 40 +++ .../Targets/SetVersionLifecycleTarget.cs | 35 +++ .../CodeQLFeatureMain.cs | 42 +++ .../CodeQLToolkit.Features.CodeQL.csproj | 21 ++ .../CodeQLToolkit.Features.Pack.csproj | 0 .../Commands/PackCommandFeature.cs | 63 +++++ .../Targets/HelloJeongsooCommandTarget.cs | 45 ++++ .../CodeQLToolkit.Features.Pack}/Common.cs | 0 .../PackFeatureMain.cs | 42 +++ .../CodeQLToolkit.Features.Query.csproj | 0 .../Commands/QueryCommandFeature.cs | 42 +++ .../Targets/InstallQueryPacksCommandTarget.cs | 47 ++++ .../CodeQLToolkit.Features.Query/Common.cs | 0 .../Lifecycle/QueryLifecycleFeature.cs | 56 ++++ .../Lifecycle/Targets/InitLifecycleTarget.cs | 25 ++ .../QueryFeatureMain.cs | 52 ++++ .../Scaffolding/QueryScaffoldFeature.cs | 77 ++++++ .../Targets/NewQueryScaffoldTarget.cs | 76 ++++++ .../Templates/Query/codeql-workspace.liquid | 3 + .../Templates/Query/cpp/expected.liquid | 1 + .../Query/cpp/new-dataflow-query.liquid | 1 + .../Templates/Query/cpp/new-query.liquid | 14 + .../Templates/Query/cpp/qlpack-query.liquid | 7 + .../Templates/Query/cpp/qlpack-test.liquid | 8 + .../Templates/Query/cpp/test.liquid | 1 + .../Templates/Query/cpp/testref.liquid | 1 + .../Query/javascript/expected.liquid | 1 + .../javascript/new-dataflow-query.liquid | 1 + .../Query/javascript/new-query.liquid | 14 + .../Query/javascript/qlpack-query.liquid | 7 + .../Query/javascript/qlpack-test.liquid | 8 + .../Templates/Query/javascript/test.liquid | 1 + .../Templates/Query/javascript/testref.liquid | 1 + .../CodeQLToolkit.Features.Test.csproj | 0 .../BaseExecuteUnitTestsCommandTarget.cs | 20 ++ .../Commands/BaseGetMatrixCommandTarget.cs | 13 + .../Actions/ExecuteUnitTestsCommandTarget.cs | 112 ++++++++ .../Targets/Actions/GetMatrixCommandTarget.cs | 75 ++++++ .../Targets/ValidateUnitTestsCommand.cs | 0 .../Commands/TestCommandFeature.cs | 160 ++++++++++++ .../CodeQLToolkit.Features.Test}/Common.cs | 0 .../Lifecycle/BaseLifecycleTarget.cs | 17 ++ .../Lifecycle/Models/TestReport.cs | 33 +++ .../Targets/Actions/InitLifecycleTarget.cs | 61 +++++ .../Lifecycle/TestLifecycleFeature.cs | 81 ++++++ .../Test/Actions/install-codeql.liquid | 109 ++++++++ .../Templates/Test/Actions/install-qlt.liquid | 88 +++++++ .../Test/Actions/run-unit-tests.liquid | 129 ++++++++++ .../TestFeatureMain.cs | 0 .../CodeQLToolkit.Features.Validation.csproj | 0 .../Targets/ValidateUnitTestsCommand.cs | 138 ++++++++++ .../Commands/ValidationCommandFeature.cs | 60 +++++ .../Common.cs | 7 + .../Models/CodeQLCliResponseModel.cs | 33 +++ .../ValidationFeatureMain.cs | 38 +++ .../CodeQL/CodeQLFeatureMain.cs | 42 +++ .../Lifecycle/CodeQLLifecycleFeature.cs | 76 ++++++ .../Targets/GetVersionLifecycleTarget.cs | 40 +++ .../Targets/SetVersionLifecycleTarget.cs | 35 +++ .../CodeQLToolkit.Features.csproj | 21 ++ .../src/CodeQLToolkit.Features/Common.cs | 7 + .../Pack/Commands/PackCommandFeature.cs | 63 +++++ .../Targets/HelloJeongsooCommandTarget.cs | 45 ++++ .../Pack/PackFeatureMain.cs | 42 +++ .../Query/Commands/QueryCommandFeature.cs | 42 +++ .../Targets/InstallQueryPacksCommandTarget.cs | 47 ++++ .../Query/Lifecycle/QueryLifecycleFeature.cs | 56 ++++ .../Lifecycle/Targets/InitLifecycleTarget.cs | 25 ++ .../Query/QueryFeatureMain.cs | 52 ++++ .../Query/Scaffolding/QueryScaffoldFeature.cs | 77 ++++++ .../Targets/NewQueryScaffoldTarget.cs | 76 ++++++ .../Templates/Query/codeql-workspace.liquid | 3 + .../Query/Templates/Query/cpp/expected.liquid | 1 + .../Query/cpp/new-dataflow-query.liquid | 1 + .../Templates/Query/cpp/new-query.liquid | 14 + .../Templates/Query/cpp/qlpack-query.liquid | 7 + .../Templates/Query/cpp/qlpack-test.liquid | 8 + .../Query/Templates/Query/cpp/test.liquid | 1 + .../Query/Templates/Query/cpp/testref.liquid | 1 + .../Query/javascript/expected.liquid | 1 + .../javascript/new-dataflow-query.liquid | 1 + .../Query/javascript/new-query.liquid | 14 + .../Query/javascript/qlpack-query.liquid | 7 + .../Query/javascript/qlpack-test.liquid | 8 + .../Templates/Query/javascript/test.liquid | 1 + .../Templates/Query/javascript/testref.liquid | 1 + .../BaseExecuteUnitTestsCommandTarget.cs | 20 ++ .../Commands/BaseGetMatrixCommandTarget.cs | 13 + .../Actions/ExecuteUnitTestsCommandTarget.cs | 112 ++++++++ .../Targets/Actions/GetMatrixCommandTarget.cs | 75 ++++++ .../Targets/ValidateUnitTestsCommand.cs | 138 ++++++++++ .../Test/Commands/TestCommandFeature.cs | 160 ++++++++++++ .../Test/Lifecycle/BaseLifecycleTarget.cs | 17 ++ .../Test/Lifecycle/Models/TestReport.cs | 33 +++ .../Targets/Actions/InitLifecycleTarget.cs | 61 +++++ .../Test/Lifecycle/TestLifecycleFeature.cs | 81 ++++++ .../Test/Actions/install-codeql.liquid | 109 ++++++++ .../Templates/Test/Actions/install-qlt.liquid | 88 +++++++ .../Test/Actions/run-unit-tests.liquid | 129 ++++++++++ .../Test/TestFeatureMain.cs | 45 ++++ .../Targets/ValidateUnitTestsCommand.cs | 138 ++++++++++ .../Commands/ValidationCommandFeature.cs | 60 +++++ .../Models/CodeQLCliResponseModel.cs | 33 +++ .../Validation/ValidationFeatureMain.cs | 38 +++ .../CodeQLToolkit.Shared.csproj | 17 ++ .../Feature/FeatureBase.cs | 36 +++ .../Feature/IToolkitCommandFeature.cs | 12 + .../Feature/IToolkitDataFeature.cs | 12 + .../Feature/IToolkitFeature.cs | 20 ++ .../Feature/IToolkitLifecycleFeature.cs | 12 + .../Feature/IToolkitScaffoldingFeature.cs | 12 + .../src/CodeQLToolkit.Shared/Logging/Log.cs | 30 +++ .../CodeQLToolkit.Shared/Options/Globals.cs | 24 ++ .../Target/CommandTarget.cs | 13 + .../Target/ILifecycleTarget.cs | 90 +++++++ .../CodeQLToolkit.Shared/Target/ITarget.cs | 20 ++ .../Target/ScaffoldTarget.cs | 51 ++++ .../Template/TemplateUtil.cs | 35 +++ .../Types/AutomationFeatureFinder.cs | 46 ++++ .../Types/AutomationType.cs | 57 +++++ .../Types/AutomationTypeAttribute.cs | 21 ++ .../CodeQLToolkit.Shared/Utils/FileUtils.cs | 31 +++ .../CodeQLToolkit.Shared/Utils/Language.cs | 239 ++++++++++++++++++ .../Utils/ProcessUtils.cs | 17 ++ .../CodeQLToolkit.Shared/Utils/QLTConfig.cs | 46 ++++ .../src/CodeQLToolkit.Shared/Utils/Query.cs | 114 +++++++++ 184 files changed, 5350 insertions(+), 61 deletions(-) rename src/{CodeQLToolkit.Features.CodeQL => CodeQLToolkit.Features/CodeQL}/CodeQLFeatureMain.cs (100%) rename src/{CodeQLToolkit.Features.CodeQL.Lifecycle => CodeQLToolkit.Features/CodeQL/Lifecycle}/CodeQLLifecycleFeature.cs (100%) rename src/{CodeQLToolkit.Features.CodeQL.Lifecycle => CodeQLToolkit.Features/CodeQL/Lifecycle}/Targets/GetVersionLifecycleTarget.cs (100%) rename src/{CodeQLToolkit.Features.CodeQL.Lifecycle => CodeQLToolkit.Features/CodeQL/Lifecycle}/Targets/SetVersionLifecycleTarget.cs (100%) create mode 100644 src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj rename src/{CodeQLToolkit.Features.Pack => CodeQLToolkit.Features}/Common.cs (100%) rename src/{CodeQLToolkit.Features.Pack => CodeQLToolkit.Features/Pack}/Commands/PackCommandFeature.cs (100%) rename src/{CodeQLToolkit.Features.Pack => CodeQLToolkit.Features/Pack}/Commands/Targets/HelloJeongsooCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Pack => CodeQLToolkit.Features/Pack}/PackFeatureMain.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Commands/QueryCommandFeature.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Commands/Targets/InstallQueryPacksCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Lifecycle/QueryLifecycleFeature.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Lifecycle/Targets/InitLifecycleTarget.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/QueryFeatureMain.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Scaffolding/QueryScaffoldFeature.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features/Query}/Scaffolding/Targets/NewQueryScaffoldTarget.cs (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/codeql-workspace.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/expected.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/new-dataflow-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/new-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/qlpack-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/qlpack-test.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/test.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/cpp/testref.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/expected.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/new-dataflow-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/new-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/qlpack-query.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/qlpack-test.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/test.liquid (100%) rename src/{CodeQLToolkit.Features.Query => CodeQLToolkit.Features}/Templates/Query/javascript/testref.liquid (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features}/Templates/Test/Actions/install-codeql.liquid (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features}/Templates/Test/Actions/install-qlt.liquid (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features}/Templates/Test/Actions/run-unit-tests.liquid (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/BaseExecuteUnitTestsCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/BaseGetMatrixCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/Targets/Actions/GetMatrixCommandTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/Targets/ValidateUnitTestsCommand.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Commands/TestCommandFeature.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Lifecycle/BaseLifecycleTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Lifecycle/Models/TestReport.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Lifecycle/Targets/Actions/InitLifecycleTarget.cs (100%) rename src/{CodeQLToolkit.Features.Test => CodeQLToolkit.Features/Test}/Lifecycle/TestLifecycleFeature.cs (100%) create mode 100644 src/CodeQLToolkit.Features/Test/TestFeatureMain.cs rename src/{CodeQLToolkit.Features.Validation => CodeQLToolkit.Features/Validation}/Commands/ValidationCommandFeature.cs (100%) rename src/{CodeQLToolkit.Features.Validation => CodeQLToolkit.Features/Validation}/Models/CodeQLCliResponseModel.cs (100%) rename src/{CodeQLToolkit.Features.Validation => CodeQLToolkit.Features/Validation}/ValidationFeatureMain.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj create mode 100644 src_backup/src/CodeQLToolkit.Core/Main.cs create mode 100644 src_backup/src/CodeQLToolkit.Core/NLog.config create mode 100644 src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json create mode 100644 src_backup/src/CodeQLToolkit.Core/ver.txt create mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs rename {src => src_backup/src}/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj (100%) rename {src => src_backup/src}/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj rename {src => src_backup/src}/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs rename {src/CodeQLToolkit.Features.Test => src_backup/src/CodeQLToolkit.Features.Pack}/Common.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs rename {src => src_backup/src}/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs rename {src => src_backup/src}/CodeQLToolkit.Features.Query/Common.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid rename {src => src_backup/src}/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs rename {src/CodeQLToolkit.Features.Validation => src_backup/src/CodeQLToolkit.Features.Test}/Commands/Targets/ValidateUnitTestsCommand.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs rename {src/CodeQLToolkit.Features.Validation => src_backup/src/CodeQLToolkit.Features.Test}/Common.cs (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid rename {src => src_backup/src}/CodeQLToolkit.Features.Test/TestFeatureMain.cs (100%) rename {src => src_backup/src}/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj (100%) create mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Common.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs create mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj create mode 100644 src_backup/src/CodeQLToolkit.Features/Common.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid create mode 100644 src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs create mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs create mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs diff --git a/CodeQLToolkit.sln b/CodeQLToolkit.sln index d5c0778..678390f 100644 --- a/CodeQLToolkit.sln +++ b/CodeQLToolkit.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33801.468 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Query", "CodeQLToolkit.Features.Query", "{15D5DFB3-16CE-460F-B361-D6FFB8498508}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{05645E0E-835A-4627-BDAE-C27EC39B23EE}" @@ -15,8 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{3038EA53-8 docs\README.md = docs\README.md EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Query", "src\CodeQLToolkit.Features.Query\CodeQLToolkit.Features.Query.csproj", "{EF2DD68B-9320-4450-8803-52FD2BB1E69D}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Core", "src\CodeQLToolkit.Core\CodeQLToolkit.Core.csproj", "{FFC777F2-B98B-4132-A3B8-896C7F8CB763}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Shared", "src\CodeQLToolkit.Shared\CodeQLToolkit.Shared.csproj", "{4C5C87E8-46E8-41D3-9CF9-F77148C432AF}" @@ -29,23 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution .github\workflows\release-build.yml = .github\workflows\release-build.yml EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Test", "CodeQLToolkit.Features.Test", "{17D032D4-AD27-46D8-9B7E-D2250850DBCA}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Test", "src\CodeQLToolkit.Features.Test\CodeQLToolkit.Features.Test.csproj", "{BFC2C06F-2836-466A-9DE3-74ECD1526048}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.CodeQL", "CodeQLToolkit.Features.CodeQL", "{47F5F5EF-C1F9-4932-878C-2D00C17411F4}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.CodeQL", "src\CodeQLToolkit.Features.CodeQL\CodeQLToolkit.Features.CodeQL.csproj", "{860F6AB3-40C2-41F9-A1CE-D708B9347CAD}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.CodeQL.Lifecycle", "src\CodeQLToolkit.Features.CodeQL.Lifecycle\CodeQLToolkit.Features.CodeQL.Lifecycle.csproj", "{FCC3A25B-29D4-4626-816A-B4BD62D14992}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Pack", "CodeQLToolkit.Features.Pack", "{DB21251D-9281-44FA-99CD-BFEE2571C340}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Pack", "src\CodeQLToolkit.Features.Pack\CodeQLToolkit.Features.Pack.csproj", "{48CF8986-5E37-43DB-8045-5F64C25076E7}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CodeQLToolkit.Features.Validation", "CodeQLToolkit.Features.Validation", "{6B355B68-9342-4B76-BCA6-B9F47185A9DC}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQLToolkit.Features.Validation", "src\CodeQLToolkit.Features.Validation\CodeQLToolkit.Features.Validation.csproj", "{87226A6E-AF29-4616-86D0-63311CA9FD38}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeQLToolkit.Features", "src\CodeQLToolkit.Features\CodeQLToolkit.Features.csproj", "{B85F1529-3321-4AD2-924A-6EA478145DC5}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,10 +33,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF2DD68B-9320-4450-8803-52FD2BB1E69D}.Release|Any CPU.Build.0 = Release|Any CPU {FFC777F2-B98B-4132-A3B8-896C7F8CB763}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FFC777F2-B98B-4132-A3B8-896C7F8CB763}.Debug|Any CPU.Build.0 = Debug|Any CPU {FFC777F2-B98B-4132-A3B8-896C7F8CB763}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -69,45 +45,19 @@ Global {A1F78CBC-9AE9-4360-A06B-395F368B183A}.Debug|Any CPU.Build.0 = Debug|Any CPU {A1F78CBC-9AE9-4360-A06B-395F368B183A}.Release|Any CPU.ActiveCfg = Release|Any CPU {A1F78CBC-9AE9-4360-A06B-395F368B183A}.Release|Any CPU.Build.0 = Release|Any CPU - {BFC2C06F-2836-466A-9DE3-74ECD1526048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BFC2C06F-2836-466A-9DE3-74ECD1526048}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BFC2C06F-2836-466A-9DE3-74ECD1526048}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BFC2C06F-2836-466A-9DE3-74ECD1526048}.Release|Any CPU.Build.0 = Release|Any CPU - {860F6AB3-40C2-41F9-A1CE-D708B9347CAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {860F6AB3-40C2-41F9-A1CE-D708B9347CAD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {860F6AB3-40C2-41F9-A1CE-D708B9347CAD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {860F6AB3-40C2-41F9-A1CE-D708B9347CAD}.Release|Any CPU.Build.0 = Release|Any CPU - {FCC3A25B-29D4-4626-816A-B4BD62D14992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FCC3A25B-29D4-4626-816A-B4BD62D14992}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FCC3A25B-29D4-4626-816A-B4BD62D14992}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FCC3A25B-29D4-4626-816A-B4BD62D14992}.Release|Any CPU.Build.0 = Release|Any CPU - {48CF8986-5E37-43DB-8045-5F64C25076E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {48CF8986-5E37-43DB-8045-5F64C25076E7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {48CF8986-5E37-43DB-8045-5F64C25076E7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {48CF8986-5E37-43DB-8045-5F64C25076E7}.Release|Any CPU.Build.0 = Release|Any CPU - {87226A6E-AF29-4616-86D0-63311CA9FD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {87226A6E-AF29-4616-86D0-63311CA9FD38}.Debug|Any CPU.Build.0 = Debug|Any CPU - {87226A6E-AF29-4616-86D0-63311CA9FD38}.Release|Any CPU.ActiveCfg = Release|Any CPU - {87226A6E-AF29-4616-86D0-63311CA9FD38}.Release|Any CPU.Build.0 = Release|Any CPU + {B85F1529-3321-4AD2-924A-6EA478145DC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B85F1529-3321-4AD2-924A-6EA478145DC5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B85F1529-3321-4AD2-924A-6EA478145DC5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B85F1529-3321-4AD2-924A-6EA478145DC5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {15D5DFB3-16CE-460F-B361-D6FFB8498508} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} - {EF2DD68B-9320-4450-8803-52FD2BB1E69D} = {15D5DFB3-16CE-460F-B361-D6FFB8498508} {FFC777F2-B98B-4132-A3B8-896C7F8CB763} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} {4C5C87E8-46E8-41D3-9CF9-F77148C432AF} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} {A1F78CBC-9AE9-4360-A06B-395F368B183A} = {05645E0E-835A-4627-BDAE-C27EC39B23EE} - {17D032D4-AD27-46D8-9B7E-D2250850DBCA} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} - {BFC2C06F-2836-466A-9DE3-74ECD1526048} = {17D032D4-AD27-46D8-9B7E-D2250850DBCA} - {47F5F5EF-C1F9-4932-878C-2D00C17411F4} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} - {860F6AB3-40C2-41F9-A1CE-D708B9347CAD} = {47F5F5EF-C1F9-4932-878C-2D00C17411F4} - {FCC3A25B-29D4-4626-816A-B4BD62D14992} = {47F5F5EF-C1F9-4932-878C-2D00C17411F4} - {DB21251D-9281-44FA-99CD-BFEE2571C340} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} - {48CF8986-5E37-43DB-8045-5F64C25076E7} = {DB21251D-9281-44FA-99CD-BFEE2571C340} - {6B355B68-9342-4B76-BCA6-B9F47185A9DC} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} - {87226A6E-AF29-4616-86D0-63311CA9FD38} = {6B355B68-9342-4B76-BCA6-B9F47185A9DC} + {B85F1529-3321-4AD2-924A-6EA478145DC5} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BF8F3B81-F4DC-4608-A41C-F00F3E5A05CA} diff --git a/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj b/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj index 8f0422a..eac0b02 100644 --- a/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj +++ b/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj @@ -22,11 +22,7 @@ - - - - - + diff --git a/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs b/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs rename to src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs diff --git a/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs b/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs rename to src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs diff --git a/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs b/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs rename to src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs diff --git a/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs b/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs rename to src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs diff --git a/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj new file mode 100644 index 0000000..e458176 --- /dev/null +++ b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj @@ -0,0 +1,77 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + Always + + + + diff --git a/src/CodeQLToolkit.Features.Pack/Common.cs b/src/CodeQLToolkit.Features/Common.cs similarity index 100% rename from src/CodeQLToolkit.Features.Pack/Common.cs rename to src/CodeQLToolkit.Features/Common.cs diff --git a/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs b/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs rename to src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs diff --git a/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs b/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs rename to src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs b/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs similarity index 100% rename from src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs rename to src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs diff --git a/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs b/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs rename to src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs diff --git a/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs b/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs rename to src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs b/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs rename to src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs diff --git a/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs b/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs rename to src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs diff --git a/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs b/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs rename to src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs diff --git a/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs b/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs rename to src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs diff --git a/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs b/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs rename to src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid b/src/CodeQLToolkit.Features/Templates/Query/codeql-workspace.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid rename to src/CodeQLToolkit.Features/Templates/Query/codeql-workspace.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/expected.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/expected.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/new-dataflow-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/new-dataflow-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/new-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/new-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/qlpack-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/qlpack-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/qlpack-test.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/qlpack-test.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/test.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/test.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid b/src/CodeQLToolkit.Features/Templates/Query/cpp/testref.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid rename to src/CodeQLToolkit.Features/Templates/Query/cpp/testref.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/expected.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/expected.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/new-dataflow-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/new-dataflow-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/new-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/new-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/qlpack-query.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/qlpack-query.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/qlpack-test.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/qlpack-test.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/test.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/test.liquid diff --git a/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid b/src/CodeQLToolkit.Features/Templates/Query/javascript/testref.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid rename to src/CodeQLToolkit.Features/Templates/Query/javascript/testref.liquid diff --git a/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid b/src/CodeQLToolkit.Features/Templates/Test/Actions/install-codeql.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid rename to src/CodeQLToolkit.Features/Templates/Test/Actions/install-codeql.liquid diff --git a/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid b/src/CodeQLToolkit.Features/Templates/Test/Actions/install-qlt.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid rename to src/CodeQLToolkit.Features/Templates/Test/Actions/install-qlt.liquid diff --git a/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid b/src/CodeQLToolkit.Features/Templates/Test/Actions/run-unit-tests.liquid similarity index 100% rename from src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid rename to src/CodeQLToolkit.Features/Templates/Test/Actions/run-unit-tests.liquid diff --git a/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs b/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs rename to src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs b/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs rename to src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs b/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs rename to src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs b/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs rename to src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs b/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs rename to src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs diff --git a/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs b/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs rename to src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs diff --git a/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs b/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs rename to src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs b/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs rename to src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs diff --git a/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs rename to src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs diff --git a/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs b/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs rename to src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs diff --git a/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs b/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs new file mode 100644 index 0000000..70f45eb --- /dev/null +++ b/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs @@ -0,0 +1,45 @@ +using CodeQLToolkit.Features.Test.Commands; +using CodeQLToolkit.Features.Test.Lifecycle; +using CodeQLToolkit.Shared.Feature; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Test +{ + public class TestFeatureMain : IToolkitFeature + + { + readonly TestLifecycleFeature lifecycleFeature; + readonly TestCommandFeature commandFeature; + readonly static TestFeatureMain instance; + + static TestFeatureMain() + { + instance = new TestFeatureMain(); + } + + private TestFeatureMain() + { + lifecycleFeature = new TestLifecycleFeature(); + commandFeature = new TestCommandFeature(); + } + public static TestFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var testCommand = new Command("test", "Features related to the running and processing of CodeQL Unit Tests."); + parentCommand.Add(testCommand); + + Log.G().LogInformation("Registering scaffolding submodule."); + lifecycleFeature.Register(testCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(testCommand); + + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs b/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs similarity index 100% rename from src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs rename to src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs diff --git a/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs b/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs similarity index 100% rename from src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs rename to src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs diff --git a/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs b/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs similarity index 100% rename from src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs rename to src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs diff --git a/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj b/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj new file mode 100644 index 0000000..8f0422a --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj @@ -0,0 +1,39 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + Always + + + + + + + + + + + + + + + + + + + Always + + + + diff --git a/src_backup/src/CodeQLToolkit.Core/Main.cs b/src_backup/src/CodeQLToolkit.Core/Main.cs new file mode 100644 index 0000000..d847037 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Core/Main.cs @@ -0,0 +1,57 @@ + +using CodeQLDevelopmentLifecycleToolkit.Features.Query; +using System.CommandLine; +using CodeQLToolkit.Shared.Logging; +using Microsoft.Extensions.Logging; +using System.IO; +using CodeQLToolkit.Shared.Options; +using CodeQLToolkit.Shared.Utils; +using CodeQLToolkit.Features.CodeQL; +using CodeQLToolkit.Features.Test; +using CodeQLToolkit.Features.Pack; +using CodeQLToolkit.Features.Validation; + +namespace CodeQLDevelopmentLifecycleToolkit.Core +{ + + internal class QLT + { + public static async Task Main(string[] args) + { + Log.G().LogInformation("QLT Startup..."); + + Console.OutputEncoding = System.Text.Encoding.UTF8; + + var rootCommand = new RootCommand(); + + // Add global option for the root directory + rootCommand.AddGlobalOption(Globals.BasePathOption); + rootCommand.AddGlobalOption(Globals.AutomationTypeOption); + + var versionCommand = new Command("version", "Get the current tool version."); + rootCommand.Add(versionCommand); + + versionCommand.SetHandler(() => + { + var version = File.ReadAllText(Path.Combine(FileUtils.GetExecutingDirectory().FullName, "ver.txt")); + + Console.Write($"QLT Version: {version}"); + }); + + // Register the `Query` feature + QueryFeatureMain.Instance.Register(rootCommand); + // Register the `CodeQL` feature + CodeQLFeatureMain.Instance.Register(rootCommand); + // Register the `Test` feature + TestFeatureMain.Instance.Register(rootCommand); + // Register the `Pack` feature + PackFeatureMain.Instance.Register(rootCommand); + // Register the `Validation` feature + ValidationFeatureMain.Instance.Register(rootCommand); + + await rootCommand.InvokeAsync(args); + + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/NLog.config b/src_backup/src/CodeQLToolkit.Core/NLog.config new file mode 100644 index 0000000..6976e51 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Core/NLog.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json b/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json new file mode 100644 index 0000000..9b17472 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "CodeQLToolkit.Core": { + "commandName": "Project", + "commandLineArgs": " --base C:\\QLPACKTEST test init" + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/ver.txt b/src_backup/src/CodeQLToolkit.Core/ver.txt new file mode 100644 index 0000000..927734f --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Core/ver.txt @@ -0,0 +1 @@ +0.0.17 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs new file mode 100644 index 0000000..73e388f --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs @@ -0,0 +1,76 @@ +using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets; +using System.CommandLine; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle +{ + public class CodeQLLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public CodeQLLifecycleFeature() + { + FeatureName = "CodeQL"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var setCommand = new Command("set", "Functions pertaining to setting variables related to CodeQL."); + parentCommand.Add(setCommand); + + var setVersionCommand = new Command("version", "Sets the version of CodeQL used."); + + var cliVersionOption = new Option("--cli-version", () => "2.11.6", "The version of the cli to use. Example: `2.11.6`.") { IsRequired = true }; + var standardLibraryVersionOption = new Option("--standard-library-version", () => "codeql-cli/v2.11.6", "The version of the standard library to use. Example: `codeql-cli/v2.11.6`.") { IsRequired = true }; + var bundleVersionOption = new Option("--bundle-version", () => "codeql-bundle-20221211", "The bundle version to use. Example: `codeql-bundle-20221211`.") { IsRequired = true }; + + setVersionCommand.Add(cliVersionOption); + setVersionCommand.Add(standardLibraryVersionOption); + setVersionCommand.Add(bundleVersionOption); + + setCommand.Add(setVersionCommand); + + var getCommand = new Command("get", "Functions pertaining to getting variables related to CodeQL."); + parentCommand.Add(getCommand); + + var getVersionCommand = new Command("version", "Gets the version of CodeQL used."); + getCommand.Add(getVersionCommand); + + { + setVersionCommand.SetHandler((cliVersion, standardLibraryVersion, bundleVersion, basePath) => + { + Log.G().LogInformation("Executing set command..."); + + new SetVersionLifecycleTarget() + { + CodeQLCLI = cliVersion, + CodeQLStandardLibrary = standardLibraryVersion, + CodeQLCLIBundle = bundleVersion, + Base = basePath + }.Run(); + + }, cliVersionOption, standardLibraryVersionOption, bundleVersionOption, Globals.BasePathOption); + } + + + { + getVersionCommand.SetHandler((basePath) => + { + Log.G().LogInformation("Executing get command..."); + + new GetVersionLifecycleTarget() + { + Base = basePath + }.Run(); + + }, Globals.BasePathOption); + } + + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj rename to src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj diff --git a/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs similarity index 100% rename from src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs rename to src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs new file mode 100644 index 0000000..2bd4823 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs @@ -0,0 +1,40 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets +{ + public class GetVersionLifecycleTarget : ILifecycleTarget + { + + override public void Run() + { + Log.G().LogInformation("Running get command..."); + + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + // This should be updated so that we can pretty print all the various options: + Console.WriteLine($"---------current settings---------"); + Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); + Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); + Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); + Console.WriteLine($"----------------------------------"); + Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); + + + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs new file mode 100644 index 0000000..9025b71 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs @@ -0,0 +1,35 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets +{ + public class SetVersionLifecycleTarget : ILifecycleTarget + { + public string CodeQLCLI { get; set; } + public string CodeQLStandardLibrary { get; set; } + public string CodeQLCLIBundle { get; set; } + + override public void Run() + { + Log.G().LogInformation("Running set command..."); + + var c = new QLTConfig() + { + CodeQLCLI = CodeQLCLI, + CodeQLStandardLibrary = CodeQLStandardLibrary, + CodeQLCLIBundle = CodeQLCLIBundle, + Base = Base + }; + + c.ToFile(); + + Log.G().LogInformation("Wrote to file..."); + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs new file mode 100644 index 0000000..c0357b8 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Shared.Feature; +using System.CommandLine; +using CodeQLToolkit.Shared.Logging; +using Microsoft.Extensions.Logging; +using CodeQLToolkit.Features.CodeQL.Lifecycle; + +namespace CodeQLToolkit.Features.CodeQL +{ + public class CodeQLFeatureMain : IToolkitFeature + { + readonly CodeQLLifecycleFeature lifecycleFeature; + readonly static CodeQLFeatureMain instance; + + static CodeQLFeatureMain() + { + instance = new CodeQLFeatureMain(); + } + + private CodeQLFeatureMain() + { + lifecycleFeature = new CodeQLLifecycleFeature(); + } + + public static CodeQLFeatureMain Instance { get { return instance; } } + + public int Run() + { + + return 0; + } + + public void Register(Command parentCommand) + { + var queryCommand = new Command("codeql", "Use the features related to managing the version of CodeQL used by this repository."); + parentCommand.Add(queryCommand); + Log.G().LogInformation("Registering scaffolding submodule."); + lifecycleFeature.Register(queryCommand); + } + + + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj new file mode 100644 index 0000000..d9467d1 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj b/src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj similarity index 100% rename from src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj rename to src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs new file mode 100644 index 0000000..d01968b --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs @@ -0,0 +1,63 @@ +using CodeQLToolkit.Features.Pack.Commands.Targets; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack.Commands +{ + public class PackCommandFeature : FeatureBase, IToolkitCommandFeature + { + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + var runCommand = new Command("run", "Functions pertaining to running pack-related commands."); + parentCommand.Add(runCommand); + + // a command that installs query packs + var sayHello = new Command("hello-jeongsoo", "Says hello!"); + var howManyTimesHello = new Option("--times", "how many times to say it") { IsRequired = true }; + sayHello.Add(howManyTimesHello); + + var sayGoodbye = new Command("goodbye-jeongsoo", "Says goodbye!"); + + var howManyTimes = new Option("--times", "how many times to say it") { IsRequired = true }; + sayGoodbye.Add(howManyTimes); + + + runCommand.Add(sayHello); + runCommand.Add(sayGoodbye); + + sayHello.SetHandler((basePath, times) => { + + new HelloJeongsooCommandTarget() { + Base = basePath, + Times = times + + }.Run(); + + }, Globals.BasePathOption, howManyTimesHello); + + sayGoodbye.SetHandler((basePath, times) => { + + Console.WriteLine($"Saying goodbye {times} number of times"); + + for (int i = 0; i < times; i++) + { + Console.WriteLine("Goodbye!"); + } + + + }, Globals.BasePathOption, howManyTimes); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs new file mode 100644 index 0000000..33b4420 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs @@ -0,0 +1,45 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack.Commands.Targets +{ + public class HelloJeongsooCommandTarget : CommandTarget + { + + public int Times { get; set; } + + + public override void Run() + { + for(int i = 0; i < Times; i++) { + Console.WriteLine($"Hello! My Base Target is: {Base}"); + } + + + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + + Console.WriteLine($"---------current settings---------"); + Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); + Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); + Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); + Console.WriteLine($"----------------------------------"); + Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); + + } + } +} diff --git a/src/CodeQLToolkit.Features.Test/Common.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Common.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/Common.cs rename to src_backup/src/CodeQLToolkit.Features.Pack/Common.cs diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs new file mode 100644 index 0000000..9fa81ea --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Features.Pack.Commands; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack +{ + public class PackFeatureMain : IToolkitFeature + { + + readonly static PackFeatureMain instance; + readonly PackCommandFeature commandFeature; + + static PackFeatureMain() + { + instance = new PackFeatureMain(); + } + + private PackFeatureMain() + { + commandFeature = new PackCommandFeature(); + } + public static PackFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var packCommand = new Command("pack", "Features CodeQL pack management and publication."); + parentCommand.Add(packCommand); + + Log.G().LogInformation("Registering scaffolding submodule."); + commandFeature.Register(packCommand); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj b/src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj similarity index 100% rename from src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj rename to src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs new file mode 100644 index 0000000..d5bb08c --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Features.Query.Commands.Targets; +using CodeQLToolkit.Features.Query.Scaffolding; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Commands +{ + public class QueryCommandFeature : FeatureBase, IToolkitCommandFeature + { + public QueryCommandFeature() + { + FeatureName = "Query"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + var runCommand = new Command("run", "Functions pertaining to running query-related commands."); + parentCommand.Add(runCommand); + + // a command that installs query packs + var installPacksQueryCommand = new Command("install-packs", "Installs CodeQL packs within the repository."); + + runCommand.Add(installPacksQueryCommand); + + installPacksQueryCommand.SetHandler((basePath) => new InstallQueryPacksCommandTarget() { Base = basePath }.Run(), Globals.BasePathOption); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs new file mode 100644 index 0000000..255faf7 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Commands.Targets +{ + public class InstallQueryPacksCommandTarget : CommandTarget + { + public override void Run() + { + Log.G().LogInformation("Finding all qlpacks..."); + + // starting at the base path, find all qlpacks and install them + string[] files = Directory.GetFiles(Base, "qlpack.yml", SearchOption.AllDirectories); + + Log.G().LogInformation($"Got {files.Length} packs..."); + + foreach ( string file in files ) + { + Log.G().LogInformation($"Installing qlpack {file}..."); + + using(Process process = new Process()) + { + process.StartInfo.FileName = "codeql"; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = false; + process.StartInfo.Arguments = $"pack install {file}"; + process.Start(); + + process.WaitForExit(); + + if(process.ExitCode !=0) + { + DieWithError($"Failed to install query pack {file}."); + } + } + + } + + Log.G().LogInformation($"Installed {files.Length} packs."); + + } + } +} diff --git a/src/CodeQLToolkit.Features.Query/Common.cs b/src_backup/src/CodeQLToolkit.Features.Query/Common.cs similarity index 100% rename from src/CodeQLToolkit.Features.Query/Common.cs rename to src_backup/src/CodeQLToolkit.Features.Query/Common.cs diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs new file mode 100644 index 0000000..2b725e0 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs @@ -0,0 +1,56 @@ +using CodeQLToolkit.Features.Query.Lifecycle.Targets; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using CodeQLToolkit.Shared.Types; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Lifecycle +{ + public class QueryLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public QueryLifecycleFeature() + { + FeatureName = "Query"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var initCommand = new Command("init", "Initialize query support in this repository."); + + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + + initCommand.AddOption(overwriteExistingOption); + + parentCommand.Add(initCommand); + + initCommand.SetHandler((basePath, overwriteExisting) => + { + Log.G().LogInformation("Executing init command..."); + + + new InitLifecycleTarget() + { + FeatureName = FeatureName, + Base = basePath, + OverwriteExisting = overwriteExisting + + }.Run(); + + + }, Globals.BasePathOption, overwriteExistingOption); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs new file mode 100644 index 0000000..c9ac216 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs @@ -0,0 +1,25 @@ +using CodeQLToolkit.Features.Query.Scaffolding.Targets; +using CodeQLToolkit.Shared.Feature; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Lifecycle.Targets +{ + public class InitLifecycleTarget : ILifecycleTarget + { + public override void Run() + { + Log.G().LogInformation("Initializing new query development workspace..."); + + Directory.CreateDirectory(Base); + + var workspaceLocation = Path.Combine(Base, "codeql-workspace.yml"); + + WriteTemplateIfOverwriteOrNotExists("codeql-workspace", workspaceLocation, "CodeQL Workspace"); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs new file mode 100644 index 0000000..6bc009e --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs @@ -0,0 +1,52 @@ +using CodeQLToolkit.Features.Query.Commands; +using CodeQLToolkit.Features.Query.Lifecycle; +using CodeQLToolkit.Features.Query.Scaffolding; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Logging; +using Microsoft.Extensions.Logging; +using System.CommandLine; + +namespace CodeQLDevelopmentLifecycleToolkit.Features.Query +{ + + public class QueryFeatureMain : IToolkitFeature + { + readonly QueryScaffoldFeature scaffoldFeature; + readonly QueryCommandFeature commandFeature; + readonly QueryLifecycleFeature lifecycleFeature; + + + readonly static QueryFeatureMain instance; + + static QueryFeatureMain() { + instance = new QueryFeatureMain(); + } + private QueryFeatureMain() + { + scaffoldFeature = new QueryScaffoldFeature(); + commandFeature = new QueryCommandFeature(); + lifecycleFeature = new QueryLifecycleFeature(); + } + + public static QueryFeatureMain Instance { get { return instance; } } + + public int Run() + { + + Console.WriteLine("[Query] RUNNING QUERY FEATURE"); + + return 0; + } + + public void Register(Command parentCommand) + { + var queryCommand = new Command("query", "Use the features related to query creation and execution."); + parentCommand.Add(queryCommand); + + scaffoldFeature.Register(queryCommand); + commandFeature.Register(queryCommand); + lifecycleFeature.Register(queryCommand); + + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs new file mode 100644 index 0000000..6b16403 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs @@ -0,0 +1,77 @@ +using CodeQLToolkit.Features.Query.Scaffolding.Targets; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Query.Scaffolding +{ + public class QueryScaffoldFeature : FeatureBase, IToolkitScaffoldingFeature + { + public QueryScaffoldFeature() { + FeatureName = "Query"; + } + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT}; } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering scaffolding submodule."); + + var scaffoldCommand = new Command("generate", "Functions pertaining to generating query-related artifacts."); + parentCommand.Add(scaffoldCommand); + + // add the types of things we can scaffold. + var newQueryCommand = new Command("new-query", "Generates a new query and associated tests. Optionally will generate a new query pack if required."); + + var createQueryPackOption = new Option("--create-query-pack", () => true, "Create a new query pack if none exists."); + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + + var createTestsOption = new Option("--create-tests", ()=> true, "Create a new unit test for this query if it doesn't already exist."); + var queryNameOption = new Option("--query-name", "Name of the query. Note: Do not specify the `.ql` extension in naming your query.") { IsRequired = true }; + var queryLanguageOption = new Option("--language", $"The language to generate a query for.") { IsRequired = true} + .FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var queryPackOption = new Option("--pack", "The name of the query pack to place this query in.") { IsRequired = true }; + var queryPackScopeOption = new Option("--scope", "The scope to use") { IsRequired = true }; + + newQueryCommand.Add(createQueryPackOption); + newQueryCommand.Add(createTestsOption); + newQueryCommand.Add(queryNameOption); + newQueryCommand.Add(queryLanguageOption); + newQueryCommand.Add(queryPackOption); + newQueryCommand.Add(overwriteExistingOption); + newQueryCommand.Add(queryPackScopeOption); + + scaffoldCommand.Add(newQueryCommand); + + { + newQueryCommand.SetHandler((createQueryPack, createTests, queryName, queryLangauge, queryPack, basePath, overwriteExisting, queryPackScope) => + { + + if (!IsSupportedLangauge(queryLangauge)) + { + DieWithError($"Unsupported langauge `{queryLangauge}`"); + } + + new NewQueryScaffoldTarget() + { + Name = queryName, + Language = LanguageTypeHelper.LanguageTypeFromOptionString(queryLangauge), + Base = basePath, + QueryPack = queryPack, + QueryPackScope = queryPackScope, + CreateTests = createTests, + CreateQueryPack = createQueryPack, + OverwriteExisting = overwriteExisting, + FeatureName = FeatureName + }.Run(); + + }, createQueryPackOption, createTestsOption, queryNameOption, queryLanguageOption, queryPackOption, Globals.BasePathOption, overwriteExistingOption, queryPackScopeOption); + } + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs new file mode 100644 index 0000000..36f8fa3 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs @@ -0,0 +1,76 @@ +using CodeQLToolkit.Shared.Template; +using CodeQLToolkit.Shared.Utils; +using System.Reflection; + +namespace CodeQLToolkit.Features.Query.Scaffolding.Targets +{ + public class NewQueryScaffoldTarget : ScaffoldTarget + { + public string QueryPack { get; set; } + public bool CreateTests { get; set; } + public bool CreateQueryPack { get; set; } + public string QueryPackScope { get; set; } + + public override void Run() + { + Log.G().LogInformation("Creating new query..."); + + var query = new Shared.Utils.Query() + { + Language = Language, + QueryPackName = QueryPack, + Name = Name, + Scope = QueryPackScope, + Base = Base + }; + + Directory.CreateDirectory(query.QueryFileDir); + + WriteTemplateIfOverwriteOrNotExists("new-query", query.QueryFilePath, "new query", new + { + language = query.Language, + queryPackName = query.QueryPackName, + queryName = query.Name, + description = "Replace this text with a description of your query.", + qlLanguageImport = query.GetLanguageImportForLangauge() + }); + + if (CreateQueryPack) + { + WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new + { + queryPackScope = query.Scope, + queryPackName = query.QueryPackName + }); + } + + if (CreateTests) + { + Directory.CreateDirectory(query.QueryFileTestDir); + + // the source file to use + WriteTemplateIfOverwriteOrNotExists("test", query.QueryFileTestPath, "new query test file", new {}); + + // the expected file + WriteTemplateIfOverwriteOrNotExists("expected", query.QueryTestExpectedFile, "new query test expected file", new { }); + + // the the qlref file + WriteTemplateIfOverwriteOrNotExists("testref", query.QueryFileQLRefPath, "new query test ref", new { + queryName = query.Name + }); + + // the qlpack file + WriteTemplateIfOverwriteOrNotExists("qlpack-test", query.QueryPackTestPath, "new query test pack", new { + queryPackDependency = $"{query.Scope}/{query.QueryPackName}", + queryPackScope = query.Scope, + queryPackName = query.QueryTestPackName + }); + + } + else + { + Log.G().LogInformation($"Not creating tests because test creation was disabled."); + } + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid new file mode 100644 index 0000000..26362dc --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid @@ -0,0 +1,3 @@ +provide: + - '**/qlpack.yml' + - '**/codeql-workspace.yml' \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid new file mode 100644 index 0000000..7962166 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid @@ -0,0 +1 @@ +// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid new file mode 100644 index 0000000..f5c42c4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid @@ -0,0 +1,14 @@ +/** + * @id {{language}}/{{query_pack_name}}/{{query_name}} + * @name {{query_name}} + * @description {{description}} + * @kind problem + * @precision medium + * @problem.severity error + * @tags {{query_pack_name}} + */ + + import {{ql_language_import}} + + from Expr e + select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid new file mode 100644 index 0000000..c3a1a45 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid @@ -0,0 +1,7 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +dependencies: + codeql/cpp-all: 0.3.5 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid new file mode 100644 index 0000000..560a515 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid @@ -0,0 +1,8 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +extractor: cpp +dependencies: + {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid new file mode 100644 index 0000000..f39be51 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid @@ -0,0 +1 @@ +// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid new file mode 100644 index 0000000..d083780 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid @@ -0,0 +1 @@ +{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid new file mode 100644 index 0000000..7962166 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid @@ -0,0 +1 @@ +// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid new file mode 100644 index 0000000..f5c42c4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid @@ -0,0 +1,14 @@ +/** + * @id {{language}}/{{query_pack_name}}/{{query_name}} + * @name {{query_name}} + * @description {{description}} + * @kind problem + * @precision medium + * @problem.severity error + * @tags {{query_pack_name}} + */ + + import {{ql_language_import}} + + from Expr e + select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid new file mode 100644 index 0000000..8120bfc --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid @@ -0,0 +1,7 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +dependencies: + codeql/javascript-all: "^0.6.3" \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid new file mode 100644 index 0000000..515d065 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid @@ -0,0 +1,8 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +extractor: javascript +dependencies: + {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid new file mode 100644 index 0000000..f39be51 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid @@ -0,0 +1 @@ +// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid new file mode 100644 index 0000000..d083780 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid @@ -0,0 +1 @@ +{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj b/src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj similarity index 100% rename from src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj rename to src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs new file mode 100644 index 0000000..9b596cb --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs @@ -0,0 +1,20 @@ +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public abstract class BaseExecuteUnitTestsCommandTarget : CommandTarget + { + public int NumThreads { get; set; } + public string WorkDirectory { get; set; } + public string RunnerOS { get; set; } + public string CLIVersion { get; set; } + public string STDLibIdent { get; set; } + public string ExtraCodeQLArgs { get; set; } + } +} + diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs new file mode 100644 index 0000000..36d79f6 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public abstract class BaseGetMatrixCommandTarget : CommandTarget + { + public string[] OSVersions { get; set; } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs new file mode 100644 index 0000000..230e217 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs @@ -0,0 +1,112 @@ +using CodeQLToolkit.Features.Test.Lifecycle.Models; +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions +{ + + [AutomationType(AutomationType.ACTIONS)] + public class ExecuteUnitTestsCommandTarget : BaseExecuteUnitTestsCommandTarget + { + + public override void Run() + { + Log.G().LogInformation($"Preparing to execute unit tests found in {Base} for Language {Language}..."); + + // get a directory to work in + var tmpDirectory = WorkDirectory; + + var languageRoot = Path.Combine(Base, Language); + + // check if the language root exists + if (!Directory.Exists(languageRoot)){ + DieWithError($"Language root {languageRoot} does not exist so unit tests cannnot be run."); + } + + // Identify the test directories. + string[] dirs = Directory.GetDirectories(languageRoot, "test", SearchOption.AllDirectories); + + Log.G().LogInformation($"Test Directory Inventory {Language}"); + Log.G().LogInformation($"-----------------------------------"); + + foreach ( string dir in dirs) + { + Log.G().LogInformation($"Found test directory: {dir}"); + } + + var transformedDirs = dirs.Select(dir => Path.GetRelativePath(Base, dir)); + + if(dirs.Length == 0) + { + DieWithError($"No tests detected. Please create unit tests before running this command."); + } + + Parallel.For(0, NumThreads, + slice => { + + TestReport report = new TestReport() + { + RunnerOS = RunnerOS, + CLIVersion = CLIVersion, + STDLibIdent = STDLibIdent, + Language = Language, + Slice = slice, + NumSlices = NumThreads + }; + + var workingDirectory = Path.GetFullPath(Base); + var testPathString = string.Join(" ", transformedDirs); + var outFileReport = Path.Combine(tmpDirectory, report.FileName); + + Log.G().LogInformation($"Executing tests in working directory {workingDirectory}."); + Log.G().LogInformation($"Test Paths: {testPathString}"); + Log.G().LogInformation($"Slice: {slice} of {NumThreads}"); + Log.G().LogInformation($"Report File: {outFileReport}..."); + + using (Process process = new Process()) + { + process.StartInfo.FileName = "codeql"; + process.StartInfo.WorkingDirectory = workingDirectory; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = false; + process.StartInfo.Arguments = $"test run {ExtraCodeQLArgs} --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}"; + + process.Start(); + + // needed for STDOUT redirection + var output = process.StandardOutput.ReadToEnd(); + + File.WriteAllText(outFileReport, output); + + process.WaitForExit(); + + if (process.ExitCode != 0) + { + // This fine + if(process.ExitCode == 122) + { + Log.G().LogError($"One more more unit tests failed. Please see the output of the validation step for more information about failed tests cases."); + } + // this is not fine + else + { + DieWithError($"Non-test related error while running unit tests. Please check debug output for more infomation."); + } + } + } + } + ); + + + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs new file mode 100644 index 0000000..666748d --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs @@ -0,0 +1,75 @@ +using CodeQLToolkit.Shared.Utils; +using System.Text.Json; + +namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions +{ + [AutomationType(AutomationType.ACTIONS)] + public class GetMatrixCommandTarget : BaseGetMatrixCommandTarget + { + public override void Run() + { + + // based on the current configuration of the repository, generate a matrix + // for actions, it looks like this: + + // { + // "include": [ + // { + // "codeql_cli": "2.12.6", + // "codeql_standard_library": "codeql-cli/v2.12.6", + // "codeql_cli_bundle": "codeql-bundle-20230403", + // "os": "ubuntu-latest", + // "codeql_standard_library_ident": "codeql-cli_v2.12.6" + // } + // ] + // } + + // For now, we only support a single version but this is easy to extend. The options for runners are what create different matrix types. + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + List configs = new List(); + + foreach(var os in OSVersions) + { + Log.G().LogInformation($"Creating matrix for {os}"); + + configs.Add(new + { + codeql_cli = config.CodeQLCLI, + codeql_standard_library = config.CodeQLStandardLibrary, + codeql_cli_bundle = config.CodeQLCLIBundle, + os = os, + codeql_standard_library_ident = config.CodeQLStandardLibraryIdent + }); + } + + var data = new + { + include = configs + }; + + var json = JsonSerializer.Serialize(data); + + var matrixVariable = $"matrix={json}"; + + string envFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT"); + + Log.G().LogInformation($"Writing matrix output {matrixVariable} to {envFile}"); + + File.AppendAllText(envFile, matrixVariable ); + + Log.G().LogInformation($"Done."); + + } + } +} diff --git a/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs similarity index 100% rename from src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs rename to src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs new file mode 100644 index 0000000..f9866ee --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs @@ -0,0 +1,160 @@ +using CodeQLToolkit.Features.Test.Commands.Targets; +using CodeQLToolkit.Features.Test.Lifecycle; +using CodeQLToolkit.Shared.Types; +using CodeQLToolkit.Shared.Utils; +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public class TestCommandFeature : FeatureBase, IToolkitLifecycleFeature + { + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; } + + public TestCommandFeature() + { + FeatureName = "Test"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining to running test-related commands."); + parentCommand.Add(runCommand); + + // a command that gets the matrix configuration + var getMatrixTestCommand = new Command("get-matrix", "Gets a CI/CD matrix based on the current configuration."); + + var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; + getMatrixTestCommand.Add(matrixOSVersion); + + // a command that runs the actual tests + var unitTestsCommand = new Command("execute-unit-tests", "Runs unit tests within a repository based on the current configuration."); + + var numThreadsOption = new Option("--num-threads", () => 4, "The number of threads to use for runner. For best performance, do not exceed the number of physical cores on your system.") { IsRequired = true }; + var workDirectoryOption = new Option("--work-dir", () => Path.GetTempPath(), "Where to place intermediate execution output files.") { IsRequired = true }; + var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var runnerOSOption = new Option("--runner-os", $"Label for the operating system running these tests.") { IsRequired = true }; + //var cliVersionOption = new Option("--cli-version", $"The version of the cli running the tests.") { IsRequired = true }; + //var stdLibIdentOption = new Option("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true }; + var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; + + unitTestsCommand.Add(numThreadsOption); + unitTestsCommand.Add(workDirectoryOption); + unitTestsCommand.Add(languageOption); + unitTestsCommand.Add(runnerOSOption); + //unitTestsCommand.Add(cliVersionOption); + //unitTestsCommand.Add(stdLibIdentOption); + unitTestsCommand.Add(extraCodeQLOptions); + + // a command validates the tests + var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems."); + + var resultsDirectoryOption = new Option("--results-directory", "Where to find the intermediate execution output files.") { IsRequired = true }; + var prettyPrintOption = new Option("--pretty-print", () => false, "Pretty print test output in a compact format. Note this will not exit with a failure code if tests fail.") { IsRequired = true }; + + validateUnitTestsCommand.Add(resultsDirectoryOption); + validateUnitTestsCommand.Add(prettyPrintOption); + + runCommand.Add(getMatrixTestCommand); + runCommand.Add(unitTestsCommand); + runCommand.Add(validateUnitTestsCommand); + + getMatrixTestCommand.SetHandler((basePath, automationType, osVersions) => { + + Log.G().LogInformation("Executing get-matrix command..."); + + // dispatch at runtime to the correct automation type + var featureTarget = AutomationFeatureFinder + .FindTargetForAutomationType( + AutomationTypeHelper.AutomationTypeFromString(automationType) + ); + + featureTarget.Base = basePath; + featureTarget.OSVersions = osVersions.Split(","); + + featureTarget.Run(); + + }, Globals.BasePathOption, Globals.AutomationTypeOption, matrixOSVersion); + + //stdLibIdent + unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, extraArgs) => { + + Log.G().LogInformation("Executing execute-unit-tests command..."); + + // dispatch at runtime to the correct automation type + var featureTarget = AutomationFeatureFinder + .FindTargetForAutomationType( + AutomationTypeHelper.AutomationTypeFromString(automationType) + ); + + // lookup cliVersion and stdLibIdent + var c = new QLTConfig() + { + Base = basePath + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + featureTarget.Base = basePath; + featureTarget.NumThreads = numThreads; + featureTarget.WorkDirectory = workDirectory; + featureTarget.Language = language; + featureTarget.RunnerOS = runnerOS; + featureTarget.CLIVersion = config.CodeQLCLI; + featureTarget.STDLibIdent = config.CodeQLStandardLibraryIdent; + featureTarget.ExtraCodeQLArgs = extraArgs; + + featureTarget.Run(); + + }, Globals.BasePathOption, + Globals.AutomationTypeOption, + numThreadsOption, + workDirectoryOption, + languageOption, + runnerOSOption, + extraCodeQLOptions + ); + + + validateUnitTestsCommand.SetHandler((resultsDirectory, prettyPrint) => + { + Log.G().LogInformation("Executing validate-unit-tests command..."); + + new ValidateUnitTestsCommand() + { + ResultsDirectory = resultsDirectory, + PrettyPrint = prettyPrint + }.Run(); + + + }, resultsDirectoryOption, prettyPrintOption); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features.Validation/Common.cs b/src_backup/src/CodeQLToolkit.Features.Test/Common.cs similarity index 100% rename from src/CodeQLToolkit.Features.Validation/Common.cs rename to src_backup/src/CodeQLToolkit.Features.Test/Common.cs diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs new file mode 100644 index 0000000..d3bdad8 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle +{ + abstract public class BaseLifecycleTarget : ILifecycleTarget + { + public int NumThreads { get; set; } + public string UseRunner { get; set; } + + public string ExtraArgs { get; set; } + + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs new file mode 100644 index 0000000..ffb2635 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle.Models +{ + public class TestReport + { + public string RunnerOS { get; set; } + public string CLIVersion { get; set; } + public string STDLibIdent { get; set; } + + public string Language { get; set; } + + public int Slice { get; set; } + public int NumSlices { get; set; } + + + public string FileName { + + get { + + var savePath = $"test_report_{RunnerOS}_{CLIVersion}_{STDLibIdent}_slice_{Slice}_of_{NumSlices}.json"; + + return savePath; + } + } + + + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs new file mode 100644 index 0000000..b505101 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions +{ + [AutomationType(AutomationType.ACTIONS)] + public class InitLifecycleTarget : BaseLifecycleTarget + { + public InitLifecycleTarget() + { + AutomationType = AutomationType.ACTIONS; + } + public override void Run() + { + Log.G().LogInformation("Running init command..."); + + // temporarily disable the language resolution + var tmpLanguage = Language; + Language = null; + + var codeqlArgs = "--threads=0"; + + if(ExtraArgs!= null && ExtraArgs.Length > 0) + { + codeqlArgs = $"{codeqlArgs} {ExtraArgs}"; + } + + WriteTemplateIfOverwriteOrNotExists("install-codeql", Path.Combine(Base, ".github", "actions", "install-codeql", "action.yml"), "install-codeql action"); + WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action"); + WriteTemplateIfOverwriteOrNotExists("run-unit-tests", Path.Combine(Base, ".github", "workflows", $"run-codeql-unit-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new + { + numThreads = NumThreads, + useRunner = UseRunner, + language = tmpLanguage, + codeqlArgs = codeqlArgs + }); + + Language = tmpLanguage; + + var message = @"------------------------------------------ +Your repository now has the CodeQL Unit Test Runner installed in `.github/workflows/`. Additionally, +QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt` and +`.github/actions/install-codeql`. + +Note that, by default, your runner will use 4 threads and defaults to the `ubuntu-latest` runner. + +You can modify the number of threads used by using the `--num-threads` argument and you can select a different +runner with the `--use-runner` argument. + +In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings. + +(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; + + + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs new file mode 100644 index 0000000..ebdd333 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs @@ -0,0 +1,81 @@ +using CodeQLToolkit.Features.Test.Lifecycle.Targets; +using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions; +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; +using System.Reflection; + +namespace CodeQLToolkit.Features.Test.Lifecycle +{ + public class TestLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public TestLifecycleFeature() + { + FeatureName = "Test"; + } + + public override LanguageType[] SupportedLangauges + { + get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var initCommand = new Command("init", "Initialize testing in this repository."); + + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + var numThreadsOption = new Option("--num-threads", () => 4, "Number of threads to use during test execution."); + var useRunnerOption = new Option("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners."); + var languageOption = new Option("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; + + initCommand.AddOption(overwriteExistingOption); + initCommand.AddOption(numThreadsOption); + initCommand.AddOption(useRunnerOption); + initCommand.AddOption(languageOption); + initCommand.AddOption(extraCodeQLOptions); + + + parentCommand.Add(initCommand); + + + + initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language, extraArgs) => + { + Log.G().LogInformation("Executing init command..."); + + // + // dispatch at runtime to the correct automation type + // + var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType(AutomationTypeHelper.AutomationTypeFromString(automationType)); + + // setup common params + featureTarget.FeatureName = FeatureName; + featureTarget.Base = basePath; + featureTarget.OverwriteExisting = overwriteExisting; + featureTarget.NumThreads = numThreads; + featureTarget.UseRunner = useRunner; + featureTarget.Language = language; + featureTarget.ExtraArgs = extraArgs; + featureTarget.Run(); + + }, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption, extraCodeQLOptions); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid new file mode 100644 index 0000000..ddb56ba --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid @@ -0,0 +1,109 @@ +name: Fetch CodeQL CLI and queries +description: | + Fetches a CodeQL CLI and a copy of the CodeQL standard libraries at the specified versions. +inputs: + codeql-cli-version: + description: | + The version of the CodeQL CLI to be downloaded. + required: false + default: 'latest' + + codeql-stdlib-version: + description: | + The tag or commit to use from the CodeQL Standard Library + required: false + default: 'latest' + + add-to-path: + description: | + Add the CodeQL CLI to the system path + required: false + default: 'true' + + codeql-home: + description: | + The directory to store the CodeQL CLI and Standard Library. + A fixed location can be used for caching the tooling. + required: false +outputs: + codeql-home: + description: 'The directory containing the CodeQL CLI and CodeQL Standard Library' + value: ${{ steps.install-codeql.outputs.codeql-home }} + +runs: + using: composite + steps: + - name: Install CodeQL + id: install-codeql + env: + RUNNER_OS: ${{ runner.os }} + RUNNER_TEMP: ${{ runner.temp }} + CODEQL_CLI_VERSION: ${{ inputs.codeql-cli-version }} + CODEQL_STDLIB_VERSION: ${{ inputs.codeql-stdlib-version }} + GITHUB_TOKEN: ${{ github.token }} + ADD_TO_PATH: ${{ inputs.add-to-path }} + CODEQL_HOME: ${{ inputs.codeql-home }} + shell: bash + run: | + echo "::debug::Determining CodeQL release for $RUNNER_OS" + case $RUNNER_OS in + "Linux") + RELEASE_PATTERN="codeql-linux64.zip" + ;; + "macOS") + RELEASE_PATTERN="codeql-osx64.zip" + ;; + "Windows") + RELEASE_PATTERN="codeql-win64.zip" + ;; + *) + echo "::error::Unsupported runner operating system $RUNNER_OS" + exit 1 + ;; + esac + echo "::debug::Selected $RELEASE_PATTERN" + + if [ "$CODEQL_HOME" == "" ] + then + echo "::debug::Creating temporary CodeQL home" + CODEQL_HOME=$(mktemp -d -p $RUNNER_TEMP codeql-home-XXXXXXXXXX) + else + echo "::debug::Creating CodeQL home at $CODEQL_HOME" + mkdir -p $CODEQL_HOME + fi + + echo "::debug::Changing directory to $CODEQL_HOME" + pushd $CODEQL_HOME + + echo "::debug::Downloading CodeQL CLI version $CODEQL_CLI_VERSION" + if [ "$CODEQL_CLI_VERSION" == "latest" ] + then + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN + else + gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN + fi + echo "::debug::Unpacking CodeQL CLI" + unzip -q $RELEASE_PATTERN + + echo "::debug::Cloning CodeQL standard library" + git clone https://github.com/github/codeql.git codeql-stdlib + + if [ "$CODEQL_STDLIB_VERSION" != "latest" ] + then + pushd codeql-stdlib + echo "::debug::Switching to revision $CODEQL_STDLIB_VERSION" + git checkout $CODEQL_STDLIB_VERSION + popd + fi + + if [ "$ADD_TO_PATH" == "true" ] + then + echo "::debug::Adding CodeQL CLI path '$(pwd)/codeql' to system path" + echo "$(pwd)/codeql" >> $GITHUB_PATH + fi + + echo "::debug::Setting output parameter codeql-home to $(pwd)" + echo "codeql-home=$(pwd)" >> $GITHUB_OUTPUT + + popd + echo "::debug::Done." diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid new file mode 100644 index 0000000..b1e7fa1 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid @@ -0,0 +1,88 @@ +name: Fetch and Install QLT +description: | + Fetches and installs QLT. +inputs: + qlt-version: + description: | + The version of QLT to be downloaded. + required: false + default: 'latest' + + add-to-path: + description: | + Add QLT to the system path + required: false + default: 'true' + + token: + description: | + Token to use for auth + required: true + + +outputs: + qlt-home: + description: 'The directory containing the QLT installation' + value: ${{ steps.install-qlt.outputs.qlt-home }} + +runs: + using: composite + steps: + - name: Install QLT + id: install-qlt + env: + RUNNER_OS: ${{ runner.os }} + RUNNER_TEMP: ${{ runner.temp }} + # GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ inputs.token }} + ADD_TO_PATH: ${{ inputs.add-to-path }} + QLT_VERSION: ${{ inputs.qlt-version }} + QLT_HOME: ${{ inputs.qlt-home }} + shell: bash + run: | + echo -e "\e[0;32m[QLT]\e[0m Determining QLT release for $RUNNER_OS" + case $RUNNER_OS in + "Linux") + RELEASE_PATTERN="qlt-linux-x86_64.zip" + ;; + *) + echo "::error::Unsupported runner operating system $RUNNER_OS" + exit 1 + ;; + esac + echo -e "\e[0;32m[QLT]\e[0m Selected $RELEASE_PATTERN" + + if [ "$QLT_HOME" == "" ] + then + echo -e "\e[0;32m[QLT]\e[0m Creating temporary QLT home" + QLT_HOME=$(mktemp -d -p $RUNNER_TEMP qlt-home-XXXXXXXXXX) + else + echo -e "\e[0;32m[QLT]\e[0m Creating CodeQL home at $QLT_HOME" + mkdir -p $QLT_HOME + fi + + echo -e "\e[0;32m[QLT]\e[0m Changing directory to $QLT_HOME" + pushd $QLT_HOME + + echo -e "\e[0;32m[QLT]\e[0m Downloading QLT version $QLT_VERSION" + if [ "$QLT_VERSION" == "latest" ] + then + # download the actual bundle + gh release download -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" + else + gh release download "$QLT_VERSION" -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" + fi + echo -e "\e[0;32m[QLT]\e[0m Unpacking QLT" + unzip $RELEASE_PATTERN + + if [ "$ADD_TO_PATH" == "true" ] + then + echo -e "\e[0;32m[QLT]\e[0m Adding QLT '$(pwd)/qlt' to system path" + echo "$(pwd)" >> $GITHUB_PATH + fi + + echo -e "\e[0;32m[QLT]\e[0m Setting output parameter qlt-home to $(pwd)" + echo "qlt-home=$(pwd)" >> $GITHUB_OUTPUT + + popd + echo -e "\e[0;32m[QLT]\e[0m Done." diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid new file mode 100644 index 0000000..7177427 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid @@ -0,0 +1,129 @@ +name: ⚙️ CodeQL - Run Unit Tests ({{language}}) +{% raw %} + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + create-unit-test-matrix: + name: Create CodeQL Unit Test Matrix + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true +{% endraw %} + - name: Export unit test matrix + id: export-unit-test-matrix + run: | + qlt test run get-matrix --os-version {{ use_runner }} +{% raw %} + run-test-suites: + name: Run Unit Tests + needs: create-unit-test-matrix + + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.create-unit-test-matrix.outputs.matrix) }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true + + - name: Install CodeQL + id: install-codeql + uses: ./.github/actions/install-codeql + with: + codeql-cli-version: ${{ matrix.codeql_cli }} + codeql-stdlib-version: ${{ matrix.codeql_standard_library }} + add-to-path: true + + - name: Verify Versions of Tooling + shell: bash + run: | + echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}" + echo -e "Checking CodeQL Version:" + codeql --version + + echo -e "Checking QLT Version:" + echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}" + qlt version + + - name: Install QL Packs + shell: bash + run: | + qlt query run install-packs + + - name: Run test suites + id: run-test-suites + env: + RUNNER_OS: ${{ runner.os }} + CODEQL_CLI: ${{ matrix.codeql_cli }} + CODEQL_STDLIB: ${{ matrix.codeql_standard_library }} + CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}} + RUNNER_TMP: ${{ runner.temp }} + shell: bash + run: > +{% endraw %} + qlt test run execute-unit-tests + --codeql-args "{{ codeql_args }}" + --num-threads {{ num_threads }} + --language {{ language }} + --runner-os $RUNNER_OS + --work-dir $RUNNER_TMP +{% raw %} + - name: Upload test results + uses: actions/upload-artifact@v2 + with: + name: test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} + path: | + ${{ runner.temp }}/test_report_${{ runner.os }}_${{ matrix.codeql_cli }}_${{ matrix.codeql_standard_library_ident }}_slice_*.json + if-no-files-found: error + + validate-test-results: + name: Validate test results + needs: [run-test-suites] + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true + + - name: Collect test results + uses: actions/download-artifact@v2 + + - name: Validate test results + run: | + qlt test run validate-unit-tests --results-directory . + qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY + +{% endraw %} \ No newline at end of file diff --git a/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs similarity index 100% rename from src/CodeQLToolkit.Features.Test/TestFeatureMain.cs rename to src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs diff --git a/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj b/src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj similarity index 100% rename from src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj rename to src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs new file mode 100644 index 0000000..2fc347b --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets +{ + + + public class UnitTestResult + { + public string test { get; set; } + public bool pass { get; set; } + public string failureStage { get; set; } + public string failureDescription { get; set; } + public object[] messages { get; set; } + public int compilationMs { get; set; } + public int evaluationMs { get; set; } + public string expected { get; set; } + public string actual { get; set; } + public string[] diff { get; set; } + } + + public class ValidateUnitTestsCommand : CommandTarget + { + public string ResultsDirectory { get; set; } + + public bool PrettyPrint { get; set; } + + public override void Run() + { + Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); + + string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); + + List unitTestResults = new List(); + + foreach (string result in results) + { + using (StreamReader r = new StreamReader(result)) + { + string json = r.ReadToEnd(); + List items = JsonConvert.DeserializeObject>(json); + + foreach(var item in items) + { + unitTestResults.Add(item); + } + } + } + + + int totalCases = unitTestResults.Count; + int currentCase = 0; + + foreach (var item in unitTestResults) + { + currentCase++; + + if (item.pass) + { + if(PrettyPrint) + { + Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : PASSED "); + Log.G().LogError($"+----------------------------------------------+"); + } + } + else + { + if (PrettyPrint) + { + Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + if (item.failureStage == "RESULT") + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : RESULT"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST DIFFERENCES |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + + + foreach (var diff in item.diff) + { + Log.G().LogError($"| {diff}"); + } + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FAILURE DESCRIPTION |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + Log.G().LogError($"| {item.failureDescription}"); + + + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + } + } + } + + var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); + + if (failedTests.Length > 0 && !PrettyPrint) + { + DieWithError("One or more failures during run unit tests."); + } + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs new file mode 100644 index 0000000..2e8db6d --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs @@ -0,0 +1,60 @@ +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public class ValidationCommandFeature : FeatureBase, IToolkitLifecycleFeature + { + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; } + + public ValidationCommandFeature() + { + FeatureName = "Validation"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining running validation commands."); + parentCommand.Add(runCommand); + + var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); + + var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; + getMatrixTestCommand.Add(matrixOSVersion); + + runCommand.Add(getMatrixTestCommand); + + + getMatrixTestCommand.SetHandler(() => + { + Log.G().LogInformation("Executing validate-unit-tests command..."); + + //new ValidateUnitTestsCommand() + //{ + // ResultsDirectory = resultsDirectory, + // PrettyPrint = prettyPrint + //}.Run(); + + + }); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs new file mode 100644 index 0000000..279d9e9 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs @@ -0,0 +1,7 @@ +global using CodeQLToolkit.Shared.Target; +global using CodeQLToolkit.Shared.Logging; +global using Microsoft.Extensions.Logging; +global using CodeQLToolkit.Shared.Feature; +global using CodeQLToolkit.Shared.Options; +global using CodeQLToolkit.Shared.Types; + diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs new file mode 100644 index 0000000..30aad10 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Models +{ + public class CodeQLCliResponseModel + { + public string query { get; set; } + public string relativeName { get; set; } + public bool success { get; set; } + public Message[] messages { get; set; } + } + + public class Message + { + public string severity { get; set; } + public string message { get; set; } + public Position position { get; set; } + } + + public class Position + { + public string fileName { get; set; } + public int line { get; set; } + public int column { get; set; } + public int endLine { get; set; } + public int endColumn { get; set; } + } + +} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs new file mode 100644 index 0000000..1f8367f --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs @@ -0,0 +1,38 @@ +using CodeQLToolkit.Features.Test.Commands; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Validation +{ + public class ValidationFeatureMain : IToolkitFeature + + { + readonly ValidationCommandFeature commandFeature; + readonly static ValidationFeatureMain instance; + + static ValidationFeatureMain() + { + instance = new ValidationFeatureMain(); + } + + private ValidationFeatureMain() + { + commandFeature = new ValidationCommandFeature(); + } + public static ValidationFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var validationCommand = new Command("validation", "Features related to the validation of CodeQL Development Repositories."); + parentCommand.Add(validationCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(validationCommand); + + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs new file mode 100644 index 0000000..c0357b8 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Shared.Feature; +using System.CommandLine; +using CodeQLToolkit.Shared.Logging; +using Microsoft.Extensions.Logging; +using CodeQLToolkit.Features.CodeQL.Lifecycle; + +namespace CodeQLToolkit.Features.CodeQL +{ + public class CodeQLFeatureMain : IToolkitFeature + { + readonly CodeQLLifecycleFeature lifecycleFeature; + readonly static CodeQLFeatureMain instance; + + static CodeQLFeatureMain() + { + instance = new CodeQLFeatureMain(); + } + + private CodeQLFeatureMain() + { + lifecycleFeature = new CodeQLLifecycleFeature(); + } + + public static CodeQLFeatureMain Instance { get { return instance; } } + + public int Run() + { + + return 0; + } + + public void Register(Command parentCommand) + { + var queryCommand = new Command("codeql", "Use the features related to managing the version of CodeQL used by this repository."); + parentCommand.Add(queryCommand); + Log.G().LogInformation("Registering scaffolding submodule."); + lifecycleFeature.Register(queryCommand); + } + + + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs new file mode 100644 index 0000000..73e388f --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs @@ -0,0 +1,76 @@ +using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets; +using System.CommandLine; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle +{ + public class CodeQLLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public CodeQLLifecycleFeature() + { + FeatureName = "CodeQL"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var setCommand = new Command("set", "Functions pertaining to setting variables related to CodeQL."); + parentCommand.Add(setCommand); + + var setVersionCommand = new Command("version", "Sets the version of CodeQL used."); + + var cliVersionOption = new Option("--cli-version", () => "2.11.6", "The version of the cli to use. Example: `2.11.6`.") { IsRequired = true }; + var standardLibraryVersionOption = new Option("--standard-library-version", () => "codeql-cli/v2.11.6", "The version of the standard library to use. Example: `codeql-cli/v2.11.6`.") { IsRequired = true }; + var bundleVersionOption = new Option("--bundle-version", () => "codeql-bundle-20221211", "The bundle version to use. Example: `codeql-bundle-20221211`.") { IsRequired = true }; + + setVersionCommand.Add(cliVersionOption); + setVersionCommand.Add(standardLibraryVersionOption); + setVersionCommand.Add(bundleVersionOption); + + setCommand.Add(setVersionCommand); + + var getCommand = new Command("get", "Functions pertaining to getting variables related to CodeQL."); + parentCommand.Add(getCommand); + + var getVersionCommand = new Command("version", "Gets the version of CodeQL used."); + getCommand.Add(getVersionCommand); + + { + setVersionCommand.SetHandler((cliVersion, standardLibraryVersion, bundleVersion, basePath) => + { + Log.G().LogInformation("Executing set command..."); + + new SetVersionLifecycleTarget() + { + CodeQLCLI = cliVersion, + CodeQLStandardLibrary = standardLibraryVersion, + CodeQLCLIBundle = bundleVersion, + Base = basePath + }.Run(); + + }, cliVersionOption, standardLibraryVersionOption, bundleVersionOption, Globals.BasePathOption); + } + + + { + getVersionCommand.SetHandler((basePath) => + { + Log.G().LogInformation("Executing get command..."); + + new GetVersionLifecycleTarget() + { + Base = basePath + }.Run(); + + }, Globals.BasePathOption); + } + + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs new file mode 100644 index 0000000..2bd4823 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs @@ -0,0 +1,40 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets +{ + public class GetVersionLifecycleTarget : ILifecycleTarget + { + + override public void Run() + { + Log.G().LogInformation("Running get command..."); + + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + // This should be updated so that we can pretty print all the various options: + Console.WriteLine($"---------current settings---------"); + Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); + Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); + Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); + Console.WriteLine($"----------------------------------"); + Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); + + + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs new file mode 100644 index 0000000..9025b71 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs @@ -0,0 +1,35 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets +{ + public class SetVersionLifecycleTarget : ILifecycleTarget + { + public string CodeQLCLI { get; set; } + public string CodeQLStandardLibrary { get; set; } + public string CodeQLCLIBundle { get; set; } + + override public void Run() + { + Log.G().LogInformation("Running set command..."); + + var c = new QLTConfig() + { + CodeQLCLI = CodeQLCLI, + CodeQLStandardLibrary = CodeQLStandardLibrary, + CodeQLCLIBundle = CodeQLCLIBundle, + Base = Base + }; + + c.ToFile(); + + Log.G().LogInformation("Wrote to file..."); + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj b/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj new file mode 100644 index 0000000..4c696ed --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/src_backup/src/CodeQLToolkit.Features/Common.cs b/src_backup/src/CodeQLToolkit.Features/Common.cs new file mode 100644 index 0000000..279d9e9 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Common.cs @@ -0,0 +1,7 @@ +global using CodeQLToolkit.Shared.Target; +global using CodeQLToolkit.Shared.Logging; +global using Microsoft.Extensions.Logging; +global using CodeQLToolkit.Shared.Feature; +global using CodeQLToolkit.Shared.Options; +global using CodeQLToolkit.Shared.Types; + diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs new file mode 100644 index 0000000..d01968b --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs @@ -0,0 +1,63 @@ +using CodeQLToolkit.Features.Pack.Commands.Targets; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack.Commands +{ + public class PackCommandFeature : FeatureBase, IToolkitCommandFeature + { + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + var runCommand = new Command("run", "Functions pertaining to running pack-related commands."); + parentCommand.Add(runCommand); + + // a command that installs query packs + var sayHello = new Command("hello-jeongsoo", "Says hello!"); + var howManyTimesHello = new Option("--times", "how many times to say it") { IsRequired = true }; + sayHello.Add(howManyTimesHello); + + var sayGoodbye = new Command("goodbye-jeongsoo", "Says goodbye!"); + + var howManyTimes = new Option("--times", "how many times to say it") { IsRequired = true }; + sayGoodbye.Add(howManyTimes); + + + runCommand.Add(sayHello); + runCommand.Add(sayGoodbye); + + sayHello.SetHandler((basePath, times) => { + + new HelloJeongsooCommandTarget() { + Base = basePath, + Times = times + + }.Run(); + + }, Globals.BasePathOption, howManyTimesHello); + + sayGoodbye.SetHandler((basePath, times) => { + + Console.WriteLine($"Saying goodbye {times} number of times"); + + for (int i = 0; i < times; i++) + { + Console.WriteLine("Goodbye!"); + } + + + }, Globals.BasePathOption, howManyTimes); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs new file mode 100644 index 0000000..33b4420 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs @@ -0,0 +1,45 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack.Commands.Targets +{ + public class HelloJeongsooCommandTarget : CommandTarget + { + + public int Times { get; set; } + + + public override void Run() + { + for(int i = 0; i < Times; i++) { + Console.WriteLine($"Hello! My Base Target is: {Base}"); + } + + + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + + Console.WriteLine($"---------current settings---------"); + Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); + Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); + Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); + Console.WriteLine($"----------------------------------"); + Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs new file mode 100644 index 0000000..9fa81ea --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Features.Pack.Commands; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Pack +{ + public class PackFeatureMain : IToolkitFeature + { + + readonly static PackFeatureMain instance; + readonly PackCommandFeature commandFeature; + + static PackFeatureMain() + { + instance = new PackFeatureMain(); + } + + private PackFeatureMain() + { + commandFeature = new PackCommandFeature(); + } + public static PackFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var packCommand = new Command("pack", "Features CodeQL pack management and publication."); + parentCommand.Add(packCommand); + + Log.G().LogInformation("Registering scaffolding submodule."); + commandFeature.Register(packCommand); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs new file mode 100644 index 0000000..d5bb08c --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs @@ -0,0 +1,42 @@ +using CodeQLToolkit.Features.Query.Commands.Targets; +using CodeQLToolkit.Features.Query.Scaffolding; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Commands +{ + public class QueryCommandFeature : FeatureBase, IToolkitCommandFeature + { + public QueryCommandFeature() + { + FeatureName = "Query"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + var runCommand = new Command("run", "Functions pertaining to running query-related commands."); + parentCommand.Add(runCommand); + + // a command that installs query packs + var installPacksQueryCommand = new Command("install-packs", "Installs CodeQL packs within the repository."); + + runCommand.Add(installPacksQueryCommand); + + installPacksQueryCommand.SetHandler((basePath) => new InstallQueryPacksCommandTarget() { Base = basePath }.Run(), Globals.BasePathOption); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs new file mode 100644 index 0000000..255faf7 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Commands.Targets +{ + public class InstallQueryPacksCommandTarget : CommandTarget + { + public override void Run() + { + Log.G().LogInformation("Finding all qlpacks..."); + + // starting at the base path, find all qlpacks and install them + string[] files = Directory.GetFiles(Base, "qlpack.yml", SearchOption.AllDirectories); + + Log.G().LogInformation($"Got {files.Length} packs..."); + + foreach ( string file in files ) + { + Log.G().LogInformation($"Installing qlpack {file}..."); + + using(Process process = new Process()) + { + process.StartInfo.FileName = "codeql"; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = false; + process.StartInfo.Arguments = $"pack install {file}"; + process.Start(); + + process.WaitForExit(); + + if(process.ExitCode !=0) + { + DieWithError($"Failed to install query pack {file}."); + } + } + + } + + Log.G().LogInformation($"Installed {files.Length} packs."); + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs new file mode 100644 index 0000000..2b725e0 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs @@ -0,0 +1,56 @@ +using CodeQLToolkit.Features.Query.Lifecycle.Targets; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using CodeQLToolkit.Shared.Types; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Lifecycle +{ + public class QueryLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public QueryLifecycleFeature() + { + FeatureName = "Query"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var initCommand = new Command("init", "Initialize query support in this repository."); + + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + + initCommand.AddOption(overwriteExistingOption); + + parentCommand.Add(initCommand); + + initCommand.SetHandler((basePath, overwriteExisting) => + { + Log.G().LogInformation("Executing init command..."); + + + new InitLifecycleTarget() + { + FeatureName = FeatureName, + Base = basePath, + OverwriteExisting = overwriteExisting + + }.Run(); + + + }, Globals.BasePathOption, overwriteExistingOption); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs new file mode 100644 index 0000000..c9ac216 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs @@ -0,0 +1,25 @@ +using CodeQLToolkit.Features.Query.Scaffolding.Targets; +using CodeQLToolkit.Shared.Feature; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Query.Lifecycle.Targets +{ + public class InitLifecycleTarget : ILifecycleTarget + { + public override void Run() + { + Log.G().LogInformation("Initializing new query development workspace..."); + + Directory.CreateDirectory(Base); + + var workspaceLocation = Path.Combine(Base, "codeql-workspace.yml"); + + WriteTemplateIfOverwriteOrNotExists("codeql-workspace", workspaceLocation, "CodeQL Workspace"); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs new file mode 100644 index 0000000..6bc009e --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs @@ -0,0 +1,52 @@ +using CodeQLToolkit.Features.Query.Commands; +using CodeQLToolkit.Features.Query.Lifecycle; +using CodeQLToolkit.Features.Query.Scaffolding; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Logging; +using Microsoft.Extensions.Logging; +using System.CommandLine; + +namespace CodeQLDevelopmentLifecycleToolkit.Features.Query +{ + + public class QueryFeatureMain : IToolkitFeature + { + readonly QueryScaffoldFeature scaffoldFeature; + readonly QueryCommandFeature commandFeature; + readonly QueryLifecycleFeature lifecycleFeature; + + + readonly static QueryFeatureMain instance; + + static QueryFeatureMain() { + instance = new QueryFeatureMain(); + } + private QueryFeatureMain() + { + scaffoldFeature = new QueryScaffoldFeature(); + commandFeature = new QueryCommandFeature(); + lifecycleFeature = new QueryLifecycleFeature(); + } + + public static QueryFeatureMain Instance { get { return instance; } } + + public int Run() + { + + Console.WriteLine("[Query] RUNNING QUERY FEATURE"); + + return 0; + } + + public void Register(Command parentCommand) + { + var queryCommand = new Command("query", "Use the features related to query creation and execution."); + parentCommand.Add(queryCommand); + + scaffoldFeature.Register(queryCommand); + commandFeature.Register(queryCommand); + lifecycleFeature.Register(queryCommand); + + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs new file mode 100644 index 0000000..6b16403 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs @@ -0,0 +1,77 @@ +using CodeQLToolkit.Features.Query.Scaffolding.Targets; +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Options; +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Query.Scaffolding +{ + public class QueryScaffoldFeature : FeatureBase, IToolkitScaffoldingFeature + { + public QueryScaffoldFeature() { + FeatureName = "Query"; + } + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT}; } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering scaffolding submodule."); + + var scaffoldCommand = new Command("generate", "Functions pertaining to generating query-related artifacts."); + parentCommand.Add(scaffoldCommand); + + // add the types of things we can scaffold. + var newQueryCommand = new Command("new-query", "Generates a new query and associated tests. Optionally will generate a new query pack if required."); + + var createQueryPackOption = new Option("--create-query-pack", () => true, "Create a new query pack if none exists."); + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + + var createTestsOption = new Option("--create-tests", ()=> true, "Create a new unit test for this query if it doesn't already exist."); + var queryNameOption = new Option("--query-name", "Name of the query. Note: Do not specify the `.ql` extension in naming your query.") { IsRequired = true }; + var queryLanguageOption = new Option("--language", $"The language to generate a query for.") { IsRequired = true} + .FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var queryPackOption = new Option("--pack", "The name of the query pack to place this query in.") { IsRequired = true }; + var queryPackScopeOption = new Option("--scope", "The scope to use") { IsRequired = true }; + + newQueryCommand.Add(createQueryPackOption); + newQueryCommand.Add(createTestsOption); + newQueryCommand.Add(queryNameOption); + newQueryCommand.Add(queryLanguageOption); + newQueryCommand.Add(queryPackOption); + newQueryCommand.Add(overwriteExistingOption); + newQueryCommand.Add(queryPackScopeOption); + + scaffoldCommand.Add(newQueryCommand); + + { + newQueryCommand.SetHandler((createQueryPack, createTests, queryName, queryLangauge, queryPack, basePath, overwriteExisting, queryPackScope) => + { + + if (!IsSupportedLangauge(queryLangauge)) + { + DieWithError($"Unsupported langauge `{queryLangauge}`"); + } + + new NewQueryScaffoldTarget() + { + Name = queryName, + Language = LanguageTypeHelper.LanguageTypeFromOptionString(queryLangauge), + Base = basePath, + QueryPack = queryPack, + QueryPackScope = queryPackScope, + CreateTests = createTests, + CreateQueryPack = createQueryPack, + OverwriteExisting = overwriteExisting, + FeatureName = FeatureName + }.Run(); + + }, createQueryPackOption, createTestsOption, queryNameOption, queryLanguageOption, queryPackOption, Globals.BasePathOption, overwriteExistingOption, queryPackScopeOption); + } + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs new file mode 100644 index 0000000..36f8fa3 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs @@ -0,0 +1,76 @@ +using CodeQLToolkit.Shared.Template; +using CodeQLToolkit.Shared.Utils; +using System.Reflection; + +namespace CodeQLToolkit.Features.Query.Scaffolding.Targets +{ + public class NewQueryScaffoldTarget : ScaffoldTarget + { + public string QueryPack { get; set; } + public bool CreateTests { get; set; } + public bool CreateQueryPack { get; set; } + public string QueryPackScope { get; set; } + + public override void Run() + { + Log.G().LogInformation("Creating new query..."); + + var query = new Shared.Utils.Query() + { + Language = Language, + QueryPackName = QueryPack, + Name = Name, + Scope = QueryPackScope, + Base = Base + }; + + Directory.CreateDirectory(query.QueryFileDir); + + WriteTemplateIfOverwriteOrNotExists("new-query", query.QueryFilePath, "new query", new + { + language = query.Language, + queryPackName = query.QueryPackName, + queryName = query.Name, + description = "Replace this text with a description of your query.", + qlLanguageImport = query.GetLanguageImportForLangauge() + }); + + if (CreateQueryPack) + { + WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new + { + queryPackScope = query.Scope, + queryPackName = query.QueryPackName + }); + } + + if (CreateTests) + { + Directory.CreateDirectory(query.QueryFileTestDir); + + // the source file to use + WriteTemplateIfOverwriteOrNotExists("test", query.QueryFileTestPath, "new query test file", new {}); + + // the expected file + WriteTemplateIfOverwriteOrNotExists("expected", query.QueryTestExpectedFile, "new query test expected file", new { }); + + // the the qlref file + WriteTemplateIfOverwriteOrNotExists("testref", query.QueryFileQLRefPath, "new query test ref", new { + queryName = query.Name + }); + + // the qlpack file + WriteTemplateIfOverwriteOrNotExists("qlpack-test", query.QueryPackTestPath, "new query test pack", new { + queryPackDependency = $"{query.Scope}/{query.QueryPackName}", + queryPackScope = query.Scope, + queryPackName = query.QueryTestPackName + }); + + } + else + { + Log.G().LogInformation($"Not creating tests because test creation was disabled."); + } + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid new file mode 100644 index 0000000..26362dc --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid @@ -0,0 +1,3 @@ +provide: + - '**/qlpack.yml' + - '**/codeql-workspace.yml' \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid new file mode 100644 index 0000000..7962166 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid @@ -0,0 +1 @@ +// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid new file mode 100644 index 0000000..f5c42c4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid @@ -0,0 +1,14 @@ +/** + * @id {{language}}/{{query_pack_name}}/{{query_name}} + * @name {{query_name}} + * @description {{description}} + * @kind problem + * @precision medium + * @problem.severity error + * @tags {{query_pack_name}} + */ + + import {{ql_language_import}} + + from Expr e + select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid new file mode 100644 index 0000000..c3a1a45 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid @@ -0,0 +1,7 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +dependencies: + codeql/cpp-all: 0.3.5 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid new file mode 100644 index 0000000..560a515 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid @@ -0,0 +1,8 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +extractor: cpp +dependencies: + {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid new file mode 100644 index 0000000..f39be51 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid @@ -0,0 +1 @@ +// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid new file mode 100644 index 0000000..d083780 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid @@ -0,0 +1 @@ +{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid new file mode 100644 index 0000000..7962166 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid @@ -0,0 +1 @@ +// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid new file mode 100644 index 0000000..f5c42c4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid @@ -0,0 +1,14 @@ +/** + * @id {{language}}/{{query_pack_name}}/{{query_name}} + * @name {{query_name}} + * @description {{description}} + * @kind problem + * @precision medium + * @problem.severity error + * @tags {{query_pack_name}} + */ + + import {{ql_language_import}} + + from Expr e + select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid new file mode 100644 index 0000000..8120bfc --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid @@ -0,0 +1,7 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +dependencies: + codeql/javascript-all: "^0.6.3" \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid new file mode 100644 index 0000000..515d065 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid @@ -0,0 +1,8 @@ +name: {{query_pack_scope}}/{{query_pack_name}} +version: 0.0.0 +description: Default description +suites: +license: +extractor: javascript +dependencies: + {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid new file mode 100644 index 0000000..f39be51 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid @@ -0,0 +1 @@ +// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid new file mode 100644 index 0000000..d083780 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid @@ -0,0 +1 @@ +{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs new file mode 100644 index 0000000..9b596cb --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs @@ -0,0 +1,20 @@ +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public abstract class BaseExecuteUnitTestsCommandTarget : CommandTarget + { + public int NumThreads { get; set; } + public string WorkDirectory { get; set; } + public string RunnerOS { get; set; } + public string CLIVersion { get; set; } + public string STDLibIdent { get; set; } + public string ExtraCodeQLArgs { get; set; } + } +} + diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs new file mode 100644 index 0000000..36d79f6 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public abstract class BaseGetMatrixCommandTarget : CommandTarget + { + public string[] OSVersions { get; set; } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs new file mode 100644 index 0000000..230e217 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs @@ -0,0 +1,112 @@ +using CodeQLToolkit.Features.Test.Lifecycle.Models; +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions +{ + + [AutomationType(AutomationType.ACTIONS)] + public class ExecuteUnitTestsCommandTarget : BaseExecuteUnitTestsCommandTarget + { + + public override void Run() + { + Log.G().LogInformation($"Preparing to execute unit tests found in {Base} for Language {Language}..."); + + // get a directory to work in + var tmpDirectory = WorkDirectory; + + var languageRoot = Path.Combine(Base, Language); + + // check if the language root exists + if (!Directory.Exists(languageRoot)){ + DieWithError($"Language root {languageRoot} does not exist so unit tests cannnot be run."); + } + + // Identify the test directories. + string[] dirs = Directory.GetDirectories(languageRoot, "test", SearchOption.AllDirectories); + + Log.G().LogInformation($"Test Directory Inventory {Language}"); + Log.G().LogInformation($"-----------------------------------"); + + foreach ( string dir in dirs) + { + Log.G().LogInformation($"Found test directory: {dir}"); + } + + var transformedDirs = dirs.Select(dir => Path.GetRelativePath(Base, dir)); + + if(dirs.Length == 0) + { + DieWithError($"No tests detected. Please create unit tests before running this command."); + } + + Parallel.For(0, NumThreads, + slice => { + + TestReport report = new TestReport() + { + RunnerOS = RunnerOS, + CLIVersion = CLIVersion, + STDLibIdent = STDLibIdent, + Language = Language, + Slice = slice, + NumSlices = NumThreads + }; + + var workingDirectory = Path.GetFullPath(Base); + var testPathString = string.Join(" ", transformedDirs); + var outFileReport = Path.Combine(tmpDirectory, report.FileName); + + Log.G().LogInformation($"Executing tests in working directory {workingDirectory}."); + Log.G().LogInformation($"Test Paths: {testPathString}"); + Log.G().LogInformation($"Slice: {slice} of {NumThreads}"); + Log.G().LogInformation($"Report File: {outFileReport}..."); + + using (Process process = new Process()) + { + process.StartInfo.FileName = "codeql"; + process.StartInfo.WorkingDirectory = workingDirectory; + process.StartInfo.UseShellExecute = false; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = false; + process.StartInfo.Arguments = $"test run {ExtraCodeQLArgs} --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}"; + + process.Start(); + + // needed for STDOUT redirection + var output = process.StandardOutput.ReadToEnd(); + + File.WriteAllText(outFileReport, output); + + process.WaitForExit(); + + if (process.ExitCode != 0) + { + // This fine + if(process.ExitCode == 122) + { + Log.G().LogError($"One more more unit tests failed. Please see the output of the validation step for more information about failed tests cases."); + } + // this is not fine + else + { + DieWithError($"Non-test related error while running unit tests. Please check debug output for more infomation."); + } + } + } + } + ); + + + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs new file mode 100644 index 0000000..666748d --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs @@ -0,0 +1,75 @@ +using CodeQLToolkit.Shared.Utils; +using System.Text.Json; + +namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions +{ + [AutomationType(AutomationType.ACTIONS)] + public class GetMatrixCommandTarget : BaseGetMatrixCommandTarget + { + public override void Run() + { + + // based on the current configuration of the repository, generate a matrix + // for actions, it looks like this: + + // { + // "include": [ + // { + // "codeql_cli": "2.12.6", + // "codeql_standard_library": "codeql-cli/v2.12.6", + // "codeql_cli_bundle": "codeql-bundle-20230403", + // "os": "ubuntu-latest", + // "codeql_standard_library_ident": "codeql-cli_v2.12.6" + // } + // ] + // } + + // For now, we only support a single version but this is easy to extend. The options for runners are what create different matrix types. + var c = new QLTConfig() + { + Base = Base + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + List configs = new List(); + + foreach(var os in OSVersions) + { + Log.G().LogInformation($"Creating matrix for {os}"); + + configs.Add(new + { + codeql_cli = config.CodeQLCLI, + codeql_standard_library = config.CodeQLStandardLibrary, + codeql_cli_bundle = config.CodeQLCLIBundle, + os = os, + codeql_standard_library_ident = config.CodeQLStandardLibraryIdent + }); + } + + var data = new + { + include = configs + }; + + var json = JsonSerializer.Serialize(data); + + var matrixVariable = $"matrix={json}"; + + string envFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT"); + + Log.G().LogInformation($"Writing matrix output {matrixVariable} to {envFile}"); + + File.AppendAllText(envFile, matrixVariable ); + + Log.G().LogInformation($"Done."); + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs new file mode 100644 index 0000000..2fc347b --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets +{ + + + public class UnitTestResult + { + public string test { get; set; } + public bool pass { get; set; } + public string failureStage { get; set; } + public string failureDescription { get; set; } + public object[] messages { get; set; } + public int compilationMs { get; set; } + public int evaluationMs { get; set; } + public string expected { get; set; } + public string actual { get; set; } + public string[] diff { get; set; } + } + + public class ValidateUnitTestsCommand : CommandTarget + { + public string ResultsDirectory { get; set; } + + public bool PrettyPrint { get; set; } + + public override void Run() + { + Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); + + string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); + + List unitTestResults = new List(); + + foreach (string result in results) + { + using (StreamReader r = new StreamReader(result)) + { + string json = r.ReadToEnd(); + List items = JsonConvert.DeserializeObject>(json); + + foreach(var item in items) + { + unitTestResults.Add(item); + } + } + } + + + int totalCases = unitTestResults.Count; + int currentCase = 0; + + foreach (var item in unitTestResults) + { + currentCase++; + + if (item.pass) + { + if(PrettyPrint) + { + Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : PASSED "); + Log.G().LogError($"+----------------------------------------------+"); + } + } + else + { + if (PrettyPrint) + { + Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + if (item.failureStage == "RESULT") + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : RESULT"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST DIFFERENCES |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + + + foreach (var diff in item.diff) + { + Log.G().LogError($"| {diff}"); + } + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FAILURE DESCRIPTION |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + Log.G().LogError($"| {item.failureDescription}"); + + + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + } + } + } + + var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); + + if (failedTests.Length > 0 && !PrettyPrint) + { + DieWithError("One or more failures during run unit tests."); + } + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs new file mode 100644 index 0000000..f9866ee --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs @@ -0,0 +1,160 @@ +using CodeQLToolkit.Features.Test.Commands.Targets; +using CodeQLToolkit.Features.Test.Lifecycle; +using CodeQLToolkit.Shared.Types; +using CodeQLToolkit.Shared.Utils; +using Microsoft.VisualBasic; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public class TestCommandFeature : FeatureBase, IToolkitLifecycleFeature + { + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; } + + public TestCommandFeature() + { + FeatureName = "Test"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining to running test-related commands."); + parentCommand.Add(runCommand); + + // a command that gets the matrix configuration + var getMatrixTestCommand = new Command("get-matrix", "Gets a CI/CD matrix based on the current configuration."); + + var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; + getMatrixTestCommand.Add(matrixOSVersion); + + // a command that runs the actual tests + var unitTestsCommand = new Command("execute-unit-tests", "Runs unit tests within a repository based on the current configuration."); + + var numThreadsOption = new Option("--num-threads", () => 4, "The number of threads to use for runner. For best performance, do not exceed the number of physical cores on your system.") { IsRequired = true }; + var workDirectoryOption = new Option("--work-dir", () => Path.GetTempPath(), "Where to place intermediate execution output files.") { IsRequired = true }; + var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var runnerOSOption = new Option("--runner-os", $"Label for the operating system running these tests.") { IsRequired = true }; + //var cliVersionOption = new Option("--cli-version", $"The version of the cli running the tests.") { IsRequired = true }; + //var stdLibIdentOption = new Option("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true }; + var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; + + unitTestsCommand.Add(numThreadsOption); + unitTestsCommand.Add(workDirectoryOption); + unitTestsCommand.Add(languageOption); + unitTestsCommand.Add(runnerOSOption); + //unitTestsCommand.Add(cliVersionOption); + //unitTestsCommand.Add(stdLibIdentOption); + unitTestsCommand.Add(extraCodeQLOptions); + + // a command validates the tests + var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems."); + + var resultsDirectoryOption = new Option("--results-directory", "Where to find the intermediate execution output files.") { IsRequired = true }; + var prettyPrintOption = new Option("--pretty-print", () => false, "Pretty print test output in a compact format. Note this will not exit with a failure code if tests fail.") { IsRequired = true }; + + validateUnitTestsCommand.Add(resultsDirectoryOption); + validateUnitTestsCommand.Add(prettyPrintOption); + + runCommand.Add(getMatrixTestCommand); + runCommand.Add(unitTestsCommand); + runCommand.Add(validateUnitTestsCommand); + + getMatrixTestCommand.SetHandler((basePath, automationType, osVersions) => { + + Log.G().LogInformation("Executing get-matrix command..."); + + // dispatch at runtime to the correct automation type + var featureTarget = AutomationFeatureFinder + .FindTargetForAutomationType( + AutomationTypeHelper.AutomationTypeFromString(automationType) + ); + + featureTarget.Base = basePath; + featureTarget.OSVersions = osVersions.Split(","); + + featureTarget.Run(); + + }, Globals.BasePathOption, Globals.AutomationTypeOption, matrixOSVersion); + + //stdLibIdent + unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, extraArgs) => { + + Log.G().LogInformation("Executing execute-unit-tests command..."); + + // dispatch at runtime to the correct automation type + var featureTarget = AutomationFeatureFinder + .FindTargetForAutomationType( + AutomationTypeHelper.AutomationTypeFromString(automationType) + ); + + // lookup cliVersion and stdLibIdent + var c = new QLTConfig() + { + Base = basePath + }; + + if (!File.Exists(c.CodeQLConfigFilePath)) + { + ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); + } + + var config = c.FromFile(); + + featureTarget.Base = basePath; + featureTarget.NumThreads = numThreads; + featureTarget.WorkDirectory = workDirectory; + featureTarget.Language = language; + featureTarget.RunnerOS = runnerOS; + featureTarget.CLIVersion = config.CodeQLCLI; + featureTarget.STDLibIdent = config.CodeQLStandardLibraryIdent; + featureTarget.ExtraCodeQLArgs = extraArgs; + + featureTarget.Run(); + + }, Globals.BasePathOption, + Globals.AutomationTypeOption, + numThreadsOption, + workDirectoryOption, + languageOption, + runnerOSOption, + extraCodeQLOptions + ); + + + validateUnitTestsCommand.SetHandler((resultsDirectory, prettyPrint) => + { + Log.G().LogInformation("Executing validate-unit-tests command..."); + + new ValidateUnitTestsCommand() + { + ResultsDirectory = resultsDirectory, + PrettyPrint = prettyPrint + }.Run(); + + + }, resultsDirectoryOption, prettyPrintOption); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs new file mode 100644 index 0000000..d3bdad8 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle +{ + abstract public class BaseLifecycleTarget : ILifecycleTarget + { + public int NumThreads { get; set; } + public string UseRunner { get; set; } + + public string ExtraArgs { get; set; } + + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs new file mode 100644 index 0000000..ffb2635 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle.Models +{ + public class TestReport + { + public string RunnerOS { get; set; } + public string CLIVersion { get; set; } + public string STDLibIdent { get; set; } + + public string Language { get; set; } + + public int Slice { get; set; } + public int NumSlices { get; set; } + + + public string FileName { + + get { + + var savePath = $"test_report_{RunnerOS}_{CLIVersion}_{STDLibIdent}_slice_{Slice}_of_{NumSlices}.json"; + + return savePath; + } + } + + + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs new file mode 100644 index 0000000..b505101 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions +{ + [AutomationType(AutomationType.ACTIONS)] + public class InitLifecycleTarget : BaseLifecycleTarget + { + public InitLifecycleTarget() + { + AutomationType = AutomationType.ACTIONS; + } + public override void Run() + { + Log.G().LogInformation("Running init command..."); + + // temporarily disable the language resolution + var tmpLanguage = Language; + Language = null; + + var codeqlArgs = "--threads=0"; + + if(ExtraArgs!= null && ExtraArgs.Length > 0) + { + codeqlArgs = $"{codeqlArgs} {ExtraArgs}"; + } + + WriteTemplateIfOverwriteOrNotExists("install-codeql", Path.Combine(Base, ".github", "actions", "install-codeql", "action.yml"), "install-codeql action"); + WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action"); + WriteTemplateIfOverwriteOrNotExists("run-unit-tests", Path.Combine(Base, ".github", "workflows", $"run-codeql-unit-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new + { + numThreads = NumThreads, + useRunner = UseRunner, + language = tmpLanguage, + codeqlArgs = codeqlArgs + }); + + Language = tmpLanguage; + + var message = @"------------------------------------------ +Your repository now has the CodeQL Unit Test Runner installed in `.github/workflows/`. Additionally, +QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt` and +`.github/actions/install-codeql`. + +Note that, by default, your runner will use 4 threads and defaults to the `ubuntu-latest` runner. + +You can modify the number of threads used by using the `--num-threads` argument and you can select a different +runner with the `--use-runner` argument. + +In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings. + +(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; + + + + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs new file mode 100644 index 0000000..ebdd333 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs @@ -0,0 +1,81 @@ +using CodeQLToolkit.Features.Test.Lifecycle.Targets; +using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions; +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; +using System.Reflection; + +namespace CodeQLToolkit.Features.Test.Lifecycle +{ + public class TestLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public TestLifecycleFeature() + { + FeatureName = "Test"; + } + + public override LanguageType[] SupportedLangauges + { + get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var initCommand = new Command("init", "Initialize testing in this repository."); + + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + var numThreadsOption = new Option("--num-threads", () => 4, "Number of threads to use during test execution."); + var useRunnerOption = new Option("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners."); + var languageOption = new Option("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; + + initCommand.AddOption(overwriteExistingOption); + initCommand.AddOption(numThreadsOption); + initCommand.AddOption(useRunnerOption); + initCommand.AddOption(languageOption); + initCommand.AddOption(extraCodeQLOptions); + + + parentCommand.Add(initCommand); + + + + initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language, extraArgs) => + { + Log.G().LogInformation("Executing init command..."); + + // + // dispatch at runtime to the correct automation type + // + var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType(AutomationTypeHelper.AutomationTypeFromString(automationType)); + + // setup common params + featureTarget.FeatureName = FeatureName; + featureTarget.Base = basePath; + featureTarget.OverwriteExisting = overwriteExisting; + featureTarget.NumThreads = numThreads; + featureTarget.UseRunner = useRunner; + featureTarget.Language = language; + featureTarget.ExtraArgs = extraArgs; + featureTarget.Run(); + + }, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption, extraCodeQLOptions); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid new file mode 100644 index 0000000..ddb56ba --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid @@ -0,0 +1,109 @@ +name: Fetch CodeQL CLI and queries +description: | + Fetches a CodeQL CLI and a copy of the CodeQL standard libraries at the specified versions. +inputs: + codeql-cli-version: + description: | + The version of the CodeQL CLI to be downloaded. + required: false + default: 'latest' + + codeql-stdlib-version: + description: | + The tag or commit to use from the CodeQL Standard Library + required: false + default: 'latest' + + add-to-path: + description: | + Add the CodeQL CLI to the system path + required: false + default: 'true' + + codeql-home: + description: | + The directory to store the CodeQL CLI and Standard Library. + A fixed location can be used for caching the tooling. + required: false +outputs: + codeql-home: + description: 'The directory containing the CodeQL CLI and CodeQL Standard Library' + value: ${{ steps.install-codeql.outputs.codeql-home }} + +runs: + using: composite + steps: + - name: Install CodeQL + id: install-codeql + env: + RUNNER_OS: ${{ runner.os }} + RUNNER_TEMP: ${{ runner.temp }} + CODEQL_CLI_VERSION: ${{ inputs.codeql-cli-version }} + CODEQL_STDLIB_VERSION: ${{ inputs.codeql-stdlib-version }} + GITHUB_TOKEN: ${{ github.token }} + ADD_TO_PATH: ${{ inputs.add-to-path }} + CODEQL_HOME: ${{ inputs.codeql-home }} + shell: bash + run: | + echo "::debug::Determining CodeQL release for $RUNNER_OS" + case $RUNNER_OS in + "Linux") + RELEASE_PATTERN="codeql-linux64.zip" + ;; + "macOS") + RELEASE_PATTERN="codeql-osx64.zip" + ;; + "Windows") + RELEASE_PATTERN="codeql-win64.zip" + ;; + *) + echo "::error::Unsupported runner operating system $RUNNER_OS" + exit 1 + ;; + esac + echo "::debug::Selected $RELEASE_PATTERN" + + if [ "$CODEQL_HOME" == "" ] + then + echo "::debug::Creating temporary CodeQL home" + CODEQL_HOME=$(mktemp -d -p $RUNNER_TEMP codeql-home-XXXXXXXXXX) + else + echo "::debug::Creating CodeQL home at $CODEQL_HOME" + mkdir -p $CODEQL_HOME + fi + + echo "::debug::Changing directory to $CODEQL_HOME" + pushd $CODEQL_HOME + + echo "::debug::Downloading CodeQL CLI version $CODEQL_CLI_VERSION" + if [ "$CODEQL_CLI_VERSION" == "latest" ] + then + gh release download --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN + else + gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN + fi + echo "::debug::Unpacking CodeQL CLI" + unzip -q $RELEASE_PATTERN + + echo "::debug::Cloning CodeQL standard library" + git clone https://github.com/github/codeql.git codeql-stdlib + + if [ "$CODEQL_STDLIB_VERSION" != "latest" ] + then + pushd codeql-stdlib + echo "::debug::Switching to revision $CODEQL_STDLIB_VERSION" + git checkout $CODEQL_STDLIB_VERSION + popd + fi + + if [ "$ADD_TO_PATH" == "true" ] + then + echo "::debug::Adding CodeQL CLI path '$(pwd)/codeql' to system path" + echo "$(pwd)/codeql" >> $GITHUB_PATH + fi + + echo "::debug::Setting output parameter codeql-home to $(pwd)" + echo "codeql-home=$(pwd)" >> $GITHUB_OUTPUT + + popd + echo "::debug::Done." diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid new file mode 100644 index 0000000..b1e7fa1 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid @@ -0,0 +1,88 @@ +name: Fetch and Install QLT +description: | + Fetches and installs QLT. +inputs: + qlt-version: + description: | + The version of QLT to be downloaded. + required: false + default: 'latest' + + add-to-path: + description: | + Add QLT to the system path + required: false + default: 'true' + + token: + description: | + Token to use for auth + required: true + + +outputs: + qlt-home: + description: 'The directory containing the QLT installation' + value: ${{ steps.install-qlt.outputs.qlt-home }} + +runs: + using: composite + steps: + - name: Install QLT + id: install-qlt + env: + RUNNER_OS: ${{ runner.os }} + RUNNER_TEMP: ${{ runner.temp }} + # GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ inputs.token }} + ADD_TO_PATH: ${{ inputs.add-to-path }} + QLT_VERSION: ${{ inputs.qlt-version }} + QLT_HOME: ${{ inputs.qlt-home }} + shell: bash + run: | + echo -e "\e[0;32m[QLT]\e[0m Determining QLT release for $RUNNER_OS" + case $RUNNER_OS in + "Linux") + RELEASE_PATTERN="qlt-linux-x86_64.zip" + ;; + *) + echo "::error::Unsupported runner operating system $RUNNER_OS" + exit 1 + ;; + esac + echo -e "\e[0;32m[QLT]\e[0m Selected $RELEASE_PATTERN" + + if [ "$QLT_HOME" == "" ] + then + echo -e "\e[0;32m[QLT]\e[0m Creating temporary QLT home" + QLT_HOME=$(mktemp -d -p $RUNNER_TEMP qlt-home-XXXXXXXXXX) + else + echo -e "\e[0;32m[QLT]\e[0m Creating CodeQL home at $QLT_HOME" + mkdir -p $QLT_HOME + fi + + echo -e "\e[0;32m[QLT]\e[0m Changing directory to $QLT_HOME" + pushd $QLT_HOME + + echo -e "\e[0;32m[QLT]\e[0m Downloading QLT version $QLT_VERSION" + if [ "$QLT_VERSION" == "latest" ] + then + # download the actual bundle + gh release download -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" + else + gh release download "$QLT_VERSION" -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" + fi + echo -e "\e[0;32m[QLT]\e[0m Unpacking QLT" + unzip $RELEASE_PATTERN + + if [ "$ADD_TO_PATH" == "true" ] + then + echo -e "\e[0;32m[QLT]\e[0m Adding QLT '$(pwd)/qlt' to system path" + echo "$(pwd)" >> $GITHUB_PATH + fi + + echo -e "\e[0;32m[QLT]\e[0m Setting output parameter qlt-home to $(pwd)" + echo "qlt-home=$(pwd)" >> $GITHUB_OUTPUT + + popd + echo -e "\e[0;32m[QLT]\e[0m Done." diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid new file mode 100644 index 0000000..7177427 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid @@ -0,0 +1,129 @@ +name: ⚙️ CodeQL - Run Unit Tests ({{language}}) +{% raw %} + +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + create-unit-test-matrix: + name: Create CodeQL Unit Test Matrix + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true +{% endraw %} + - name: Export unit test matrix + id: export-unit-test-matrix + run: | + qlt test run get-matrix --os-version {{ use_runner }} +{% raw %} + run-test-suites: + name: Run Unit Tests + needs: create-unit-test-matrix + + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.create-unit-test-matrix.outputs.matrix) }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true + + - name: Install CodeQL + id: install-codeql + uses: ./.github/actions/install-codeql + with: + codeql-cli-version: ${{ matrix.codeql_cli }} + codeql-stdlib-version: ${{ matrix.codeql_standard_library }} + add-to-path: true + + - name: Verify Versions of Tooling + shell: bash + run: | + echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}" + echo -e "Checking CodeQL Version:" + codeql --version + + echo -e "Checking QLT Version:" + echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}" + qlt version + + - name: Install QL Packs + shell: bash + run: | + qlt query run install-packs + + - name: Run test suites + id: run-test-suites + env: + RUNNER_OS: ${{ runner.os }} + CODEQL_CLI: ${{ matrix.codeql_cli }} + CODEQL_STDLIB: ${{ matrix.codeql_standard_library }} + CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}} + RUNNER_TMP: ${{ runner.temp }} + shell: bash + run: > +{% endraw %} + qlt test run execute-unit-tests + --codeql-args "{{ codeql_args }}" + --num-threads {{ num_threads }} + --language {{ language }} + --runner-os $RUNNER_OS + --work-dir $RUNNER_TMP +{% raw %} + - name: Upload test results + uses: actions/upload-artifact@v2 + with: + name: test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} + path: | + ${{ runner.temp }}/test_report_${{ runner.os }}_${{ matrix.codeql_cli }}_${{ matrix.codeql_standard_library_ident }}_slice_*.json + if-no-files-found: error + + validate-test-results: + name: Validate test results + needs: [run-test-suites] + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true + + - name: Collect test results + uses: actions/download-artifact@v2 + + - name: Validate test results + run: | + qlt test run validate-unit-tests --results-directory . + qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY + +{% endraw %} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs new file mode 100644 index 0000000..c2c3bf4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs @@ -0,0 +1,45 @@ +using CodeQLToolkit.Features.Test.Commands; +using CodeQLToolkit.Features.Test.Lifecycle; +using CodeQLToolkit.Shared.Feature; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Test +{ + public class TestFeatureMain : IToolkitFeature + + { + readonly TestLifecycleFeature lifecycleFeature; + readonly TestCommandFeature commandFeature; + readonly static TestFeatureMain instance; + + static TestFeatureMain() + { + instance = new TestFeatureMain(); + } + + private TestFeatureMain() + { + lifecycleFeature = new TestLifecycleFeature(); + commandFeature = new TestCommandFeature(); + } + public static TestFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var testCommand = new Command("test", "Features related to the running and processing of CodeQL Unit Tests."); + parentCommand.Add(testCommand); + + Log.G().LogInformation("Registering scaffolding submodule."); + lifecycleFeature.Register(testCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(testCommand); + + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs new file mode 100644 index 0000000..2fc347b --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs @@ -0,0 +1,138 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Test.Commands.Targets +{ + + + public class UnitTestResult + { + public string test { get; set; } + public bool pass { get; set; } + public string failureStage { get; set; } + public string failureDescription { get; set; } + public object[] messages { get; set; } + public int compilationMs { get; set; } + public int evaluationMs { get; set; } + public string expected { get; set; } + public string actual { get; set; } + public string[] diff { get; set; } + } + + public class ValidateUnitTestsCommand : CommandTarget + { + public string ResultsDirectory { get; set; } + + public bool PrettyPrint { get; set; } + + public override void Run() + { + Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); + + string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); + + List unitTestResults = new List(); + + foreach (string result in results) + { + using (StreamReader r = new StreamReader(result)) + { + string json = r.ReadToEnd(); + List items = JsonConvert.DeserializeObject>(json); + + foreach(var item in items) + { + unitTestResults.Add(item); + } + } + } + + + int totalCases = unitTestResults.Count; + int currentCase = 0; + + foreach (var item in unitTestResults) + { + currentCase++; + + if (item.pass) + { + if(PrettyPrint) + { + Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : PASSED "); + Log.G().LogError($"+----------------------------------------------+"); + } + } + else + { + if (PrettyPrint) + { + Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); + } + else + { + if (item.failureStage == "RESULT") + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : RESULT"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST DIFFERENCES |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + + + foreach (var diff in item.diff) + { + Log.G().LogError($"| {diff}"); + } + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + else + { + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| STATUS : FAILED "); + Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FAILURE DESCRIPTION |"); + Log.G().LogError($"+----------------------------------------------+"); + Log.G().LogError($"| FULL PATH : {item.test}"); + Log.G().LogError($"| {item.failureDescription}"); + + + Log.G().LogError($"+----------------------------------------------+"); + + Log.G().LogError($"\n\n\n\n"); + + } + } + } + } + + var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); + + if (failedTests.Length > 0 && !PrettyPrint) + { + DieWithError("One or more failures during run unit tests."); + } + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs new file mode 100644 index 0000000..2e8db6d --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs @@ -0,0 +1,60 @@ +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Test.Commands +{ + public class ValidationCommandFeature : FeatureBase, IToolkitLifecycleFeature + { + public override LanguageType[] SupportedLangauges { get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; } + + public ValidationCommandFeature() + { + FeatureName = "Validation"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining running validation commands."); + parentCommand.Add(runCommand); + + var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); + + var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; + getMatrixTestCommand.Add(matrixOSVersion); + + runCommand.Add(getMatrixTestCommand); + + + getMatrixTestCommand.SetHandler(() => + { + Log.G().LogInformation("Executing validate-unit-tests command..."); + + //new ValidateUnitTestsCommand() + //{ + // ResultsDirectory = resultsDirectory, + // PrettyPrint = prettyPrint + //}.Run(); + + + }); + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs new file mode 100644 index 0000000..30aad10 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Models +{ + public class CodeQLCliResponseModel + { + public string query { get; set; } + public string relativeName { get; set; } + public bool success { get; set; } + public Message[] messages { get; set; } + } + + public class Message + { + public string severity { get; set; } + public string message { get; set; } + public Position position { get; set; } + } + + public class Position + { + public string fileName { get; set; } + public int line { get; set; } + public int column { get; set; } + public int endLine { get; set; } + public int endColumn { get; set; } + } + +} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs new file mode 100644 index 0000000..1f8367f --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs @@ -0,0 +1,38 @@ +using CodeQLToolkit.Features.Test.Commands; +using System.CommandLine; + +namespace CodeQLToolkit.Features.Validation +{ + public class ValidationFeatureMain : IToolkitFeature + + { + readonly ValidationCommandFeature commandFeature; + readonly static ValidationFeatureMain instance; + + static ValidationFeatureMain() + { + instance = new ValidationFeatureMain(); + } + + private ValidationFeatureMain() + { + commandFeature = new ValidationCommandFeature(); + } + public static ValidationFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var validationCommand = new Command("validation", "Features related to the validation of CodeQL Development Repositories."); + parentCommand.Add(validationCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(validationCommand); + + } + + public int Run() + { + return 0; + } + } +} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj b/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj new file mode 100644 index 0000000..506c392 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs new file mode 100644 index 0000000..4ecfbf7 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs @@ -0,0 +1,36 @@ +using CodeQLToolkit.Shared.Template; +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + abstract public class FeatureBase + { + public string FeatureName { get; set; } + + public virtual LanguageType[] SupportedLangauges { get; } = { }; + public bool IsSupportedLangauge(string language) + { + var strLangauges = SupportedLangauges.Select(x => x.ToOptionString()).ToArray(); + return strLangauges.Contains(language); + } + + public bool IsSupportedLangauge(LanguageType language) + { + return SupportedLangauges.Contains(language); + } + public string GetSupportedLangaugeString() + { + return String.Join(", ", SupportedLangauges); + } + + public void DieWithError(string message) + { + ProcessUtils.DieWithError(message); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs new file mode 100644 index 0000000..460b6d8 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + public interface IToolkitCommandFeature : IToolkitFeature + { + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs new file mode 100644 index 0000000..f3133f2 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + public interface IToolkitDataFeature + { + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs new file mode 100644 index 0000000..16238be --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + public interface IToolkitFeature + { + public void Register(Command parentCommand); + public int Run(); + + public void DieWithError(string message) + { + Console.Error.WriteLine(message); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs new file mode 100644 index 0000000..3eb4893 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + public interface IToolkitLifecycleFeature : IToolkitFeature + { + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs new file mode 100644 index 0000000..de754f0 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Feature +{ + public interface IToolkitScaffoldingFeature : IToolkitFeature + { + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs b/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs new file mode 100644 index 0000000..9ea52e4 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace CodeQLToolkit.Shared.Logging +{ + public class Log + { + public static readonly Log instance; + private ILogger _logger { get; set; } + + static Log() + { + instance = new Log(); + } + private Log() + { + _logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger(); + } + + public static ILogger G() + { + return instance._logger; + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs b/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs new file mode 100644 index 0000000..ea6d620 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs @@ -0,0 +1,24 @@ +using CodeQLToolkit.Shared.Types; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CodeQLToolkit.Shared.Types; + +namespace CodeQLToolkit.Shared.Options +{ + public class Globals + { + public static string[] SupportedAutomationTypes { get => new string[] { "actions" }; } + + public static Option BasePathOption { get; } = new Option("--base", () => { + return Directory.GetCurrentDirectory(); + }, "The base path to find the query repository."); + + public static Option AutomationTypeOption { get; } = new Option("--automation-type", () => { + return "actions"; + }, "The base path to find the query repository.") { IsRequired = true }.FromAmong(SupportedAutomationTypes); + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs new file mode 100644 index 0000000..a1338df --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Target +{ + public abstract class CommandTarget : ITarget + { + public string Language { get; set; } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs new file mode 100644 index 0000000..6d187fe --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs @@ -0,0 +1,90 @@ +using CodeQLToolkit.Shared.Logging; +using CodeQLToolkit.Shared.Template; +using CodeQLToolkit.Shared.Types; +using Microsoft.Extensions.Logging; + + +namespace CodeQLToolkit.Shared.Target +{ + public abstract class ILifecycleTarget : ITarget + { + public string Name { get; set; } + public string Language { get; set; } + public bool OverwriteExisting { get; set; } + public string FeatureName { get; set; } + public AutomationType AutomationType { get; set; } = AutomationType.ANY; + + + public string GetTemplatePath(string templateName) + { + var languagePath = Language; + + List pathElements = new List(); + + pathElements.Add("Templates"); + pathElements.Add(FeatureName); + + + if (AutomationType != AutomationType.ANY) + { + pathElements.Add(AutomationType.ToDirectory()); + } + + if (languagePath != null) + { + if (languagePath == "c") + { + languagePath = "cpp"; + } + + pathElements.Add(languagePath); + } + + pathElements.Add(templateName + ".liquid"); + + return Path.Combine(pathElements.ToArray()); + } + + public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description) + { + WriteTemplateIfOverwriteOrNotExists(template, path, description, null); + } + + + public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description, object model) + { + if (!File.Exists(path) || OverwriteExisting) + { + + Directory.CreateDirectory(Path.GetDirectoryName(path)); + + Log.G().LogInformation($"Writing new {description} in {path}."); + + var templatePath = GetTemplatePath(template); + + + if (model == null) + { + var rendered = new TemplateUtil().RawTemplateFromFile(templatePath); + Log.G().LogInformation($"Loaded raw template {templatePath}"); + + File.WriteAllText(path, rendered); + } + else + { + var t = new TemplateUtil().TemplateFromFile(templatePath); + + Log.G().LogInformation($"Loaded template {templatePath}"); + + var rendered = t.Render(model); + File.WriteAllText(path, rendered); + } + + } + else + { + Log.G().LogInformation($"Refusing to overwrite existing {description} in {path}"); + } + } +} +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs new file mode 100644 index 0000000..54c0a23 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs @@ -0,0 +1,20 @@ +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Target +{ + public abstract class ITarget + { + public string Base { get; set; } + public abstract void Run(); + + public void DieWithError(string message) + { + ProcessUtils.DieWithError(message); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs new file mode 100644 index 0000000..402fcac --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs @@ -0,0 +1,51 @@ +using CodeQLToolkit.Shared.Logging; +using CodeQLToolkit.Shared.Template; +using CodeQLToolkit.Shared.Utils; +using Microsoft.Extensions.Logging; + +namespace CodeQLToolkit.Shared.Target +{ + public abstract class ScaffoldTarget : ITarget + { + + public string Name { get; set; } + public LanguageType Language { get; set; } + public bool OverwriteExisting { get; set; } + public string FeatureName { get; set; } + + + + public string GetTemplatePathForLanguage(string templateName) + { + var languagePath = Language; + + return Path.Combine("Templates", FeatureName, Language.ToDirectory(), templateName + ".liquid"); + } + + + + public string GetTemplatePath(string templateName) + { + return Path.Combine("Templates", FeatureName, "all", templateName + ".liquid"); + } + + public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description, object model) + { + if (!File.Exists(path) || OverwriteExisting) + { + Log.G().LogInformation($"Writing new {description} in {path}."); + + var t = new TemplateUtil().TemplateFromFile(GetTemplatePathForLanguage(template)); + + var rendered = t.Render(model); + + File.WriteAllText(path, rendered); + } + else + { + Log.G().LogInformation($"Refusing to overwrite existing {description} in {path}"); + } + } + + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs b/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs new file mode 100644 index 0000000..5bc1a58 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs @@ -0,0 +1,35 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Scriban; + +namespace CodeQLToolkit.Shared.Template +{ + public class TemplateUtil + { + public string TemplatePath { get; set; } = Utils.FileUtils.GetExecutingDirectory().FullName; + + public Scriban.Template TemplateFromFile(string templateFile) + { + var templateFilePath = Path.Combine(TemplatePath, templateFile); + + var data = File.ReadAllText(templateFilePath); + + var template = Scriban.Template.ParseLiquid(data); + + return template; + } + + public string RawTemplateFromFile(string templateFile) + { + var templateFilePath = Path.Combine(TemplatePath, templateFile); + + var data = File.ReadAllText(templateFilePath); + + return data; + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs new file mode 100644 index 0000000..a67d6c5 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs @@ -0,0 +1,46 @@ +using CodeQLToolkit.Shared.Feature; +using CodeQLToolkit.Shared.Target; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Types +{ + public class AutomationFeatureFinder + { + public static T FindTargetForAutomationType(AutomationType automationType) + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + foreach (var assembly in assemblies) + { + var types = assembly.GetTypes(); + + foreach (var type in types) + { + // restrict this to just things that are subtypes + // of targets + if (!type.IsSubclassOf(typeof(ITarget)) || !type.IsSubclassOf(typeof(T))) + { + continue; + } + + var attributes = type.GetCustomAttributes(typeof(AutomationTypeAttribute), true); + + // match the first thing with the automation type attribute + foreach (var attribute in attributes) + { + if (((AutomationTypeAttribute)attribute).AutomationType == automationType) + { + return (T)Activator.CreateInstance(type); + } + } + } + } + throw new NotImplementedException(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs new file mode 100644 index 0000000..ab4aeb0 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Types +{ + public enum AutomationType + { + ANY, + ACTIONS + } + + public static class AutomationTypeMethods + { + public static AutomationType FromString(this AutomationType automationType, string value) + { + if (value.ToLower().Equals("actions")) + { + return AutomationType.ACTIONS; + } + + throw new NotImplementedException(); + } + + public static string ToDirectory(this AutomationType automationType) + { + if(automationType == AutomationType.ANY) + { + return "Any"; + } + + if(automationType == AutomationType.ACTIONS) + { + return "Actions"; + } + + throw new NotImplementedException(); + } + + } + + + public class AutomationTypeHelper + { + public static AutomationType AutomationTypeFromString(string automationType) + { + return new AutomationType().FromString(automationType); + } + + public static string AutomationTypeToString(AutomationType automationType) + { + return automationType.ToDirectory(); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs new file mode 100644 index 0000000..a57592d --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Types +{ + + [AttributeUsage(AttributeTargets.Class | + AttributeTargets.Struct) + ] + public class AutomationTypeAttribute : Attribute + { + public AutomationType AutomationType { get; set; } + public AutomationTypeAttribute(AutomationType automationType) + { + AutomationType = automationType; + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs new file mode 100644 index 0000000..4f6d013 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Utils +{ + public class FileUtils + { + public static DirectoryInfo GetExecutingDirectory() + { + var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase); + return new FileInfo(location.AbsolutePath).Directory; + } + + public static string CreateTempDirectory() + { + return CreateTempDirectory(Path.GetTempPath()); + } + + public static string CreateTempDirectory(string baseDir) + { + string tempDirectory = Path.Combine(baseDir, Path.GetRandomFileName()); + Directory.CreateDirectory(tempDirectory); + return tempDirectory; + } + + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs new file mode 100644 index 0000000..ea17bd2 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs @@ -0,0 +1,239 @@ +using CodeQLToolkit.Shared.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Utils +{ + public enum LanguageType + { + C, + CPP, + JAVASCRIPT, + GO, + RUBY, + PYTHON, + JAVA, + CSHARP + } + + public static class LanguageTypeMethods + { + public static LanguageType FromOptionString(this LanguageType LanguageType, string value) + { + if (value.ToLower().Equals("c")) + { + return LanguageType.C; + } + + if (value.ToLower().Equals("cpp")) + { + return LanguageType.CPP; + } + + if (value.ToLower().Equals("javascript")) + { + return LanguageType.JAVASCRIPT; + } + + if (value.ToLower().Equals("go")) + { + return LanguageType.GO; + } + + if (value.ToLower().Equals("ruby")) + { + return LanguageType.RUBY; + } + + if (value.ToLower().Equals("java")) + { + return LanguageType.JAVA; + } + + if (value.ToLower().Equals("csharp")) + { + return LanguageType.CSHARP; + } + + throw new NotImplementedException(); + } + + + public static string ToOptionString(this LanguageType LanguageType) + { + if (LanguageType == LanguageType.C) + { + return "c"; + } + + if (LanguageType == LanguageType.CPP) + { + return "cpp"; + } + + if (LanguageType == LanguageType.JAVASCRIPT) + { + return "javascript"; + } + if (LanguageType == LanguageType.GO) + { + return "go"; + } + if (LanguageType == LanguageType.RUBY) + { + return "ruby"; + } + if (LanguageType == LanguageType.PYTHON) + { + return "python"; + } + if (LanguageType == LanguageType.JAVA) + { + return "java"; + } + if (LanguageType == LanguageType.CSHARP) + { + return "csharp"; + } + + throw new NotImplementedException(); + } + + + public static string ToDirectory(this LanguageType LanguageType) + { + if (LanguageType == LanguageType.C) + { + return "cpp"; + } + + if (LanguageType == LanguageType.CPP) + { + return "cpp"; + } + + if (LanguageType == LanguageType.JAVASCRIPT) + { + return "javascript"; + } + if (LanguageType == LanguageType.GO) + { + return "go"; + } + if (LanguageType == LanguageType.RUBY) + { + return "ruby"; + } + if (LanguageType == LanguageType.PYTHON) + { + return "python"; + } + if (LanguageType == LanguageType.JAVA) + { + return "java"; + } + if (LanguageType == LanguageType.CSHARP) + { + return "csharp"; + } + + throw new NotImplementedException(); + } + + public static string ToImport(this LanguageType LanguageType) + { + if (LanguageType == LanguageType.C) + { + return "cpp"; + } + + if (LanguageType == LanguageType.CPP) + { + return "cpp"; + } + + if (LanguageType == LanguageType.JAVASCRIPT) + { + return "javascript"; + } + if (LanguageType == LanguageType.GO) + { + return "go"; + } + if (LanguageType == LanguageType.RUBY) + { + return "ruby"; + } + if (LanguageType == LanguageType.PYTHON) + { + return "python"; + } + if (LanguageType == LanguageType.JAVA) + { + return "java"; + } + if (LanguageType == LanguageType.CSHARP) + { + return "csharp"; + } + + throw new NotImplementedException(); + } + + + public static string ToExtension(this LanguageType LanguageType) + { + if (LanguageType == LanguageType.C) + { + return "c"; + } + + if(LanguageType == LanguageType.CPP) + { + return "cpp"; + } + + if(LanguageType == LanguageType.JAVASCRIPT) + { + return "js"; + } + if(LanguageType == LanguageType.GO) + { + return "go"; + } + if(LanguageType == LanguageType.RUBY) + { + return "rb"; + } + if(LanguageType == LanguageType.PYTHON) + { + return "py"; + } + if(LanguageType == LanguageType.JAVA) + { + return "java"; + } + if (LanguageType == LanguageType.CSHARP) + { + return "cs"; + } + + + throw new NotImplementedException(); + } + + } + + + public class LanguageTypeHelper + { + public static LanguageType LanguageTypeFromOptionString(string LanguageType) + { + return new LanguageType().FromOptionString(LanguageType); + } + } + +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs new file mode 100644 index 0000000..bffa245 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Utils +{ + public class ProcessUtils + { + public static void DieWithError(string message) + { + Console.Error.WriteLine(message); + Environment.Exit(1); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs new file mode 100644 index 0000000..a209548 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Utils +{ + public class QLTConfig + { + public string CodeQLCLI { get; set; } + public string CodeQLStandardLibrary { get; set; } + public string CodeQLCLIBundle { get; set; } + + public string CodeQLStandardLibraryIdent { + get { + return CodeQLStandardLibrary.Replace("/", "_"); + } + } + + + [JsonIgnore] + public string Base { get; set; } + + [JsonIgnore] + public string CodeQLConfigFilePath + { + get + { + return Path.Combine(Base, "qlt.conf.json"); + } + } + + public QLTConfig FromFile() { + var data = File.ReadAllText(CodeQLConfigFilePath); + return JsonConvert.DeserializeObject(data); + } + + public void ToFile() + { + var data = JsonConvert.SerializeObject(this, Formatting.Indented); + File.WriteAllText(CodeQLConfigFilePath, data); + } + } +} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs new file mode 100644 index 0000000..9f035a3 --- /dev/null +++ b/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs @@ -0,0 +1,114 @@ + using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Shared.Utils +{ + public class Query + { + public string Base { get; set; } + public LanguageType Language { get; set; } + public string QueryPackName { get; set; } + public string Scope { get; set; } + public string Name { get; set; } + + public string QuerySrcDir + { + get + { + return Path.Combine(Base, Language.ToDirectory(), QueryPackName, "src"); + } + } + + public string QueryFileDir + { + get + { + return Path.Combine(QuerySrcDir, Name); + } + } + + public string QueryFilePath + { + get + { + return Path.Combine(QueryFileDir, $"{Name}.ql"); + } + } + + public string QueryPackPath + { + get + { + return Path.Combine(QuerySrcDir, "qlpack.yml"); + + } + } + + // + public string QueryTestDir + { + get + { + return Path.Combine(Base, Language.ToDirectory(), QueryPackName, "test"); + } + } + + public string QueryFileTestDir + { + get + { + return Path.Combine(QueryTestDir, Name); + } + } + + public string QueryFileTestPath + { + get + { + return Path.Combine(QueryFileTestDir, $"{Name}.{Language.ToExtension()}"); + } + } + + public string QueryFileQLRefPath + { + get + { + return Path.Combine(QueryFileTestDir, $"{Name}.qlref"); + } + } + + public string QueryPackTestPath + { + get + { + return Path.Combine(QueryTestDir, "qlpack.yml"); + + } + } + + public string QueryTestExpectedFile + { + get + { + return Path.Combine(QueryFileTestDir, $"{Name}.expected"); + + } + } + + public string QueryTestPackName + { + get + { + return $"{QueryPackName}-tests"; + } + } + + public string GetLanguageImportForLangauge() + { + return Language.ToImport(); + } + } +} From 875bcd2c61027c5a3cd3b21fdb91d9b86f244516 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 28 Nov 2023 15:01:26 -0500 Subject: [PATCH 3/5] big refactor --- .../CodeQLToolkit.Features.CodeQL.csproj | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj diff --git a/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj b/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj deleted file mode 100644 index d9467d1..0000000 --- a/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - - - From 1aabe16d8381c113139803b0d631068389110714 Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Tue, 28 Nov 2023 15:01:40 -0500 Subject: [PATCH 4/5] removed backup --- .../CodeQLToolkit.Core.csproj | 39 --- src_backup/src/CodeQLToolkit.Core/Main.cs | 57 ----- src_backup/src/CodeQLToolkit.Core/NLog.config | 14 - .../Properties/launchSettings.json | 8 - src_backup/src/CodeQLToolkit.Core/ver.txt | 1 - .../CodeQLLifecycleFeature.cs | 76 ------ ...QLToolkit.Features.CodeQL.Lifecycle.csproj | 19 -- .../Common.cs | 6 - .../Targets/GetVersionLifecycleTarget.cs | 40 --- .../Targets/SetVersionLifecycleTarget.cs | 35 --- .../CodeQLFeatureMain.cs | 42 --- .../CodeQLToolkit.Features.CodeQL.csproj | 21 -- .../CodeQLToolkit.Features.Pack.csproj | 18 -- .../Commands/PackCommandFeature.cs | 63 ----- .../Targets/HelloJeongsooCommandTarget.cs | 45 ---- .../src/CodeQLToolkit.Features.Pack/Common.cs | 7 - .../PackFeatureMain.cs | 42 --- .../CodeQLToolkit.Features.Query.csproj | 76 ------ .../Commands/QueryCommandFeature.cs | 42 --- .../Targets/InstallQueryPacksCommandTarget.cs | 47 ---- .../CodeQLToolkit.Features.Query/Common.cs | 3 - .../Lifecycle/QueryLifecycleFeature.cs | 56 ---- .../Lifecycle/Targets/InitLifecycleTarget.cs | 25 -- .../QueryFeatureMain.cs | 52 ---- .../Scaffolding/QueryScaffoldFeature.cs | 77 ------ .../Targets/NewQueryScaffoldTarget.cs | 76 ------ .../Templates/Query/codeql-workspace.liquid | 3 - .../Templates/Query/cpp/expected.liquid | 1 - .../Query/cpp/new-dataflow-query.liquid | 1 - .../Templates/Query/cpp/new-query.liquid | 14 - .../Templates/Query/cpp/qlpack-query.liquid | 7 - .../Templates/Query/cpp/qlpack-test.liquid | 8 - .../Templates/Query/cpp/test.liquid | 1 - .../Templates/Query/cpp/testref.liquid | 1 - .../Query/javascript/expected.liquid | 1 - .../javascript/new-dataflow-query.liquid | 1 - .../Query/javascript/new-query.liquid | 14 - .../Query/javascript/qlpack-query.liquid | 7 - .../Query/javascript/qlpack-test.liquid | 8 - .../Templates/Query/javascript/test.liquid | 1 - .../Templates/Query/javascript/testref.liquid | 1 - .../CodeQLToolkit.Features.Test.csproj | 29 --- .../BaseExecuteUnitTestsCommandTarget.cs | 20 -- .../Commands/BaseGetMatrixCommandTarget.cs | 13 - .../Actions/ExecuteUnitTestsCommandTarget.cs | 112 -------- .../Targets/Actions/GetMatrixCommandTarget.cs | 75 ------ .../Targets/ValidateUnitTestsCommand.cs | 138 ---------- .../Commands/TestCommandFeature.cs | 160 ------------ .../src/CodeQLToolkit.Features.Test/Common.cs | 7 - .../Lifecycle/BaseLifecycleTarget.cs | 17 -- .../Lifecycle/Models/TestReport.cs | 33 --- .../Targets/Actions/InitLifecycleTarget.cs | 61 ----- .../Lifecycle/TestLifecycleFeature.cs | 81 ------ .../Test/Actions/install-codeql.liquid | 109 -------- .../Templates/Test/Actions/install-qlt.liquid | 88 ------- .../Test/Actions/run-unit-tests.liquid | 129 ---------- .../TestFeatureMain.cs | 45 ---- .../CodeQLToolkit.Features.Validation.csproj | 13 - .../Targets/ValidateUnitTestsCommand.cs | 138 ---------- .../Commands/ValidationCommandFeature.cs | 60 ----- .../Common.cs | 7 - .../Models/CodeQLCliResponseModel.cs | 33 --- .../ValidationFeatureMain.cs | 38 --- .../CodeQL/CodeQLFeatureMain.cs | 42 --- .../Lifecycle/CodeQLLifecycleFeature.cs | 76 ------ .../Targets/GetVersionLifecycleTarget.cs | 40 --- .../Targets/SetVersionLifecycleTarget.cs | 35 --- .../CodeQLToolkit.Features.csproj | 21 -- .../src/CodeQLToolkit.Features/Common.cs | 7 - .../Pack/Commands/PackCommandFeature.cs | 63 ----- .../Targets/HelloJeongsooCommandTarget.cs | 45 ---- .../Pack/PackFeatureMain.cs | 42 --- .../Query/Commands/QueryCommandFeature.cs | 42 --- .../Targets/InstallQueryPacksCommandTarget.cs | 47 ---- .../Query/Lifecycle/QueryLifecycleFeature.cs | 56 ---- .../Lifecycle/Targets/InitLifecycleTarget.cs | 25 -- .../Query/QueryFeatureMain.cs | 52 ---- .../Query/Scaffolding/QueryScaffoldFeature.cs | 77 ------ .../Targets/NewQueryScaffoldTarget.cs | 76 ------ .../Templates/Query/codeql-workspace.liquid | 3 - .../Query/Templates/Query/cpp/expected.liquid | 1 - .../Query/cpp/new-dataflow-query.liquid | 1 - .../Templates/Query/cpp/new-query.liquid | 14 - .../Templates/Query/cpp/qlpack-query.liquid | 7 - .../Templates/Query/cpp/qlpack-test.liquid | 8 - .../Query/Templates/Query/cpp/test.liquid | 1 - .../Query/Templates/Query/cpp/testref.liquid | 1 - .../Query/javascript/expected.liquid | 1 - .../javascript/new-dataflow-query.liquid | 1 - .../Query/javascript/new-query.liquid | 14 - .../Query/javascript/qlpack-query.liquid | 7 - .../Query/javascript/qlpack-test.liquid | 8 - .../Templates/Query/javascript/test.liquid | 1 - .../Templates/Query/javascript/testref.liquid | 1 - .../BaseExecuteUnitTestsCommandTarget.cs | 20 -- .../Commands/BaseGetMatrixCommandTarget.cs | 13 - .../Actions/ExecuteUnitTestsCommandTarget.cs | 112 -------- .../Targets/Actions/GetMatrixCommandTarget.cs | 75 ------ .../Targets/ValidateUnitTestsCommand.cs | 138 ---------- .../Test/Commands/TestCommandFeature.cs | 160 ------------ .../Test/Lifecycle/BaseLifecycleTarget.cs | 17 -- .../Test/Lifecycle/Models/TestReport.cs | 33 --- .../Targets/Actions/InitLifecycleTarget.cs | 61 ----- .../Test/Lifecycle/TestLifecycleFeature.cs | 81 ------ .../Test/Actions/install-codeql.liquid | 109 -------- .../Templates/Test/Actions/install-qlt.liquid | 88 ------- .../Test/Actions/run-unit-tests.liquid | 129 ---------- .../Test/TestFeatureMain.cs | 45 ---- .../Targets/ValidateUnitTestsCommand.cs | 138 ---------- .../Commands/ValidationCommandFeature.cs | 60 ----- .../Models/CodeQLCliResponseModel.cs | 33 --- .../Validation/ValidationFeatureMain.cs | 38 --- .../CodeQLToolkit.Shared.csproj | 17 -- .../Feature/FeatureBase.cs | 36 --- .../Feature/IToolkitCommandFeature.cs | 12 - .../Feature/IToolkitDataFeature.cs | 12 - .../Feature/IToolkitFeature.cs | 20 -- .../Feature/IToolkitLifecycleFeature.cs | 12 - .../Feature/IToolkitScaffoldingFeature.cs | 12 - .../src/CodeQLToolkit.Shared/Logging/Log.cs | 30 --- .../CodeQLToolkit.Shared/Options/Globals.cs | 24 -- .../Target/CommandTarget.cs | 13 - .../Target/ILifecycleTarget.cs | 90 ------- .../CodeQLToolkit.Shared/Target/ITarget.cs | 20 -- .../Target/ScaffoldTarget.cs | 51 ---- .../Template/TemplateUtil.cs | 35 --- .../Types/AutomationFeatureFinder.cs | 46 ---- .../Types/AutomationType.cs | 57 ----- .../Types/AutomationTypeAttribute.cs | 21 -- .../CodeQLToolkit.Shared/Utils/FileUtils.cs | 31 --- .../CodeQLToolkit.Shared/Utils/Language.cs | 239 ------------------ .../Utils/ProcessUtils.cs | 17 -- .../CodeQLToolkit.Shared/Utils/QLTConfig.cs | 46 ---- .../src/CodeQLToolkit.Shared/Utils/Query.cs | 114 --------- 134 files changed, 5582 deletions(-) delete mode 100644 src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Core/Main.cs delete mode 100644 src_backup/src/CodeQLToolkit.Core/NLog.config delete mode 100644 src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json delete mode 100644 src_backup/src/CodeQLToolkit.Core/ver.txt delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Features/Common.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid delete mode 100644 src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs delete mode 100644 src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs delete mode 100644 src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs diff --git a/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj b/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj deleted file mode 100644 index 8f0422a..0000000 --- a/src_backup/src/CodeQLToolkit.Core/CodeQLToolkit.Core.csproj +++ /dev/null @@ -1,39 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - Always - - - - - - - - - - - - - - - - - - - Always - - - - diff --git a/src_backup/src/CodeQLToolkit.Core/Main.cs b/src_backup/src/CodeQLToolkit.Core/Main.cs deleted file mode 100644 index d847037..0000000 --- a/src_backup/src/CodeQLToolkit.Core/Main.cs +++ /dev/null @@ -1,57 +0,0 @@ - -using CodeQLDevelopmentLifecycleToolkit.Features.Query; -using System.CommandLine; -using CodeQLToolkit.Shared.Logging; -using Microsoft.Extensions.Logging; -using System.IO; -using CodeQLToolkit.Shared.Options; -using CodeQLToolkit.Shared.Utils; -using CodeQLToolkit.Features.CodeQL; -using CodeQLToolkit.Features.Test; -using CodeQLToolkit.Features.Pack; -using CodeQLToolkit.Features.Validation; - -namespace CodeQLDevelopmentLifecycleToolkit.Core -{ - - internal class QLT - { - public static async Task Main(string[] args) - { - Log.G().LogInformation("QLT Startup..."); - - Console.OutputEncoding = System.Text.Encoding.UTF8; - - var rootCommand = new RootCommand(); - - // Add global option for the root directory - rootCommand.AddGlobalOption(Globals.BasePathOption); - rootCommand.AddGlobalOption(Globals.AutomationTypeOption); - - var versionCommand = new Command("version", "Get the current tool version."); - rootCommand.Add(versionCommand); - - versionCommand.SetHandler(() => - { - var version = File.ReadAllText(Path.Combine(FileUtils.GetExecutingDirectory().FullName, "ver.txt")); - - Console.Write($"QLT Version: {version}"); - }); - - // Register the `Query` feature - QueryFeatureMain.Instance.Register(rootCommand); - // Register the `CodeQL` feature - CodeQLFeatureMain.Instance.Register(rootCommand); - // Register the `Test` feature - TestFeatureMain.Instance.Register(rootCommand); - // Register the `Pack` feature - PackFeatureMain.Instance.Register(rootCommand); - // Register the `Validation` feature - ValidationFeatureMain.Instance.Register(rootCommand); - - await rootCommand.InvokeAsync(args); - - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/NLog.config b/src_backup/src/CodeQLToolkit.Core/NLog.config deleted file mode 100644 index 6976e51..0000000 --- a/src_backup/src/CodeQLToolkit.Core/NLog.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json b/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json deleted file mode 100644 index 9b17472..0000000 --- a/src_backup/src/CodeQLToolkit.Core/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "CodeQLToolkit.Core": { - "commandName": "Project", - "commandLineArgs": " --base C:\\QLPACKTEST test init" - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Core/ver.txt b/src_backup/src/CodeQLToolkit.Core/ver.txt deleted file mode 100644 index 927734f..0000000 --- a/src_backup/src/CodeQLToolkit.Core/ver.txt +++ /dev/null @@ -1 +0,0 @@ -0.0.17 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs deleted file mode 100644 index 73e388f..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLLifecycleFeature.cs +++ /dev/null @@ -1,76 +0,0 @@ -using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets; -using System.CommandLine; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle -{ - public class CodeQLLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public CodeQLLifecycleFeature() - { - FeatureName = "CodeQL"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var setCommand = new Command("set", "Functions pertaining to setting variables related to CodeQL."); - parentCommand.Add(setCommand); - - var setVersionCommand = new Command("version", "Sets the version of CodeQL used."); - - var cliVersionOption = new Option("--cli-version", () => "2.11.6", "The version of the cli to use. Example: `2.11.6`.") { IsRequired = true }; - var standardLibraryVersionOption = new Option("--standard-library-version", () => "codeql-cli/v2.11.6", "The version of the standard library to use. Example: `codeql-cli/v2.11.6`.") { IsRequired = true }; - var bundleVersionOption = new Option("--bundle-version", () => "codeql-bundle-20221211", "The bundle version to use. Example: `codeql-bundle-20221211`.") { IsRequired = true }; - - setVersionCommand.Add(cliVersionOption); - setVersionCommand.Add(standardLibraryVersionOption); - setVersionCommand.Add(bundleVersionOption); - - setCommand.Add(setVersionCommand); - - var getCommand = new Command("get", "Functions pertaining to getting variables related to CodeQL."); - parentCommand.Add(getCommand); - - var getVersionCommand = new Command("version", "Gets the version of CodeQL used."); - getCommand.Add(getVersionCommand); - - { - setVersionCommand.SetHandler((cliVersion, standardLibraryVersion, bundleVersion, basePath) => - { - Log.G().LogInformation("Executing set command..."); - - new SetVersionLifecycleTarget() - { - CodeQLCLI = cliVersion, - CodeQLStandardLibrary = standardLibraryVersion, - CodeQLCLIBundle = bundleVersion, - Base = basePath - }.Run(); - - }, cliVersionOption, standardLibraryVersionOption, bundleVersionOption, Globals.BasePathOption); - } - - - { - getVersionCommand.SetHandler((basePath) => - { - Log.G().LogInformation("Executing get command..."); - - new GetVersionLifecycleTarget() - { - Base = basePath - }.Run(); - - }, Globals.BasePathOption); - } - - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj deleted file mode 100644 index 3ad166c..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/CodeQLToolkit.Features.CodeQL.Lifecycle.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs deleted file mode 100644 index 1211c0b..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Common.cs +++ /dev/null @@ -1,6 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; -global using CodeQLToolkit.Shared.Feature; -global using CodeQLToolkit.Shared.Options; - diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs deleted file mode 100644 index 2bd4823..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/GetVersionLifecycleTarget.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets -{ - public class GetVersionLifecycleTarget : ILifecycleTarget - { - - override public void Run() - { - Log.G().LogInformation("Running get command..."); - - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - // This should be updated so that we can pretty print all the various options: - Console.WriteLine($"---------current settings---------"); - Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); - Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); - Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); - Console.WriteLine($"----------------------------------"); - Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); - - - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs deleted file mode 100644 index 9025b71..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL.Lifecycle/Targets/SetVersionLifecycleTarget.cs +++ /dev/null @@ -1,35 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets -{ - public class SetVersionLifecycleTarget : ILifecycleTarget - { - public string CodeQLCLI { get; set; } - public string CodeQLStandardLibrary { get; set; } - public string CodeQLCLIBundle { get; set; } - - override public void Run() - { - Log.G().LogInformation("Running set command..."); - - var c = new QLTConfig() - { - CodeQLCLI = CodeQLCLI, - CodeQLStandardLibrary = CodeQLStandardLibrary, - CodeQLCLIBundle = CodeQLCLIBundle, - Base = Base - }; - - c.ToFile(); - - Log.G().LogInformation("Wrote to file..."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs deleted file mode 100644 index c0357b8..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLFeatureMain.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Shared.Feature; -using System.CommandLine; -using CodeQLToolkit.Shared.Logging; -using Microsoft.Extensions.Logging; -using CodeQLToolkit.Features.CodeQL.Lifecycle; - -namespace CodeQLToolkit.Features.CodeQL -{ - public class CodeQLFeatureMain : IToolkitFeature - { - readonly CodeQLLifecycleFeature lifecycleFeature; - readonly static CodeQLFeatureMain instance; - - static CodeQLFeatureMain() - { - instance = new CodeQLFeatureMain(); - } - - private CodeQLFeatureMain() - { - lifecycleFeature = new CodeQLLifecycleFeature(); - } - - public static CodeQLFeatureMain Instance { get { return instance; } } - - public int Run() - { - - return 0; - } - - public void Register(Command parentCommand) - { - var queryCommand = new Command("codeql", "Use the features related to managing the version of CodeQL used by this repository."); - parentCommand.Add(queryCommand); - Log.G().LogInformation("Registering scaffolding submodule."); - lifecycleFeature.Register(queryCommand); - } - - - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj b/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj deleted file mode 100644 index d9467d1..0000000 --- a/src_backup/src/CodeQLToolkit.Features.CodeQL/CodeQLToolkit.Features.CodeQL.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj b/src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj deleted file mode 100644 index 0fdbb7f..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Pack/CodeQLToolkit.Features.Pack.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs deleted file mode 100644 index d01968b..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/PackCommandFeature.cs +++ /dev/null @@ -1,63 +0,0 @@ -using CodeQLToolkit.Features.Pack.Commands.Targets; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack.Commands -{ - public class PackCommandFeature : FeatureBase, IToolkitCommandFeature - { - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - var runCommand = new Command("run", "Functions pertaining to running pack-related commands."); - parentCommand.Add(runCommand); - - // a command that installs query packs - var sayHello = new Command("hello-jeongsoo", "Says hello!"); - var howManyTimesHello = new Option("--times", "how many times to say it") { IsRequired = true }; - sayHello.Add(howManyTimesHello); - - var sayGoodbye = new Command("goodbye-jeongsoo", "Says goodbye!"); - - var howManyTimes = new Option("--times", "how many times to say it") { IsRequired = true }; - sayGoodbye.Add(howManyTimes); - - - runCommand.Add(sayHello); - runCommand.Add(sayGoodbye); - - sayHello.SetHandler((basePath, times) => { - - new HelloJeongsooCommandTarget() { - Base = basePath, - Times = times - - }.Run(); - - }, Globals.BasePathOption, howManyTimesHello); - - sayGoodbye.SetHandler((basePath, times) => { - - Console.WriteLine($"Saying goodbye {times} number of times"); - - for (int i = 0; i < times; i++) - { - Console.WriteLine("Goodbye!"); - } - - - }, Globals.BasePathOption, howManyTimes); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs deleted file mode 100644 index 33b4420..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Pack/Commands/Targets/HelloJeongsooCommandTarget.cs +++ /dev/null @@ -1,45 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack.Commands.Targets -{ - public class HelloJeongsooCommandTarget : CommandTarget - { - - public int Times { get; set; } - - - public override void Run() - { - for(int i = 0; i < Times; i++) { - Console.WriteLine($"Hello! My Base Target is: {Base}"); - } - - - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - - Console.WriteLine($"---------current settings---------"); - Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); - Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); - Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); - Console.WriteLine($"----------------------------------"); - Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/Common.cs b/src_backup/src/CodeQLToolkit.Features.Pack/Common.cs deleted file mode 100644 index 279d9e9..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Pack/Common.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; -global using CodeQLToolkit.Shared.Feature; -global using CodeQLToolkit.Shared.Options; -global using CodeQLToolkit.Shared.Types; - diff --git a/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs deleted file mode 100644 index 9fa81ea..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Pack/PackFeatureMain.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Features.Pack.Commands; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack -{ - public class PackFeatureMain : IToolkitFeature - { - - readonly static PackFeatureMain instance; - readonly PackCommandFeature commandFeature; - - static PackFeatureMain() - { - instance = new PackFeatureMain(); - } - - private PackFeatureMain() - { - commandFeature = new PackCommandFeature(); - } - public static PackFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var packCommand = new Command("pack", "Features CodeQL pack management and publication."); - parentCommand.Add(packCommand); - - Log.G().LogInformation("Registering scaffolding submodule."); - commandFeature.Register(packCommand); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj b/src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj deleted file mode 100644 index 166d68e..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/CodeQLToolkit.Features.Query.csproj +++ /dev/null @@ -1,76 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - Always - - - Always - - - - - - - - - - - - - - - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - Always - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs deleted file mode 100644 index d5bb08c..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Commands/QueryCommandFeature.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Features.Query.Commands.Targets; -using CodeQLToolkit.Features.Query.Scaffolding; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Commands -{ - public class QueryCommandFeature : FeatureBase, IToolkitCommandFeature - { - public QueryCommandFeature() - { - FeatureName = "Query"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - var runCommand = new Command("run", "Functions pertaining to running query-related commands."); - parentCommand.Add(runCommand); - - // a command that installs query packs - var installPacksQueryCommand = new Command("install-packs", "Installs CodeQL packs within the repository."); - - runCommand.Add(installPacksQueryCommand); - - installPacksQueryCommand.SetHandler((basePath) => new InstallQueryPacksCommandTarget() { Base = basePath }.Run(), Globals.BasePathOption); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs deleted file mode 100644 index 255faf7..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Commands/Targets/InstallQueryPacksCommandTarget.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Commands.Targets -{ - public class InstallQueryPacksCommandTarget : CommandTarget - { - public override void Run() - { - Log.G().LogInformation("Finding all qlpacks..."); - - // starting at the base path, find all qlpacks and install them - string[] files = Directory.GetFiles(Base, "qlpack.yml", SearchOption.AllDirectories); - - Log.G().LogInformation($"Got {files.Length} packs..."); - - foreach ( string file in files ) - { - Log.G().LogInformation($"Installing qlpack {file}..."); - - using(Process process = new Process()) - { - process.StartInfo.FileName = "codeql"; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = false; - process.StartInfo.Arguments = $"pack install {file}"; - process.Start(); - - process.WaitForExit(); - - if(process.ExitCode !=0) - { - DieWithError($"Failed to install query pack {file}."); - } - } - - } - - Log.G().LogInformation($"Installed {files.Length} packs."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Common.cs b/src_backup/src/CodeQLToolkit.Features.Query/Common.cs deleted file mode 100644 index 6b4bffa..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Common.cs +++ /dev/null @@ -1,3 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs deleted file mode 100644 index 2b725e0..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/QueryLifecycleFeature.cs +++ /dev/null @@ -1,56 +0,0 @@ -using CodeQLToolkit.Features.Query.Lifecycle.Targets; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using CodeQLToolkit.Shared.Types; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Lifecycle -{ - public class QueryLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public QueryLifecycleFeature() - { - FeatureName = "Query"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var initCommand = new Command("init", "Initialize query support in this repository."); - - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - - initCommand.AddOption(overwriteExistingOption); - - parentCommand.Add(initCommand); - - initCommand.SetHandler((basePath, overwriteExisting) => - { - Log.G().LogInformation("Executing init command..."); - - - new InitLifecycleTarget() - { - FeatureName = FeatureName, - Base = basePath, - OverwriteExisting = overwriteExisting - - }.Run(); - - - }, Globals.BasePathOption, overwriteExistingOption); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs deleted file mode 100644 index c9ac216..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Lifecycle/Targets/InitLifecycleTarget.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CodeQLToolkit.Features.Query.Scaffolding.Targets; -using CodeQLToolkit.Shared.Feature; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Lifecycle.Targets -{ - public class InitLifecycleTarget : ILifecycleTarget - { - public override void Run() - { - Log.G().LogInformation("Initializing new query development workspace..."); - - Directory.CreateDirectory(Base); - - var workspaceLocation = Path.Combine(Base, "codeql-workspace.yml"); - - WriteTemplateIfOverwriteOrNotExists("codeql-workspace", workspaceLocation, "CodeQL Workspace"); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs deleted file mode 100644 index 6bc009e..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/QueryFeatureMain.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CodeQLToolkit.Features.Query.Commands; -using CodeQLToolkit.Features.Query.Lifecycle; -using CodeQLToolkit.Features.Query.Scaffolding; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Logging; -using Microsoft.Extensions.Logging; -using System.CommandLine; - -namespace CodeQLDevelopmentLifecycleToolkit.Features.Query -{ - - public class QueryFeatureMain : IToolkitFeature - { - readonly QueryScaffoldFeature scaffoldFeature; - readonly QueryCommandFeature commandFeature; - readonly QueryLifecycleFeature lifecycleFeature; - - - readonly static QueryFeatureMain instance; - - static QueryFeatureMain() { - instance = new QueryFeatureMain(); - } - private QueryFeatureMain() - { - scaffoldFeature = new QueryScaffoldFeature(); - commandFeature = new QueryCommandFeature(); - lifecycleFeature = new QueryLifecycleFeature(); - } - - public static QueryFeatureMain Instance { get { return instance; } } - - public int Run() - { - - Console.WriteLine("[Query] RUNNING QUERY FEATURE"); - - return 0; - } - - public void Register(Command parentCommand) - { - var queryCommand = new Command("query", "Use the features related to query creation and execution."); - parentCommand.Add(queryCommand); - - scaffoldFeature.Register(queryCommand); - commandFeature.Register(queryCommand); - lifecycleFeature.Register(queryCommand); - - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs deleted file mode 100644 index 6b16403..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/QueryScaffoldFeature.cs +++ /dev/null @@ -1,77 +0,0 @@ -using CodeQLToolkit.Features.Query.Scaffolding.Targets; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Query.Scaffolding -{ - public class QueryScaffoldFeature : FeatureBase, IToolkitScaffoldingFeature - { - public QueryScaffoldFeature() { - FeatureName = "Query"; - } - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT}; } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering scaffolding submodule."); - - var scaffoldCommand = new Command("generate", "Functions pertaining to generating query-related artifacts."); - parentCommand.Add(scaffoldCommand); - - // add the types of things we can scaffold. - var newQueryCommand = new Command("new-query", "Generates a new query and associated tests. Optionally will generate a new query pack if required."); - - var createQueryPackOption = new Option("--create-query-pack", () => true, "Create a new query pack if none exists."); - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - - var createTestsOption = new Option("--create-tests", ()=> true, "Create a new unit test for this query if it doesn't already exist."); - var queryNameOption = new Option("--query-name", "Name of the query. Note: Do not specify the `.ql` extension in naming your query.") { IsRequired = true }; - var queryLanguageOption = new Option("--language", $"The language to generate a query for.") { IsRequired = true} - .FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var queryPackOption = new Option("--pack", "The name of the query pack to place this query in.") { IsRequired = true }; - var queryPackScopeOption = new Option("--scope", "The scope to use") { IsRequired = true }; - - newQueryCommand.Add(createQueryPackOption); - newQueryCommand.Add(createTestsOption); - newQueryCommand.Add(queryNameOption); - newQueryCommand.Add(queryLanguageOption); - newQueryCommand.Add(queryPackOption); - newQueryCommand.Add(overwriteExistingOption); - newQueryCommand.Add(queryPackScopeOption); - - scaffoldCommand.Add(newQueryCommand); - - { - newQueryCommand.SetHandler((createQueryPack, createTests, queryName, queryLangauge, queryPack, basePath, overwriteExisting, queryPackScope) => - { - - if (!IsSupportedLangauge(queryLangauge)) - { - DieWithError($"Unsupported langauge `{queryLangauge}`"); - } - - new NewQueryScaffoldTarget() - { - Name = queryName, - Language = LanguageTypeHelper.LanguageTypeFromOptionString(queryLangauge), - Base = basePath, - QueryPack = queryPack, - QueryPackScope = queryPackScope, - CreateTests = createTests, - CreateQueryPack = createQueryPack, - OverwriteExisting = overwriteExisting, - FeatureName = FeatureName - }.Run(); - - }, createQueryPackOption, createTestsOption, queryNameOption, queryLanguageOption, queryPackOption, Globals.BasePathOption, overwriteExistingOption, queryPackScopeOption); - } - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs deleted file mode 100644 index 36f8fa3..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs +++ /dev/null @@ -1,76 +0,0 @@ -using CodeQLToolkit.Shared.Template; -using CodeQLToolkit.Shared.Utils; -using System.Reflection; - -namespace CodeQLToolkit.Features.Query.Scaffolding.Targets -{ - public class NewQueryScaffoldTarget : ScaffoldTarget - { - public string QueryPack { get; set; } - public bool CreateTests { get; set; } - public bool CreateQueryPack { get; set; } - public string QueryPackScope { get; set; } - - public override void Run() - { - Log.G().LogInformation("Creating new query..."); - - var query = new Shared.Utils.Query() - { - Language = Language, - QueryPackName = QueryPack, - Name = Name, - Scope = QueryPackScope, - Base = Base - }; - - Directory.CreateDirectory(query.QueryFileDir); - - WriteTemplateIfOverwriteOrNotExists("new-query", query.QueryFilePath, "new query", new - { - language = query.Language, - queryPackName = query.QueryPackName, - queryName = query.Name, - description = "Replace this text with a description of your query.", - qlLanguageImport = query.GetLanguageImportForLangauge() - }); - - if (CreateQueryPack) - { - WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new - { - queryPackScope = query.Scope, - queryPackName = query.QueryPackName - }); - } - - if (CreateTests) - { - Directory.CreateDirectory(query.QueryFileTestDir); - - // the source file to use - WriteTemplateIfOverwriteOrNotExists("test", query.QueryFileTestPath, "new query test file", new {}); - - // the expected file - WriteTemplateIfOverwriteOrNotExists("expected", query.QueryTestExpectedFile, "new query test expected file", new { }); - - // the the qlref file - WriteTemplateIfOverwriteOrNotExists("testref", query.QueryFileQLRefPath, "new query test ref", new { - queryName = query.Name - }); - - // the qlpack file - WriteTemplateIfOverwriteOrNotExists("qlpack-test", query.QueryPackTestPath, "new query test pack", new { - queryPackDependency = $"{query.Scope}/{query.QueryPackName}", - queryPackScope = query.Scope, - queryPackName = query.QueryTestPackName - }); - - } - else - { - Log.G().LogInformation($"Not creating tests because test creation was disabled."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid deleted file mode 100644 index 26362dc..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/codeql-workspace.liquid +++ /dev/null @@ -1,3 +0,0 @@ -provide: - - '**/qlpack.yml' - - '**/codeql-workspace.yml' \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid deleted file mode 100644 index 7962166..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/expected.liquid +++ /dev/null @@ -1 +0,0 @@ -// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid deleted file mode 100644 index 5f28270..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-dataflow-query.liquid +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid deleted file mode 100644 index f5c42c4..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/new-query.liquid +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @id {{language}}/{{query_pack_name}}/{{query_name}} - * @name {{query_name}} - * @description {{description}} - * @kind problem - * @precision medium - * @problem.severity error - * @tags {{query_pack_name}} - */ - - import {{ql_language_import}} - - from Expr e - select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid deleted file mode 100644 index c3a1a45..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-query.liquid +++ /dev/null @@ -1,7 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -dependencies: - codeql/cpp-all: 0.3.5 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid deleted file mode 100644 index 560a515..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/qlpack-test.liquid +++ /dev/null @@ -1,8 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -extractor: cpp -dependencies: - {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid deleted file mode 100644 index f39be51..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/test.liquid +++ /dev/null @@ -1 +0,0 @@ -// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid deleted file mode 100644 index d083780..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/cpp/testref.liquid +++ /dev/null @@ -1 +0,0 @@ -{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid deleted file mode 100644 index 7962166..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/expected.liquid +++ /dev/null @@ -1 +0,0 @@ -// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid deleted file mode 100644 index 5f28270..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-dataflow-query.liquid +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid deleted file mode 100644 index f5c42c4..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/new-query.liquid +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @id {{language}}/{{query_pack_name}}/{{query_name}} - * @name {{query_name}} - * @description {{description}} - * @kind problem - * @precision medium - * @problem.severity error - * @tags {{query_pack_name}} - */ - - import {{ql_language_import}} - - from Expr e - select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid deleted file mode 100644 index 8120bfc..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-query.liquid +++ /dev/null @@ -1,7 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -dependencies: - codeql/javascript-all: "^0.6.3" \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid deleted file mode 100644 index 515d065..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/qlpack-test.liquid +++ /dev/null @@ -1,8 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -extractor: javascript -dependencies: - {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid deleted file mode 100644 index f39be51..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/test.liquid +++ /dev/null @@ -1 +0,0 @@ -// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid b/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid deleted file mode 100644 index d083780..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Query/Templates/Query/javascript/testref.liquid +++ /dev/null @@ -1 +0,0 @@ -{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj b/src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj deleted file mode 100644 index 63f467f..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/CodeQLToolkit.Features.Test.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - Always - - - Always - - - Always - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs deleted file mode 100644 index 9b596cb..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseExecuteUnitTestsCommandTarget.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.VisualBasic; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public abstract class BaseExecuteUnitTestsCommandTarget : CommandTarget - { - public int NumThreads { get; set; } - public string WorkDirectory { get; set; } - public string RunnerOS { get; set; } - public string CLIVersion { get; set; } - public string STDLibIdent { get; set; } - public string ExtraCodeQLArgs { get; set; } - } -} - diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs deleted file mode 100644 index 36d79f6..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/BaseGetMatrixCommandTarget.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public abstract class BaseGetMatrixCommandTarget : CommandTarget - { - public string[] OSVersions { get; set; } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs deleted file mode 100644 index 230e217..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs +++ /dev/null @@ -1,112 +0,0 @@ -using CodeQLToolkit.Features.Test.Lifecycle.Models; -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions -{ - - [AutomationType(AutomationType.ACTIONS)] - public class ExecuteUnitTestsCommandTarget : BaseExecuteUnitTestsCommandTarget - { - - public override void Run() - { - Log.G().LogInformation($"Preparing to execute unit tests found in {Base} for Language {Language}..."); - - // get a directory to work in - var tmpDirectory = WorkDirectory; - - var languageRoot = Path.Combine(Base, Language); - - // check if the language root exists - if (!Directory.Exists(languageRoot)){ - DieWithError($"Language root {languageRoot} does not exist so unit tests cannnot be run."); - } - - // Identify the test directories. - string[] dirs = Directory.GetDirectories(languageRoot, "test", SearchOption.AllDirectories); - - Log.G().LogInformation($"Test Directory Inventory {Language}"); - Log.G().LogInformation($"-----------------------------------"); - - foreach ( string dir in dirs) - { - Log.G().LogInformation($"Found test directory: {dir}"); - } - - var transformedDirs = dirs.Select(dir => Path.GetRelativePath(Base, dir)); - - if(dirs.Length == 0) - { - DieWithError($"No tests detected. Please create unit tests before running this command."); - } - - Parallel.For(0, NumThreads, - slice => { - - TestReport report = new TestReport() - { - RunnerOS = RunnerOS, - CLIVersion = CLIVersion, - STDLibIdent = STDLibIdent, - Language = Language, - Slice = slice, - NumSlices = NumThreads - }; - - var workingDirectory = Path.GetFullPath(Base); - var testPathString = string.Join(" ", transformedDirs); - var outFileReport = Path.Combine(tmpDirectory, report.FileName); - - Log.G().LogInformation($"Executing tests in working directory {workingDirectory}."); - Log.G().LogInformation($"Test Paths: {testPathString}"); - Log.G().LogInformation($"Slice: {slice} of {NumThreads}"); - Log.G().LogInformation($"Report File: {outFileReport}..."); - - using (Process process = new Process()) - { - process.StartInfo.FileName = "codeql"; - process.StartInfo.WorkingDirectory = workingDirectory; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = false; - process.StartInfo.Arguments = $"test run {ExtraCodeQLArgs} --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}"; - - process.Start(); - - // needed for STDOUT redirection - var output = process.StandardOutput.ReadToEnd(); - - File.WriteAllText(outFileReport, output); - - process.WaitForExit(); - - if (process.ExitCode != 0) - { - // This fine - if(process.ExitCode == 122) - { - Log.G().LogError($"One more more unit tests failed. Please see the output of the validation step for more information about failed tests cases."); - } - // this is not fine - else - { - DieWithError($"Non-test related error while running unit tests. Please check debug output for more infomation."); - } - } - } - } - ); - - - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs deleted file mode 100644 index 666748d..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs +++ /dev/null @@ -1,75 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System.Text.Json; - -namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions -{ - [AutomationType(AutomationType.ACTIONS)] - public class GetMatrixCommandTarget : BaseGetMatrixCommandTarget - { - public override void Run() - { - - // based on the current configuration of the repository, generate a matrix - // for actions, it looks like this: - - // { - // "include": [ - // { - // "codeql_cli": "2.12.6", - // "codeql_standard_library": "codeql-cli/v2.12.6", - // "codeql_cli_bundle": "codeql-bundle-20230403", - // "os": "ubuntu-latest", - // "codeql_standard_library_ident": "codeql-cli_v2.12.6" - // } - // ] - // } - - // For now, we only support a single version but this is easy to extend. The options for runners are what create different matrix types. - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - List configs = new List(); - - foreach(var os in OSVersions) - { - Log.G().LogInformation($"Creating matrix for {os}"); - - configs.Add(new - { - codeql_cli = config.CodeQLCLI, - codeql_standard_library = config.CodeQLStandardLibrary, - codeql_cli_bundle = config.CodeQLCLIBundle, - os = os, - codeql_standard_library_ident = config.CodeQLStandardLibraryIdent - }); - } - - var data = new - { - include = configs - }; - - var json = JsonSerializer.Serialize(data); - - var matrixVariable = $"matrix={json}"; - - string envFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT"); - - Log.G().LogInformation($"Writing matrix output {matrixVariable} to {envFile}"); - - File.AppendAllText(envFile, matrixVariable ); - - Log.G().LogInformation($"Done."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs deleted file mode 100644 index 2fc347b..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/Targets/ValidateUnitTestsCommand.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets -{ - - - public class UnitTestResult - { - public string test { get; set; } - public bool pass { get; set; } - public string failureStage { get; set; } - public string failureDescription { get; set; } - public object[] messages { get; set; } - public int compilationMs { get; set; } - public int evaluationMs { get; set; } - public string expected { get; set; } - public string actual { get; set; } - public string[] diff { get; set; } - } - - public class ValidateUnitTestsCommand : CommandTarget - { - public string ResultsDirectory { get; set; } - - public bool PrettyPrint { get; set; } - - public override void Run() - { - Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); - - string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); - - List unitTestResults = new List(); - - foreach (string result in results) - { - using (StreamReader r = new StreamReader(result)) - { - string json = r.ReadToEnd(); - List items = JsonConvert.DeserializeObject>(json); - - foreach(var item in items) - { - unitTestResults.Add(item); - } - } - } - - - int totalCases = unitTestResults.Count; - int currentCase = 0; - - foreach (var item in unitTestResults) - { - currentCase++; - - if (item.pass) - { - if(PrettyPrint) - { - Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : PASSED "); - Log.G().LogError($"+----------------------------------------------+"); - } - } - else - { - if (PrettyPrint) - { - Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - if (item.failureStage == "RESULT") - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : RESULT"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST DIFFERENCES |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - - - foreach (var diff in item.diff) - { - Log.G().LogError($"| {diff}"); - } - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FAILURE DESCRIPTION |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - Log.G().LogError($"| {item.failureDescription}"); - - - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - } - } - } - - var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); - - if (failedTests.Length > 0 && !PrettyPrint) - { - DieWithError("One or more failures during run unit tests."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs deleted file mode 100644 index f9866ee..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Commands/TestCommandFeature.cs +++ /dev/null @@ -1,160 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands.Targets; -using CodeQLToolkit.Features.Test.Lifecycle; -using CodeQLToolkit.Shared.Types; -using CodeQLToolkit.Shared.Utils; -using Microsoft.VisualBasic; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public class TestCommandFeature : FeatureBase, IToolkitLifecycleFeature - { - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; } - - public TestCommandFeature() - { - FeatureName = "Test"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - - var runCommand = new Command("run", "Functions pertaining to running test-related commands."); - parentCommand.Add(runCommand); - - // a command that gets the matrix configuration - var getMatrixTestCommand = new Command("get-matrix", "Gets a CI/CD matrix based on the current configuration."); - - var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; - getMatrixTestCommand.Add(matrixOSVersion); - - // a command that runs the actual tests - var unitTestsCommand = new Command("execute-unit-tests", "Runs unit tests within a repository based on the current configuration."); - - var numThreadsOption = new Option("--num-threads", () => 4, "The number of threads to use for runner. For best performance, do not exceed the number of physical cores on your system.") { IsRequired = true }; - var workDirectoryOption = new Option("--work-dir", () => Path.GetTempPath(), "Where to place intermediate execution output files.") { IsRequired = true }; - var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var runnerOSOption = new Option("--runner-os", $"Label for the operating system running these tests.") { IsRequired = true }; - //var cliVersionOption = new Option("--cli-version", $"The version of the cli running the tests.") { IsRequired = true }; - //var stdLibIdentOption = new Option("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true }; - var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; - - unitTestsCommand.Add(numThreadsOption); - unitTestsCommand.Add(workDirectoryOption); - unitTestsCommand.Add(languageOption); - unitTestsCommand.Add(runnerOSOption); - //unitTestsCommand.Add(cliVersionOption); - //unitTestsCommand.Add(stdLibIdentOption); - unitTestsCommand.Add(extraCodeQLOptions); - - // a command validates the tests - var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems."); - - var resultsDirectoryOption = new Option("--results-directory", "Where to find the intermediate execution output files.") { IsRequired = true }; - var prettyPrintOption = new Option("--pretty-print", () => false, "Pretty print test output in a compact format. Note this will not exit with a failure code if tests fail.") { IsRequired = true }; - - validateUnitTestsCommand.Add(resultsDirectoryOption); - validateUnitTestsCommand.Add(prettyPrintOption); - - runCommand.Add(getMatrixTestCommand); - runCommand.Add(unitTestsCommand); - runCommand.Add(validateUnitTestsCommand); - - getMatrixTestCommand.SetHandler((basePath, automationType, osVersions) => { - - Log.G().LogInformation("Executing get-matrix command..."); - - // dispatch at runtime to the correct automation type - var featureTarget = AutomationFeatureFinder - .FindTargetForAutomationType( - AutomationTypeHelper.AutomationTypeFromString(automationType) - ); - - featureTarget.Base = basePath; - featureTarget.OSVersions = osVersions.Split(","); - - featureTarget.Run(); - - }, Globals.BasePathOption, Globals.AutomationTypeOption, matrixOSVersion); - - //stdLibIdent - unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, extraArgs) => { - - Log.G().LogInformation("Executing execute-unit-tests command..."); - - // dispatch at runtime to the correct automation type - var featureTarget = AutomationFeatureFinder - .FindTargetForAutomationType( - AutomationTypeHelper.AutomationTypeFromString(automationType) - ); - - // lookup cliVersion and stdLibIdent - var c = new QLTConfig() - { - Base = basePath - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - featureTarget.Base = basePath; - featureTarget.NumThreads = numThreads; - featureTarget.WorkDirectory = workDirectory; - featureTarget.Language = language; - featureTarget.RunnerOS = runnerOS; - featureTarget.CLIVersion = config.CodeQLCLI; - featureTarget.STDLibIdent = config.CodeQLStandardLibraryIdent; - featureTarget.ExtraCodeQLArgs = extraArgs; - - featureTarget.Run(); - - }, Globals.BasePathOption, - Globals.AutomationTypeOption, - numThreadsOption, - workDirectoryOption, - languageOption, - runnerOSOption, - extraCodeQLOptions - ); - - - validateUnitTestsCommand.SetHandler((resultsDirectory, prettyPrint) => - { - Log.G().LogInformation("Executing validate-unit-tests command..."); - - new ValidateUnitTestsCommand() - { - ResultsDirectory = resultsDirectory, - PrettyPrint = prettyPrint - }.Run(); - - - }, resultsDirectoryOption, prettyPrintOption); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Common.cs b/src_backup/src/CodeQLToolkit.Features.Test/Common.cs deleted file mode 100644 index 279d9e9..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Common.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; -global using CodeQLToolkit.Shared.Feature; -global using CodeQLToolkit.Shared.Options; -global using CodeQLToolkit.Shared.Types; - diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs deleted file mode 100644 index d3bdad8..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/BaseLifecycleTarget.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle -{ - abstract public class BaseLifecycleTarget : ILifecycleTarget - { - public int NumThreads { get; set; } - public string UseRunner { get; set; } - - public string ExtraArgs { get; set; } - - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs deleted file mode 100644 index ffb2635..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Models/TestReport.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle.Models -{ - public class TestReport - { - public string RunnerOS { get; set; } - public string CLIVersion { get; set; } - public string STDLibIdent { get; set; } - - public string Language { get; set; } - - public int Slice { get; set; } - public int NumSlices { get; set; } - - - public string FileName { - - get { - - var savePath = $"test_report_{RunnerOS}_{CLIVersion}_{STDLibIdent}_slice_{Slice}_of_{NumSlices}.json"; - - return savePath; - } - } - - - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs deleted file mode 100644 index b505101..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions -{ - [AutomationType(AutomationType.ACTIONS)] - public class InitLifecycleTarget : BaseLifecycleTarget - { - public InitLifecycleTarget() - { - AutomationType = AutomationType.ACTIONS; - } - public override void Run() - { - Log.G().LogInformation("Running init command..."); - - // temporarily disable the language resolution - var tmpLanguage = Language; - Language = null; - - var codeqlArgs = "--threads=0"; - - if(ExtraArgs!= null && ExtraArgs.Length > 0) - { - codeqlArgs = $"{codeqlArgs} {ExtraArgs}"; - } - - WriteTemplateIfOverwriteOrNotExists("install-codeql", Path.Combine(Base, ".github", "actions", "install-codeql", "action.yml"), "install-codeql action"); - WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action"); - WriteTemplateIfOverwriteOrNotExists("run-unit-tests", Path.Combine(Base, ".github", "workflows", $"run-codeql-unit-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new - { - numThreads = NumThreads, - useRunner = UseRunner, - language = tmpLanguage, - codeqlArgs = codeqlArgs - }); - - Language = tmpLanguage; - - var message = @"------------------------------------------ -Your repository now has the CodeQL Unit Test Runner installed in `.github/workflows/`. Additionally, -QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt` and -`.github/actions/install-codeql`. - -Note that, by default, your runner will use 4 threads and defaults to the `ubuntu-latest` runner. - -You can modify the number of threads used by using the `--num-threads` argument and you can select a different -runner with the `--use-runner` argument. - -In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings. - -(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; - - - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs deleted file mode 100644 index ebdd333..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Lifecycle/TestLifecycleFeature.cs +++ /dev/null @@ -1,81 +0,0 @@ -using CodeQLToolkit.Features.Test.Lifecycle.Targets; -using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions; -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; -using System.Reflection; - -namespace CodeQLToolkit.Features.Test.Lifecycle -{ - public class TestLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public TestLifecycleFeature() - { - FeatureName = "Test"; - } - - public override LanguageType[] SupportedLangauges - { - get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var initCommand = new Command("init", "Initialize testing in this repository."); - - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - var numThreadsOption = new Option("--num-threads", () => 4, "Number of threads to use during test execution."); - var useRunnerOption = new Option("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners."); - var languageOption = new Option("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; - - initCommand.AddOption(overwriteExistingOption); - initCommand.AddOption(numThreadsOption); - initCommand.AddOption(useRunnerOption); - initCommand.AddOption(languageOption); - initCommand.AddOption(extraCodeQLOptions); - - - parentCommand.Add(initCommand); - - - - initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language, extraArgs) => - { - Log.G().LogInformation("Executing init command..."); - - // - // dispatch at runtime to the correct automation type - // - var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType(AutomationTypeHelper.AutomationTypeFromString(automationType)); - - // setup common params - featureTarget.FeatureName = FeatureName; - featureTarget.Base = basePath; - featureTarget.OverwriteExisting = overwriteExisting; - featureTarget.NumThreads = numThreads; - featureTarget.UseRunner = useRunner; - featureTarget.Language = language; - featureTarget.ExtraArgs = extraArgs; - featureTarget.Run(); - - }, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption, extraCodeQLOptions); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid deleted file mode 100644 index ddb56ba..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-codeql.liquid +++ /dev/null @@ -1,109 +0,0 @@ -name: Fetch CodeQL CLI and queries -description: | - Fetches a CodeQL CLI and a copy of the CodeQL standard libraries at the specified versions. -inputs: - codeql-cli-version: - description: | - The version of the CodeQL CLI to be downloaded. - required: false - default: 'latest' - - codeql-stdlib-version: - description: | - The tag or commit to use from the CodeQL Standard Library - required: false - default: 'latest' - - add-to-path: - description: | - Add the CodeQL CLI to the system path - required: false - default: 'true' - - codeql-home: - description: | - The directory to store the CodeQL CLI and Standard Library. - A fixed location can be used for caching the tooling. - required: false -outputs: - codeql-home: - description: 'The directory containing the CodeQL CLI and CodeQL Standard Library' - value: ${{ steps.install-codeql.outputs.codeql-home }} - -runs: - using: composite - steps: - - name: Install CodeQL - id: install-codeql - env: - RUNNER_OS: ${{ runner.os }} - RUNNER_TEMP: ${{ runner.temp }} - CODEQL_CLI_VERSION: ${{ inputs.codeql-cli-version }} - CODEQL_STDLIB_VERSION: ${{ inputs.codeql-stdlib-version }} - GITHUB_TOKEN: ${{ github.token }} - ADD_TO_PATH: ${{ inputs.add-to-path }} - CODEQL_HOME: ${{ inputs.codeql-home }} - shell: bash - run: | - echo "::debug::Determining CodeQL release for $RUNNER_OS" - case $RUNNER_OS in - "Linux") - RELEASE_PATTERN="codeql-linux64.zip" - ;; - "macOS") - RELEASE_PATTERN="codeql-osx64.zip" - ;; - "Windows") - RELEASE_PATTERN="codeql-win64.zip" - ;; - *) - echo "::error::Unsupported runner operating system $RUNNER_OS" - exit 1 - ;; - esac - echo "::debug::Selected $RELEASE_PATTERN" - - if [ "$CODEQL_HOME" == "" ] - then - echo "::debug::Creating temporary CodeQL home" - CODEQL_HOME=$(mktemp -d -p $RUNNER_TEMP codeql-home-XXXXXXXXXX) - else - echo "::debug::Creating CodeQL home at $CODEQL_HOME" - mkdir -p $CODEQL_HOME - fi - - echo "::debug::Changing directory to $CODEQL_HOME" - pushd $CODEQL_HOME - - echo "::debug::Downloading CodeQL CLI version $CODEQL_CLI_VERSION" - if [ "$CODEQL_CLI_VERSION" == "latest" ] - then - gh release download --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN - else - gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN - fi - echo "::debug::Unpacking CodeQL CLI" - unzip -q $RELEASE_PATTERN - - echo "::debug::Cloning CodeQL standard library" - git clone https://github.com/github/codeql.git codeql-stdlib - - if [ "$CODEQL_STDLIB_VERSION" != "latest" ] - then - pushd codeql-stdlib - echo "::debug::Switching to revision $CODEQL_STDLIB_VERSION" - git checkout $CODEQL_STDLIB_VERSION - popd - fi - - if [ "$ADD_TO_PATH" == "true" ] - then - echo "::debug::Adding CodeQL CLI path '$(pwd)/codeql' to system path" - echo "$(pwd)/codeql" >> $GITHUB_PATH - fi - - echo "::debug::Setting output parameter codeql-home to $(pwd)" - echo "codeql-home=$(pwd)" >> $GITHUB_OUTPUT - - popd - echo "::debug::Done." diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid deleted file mode 100644 index b1e7fa1..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/install-qlt.liquid +++ /dev/null @@ -1,88 +0,0 @@ -name: Fetch and Install QLT -description: | - Fetches and installs QLT. -inputs: - qlt-version: - description: | - The version of QLT to be downloaded. - required: false - default: 'latest' - - add-to-path: - description: | - Add QLT to the system path - required: false - default: 'true' - - token: - description: | - Token to use for auth - required: true - - -outputs: - qlt-home: - description: 'The directory containing the QLT installation' - value: ${{ steps.install-qlt.outputs.qlt-home }} - -runs: - using: composite - steps: - - name: Install QLT - id: install-qlt - env: - RUNNER_OS: ${{ runner.os }} - RUNNER_TEMP: ${{ runner.temp }} - # GITHUB_TOKEN: ${{ github.token }} - GITHUB_TOKEN: ${{ inputs.token }} - ADD_TO_PATH: ${{ inputs.add-to-path }} - QLT_VERSION: ${{ inputs.qlt-version }} - QLT_HOME: ${{ inputs.qlt-home }} - shell: bash - run: | - echo -e "\e[0;32m[QLT]\e[0m Determining QLT release for $RUNNER_OS" - case $RUNNER_OS in - "Linux") - RELEASE_PATTERN="qlt-linux-x86_64.zip" - ;; - *) - echo "::error::Unsupported runner operating system $RUNNER_OS" - exit 1 - ;; - esac - echo -e "\e[0;32m[QLT]\e[0m Selected $RELEASE_PATTERN" - - if [ "$QLT_HOME" == "" ] - then - echo -e "\e[0;32m[QLT]\e[0m Creating temporary QLT home" - QLT_HOME=$(mktemp -d -p $RUNNER_TEMP qlt-home-XXXXXXXXXX) - else - echo -e "\e[0;32m[QLT]\e[0m Creating CodeQL home at $QLT_HOME" - mkdir -p $QLT_HOME - fi - - echo -e "\e[0;32m[QLT]\e[0m Changing directory to $QLT_HOME" - pushd $QLT_HOME - - echo -e "\e[0;32m[QLT]\e[0m Downloading QLT version $QLT_VERSION" - if [ "$QLT_VERSION" == "latest" ] - then - # download the actual bundle - gh release download -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" - else - gh release download "$QLT_VERSION" -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" - fi - echo -e "\e[0;32m[QLT]\e[0m Unpacking QLT" - unzip $RELEASE_PATTERN - - if [ "$ADD_TO_PATH" == "true" ] - then - echo -e "\e[0;32m[QLT]\e[0m Adding QLT '$(pwd)/qlt' to system path" - echo "$(pwd)" >> $GITHUB_PATH - fi - - echo -e "\e[0;32m[QLT]\e[0m Setting output parameter qlt-home to $(pwd)" - echo "qlt-home=$(pwd)" >> $GITHUB_OUTPUT - - popd - echo -e "\e[0;32m[QLT]\e[0m Done." diff --git a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid b/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid deleted file mode 100644 index 7177427..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/Templates/Test/Actions/run-unit-tests.liquid +++ /dev/null @@ -1,129 +0,0 @@ -name: ⚙️ CodeQL - Run Unit Tests ({{language}}) -{% raw %} - -on: - push: - branches: - - '**' - pull_request: - branches: - - '**' - workflow_dispatch: - -jobs: - create-unit-test-matrix: - name: Create CodeQL Unit Test Matrix - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true -{% endraw %} - - name: Export unit test matrix - id: export-unit-test-matrix - run: | - qlt test run get-matrix --os-version {{ use_runner }} -{% raw %} - run-test-suites: - name: Run Unit Tests - needs: create-unit-test-matrix - - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.create-unit-test-matrix.outputs.matrix) }} - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true - - - name: Install CodeQL - id: install-codeql - uses: ./.github/actions/install-codeql - with: - codeql-cli-version: ${{ matrix.codeql_cli }} - codeql-stdlib-version: ${{ matrix.codeql_standard_library }} - add-to-path: true - - - name: Verify Versions of Tooling - shell: bash - run: | - echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}" - echo -e "Checking CodeQL Version:" - codeql --version - - echo -e "Checking QLT Version:" - echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}" - qlt version - - - name: Install QL Packs - shell: bash - run: | - qlt query run install-packs - - - name: Run test suites - id: run-test-suites - env: - RUNNER_OS: ${{ runner.os }} - CODEQL_CLI: ${{ matrix.codeql_cli }} - CODEQL_STDLIB: ${{ matrix.codeql_standard_library }} - CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}} - RUNNER_TMP: ${{ runner.temp }} - shell: bash - run: > -{% endraw %} - qlt test run execute-unit-tests - --codeql-args "{{ codeql_args }}" - --num-threads {{ num_threads }} - --language {{ language }} - --runner-os $RUNNER_OS - --work-dir $RUNNER_TMP -{% raw %} - - name: Upload test results - uses: actions/upload-artifact@v2 - with: - name: test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} - path: | - ${{ runner.temp }}/test_report_${{ runner.os }}_${{ matrix.codeql_cli }}_${{ matrix.codeql_standard_library_ident }}_slice_*.json - if-no-files-found: error - - validate-test-results: - name: Validate test results - needs: [run-test-suites] - runs-on: ubuntu-latest - steps: - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true - - - name: Collect test results - uses: actions/download-artifact@v2 - - - name: Validate test results - run: | - qlt test run validate-unit-tests --results-directory . - qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY - -{% endraw %} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs deleted file mode 100644 index c2c3bf4..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Test/TestFeatureMain.cs +++ /dev/null @@ -1,45 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands; -using CodeQLToolkit.Features.Test.Lifecycle; -using CodeQLToolkit.Shared.Feature; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Test -{ - public class TestFeatureMain : IToolkitFeature - - { - readonly TestLifecycleFeature lifecycleFeature; - readonly TestCommandFeature commandFeature; - readonly static TestFeatureMain instance; - - static TestFeatureMain() - { - instance = new TestFeatureMain(); - } - - private TestFeatureMain() - { - lifecycleFeature = new TestLifecycleFeature(); - commandFeature = new TestCommandFeature(); - } - public static TestFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var testCommand = new Command("test", "Features related to the running and processing of CodeQL Unit Tests."); - parentCommand.Add(testCommand); - - Log.G().LogInformation("Registering scaffolding submodule."); - lifecycleFeature.Register(testCommand); - - Log.G().LogInformation("Registering command submodule."); - commandFeature.Register(testCommand); - - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj b/src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj deleted file mode 100644 index 6133b9c..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/CodeQLToolkit.Features.Validation.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs deleted file mode 100644 index 2fc347b..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/Targets/ValidateUnitTestsCommand.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets -{ - - - public class UnitTestResult - { - public string test { get; set; } - public bool pass { get; set; } - public string failureStage { get; set; } - public string failureDescription { get; set; } - public object[] messages { get; set; } - public int compilationMs { get; set; } - public int evaluationMs { get; set; } - public string expected { get; set; } - public string actual { get; set; } - public string[] diff { get; set; } - } - - public class ValidateUnitTestsCommand : CommandTarget - { - public string ResultsDirectory { get; set; } - - public bool PrettyPrint { get; set; } - - public override void Run() - { - Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); - - string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); - - List unitTestResults = new List(); - - foreach (string result in results) - { - using (StreamReader r = new StreamReader(result)) - { - string json = r.ReadToEnd(); - List items = JsonConvert.DeserializeObject>(json); - - foreach(var item in items) - { - unitTestResults.Add(item); - } - } - } - - - int totalCases = unitTestResults.Count; - int currentCase = 0; - - foreach (var item in unitTestResults) - { - currentCase++; - - if (item.pass) - { - if(PrettyPrint) - { - Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : PASSED "); - Log.G().LogError($"+----------------------------------------------+"); - } - } - else - { - if (PrettyPrint) - { - Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - if (item.failureStage == "RESULT") - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : RESULT"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST DIFFERENCES |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - - - foreach (var diff in item.diff) - { - Log.G().LogError($"| {diff}"); - } - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FAILURE DESCRIPTION |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - Log.G().LogError($"| {item.failureDescription}"); - - - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - } - } - } - - var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); - - if (failedTests.Length > 0 && !PrettyPrint) - { - DieWithError("One or more failures during run unit tests."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs deleted file mode 100644 index 2e8db6d..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/Commands/ValidationCommandFeature.cs +++ /dev/null @@ -1,60 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public class ValidationCommandFeature : FeatureBase, IToolkitLifecycleFeature - { - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; } - - public ValidationCommandFeature() - { - FeatureName = "Validation"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - - var runCommand = new Command("run", "Functions pertaining running validation commands."); - parentCommand.Add(runCommand); - - var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); - - var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; - getMatrixTestCommand.Add(matrixOSVersion); - - runCommand.Add(getMatrixTestCommand); - - - getMatrixTestCommand.SetHandler(() => - { - Log.G().LogInformation("Executing validate-unit-tests command..."); - - //new ValidateUnitTestsCommand() - //{ - // ResultsDirectory = resultsDirectory, - // PrettyPrint = prettyPrint - //}.Run(); - - - }); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs deleted file mode 100644 index 279d9e9..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/Common.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; -global using CodeQLToolkit.Shared.Feature; -global using CodeQLToolkit.Shared.Options; -global using CodeQLToolkit.Shared.Types; - diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs b/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs deleted file mode 100644 index 30aad10..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/Models/CodeQLCliResponseModel.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Validation.Models -{ - public class CodeQLCliResponseModel - { - public string query { get; set; } - public string relativeName { get; set; } - public bool success { get; set; } - public Message[] messages { get; set; } - } - - public class Message - { - public string severity { get; set; } - public string message { get; set; } - public Position position { get; set; } - } - - public class Position - { - public string fileName { get; set; } - public int line { get; set; } - public int column { get; set; } - public int endLine { get; set; } - public int endColumn { get; set; } - } - -} diff --git a/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs deleted file mode 100644 index 1f8367f..0000000 --- a/src_backup/src/CodeQLToolkit.Features.Validation/ValidationFeatureMain.cs +++ /dev/null @@ -1,38 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Validation -{ - public class ValidationFeatureMain : IToolkitFeature - - { - readonly ValidationCommandFeature commandFeature; - readonly static ValidationFeatureMain instance; - - static ValidationFeatureMain() - { - instance = new ValidationFeatureMain(); - } - - private ValidationFeatureMain() - { - commandFeature = new ValidationCommandFeature(); - } - public static ValidationFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var validationCommand = new Command("validation", "Features related to the validation of CodeQL Development Repositories."); - parentCommand.Add(validationCommand); - - Log.G().LogInformation("Registering command submodule."); - commandFeature.Register(validationCommand); - - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs deleted file mode 100644 index c0357b8..0000000 --- a/src_backup/src/CodeQLToolkit.Features/CodeQL/CodeQLFeatureMain.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Shared.Feature; -using System.CommandLine; -using CodeQLToolkit.Shared.Logging; -using Microsoft.Extensions.Logging; -using CodeQLToolkit.Features.CodeQL.Lifecycle; - -namespace CodeQLToolkit.Features.CodeQL -{ - public class CodeQLFeatureMain : IToolkitFeature - { - readonly CodeQLLifecycleFeature lifecycleFeature; - readonly static CodeQLFeatureMain instance; - - static CodeQLFeatureMain() - { - instance = new CodeQLFeatureMain(); - } - - private CodeQLFeatureMain() - { - lifecycleFeature = new CodeQLLifecycleFeature(); - } - - public static CodeQLFeatureMain Instance { get { return instance; } } - - public int Run() - { - - return 0; - } - - public void Register(Command parentCommand) - { - var queryCommand = new Command("codeql", "Use the features related to managing the version of CodeQL used by this repository."); - parentCommand.Add(queryCommand); - Log.G().LogInformation("Registering scaffolding submodule."); - lifecycleFeature.Register(queryCommand); - } - - - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs deleted file mode 100644 index 73e388f..0000000 --- a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/CodeQLLifecycleFeature.cs +++ /dev/null @@ -1,76 +0,0 @@ -using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets; -using System.CommandLine; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle -{ - public class CodeQLLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public CodeQLLifecycleFeature() - { - FeatureName = "CodeQL"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var setCommand = new Command("set", "Functions pertaining to setting variables related to CodeQL."); - parentCommand.Add(setCommand); - - var setVersionCommand = new Command("version", "Sets the version of CodeQL used."); - - var cliVersionOption = new Option("--cli-version", () => "2.11.6", "The version of the cli to use. Example: `2.11.6`.") { IsRequired = true }; - var standardLibraryVersionOption = new Option("--standard-library-version", () => "codeql-cli/v2.11.6", "The version of the standard library to use. Example: `codeql-cli/v2.11.6`.") { IsRequired = true }; - var bundleVersionOption = new Option("--bundle-version", () => "codeql-bundle-20221211", "The bundle version to use. Example: `codeql-bundle-20221211`.") { IsRequired = true }; - - setVersionCommand.Add(cliVersionOption); - setVersionCommand.Add(standardLibraryVersionOption); - setVersionCommand.Add(bundleVersionOption); - - setCommand.Add(setVersionCommand); - - var getCommand = new Command("get", "Functions pertaining to getting variables related to CodeQL."); - parentCommand.Add(getCommand); - - var getVersionCommand = new Command("version", "Gets the version of CodeQL used."); - getCommand.Add(getVersionCommand); - - { - setVersionCommand.SetHandler((cliVersion, standardLibraryVersion, bundleVersion, basePath) => - { - Log.G().LogInformation("Executing set command..."); - - new SetVersionLifecycleTarget() - { - CodeQLCLI = cliVersion, - CodeQLStandardLibrary = standardLibraryVersion, - CodeQLCLIBundle = bundleVersion, - Base = basePath - }.Run(); - - }, cliVersionOption, standardLibraryVersionOption, bundleVersionOption, Globals.BasePathOption); - } - - - { - getVersionCommand.SetHandler((basePath) => - { - Log.G().LogInformation("Executing get command..."); - - new GetVersionLifecycleTarget() - { - Base = basePath - }.Run(); - - }, Globals.BasePathOption); - } - - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs deleted file mode 100644 index 2bd4823..0000000 --- a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/GetVersionLifecycleTarget.cs +++ /dev/null @@ -1,40 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets -{ - public class GetVersionLifecycleTarget : ILifecycleTarget - { - - override public void Run() - { - Log.G().LogInformation("Running get command..."); - - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - // This should be updated so that we can pretty print all the various options: - Console.WriteLine($"---------current settings---------"); - Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); - Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); - Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); - Console.WriteLine($"----------------------------------"); - Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); - - - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs deleted file mode 100644 index 9025b71..0000000 --- a/src_backup/src/CodeQLToolkit.Features/CodeQL/Lifecycle/Targets/SetVersionLifecycleTarget.cs +++ /dev/null @@ -1,35 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.CodeQL.Lifecycle.Targets -{ - public class SetVersionLifecycleTarget : ILifecycleTarget - { - public string CodeQLCLI { get; set; } - public string CodeQLStandardLibrary { get; set; } - public string CodeQLCLIBundle { get; set; } - - override public void Run() - { - Log.G().LogInformation("Running set command..."); - - var c = new QLTConfig() - { - CodeQLCLI = CodeQLCLI, - CodeQLStandardLibrary = CodeQLStandardLibrary, - CodeQLCLIBundle = CodeQLCLIBundle, - Base = Base - }; - - c.ToFile(); - - Log.G().LogInformation("Wrote to file..."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj b/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj deleted file mode 100644 index 4c696ed..0000000 --- a/src_backup/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Features/Common.cs b/src_backup/src/CodeQLToolkit.Features/Common.cs deleted file mode 100644 index 279d9e9..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Common.cs +++ /dev/null @@ -1,7 +0,0 @@ -global using CodeQLToolkit.Shared.Target; -global using CodeQLToolkit.Shared.Logging; -global using Microsoft.Extensions.Logging; -global using CodeQLToolkit.Shared.Feature; -global using CodeQLToolkit.Shared.Options; -global using CodeQLToolkit.Shared.Types; - diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs deleted file mode 100644 index d01968b..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/PackCommandFeature.cs +++ /dev/null @@ -1,63 +0,0 @@ -using CodeQLToolkit.Features.Pack.Commands.Targets; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack.Commands -{ - public class PackCommandFeature : FeatureBase, IToolkitCommandFeature - { - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - var runCommand = new Command("run", "Functions pertaining to running pack-related commands."); - parentCommand.Add(runCommand); - - // a command that installs query packs - var sayHello = new Command("hello-jeongsoo", "Says hello!"); - var howManyTimesHello = new Option("--times", "how many times to say it") { IsRequired = true }; - sayHello.Add(howManyTimesHello); - - var sayGoodbye = new Command("goodbye-jeongsoo", "Says goodbye!"); - - var howManyTimes = new Option("--times", "how many times to say it") { IsRequired = true }; - sayGoodbye.Add(howManyTimes); - - - runCommand.Add(sayHello); - runCommand.Add(sayGoodbye); - - sayHello.SetHandler((basePath, times) => { - - new HelloJeongsooCommandTarget() { - Base = basePath, - Times = times - - }.Run(); - - }, Globals.BasePathOption, howManyTimesHello); - - sayGoodbye.SetHandler((basePath, times) => { - - Console.WriteLine($"Saying goodbye {times} number of times"); - - for (int i = 0; i < times; i++) - { - Console.WriteLine("Goodbye!"); - } - - - }, Globals.BasePathOption, howManyTimes); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs deleted file mode 100644 index 33b4420..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Pack/Commands/Targets/HelloJeongsooCommandTarget.cs +++ /dev/null @@ -1,45 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack.Commands.Targets -{ - public class HelloJeongsooCommandTarget : CommandTarget - { - - public int Times { get; set; } - - - public override void Run() - { - for(int i = 0; i < Times; i++) { - Console.WriteLine($"Hello! My Base Target is: {Base}"); - } - - - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - - Console.WriteLine($"---------current settings---------"); - Console.WriteLine($"CodeQL CLI Version: {config.CodeQLCLI}"); - Console.WriteLine($"CodeQL Standard Library Version: {config.CodeQLStandardLibrary}"); - Console.WriteLine($"CodeQL CLI Bundle Version: {config.CodeQLCLIBundle}"); - Console.WriteLine($"----------------------------------"); - Console.WriteLine("(hint: use `qlt codeql set` to modify these values.)"); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs deleted file mode 100644 index 9fa81ea..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Pack/PackFeatureMain.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Features.Pack.Commands; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Pack -{ - public class PackFeatureMain : IToolkitFeature - { - - readonly static PackFeatureMain instance; - readonly PackCommandFeature commandFeature; - - static PackFeatureMain() - { - instance = new PackFeatureMain(); - } - - private PackFeatureMain() - { - commandFeature = new PackCommandFeature(); - } - public static PackFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var packCommand = new Command("pack", "Features CodeQL pack management and publication."); - parentCommand.Add(packCommand); - - Log.G().LogInformation("Registering scaffolding submodule."); - commandFeature.Register(packCommand); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs deleted file mode 100644 index d5bb08c..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Commands/QueryCommandFeature.cs +++ /dev/null @@ -1,42 +0,0 @@ -using CodeQLToolkit.Features.Query.Commands.Targets; -using CodeQLToolkit.Features.Query.Scaffolding; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Commands -{ - public class QueryCommandFeature : FeatureBase, IToolkitCommandFeature - { - public QueryCommandFeature() - { - FeatureName = "Query"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - var runCommand = new Command("run", "Functions pertaining to running query-related commands."); - parentCommand.Add(runCommand); - - // a command that installs query packs - var installPacksQueryCommand = new Command("install-packs", "Installs CodeQL packs within the repository."); - - runCommand.Add(installPacksQueryCommand); - - installPacksQueryCommand.SetHandler((basePath) => new InstallQueryPacksCommandTarget() { Base = basePath }.Run(), Globals.BasePathOption); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs deleted file mode 100644 index 255faf7..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Commands/Targets/InstallQueryPacksCommandTarget.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Commands.Targets -{ - public class InstallQueryPacksCommandTarget : CommandTarget - { - public override void Run() - { - Log.G().LogInformation("Finding all qlpacks..."); - - // starting at the base path, find all qlpacks and install them - string[] files = Directory.GetFiles(Base, "qlpack.yml", SearchOption.AllDirectories); - - Log.G().LogInformation($"Got {files.Length} packs..."); - - foreach ( string file in files ) - { - Log.G().LogInformation($"Installing qlpack {file}..."); - - using(Process process = new Process()) - { - process.StartInfo.FileName = "codeql"; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = false; - process.StartInfo.Arguments = $"pack install {file}"; - process.Start(); - - process.WaitForExit(); - - if(process.ExitCode !=0) - { - DieWithError($"Failed to install query pack {file}."); - } - } - - } - - Log.G().LogInformation($"Installed {files.Length} packs."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs deleted file mode 100644 index 2b725e0..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/QueryLifecycleFeature.cs +++ /dev/null @@ -1,56 +0,0 @@ -using CodeQLToolkit.Features.Query.Lifecycle.Targets; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using CodeQLToolkit.Shared.Types; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Lifecycle -{ - public class QueryLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public QueryLifecycleFeature() - { - FeatureName = "Query"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var initCommand = new Command("init", "Initialize query support in this repository."); - - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - - initCommand.AddOption(overwriteExistingOption); - - parentCommand.Add(initCommand); - - initCommand.SetHandler((basePath, overwriteExisting) => - { - Log.G().LogInformation("Executing init command..."); - - - new InitLifecycleTarget() - { - FeatureName = FeatureName, - Base = basePath, - OverwriteExisting = overwriteExisting - - }.Run(); - - - }, Globals.BasePathOption, overwriteExistingOption); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs deleted file mode 100644 index c9ac216..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Lifecycle/Targets/InitLifecycleTarget.cs +++ /dev/null @@ -1,25 +0,0 @@ -using CodeQLToolkit.Features.Query.Scaffolding.Targets; -using CodeQLToolkit.Shared.Feature; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Query.Lifecycle.Targets -{ - public class InitLifecycleTarget : ILifecycleTarget - { - public override void Run() - { - Log.G().LogInformation("Initializing new query development workspace..."); - - Directory.CreateDirectory(Base); - - var workspaceLocation = Path.Combine(Base, "codeql-workspace.yml"); - - WriteTemplateIfOverwriteOrNotExists("codeql-workspace", workspaceLocation, "CodeQL Workspace"); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs deleted file mode 100644 index 6bc009e..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/QueryFeatureMain.cs +++ /dev/null @@ -1,52 +0,0 @@ -using CodeQLToolkit.Features.Query.Commands; -using CodeQLToolkit.Features.Query.Lifecycle; -using CodeQLToolkit.Features.Query.Scaffolding; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Logging; -using Microsoft.Extensions.Logging; -using System.CommandLine; - -namespace CodeQLDevelopmentLifecycleToolkit.Features.Query -{ - - public class QueryFeatureMain : IToolkitFeature - { - readonly QueryScaffoldFeature scaffoldFeature; - readonly QueryCommandFeature commandFeature; - readonly QueryLifecycleFeature lifecycleFeature; - - - readonly static QueryFeatureMain instance; - - static QueryFeatureMain() { - instance = new QueryFeatureMain(); - } - private QueryFeatureMain() - { - scaffoldFeature = new QueryScaffoldFeature(); - commandFeature = new QueryCommandFeature(); - lifecycleFeature = new QueryLifecycleFeature(); - } - - public static QueryFeatureMain Instance { get { return instance; } } - - public int Run() - { - - Console.WriteLine("[Query] RUNNING QUERY FEATURE"); - - return 0; - } - - public void Register(Command parentCommand) - { - var queryCommand = new Command("query", "Use the features related to query creation and execution."); - parentCommand.Add(queryCommand); - - scaffoldFeature.Register(queryCommand); - commandFeature.Register(queryCommand); - lifecycleFeature.Register(queryCommand); - - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs deleted file mode 100644 index 6b16403..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs +++ /dev/null @@ -1,77 +0,0 @@ -using CodeQLToolkit.Features.Query.Scaffolding.Targets; -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Options; -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Query.Scaffolding -{ - public class QueryScaffoldFeature : FeatureBase, IToolkitScaffoldingFeature - { - public QueryScaffoldFeature() { - FeatureName = "Query"; - } - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT}; } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering scaffolding submodule."); - - var scaffoldCommand = new Command("generate", "Functions pertaining to generating query-related artifacts."); - parentCommand.Add(scaffoldCommand); - - // add the types of things we can scaffold. - var newQueryCommand = new Command("new-query", "Generates a new query and associated tests. Optionally will generate a new query pack if required."); - - var createQueryPackOption = new Option("--create-query-pack", () => true, "Create a new query pack if none exists."); - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - - var createTestsOption = new Option("--create-tests", ()=> true, "Create a new unit test for this query if it doesn't already exist."); - var queryNameOption = new Option("--query-name", "Name of the query. Note: Do not specify the `.ql` extension in naming your query.") { IsRequired = true }; - var queryLanguageOption = new Option("--language", $"The language to generate a query for.") { IsRequired = true} - .FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var queryPackOption = new Option("--pack", "The name of the query pack to place this query in.") { IsRequired = true }; - var queryPackScopeOption = new Option("--scope", "The scope to use") { IsRequired = true }; - - newQueryCommand.Add(createQueryPackOption); - newQueryCommand.Add(createTestsOption); - newQueryCommand.Add(queryNameOption); - newQueryCommand.Add(queryLanguageOption); - newQueryCommand.Add(queryPackOption); - newQueryCommand.Add(overwriteExistingOption); - newQueryCommand.Add(queryPackScopeOption); - - scaffoldCommand.Add(newQueryCommand); - - { - newQueryCommand.SetHandler((createQueryPack, createTests, queryName, queryLangauge, queryPack, basePath, overwriteExisting, queryPackScope) => - { - - if (!IsSupportedLangauge(queryLangauge)) - { - DieWithError($"Unsupported langauge `{queryLangauge}`"); - } - - new NewQueryScaffoldTarget() - { - Name = queryName, - Language = LanguageTypeHelper.LanguageTypeFromOptionString(queryLangauge), - Base = basePath, - QueryPack = queryPack, - QueryPackScope = queryPackScope, - CreateTests = createTests, - CreateQueryPack = createQueryPack, - OverwriteExisting = overwriteExisting, - FeatureName = FeatureName - }.Run(); - - }, createQueryPackOption, createTestsOption, queryNameOption, queryLanguageOption, queryPackOption, Globals.BasePathOption, overwriteExistingOption, queryPackScopeOption); - } - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs deleted file mode 100644 index 36f8fa3..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs +++ /dev/null @@ -1,76 +0,0 @@ -using CodeQLToolkit.Shared.Template; -using CodeQLToolkit.Shared.Utils; -using System.Reflection; - -namespace CodeQLToolkit.Features.Query.Scaffolding.Targets -{ - public class NewQueryScaffoldTarget : ScaffoldTarget - { - public string QueryPack { get; set; } - public bool CreateTests { get; set; } - public bool CreateQueryPack { get; set; } - public string QueryPackScope { get; set; } - - public override void Run() - { - Log.G().LogInformation("Creating new query..."); - - var query = new Shared.Utils.Query() - { - Language = Language, - QueryPackName = QueryPack, - Name = Name, - Scope = QueryPackScope, - Base = Base - }; - - Directory.CreateDirectory(query.QueryFileDir); - - WriteTemplateIfOverwriteOrNotExists("new-query", query.QueryFilePath, "new query", new - { - language = query.Language, - queryPackName = query.QueryPackName, - queryName = query.Name, - description = "Replace this text with a description of your query.", - qlLanguageImport = query.GetLanguageImportForLangauge() - }); - - if (CreateQueryPack) - { - WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new - { - queryPackScope = query.Scope, - queryPackName = query.QueryPackName - }); - } - - if (CreateTests) - { - Directory.CreateDirectory(query.QueryFileTestDir); - - // the source file to use - WriteTemplateIfOverwriteOrNotExists("test", query.QueryFileTestPath, "new query test file", new {}); - - // the expected file - WriteTemplateIfOverwriteOrNotExists("expected", query.QueryTestExpectedFile, "new query test expected file", new { }); - - // the the qlref file - WriteTemplateIfOverwriteOrNotExists("testref", query.QueryFileQLRefPath, "new query test ref", new { - queryName = query.Name - }); - - // the qlpack file - WriteTemplateIfOverwriteOrNotExists("qlpack-test", query.QueryPackTestPath, "new query test pack", new { - queryPackDependency = $"{query.Scope}/{query.QueryPackName}", - queryPackScope = query.Scope, - queryPackName = query.QueryTestPackName - }); - - } - else - { - Log.G().LogInformation($"Not creating tests because test creation was disabled."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid deleted file mode 100644 index 26362dc..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/codeql-workspace.liquid +++ /dev/null @@ -1,3 +0,0 @@ -provide: - - '**/qlpack.yml' - - '**/codeql-workspace.yml' \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid deleted file mode 100644 index 7962166..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/expected.liquid +++ /dev/null @@ -1 +0,0 @@ -// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid deleted file mode 100644 index 5f28270..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-dataflow-query.liquid +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid deleted file mode 100644 index f5c42c4..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/new-query.liquid +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @id {{language}}/{{query_pack_name}}/{{query_name}} - * @name {{query_name}} - * @description {{description}} - * @kind problem - * @precision medium - * @problem.severity error - * @tags {{query_pack_name}} - */ - - import {{ql_language_import}} - - from Expr e - select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid deleted file mode 100644 index c3a1a45..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-query.liquid +++ /dev/null @@ -1,7 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -dependencies: - codeql/cpp-all: 0.3.5 \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid deleted file mode 100644 index 560a515..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/qlpack-test.liquid +++ /dev/null @@ -1,8 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -extractor: cpp -dependencies: - {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid deleted file mode 100644 index f39be51..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/test.liquid +++ /dev/null @@ -1 +0,0 @@ -// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid deleted file mode 100644 index d083780..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/cpp/testref.liquid +++ /dev/null @@ -1 +0,0 @@ -{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid deleted file mode 100644 index 7962166..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/expected.liquid +++ /dev/null @@ -1 +0,0 @@ -// not implemented \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid deleted file mode 100644 index 5f28270..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-dataflow-query.liquid +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid deleted file mode 100644 index f5c42c4..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/new-query.liquid +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @id {{language}}/{{query_pack_name}}/{{query_name}} - * @name {{query_name}} - * @description {{description}} - * @kind problem - * @precision medium - * @problem.severity error - * @tags {{query_pack_name}} - */ - - import {{ql_language_import}} - - from Expr e - select e, "Replace this with your query." \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid deleted file mode 100644 index 8120bfc..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-query.liquid +++ /dev/null @@ -1,7 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -dependencies: - codeql/javascript-all: "^0.6.3" \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid deleted file mode 100644 index 515d065..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/qlpack-test.liquid +++ /dev/null @@ -1,8 +0,0 @@ -name: {{query_pack_scope}}/{{query_pack_name}} -version: 0.0.0 -description: Default description -suites: -license: -extractor: javascript -dependencies: - {{query_pack_dependency}}: '*' diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid deleted file mode 100644 index f39be51..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/test.liquid +++ /dev/null @@ -1 +0,0 @@ -// replace with your test file \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid b/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid deleted file mode 100644 index d083780..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Query/Templates/Query/javascript/testref.liquid +++ /dev/null @@ -1 +0,0 @@ -{{query_name}}/{{query_name}}.ql \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs deleted file mode 100644 index 9b596cb..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseExecuteUnitTestsCommandTarget.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.VisualBasic; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public abstract class BaseExecuteUnitTestsCommandTarget : CommandTarget - { - public int NumThreads { get; set; } - public string WorkDirectory { get; set; } - public string RunnerOS { get; set; } - public string CLIVersion { get; set; } - public string STDLibIdent { get; set; } - public string ExtraCodeQLArgs { get; set; } - } -} - diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs deleted file mode 100644 index 36d79f6..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/BaseGetMatrixCommandTarget.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public abstract class BaseGetMatrixCommandTarget : CommandTarget - { - public string[] OSVersions { get; set; } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs deleted file mode 100644 index 230e217..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/ExecuteUnitTestsCommandTarget.cs +++ /dev/null @@ -1,112 +0,0 @@ -using CodeQLToolkit.Features.Test.Lifecycle.Models; -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions -{ - - [AutomationType(AutomationType.ACTIONS)] - public class ExecuteUnitTestsCommandTarget : BaseExecuteUnitTestsCommandTarget - { - - public override void Run() - { - Log.G().LogInformation($"Preparing to execute unit tests found in {Base} for Language {Language}..."); - - // get a directory to work in - var tmpDirectory = WorkDirectory; - - var languageRoot = Path.Combine(Base, Language); - - // check if the language root exists - if (!Directory.Exists(languageRoot)){ - DieWithError($"Language root {languageRoot} does not exist so unit tests cannnot be run."); - } - - // Identify the test directories. - string[] dirs = Directory.GetDirectories(languageRoot, "test", SearchOption.AllDirectories); - - Log.G().LogInformation($"Test Directory Inventory {Language}"); - Log.G().LogInformation($"-----------------------------------"); - - foreach ( string dir in dirs) - { - Log.G().LogInformation($"Found test directory: {dir}"); - } - - var transformedDirs = dirs.Select(dir => Path.GetRelativePath(Base, dir)); - - if(dirs.Length == 0) - { - DieWithError($"No tests detected. Please create unit tests before running this command."); - } - - Parallel.For(0, NumThreads, - slice => { - - TestReport report = new TestReport() - { - RunnerOS = RunnerOS, - CLIVersion = CLIVersion, - STDLibIdent = STDLibIdent, - Language = Language, - Slice = slice, - NumSlices = NumThreads - }; - - var workingDirectory = Path.GetFullPath(Base); - var testPathString = string.Join(" ", transformedDirs); - var outFileReport = Path.Combine(tmpDirectory, report.FileName); - - Log.G().LogInformation($"Executing tests in working directory {workingDirectory}."); - Log.G().LogInformation($"Test Paths: {testPathString}"); - Log.G().LogInformation($"Slice: {slice} of {NumThreads}"); - Log.G().LogInformation($"Report File: {outFileReport}..."); - - using (Process process = new Process()) - { - process.StartInfo.FileName = "codeql"; - process.StartInfo.WorkingDirectory = workingDirectory; - process.StartInfo.UseShellExecute = false; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.RedirectStandardError = false; - process.StartInfo.Arguments = $"test run {ExtraCodeQLArgs} --failing-exitcode=122 --slice={slice+1}/{NumThreads} --ram=2048 --format=json --search-path={Language} {testPathString}"; - - process.Start(); - - // needed for STDOUT redirection - var output = process.StandardOutput.ReadToEnd(); - - File.WriteAllText(outFileReport, output); - - process.WaitForExit(); - - if (process.ExitCode != 0) - { - // This fine - if(process.ExitCode == 122) - { - Log.G().LogError($"One more more unit tests failed. Please see the output of the validation step for more information about failed tests cases."); - } - // this is not fine - else - { - DieWithError($"Non-test related error while running unit tests. Please check debug output for more infomation."); - } - } - } - } - ); - - - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs deleted file mode 100644 index 666748d..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/Actions/GetMatrixCommandTarget.cs +++ /dev/null @@ -1,75 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System.Text.Json; - -namespace CodeQLToolkit.Features.Test.Commands.Targets.Actions -{ - [AutomationType(AutomationType.ACTIONS)] - public class GetMatrixCommandTarget : BaseGetMatrixCommandTarget - { - public override void Run() - { - - // based on the current configuration of the repository, generate a matrix - // for actions, it looks like this: - - // { - // "include": [ - // { - // "codeql_cli": "2.12.6", - // "codeql_standard_library": "codeql-cli/v2.12.6", - // "codeql_cli_bundle": "codeql-bundle-20230403", - // "os": "ubuntu-latest", - // "codeql_standard_library_ident": "codeql-cli_v2.12.6" - // } - // ] - // } - - // For now, we only support a single version but this is easy to extend. The options for runners are what create different matrix types. - var c = new QLTConfig() - { - Base = Base - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - List configs = new List(); - - foreach(var os in OSVersions) - { - Log.G().LogInformation($"Creating matrix for {os}"); - - configs.Add(new - { - codeql_cli = config.CodeQLCLI, - codeql_standard_library = config.CodeQLStandardLibrary, - codeql_cli_bundle = config.CodeQLCLIBundle, - os = os, - codeql_standard_library_ident = config.CodeQLStandardLibraryIdent - }); - } - - var data = new - { - include = configs - }; - - var json = JsonSerializer.Serialize(data); - - var matrixVariable = $"matrix={json}"; - - string envFile = Environment.GetEnvironmentVariable("GITHUB_OUTPUT"); - - Log.G().LogInformation($"Writing matrix output {matrixVariable} to {envFile}"); - - File.AppendAllText(envFile, matrixVariable ); - - Log.G().LogInformation($"Done."); - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs deleted file mode 100644 index 2fc347b..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/Targets/ValidateUnitTestsCommand.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets -{ - - - public class UnitTestResult - { - public string test { get; set; } - public bool pass { get; set; } - public string failureStage { get; set; } - public string failureDescription { get; set; } - public object[] messages { get; set; } - public int compilationMs { get; set; } - public int evaluationMs { get; set; } - public string expected { get; set; } - public string actual { get; set; } - public string[] diff { get; set; } - } - - public class ValidateUnitTestsCommand : CommandTarget - { - public string ResultsDirectory { get; set; } - - public bool PrettyPrint { get; set; } - - public override void Run() - { - Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); - - string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); - - List unitTestResults = new List(); - - foreach (string result in results) - { - using (StreamReader r = new StreamReader(result)) - { - string json = r.ReadToEnd(); - List items = JsonConvert.DeserializeObject>(json); - - foreach(var item in items) - { - unitTestResults.Add(item); - } - } - } - - - int totalCases = unitTestResults.Count; - int currentCase = 0; - - foreach (var item in unitTestResults) - { - currentCase++; - - if (item.pass) - { - if(PrettyPrint) - { - Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : PASSED "); - Log.G().LogError($"+----------------------------------------------+"); - } - } - else - { - if (PrettyPrint) - { - Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - if (item.failureStage == "RESULT") - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : RESULT"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST DIFFERENCES |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - - - foreach (var diff in item.diff) - { - Log.G().LogError($"| {diff}"); - } - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FAILURE DESCRIPTION |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - Log.G().LogError($"| {item.failureDescription}"); - - - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - } - } - } - - var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); - - if (failedTests.Length > 0 && !PrettyPrint) - { - DieWithError("One or more failures during run unit tests."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs deleted file mode 100644 index f9866ee..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Commands/TestCommandFeature.cs +++ /dev/null @@ -1,160 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands.Targets; -using CodeQLToolkit.Features.Test.Lifecycle; -using CodeQLToolkit.Shared.Types; -using CodeQLToolkit.Shared.Utils; -using Microsoft.VisualBasic; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public class TestCommandFeature : FeatureBase, IToolkitLifecycleFeature - { - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; } - - public TestCommandFeature() - { - FeatureName = "Test"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - - var runCommand = new Command("run", "Functions pertaining to running test-related commands."); - parentCommand.Add(runCommand); - - // a command that gets the matrix configuration - var getMatrixTestCommand = new Command("get-matrix", "Gets a CI/CD matrix based on the current configuration."); - - var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; - getMatrixTestCommand.Add(matrixOSVersion); - - // a command that runs the actual tests - var unitTestsCommand = new Command("execute-unit-tests", "Runs unit tests within a repository based on the current configuration."); - - var numThreadsOption = new Option("--num-threads", () => 4, "The number of threads to use for runner. For best performance, do not exceed the number of physical cores on your system.") { IsRequired = true }; - var workDirectoryOption = new Option("--work-dir", () => Path.GetTempPath(), "Where to place intermediate execution output files.") { IsRequired = true }; - var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var runnerOSOption = new Option("--runner-os", $"Label for the operating system running these tests.") { IsRequired = true }; - //var cliVersionOption = new Option("--cli-version", $"The version of the cli running the tests.") { IsRequired = true }; - //var stdLibIdentOption = new Option("--stdlib-ident", $"A string identifying the standard library used.") { IsRequired = true }; - var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; - - unitTestsCommand.Add(numThreadsOption); - unitTestsCommand.Add(workDirectoryOption); - unitTestsCommand.Add(languageOption); - unitTestsCommand.Add(runnerOSOption); - //unitTestsCommand.Add(cliVersionOption); - //unitTestsCommand.Add(stdLibIdentOption); - unitTestsCommand.Add(extraCodeQLOptions); - - // a command validates the tests - var validateUnitTestsCommand = new Command("validate-unit-tests", "Validates a unit test run in a fashion suitable for use in CI/CD systems."); - - var resultsDirectoryOption = new Option("--results-directory", "Where to find the intermediate execution output files.") { IsRequired = true }; - var prettyPrintOption = new Option("--pretty-print", () => false, "Pretty print test output in a compact format. Note this will not exit with a failure code if tests fail.") { IsRequired = true }; - - validateUnitTestsCommand.Add(resultsDirectoryOption); - validateUnitTestsCommand.Add(prettyPrintOption); - - runCommand.Add(getMatrixTestCommand); - runCommand.Add(unitTestsCommand); - runCommand.Add(validateUnitTestsCommand); - - getMatrixTestCommand.SetHandler((basePath, automationType, osVersions) => { - - Log.G().LogInformation("Executing get-matrix command..."); - - // dispatch at runtime to the correct automation type - var featureTarget = AutomationFeatureFinder - .FindTargetForAutomationType( - AutomationTypeHelper.AutomationTypeFromString(automationType) - ); - - featureTarget.Base = basePath; - featureTarget.OSVersions = osVersions.Split(","); - - featureTarget.Run(); - - }, Globals.BasePathOption, Globals.AutomationTypeOption, matrixOSVersion); - - //stdLibIdent - unitTestsCommand.SetHandler((basePath, automationType, numThreads, workDirectory, language, runnerOS, extraArgs) => { - - Log.G().LogInformation("Executing execute-unit-tests command..."); - - // dispatch at runtime to the correct automation type - var featureTarget = AutomationFeatureFinder - .FindTargetForAutomationType( - AutomationTypeHelper.AutomationTypeFromString(automationType) - ); - - // lookup cliVersion and stdLibIdent - var c = new QLTConfig() - { - Base = basePath - }; - - if (!File.Exists(c.CodeQLConfigFilePath)) - { - ProcessUtils.DieWithError($"Cannot read values from missing file {c.CodeQLConfigFilePath}"); - } - - var config = c.FromFile(); - - featureTarget.Base = basePath; - featureTarget.NumThreads = numThreads; - featureTarget.WorkDirectory = workDirectory; - featureTarget.Language = language; - featureTarget.RunnerOS = runnerOS; - featureTarget.CLIVersion = config.CodeQLCLI; - featureTarget.STDLibIdent = config.CodeQLStandardLibraryIdent; - featureTarget.ExtraCodeQLArgs = extraArgs; - - featureTarget.Run(); - - }, Globals.BasePathOption, - Globals.AutomationTypeOption, - numThreadsOption, - workDirectoryOption, - languageOption, - runnerOSOption, - extraCodeQLOptions - ); - - - validateUnitTestsCommand.SetHandler((resultsDirectory, prettyPrint) => - { - Log.G().LogInformation("Executing validate-unit-tests command..."); - - new ValidateUnitTestsCommand() - { - ResultsDirectory = resultsDirectory, - PrettyPrint = prettyPrint - }.Run(); - - - }, resultsDirectoryOption, prettyPrintOption); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs deleted file mode 100644 index d3bdad8..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/BaseLifecycleTarget.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle -{ - abstract public class BaseLifecycleTarget : ILifecycleTarget - { - public int NumThreads { get; set; } - public string UseRunner { get; set; } - - public string ExtraArgs { get; set; } - - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs deleted file mode 100644 index ffb2635..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Models/TestReport.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle.Models -{ - public class TestReport - { - public string RunnerOS { get; set; } - public string CLIVersion { get; set; } - public string STDLibIdent { get; set; } - - public string Language { get; set; } - - public int Slice { get; set; } - public int NumSlices { get; set; } - - - public string FileName { - - get { - - var savePath = $"test_report_{RunnerOS}_{CLIVersion}_{STDLibIdent}_slice_{Slice}_of_{NumSlices}.json"; - - return savePath; - } - } - - - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs deleted file mode 100644 index b505101..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions -{ - [AutomationType(AutomationType.ACTIONS)] - public class InitLifecycleTarget : BaseLifecycleTarget - { - public InitLifecycleTarget() - { - AutomationType = AutomationType.ACTIONS; - } - public override void Run() - { - Log.G().LogInformation("Running init command..."); - - // temporarily disable the language resolution - var tmpLanguage = Language; - Language = null; - - var codeqlArgs = "--threads=0"; - - if(ExtraArgs!= null && ExtraArgs.Length > 0) - { - codeqlArgs = $"{codeqlArgs} {ExtraArgs}"; - } - - WriteTemplateIfOverwriteOrNotExists("install-codeql", Path.Combine(Base, ".github", "actions", "install-codeql", "action.yml"), "install-codeql action"); - WriteTemplateIfOverwriteOrNotExists("install-qlt", Path.Combine(Base, ".github", "actions", "install-qlt", "action.yml"), "install-qlt action"); - WriteTemplateIfOverwriteOrNotExists("run-unit-tests", Path.Combine(Base, ".github", "workflows", $"run-codeql-unit-tests-{tmpLanguage}.yml"), $"Run CodeQL Unit Tests ({Language})", new - { - numThreads = NumThreads, - useRunner = UseRunner, - language = tmpLanguage, - codeqlArgs = codeqlArgs - }); - - Language = tmpLanguage; - - var message = @"------------------------------------------ -Your repository now has the CodeQL Unit Test Runner installed in `.github/workflows/`. Additionally, -QLT has installed necessary actions for keeping your version of QLT and CodeQL current in `.github/actions/install-qlt` and -`.github/actions/install-codeql`. - -Note that, by default, your runner will use 4 threads and defaults to the `ubuntu-latest` runner. - -You can modify the number of threads used by using the `--num-threads` argument and you can select a different -runner with the `--use-runner` argument. - -In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings. - -(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; - - - - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs deleted file mode 100644 index ebdd333..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Lifecycle/TestLifecycleFeature.cs +++ /dev/null @@ -1,81 +0,0 @@ -using CodeQLToolkit.Features.Test.Lifecycle.Targets; -using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions; -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; -using System.Reflection; - -namespace CodeQLToolkit.Features.Test.Lifecycle -{ - public class TestLifecycleFeature : FeatureBase, IToolkitLifecycleFeature - { - public TestLifecycleFeature() - { - FeatureName = "Test"; - } - - public override LanguageType[] SupportedLangauges - { - get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering lifecycle submodule."); - - var initCommand = new Command("init", "Initialize testing in this repository."); - - var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); - var numThreadsOption = new Option("--num-threads", () => 4, "Number of threads to use during test execution."); - var useRunnerOption = new Option("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners."); - var languageOption = new Option("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var extraCodeQLOptions = new Option("--codeql-args", $"Extra arguments to pass to CodeQL.") { IsRequired = false }; - - initCommand.AddOption(overwriteExistingOption); - initCommand.AddOption(numThreadsOption); - initCommand.AddOption(useRunnerOption); - initCommand.AddOption(languageOption); - initCommand.AddOption(extraCodeQLOptions); - - - parentCommand.Add(initCommand); - - - - initCommand.SetHandler((basePath, automationType, overwriteExisting, numThreads, useRunner, language, extraArgs) => - { - Log.G().LogInformation("Executing init command..."); - - // - // dispatch at runtime to the correct automation type - // - var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType(AutomationTypeHelper.AutomationTypeFromString(automationType)); - - // setup common params - featureTarget.FeatureName = FeatureName; - featureTarget.Base = basePath; - featureTarget.OverwriteExisting = overwriteExisting; - featureTarget.NumThreads = numThreads; - featureTarget.UseRunner = useRunner; - featureTarget.Language = language; - featureTarget.ExtraArgs = extraArgs; - featureTarget.Run(); - - }, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, numThreadsOption, useRunnerOption, languageOption, extraCodeQLOptions); - - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid deleted file mode 100644 index ddb56ba..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-codeql.liquid +++ /dev/null @@ -1,109 +0,0 @@ -name: Fetch CodeQL CLI and queries -description: | - Fetches a CodeQL CLI and a copy of the CodeQL standard libraries at the specified versions. -inputs: - codeql-cli-version: - description: | - The version of the CodeQL CLI to be downloaded. - required: false - default: 'latest' - - codeql-stdlib-version: - description: | - The tag or commit to use from the CodeQL Standard Library - required: false - default: 'latest' - - add-to-path: - description: | - Add the CodeQL CLI to the system path - required: false - default: 'true' - - codeql-home: - description: | - The directory to store the CodeQL CLI and Standard Library. - A fixed location can be used for caching the tooling. - required: false -outputs: - codeql-home: - description: 'The directory containing the CodeQL CLI and CodeQL Standard Library' - value: ${{ steps.install-codeql.outputs.codeql-home }} - -runs: - using: composite - steps: - - name: Install CodeQL - id: install-codeql - env: - RUNNER_OS: ${{ runner.os }} - RUNNER_TEMP: ${{ runner.temp }} - CODEQL_CLI_VERSION: ${{ inputs.codeql-cli-version }} - CODEQL_STDLIB_VERSION: ${{ inputs.codeql-stdlib-version }} - GITHUB_TOKEN: ${{ github.token }} - ADD_TO_PATH: ${{ inputs.add-to-path }} - CODEQL_HOME: ${{ inputs.codeql-home }} - shell: bash - run: | - echo "::debug::Determining CodeQL release for $RUNNER_OS" - case $RUNNER_OS in - "Linux") - RELEASE_PATTERN="codeql-linux64.zip" - ;; - "macOS") - RELEASE_PATTERN="codeql-osx64.zip" - ;; - "Windows") - RELEASE_PATTERN="codeql-win64.zip" - ;; - *) - echo "::error::Unsupported runner operating system $RUNNER_OS" - exit 1 - ;; - esac - echo "::debug::Selected $RELEASE_PATTERN" - - if [ "$CODEQL_HOME" == "" ] - then - echo "::debug::Creating temporary CodeQL home" - CODEQL_HOME=$(mktemp -d -p $RUNNER_TEMP codeql-home-XXXXXXXXXX) - else - echo "::debug::Creating CodeQL home at $CODEQL_HOME" - mkdir -p $CODEQL_HOME - fi - - echo "::debug::Changing directory to $CODEQL_HOME" - pushd $CODEQL_HOME - - echo "::debug::Downloading CodeQL CLI version $CODEQL_CLI_VERSION" - if [ "$CODEQL_CLI_VERSION" == "latest" ] - then - gh release download --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN - else - gh release download "v${CODEQL_CLI_VERSION}" --repo https://github.com/github/codeql-cli-binaries --pattern $RELEASE_PATTERN - fi - echo "::debug::Unpacking CodeQL CLI" - unzip -q $RELEASE_PATTERN - - echo "::debug::Cloning CodeQL standard library" - git clone https://github.com/github/codeql.git codeql-stdlib - - if [ "$CODEQL_STDLIB_VERSION" != "latest" ] - then - pushd codeql-stdlib - echo "::debug::Switching to revision $CODEQL_STDLIB_VERSION" - git checkout $CODEQL_STDLIB_VERSION - popd - fi - - if [ "$ADD_TO_PATH" == "true" ] - then - echo "::debug::Adding CodeQL CLI path '$(pwd)/codeql' to system path" - echo "$(pwd)/codeql" >> $GITHUB_PATH - fi - - echo "::debug::Setting output parameter codeql-home to $(pwd)" - echo "codeql-home=$(pwd)" >> $GITHUB_OUTPUT - - popd - echo "::debug::Done." diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid deleted file mode 100644 index b1e7fa1..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/install-qlt.liquid +++ /dev/null @@ -1,88 +0,0 @@ -name: Fetch and Install QLT -description: | - Fetches and installs QLT. -inputs: - qlt-version: - description: | - The version of QLT to be downloaded. - required: false - default: 'latest' - - add-to-path: - description: | - Add QLT to the system path - required: false - default: 'true' - - token: - description: | - Token to use for auth - required: true - - -outputs: - qlt-home: - description: 'The directory containing the QLT installation' - value: ${{ steps.install-qlt.outputs.qlt-home }} - -runs: - using: composite - steps: - - name: Install QLT - id: install-qlt - env: - RUNNER_OS: ${{ runner.os }} - RUNNER_TEMP: ${{ runner.temp }} - # GITHUB_TOKEN: ${{ github.token }} - GITHUB_TOKEN: ${{ inputs.token }} - ADD_TO_PATH: ${{ inputs.add-to-path }} - QLT_VERSION: ${{ inputs.qlt-version }} - QLT_HOME: ${{ inputs.qlt-home }} - shell: bash - run: | - echo -e "\e[0;32m[QLT]\e[0m Determining QLT release for $RUNNER_OS" - case $RUNNER_OS in - "Linux") - RELEASE_PATTERN="qlt-linux-x86_64.zip" - ;; - *) - echo "::error::Unsupported runner operating system $RUNNER_OS" - exit 1 - ;; - esac - echo -e "\e[0;32m[QLT]\e[0m Selected $RELEASE_PATTERN" - - if [ "$QLT_HOME" == "" ] - then - echo -e "\e[0;32m[QLT]\e[0m Creating temporary QLT home" - QLT_HOME=$(mktemp -d -p $RUNNER_TEMP qlt-home-XXXXXXXXXX) - else - echo -e "\e[0;32m[QLT]\e[0m Creating CodeQL home at $QLT_HOME" - mkdir -p $QLT_HOME - fi - - echo -e "\e[0;32m[QLT]\e[0m Changing directory to $QLT_HOME" - pushd $QLT_HOME - - echo -e "\e[0;32m[QLT]\e[0m Downloading QLT version $QLT_VERSION" - if [ "$QLT_VERSION" == "latest" ] - then - # download the actual bundle - gh release download -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" - else - gh release download "$QLT_VERSION" -R advanced-security/codeql-development-toolkit --pattern "$RELEASE_PATTERN" - fi - echo -e "\e[0;32m[QLT]\e[0m Unpacking QLT" - unzip $RELEASE_PATTERN - - if [ "$ADD_TO_PATH" == "true" ] - then - echo -e "\e[0;32m[QLT]\e[0m Adding QLT '$(pwd)/qlt' to system path" - echo "$(pwd)" >> $GITHUB_PATH - fi - - echo -e "\e[0;32m[QLT]\e[0m Setting output parameter qlt-home to $(pwd)" - echo "qlt-home=$(pwd)" >> $GITHUB_OUTPUT - - popd - echo -e "\e[0;32m[QLT]\e[0m Done." diff --git a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid b/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid deleted file mode 100644 index 7177427..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/Templates/Test/Actions/run-unit-tests.liquid +++ /dev/null @@ -1,129 +0,0 @@ -name: ⚙️ CodeQL - Run Unit Tests ({{language}}) -{% raw %} - -on: - push: - branches: - - '**' - pull_request: - branches: - - '**' - workflow_dispatch: - -jobs: - create-unit-test-matrix: - name: Create CodeQL Unit Test Matrix - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.export-unit-test-matrix.outputs.matrix }} - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true -{% endraw %} - - name: Export unit test matrix - id: export-unit-test-matrix - run: | - qlt test run get-matrix --os-version {{ use_runner }} -{% raw %} - run-test-suites: - name: Run Unit Tests - needs: create-unit-test-matrix - - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: ${{ fromJSON(needs.create-unit-test-matrix.outputs.matrix) }} - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true - - - name: Install CodeQL - id: install-codeql - uses: ./.github/actions/install-codeql - with: - codeql-cli-version: ${{ matrix.codeql_cli }} - codeql-stdlib-version: ${{ matrix.codeql_standard_library }} - add-to-path: true - - - name: Verify Versions of Tooling - shell: bash - run: | - echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}" - echo -e "Checking CodeQL Version:" - codeql --version - - echo -e "Checking QLT Version:" - echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}" - qlt version - - - name: Install QL Packs - shell: bash - run: | - qlt query run install-packs - - - name: Run test suites - id: run-test-suites - env: - RUNNER_OS: ${{ runner.os }} - CODEQL_CLI: ${{ matrix.codeql_cli }} - CODEQL_STDLIB: ${{ matrix.codeql_standard_library }} - CODEQL_STDLIB_IDENT: ${{matrix.codeql_standard_library_ident}} - RUNNER_TMP: ${{ runner.temp }} - shell: bash - run: > -{% endraw %} - qlt test run execute-unit-tests - --codeql-args "{{ codeql_args }}" - --num-threads {{ num_threads }} - --language {{ language }} - --runner-os $RUNNER_OS - --work-dir $RUNNER_TMP -{% raw %} - - name: Upload test results - uses: actions/upload-artifact@v2 - with: - name: test-results-${{ runner.os }}-${{ matrix.codeql_cli }}-${{ matrix.codeql_standard_library_ident }} - path: | - ${{ runner.temp }}/test_report_${{ runner.os }}_${{ matrix.codeql_cli }}_${{ matrix.codeql_standard_library_ident }}_slice_*.json - if-no-files-found: error - - validate-test-results: - name: Validate test results - needs: [run-test-suites] - runs-on: ubuntu-latest - steps: - - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install QLT - id: install-qlt - uses: ./.github/actions/install-qlt - with: - qlt-version: 'latest' - add-to-path: true - - - name: Collect test results - uses: actions/download-artifact@v2 - - - name: Validate test results - run: | - qlt test run validate-unit-tests --results-directory . - qlt test run validate-unit-tests --pretty-print --results-directory . >> $GITHUB_STEP_SUMMARY - -{% endraw %} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs deleted file mode 100644 index c2c3bf4..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Test/TestFeatureMain.cs +++ /dev/null @@ -1,45 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands; -using CodeQLToolkit.Features.Test.Lifecycle; -using CodeQLToolkit.Shared.Feature; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Test -{ - public class TestFeatureMain : IToolkitFeature - - { - readonly TestLifecycleFeature lifecycleFeature; - readonly TestCommandFeature commandFeature; - readonly static TestFeatureMain instance; - - static TestFeatureMain() - { - instance = new TestFeatureMain(); - } - - private TestFeatureMain() - { - lifecycleFeature = new TestLifecycleFeature(); - commandFeature = new TestCommandFeature(); - } - public static TestFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var testCommand = new Command("test", "Features related to the running and processing of CodeQL Unit Tests."); - parentCommand.Add(testCommand); - - Log.G().LogInformation("Registering scaffolding submodule."); - lifecycleFeature.Register(testCommand); - - Log.G().LogInformation("Registering command submodule."); - commandFeature.Register(testCommand); - - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs deleted file mode 100644 index 2fc347b..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/Targets/ValidateUnitTestsCommand.cs +++ /dev/null @@ -1,138 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Test.Commands.Targets -{ - - - public class UnitTestResult - { - public string test { get; set; } - public bool pass { get; set; } - public string failureStage { get; set; } - public string failureDescription { get; set; } - public object[] messages { get; set; } - public int compilationMs { get; set; } - public int evaluationMs { get; set; } - public string expected { get; set; } - public string actual { get; set; } - public string[] diff { get; set; } - } - - public class ValidateUnitTestsCommand : CommandTarget - { - public string ResultsDirectory { get; set; } - - public bool PrettyPrint { get; set; } - - public override void Run() - { - Log.G().LogInformation($"Validating unit tests in {ResultsDirectory}"); - - string[] results = Directory.GetFiles(ResultsDirectory, "test_report_*", SearchOption.AllDirectories); - - List unitTestResults = new List(); - - foreach (string result in results) - { - using (StreamReader r = new StreamReader(result)) - { - string json = r.ReadToEnd(); - List items = JsonConvert.DeserializeObject>(json); - - foreach(var item in items) - { - unitTestResults.Add(item); - } - } - } - - - int totalCases = unitTestResults.Count; - int currentCase = 0; - - foreach (var item in unitTestResults) - { - currentCase++; - - if (item.pass) - { - if(PrettyPrint) - { - Console.WriteLine($" ✅ [PASS] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : PASSED "); - Log.G().LogError($"+----------------------------------------------+"); - } - } - else - { - if (PrettyPrint) - { - Console.WriteLine($"❌ [FAIL] ({currentCase} of {totalCases}) {item.test}"); - } - else - { - if (item.failureStage == "RESULT") - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : RESULT"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST DIFFERENCES |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - - - foreach (var diff in item.diff) - { - Log.G().LogError($"| {diff}"); - } - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - else - { - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| TEST CASE ({currentCase} of {totalCases}) : {Path.GetFileName(item.test)}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| STATUS : FAILED "); - Log.G().LogError($"| FAILURE TYPE : {item.failureStage}"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FAILURE DESCRIPTION |"); - Log.G().LogError($"+----------------------------------------------+"); - Log.G().LogError($"| FULL PATH : {item.test}"); - Log.G().LogError($"| {item.failureDescription}"); - - - Log.G().LogError($"+----------------------------------------------+"); - - Log.G().LogError($"\n\n\n\n"); - - } - } - } - } - - var failedTests = unitTestResults.Select(x=>x).Where(x=>x.pass==false).ToArray(); - - if (failedTests.Length > 0 && !PrettyPrint) - { - DieWithError("One or more failures during run unit tests."); - } - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs deleted file mode 100644 index 2e8db6d..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs +++ /dev/null @@ -1,60 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Test.Commands -{ - public class ValidationCommandFeature : FeatureBase, IToolkitLifecycleFeature - { - public override LanguageType[] SupportedLangauges { get => new LanguageType[] { - LanguageType.C, - LanguageType.CPP, - LanguageType.CSHARP, - LanguageType.JAVA, - LanguageType.JAVASCRIPT, - LanguageType.GO, - LanguageType.RUBY, - LanguageType.PYTHON - }; } - - public ValidationCommandFeature() - { - FeatureName = "Validation"; - } - - public void Register(Command parentCommand) - { - Log.G().LogInformation("Registering command submodule."); - - - var runCommand = new Command("run", "Functions pertaining running validation commands."); - parentCommand.Add(runCommand); - - var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); - - var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; - getMatrixTestCommand.Add(matrixOSVersion); - - runCommand.Add(getMatrixTestCommand); - - - getMatrixTestCommand.SetHandler(() => - { - Log.G().LogInformation("Executing validate-unit-tests command..."); - - //new ValidateUnitTestsCommand() - //{ - // ResultsDirectory = resultsDirectory, - // PrettyPrint = prettyPrint - //}.Run(); - - - }); - } - - public int Run() - { - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs b/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs deleted file mode 100644 index 30aad10..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Validation/Models/CodeQLCliResponseModel.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Features.Validation.Models -{ - public class CodeQLCliResponseModel - { - public string query { get; set; } - public string relativeName { get; set; } - public bool success { get; set; } - public Message[] messages { get; set; } - } - - public class Message - { - public string severity { get; set; } - public string message { get; set; } - public Position position { get; set; } - } - - public class Position - { - public string fileName { get; set; } - public int line { get; set; } - public int column { get; set; } - public int endLine { get; set; } - public int endColumn { get; set; } - } - -} diff --git a/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs b/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs deleted file mode 100644 index 1f8367f..0000000 --- a/src_backup/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs +++ /dev/null @@ -1,38 +0,0 @@ -using CodeQLToolkit.Features.Test.Commands; -using System.CommandLine; - -namespace CodeQLToolkit.Features.Validation -{ - public class ValidationFeatureMain : IToolkitFeature - - { - readonly ValidationCommandFeature commandFeature; - readonly static ValidationFeatureMain instance; - - static ValidationFeatureMain() - { - instance = new ValidationFeatureMain(); - } - - private ValidationFeatureMain() - { - commandFeature = new ValidationCommandFeature(); - } - public static ValidationFeatureMain Instance { get { return instance; } } - - public void Register(Command parentCommand) - { - var validationCommand = new Command("validation", "Features related to the validation of CodeQL Development Repositories."); - parentCommand.Add(validationCommand); - - Log.G().LogInformation("Registering command submodule."); - commandFeature.Register(validationCommand); - - } - - public int Run() - { - return 0; - } - } -} \ No newline at end of file diff --git a/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj b/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj deleted file mode 100644 index 506c392..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/CodeQLToolkit.Shared.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - - - - - diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs deleted file mode 100644 index 4ecfbf7..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/FeatureBase.cs +++ /dev/null @@ -1,36 +0,0 @@ -using CodeQLToolkit.Shared.Template; -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - abstract public class FeatureBase - { - public string FeatureName { get; set; } - - public virtual LanguageType[] SupportedLangauges { get; } = { }; - public bool IsSupportedLangauge(string language) - { - var strLangauges = SupportedLangauges.Select(x => x.ToOptionString()).ToArray(); - return strLangauges.Contains(language); - } - - public bool IsSupportedLangauge(LanguageType language) - { - return SupportedLangauges.Contains(language); - } - public string GetSupportedLangaugeString() - { - return String.Join(", ", SupportedLangauges); - } - - public void DieWithError(string message) - { - ProcessUtils.DieWithError(message); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs deleted file mode 100644 index 460b6d8..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitCommandFeature.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - public interface IToolkitCommandFeature : IToolkitFeature - { - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs deleted file mode 100644 index f3133f2..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitDataFeature.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - public interface IToolkitDataFeature - { - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs deleted file mode 100644 index 16238be..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitFeature.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - public interface IToolkitFeature - { - public void Register(Command parentCommand); - public int Run(); - - public void DieWithError(string message) - { - Console.Error.WriteLine(message); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs deleted file mode 100644 index 3eb4893..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitLifecycleFeature.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - public interface IToolkitLifecycleFeature : IToolkitFeature - { - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs b/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs deleted file mode 100644 index de754f0..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Feature/IToolkitScaffoldingFeature.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Feature -{ - public interface IToolkitScaffoldingFeature : IToolkitFeature - { - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs b/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs deleted file mode 100644 index 9ea52e4..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Logging/Log.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using NLog.Extensions.Logging; - -namespace CodeQLToolkit.Shared.Logging -{ - public class Log - { - public static readonly Log instance; - private ILogger _logger { get; set; } - - static Log() - { - instance = new Log(); - } - private Log() - { - _logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger(); - } - - public static ILogger G() - { - return instance._logger; - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs b/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs deleted file mode 100644 index ea6d620..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Options/Globals.cs +++ /dev/null @@ -1,24 +0,0 @@ -using CodeQLToolkit.Shared.Types; -using System; -using System.Collections.Generic; -using System.CommandLine; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using CodeQLToolkit.Shared.Types; - -namespace CodeQLToolkit.Shared.Options -{ - public class Globals - { - public static string[] SupportedAutomationTypes { get => new string[] { "actions" }; } - - public static Option BasePathOption { get; } = new Option("--base", () => { - return Directory.GetCurrentDirectory(); - }, "The base path to find the query repository."); - - public static Option AutomationTypeOption { get; } = new Option("--automation-type", () => { - return "actions"; - }, "The base path to find the query repository.") { IsRequired = true }.FromAmong(SupportedAutomationTypes); - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs deleted file mode 100644 index a1338df..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Target/CommandTarget.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Target -{ - public abstract class CommandTarget : ITarget - { - public string Language { get; set; } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs deleted file mode 100644 index 6d187fe..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Target/ILifecycleTarget.cs +++ /dev/null @@ -1,90 +0,0 @@ -using CodeQLToolkit.Shared.Logging; -using CodeQLToolkit.Shared.Template; -using CodeQLToolkit.Shared.Types; -using Microsoft.Extensions.Logging; - - -namespace CodeQLToolkit.Shared.Target -{ - public abstract class ILifecycleTarget : ITarget - { - public string Name { get; set; } - public string Language { get; set; } - public bool OverwriteExisting { get; set; } - public string FeatureName { get; set; } - public AutomationType AutomationType { get; set; } = AutomationType.ANY; - - - public string GetTemplatePath(string templateName) - { - var languagePath = Language; - - List pathElements = new List(); - - pathElements.Add("Templates"); - pathElements.Add(FeatureName); - - - if (AutomationType != AutomationType.ANY) - { - pathElements.Add(AutomationType.ToDirectory()); - } - - if (languagePath != null) - { - if (languagePath == "c") - { - languagePath = "cpp"; - } - - pathElements.Add(languagePath); - } - - pathElements.Add(templateName + ".liquid"); - - return Path.Combine(pathElements.ToArray()); - } - - public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description) - { - WriteTemplateIfOverwriteOrNotExists(template, path, description, null); - } - - - public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description, object model) - { - if (!File.Exists(path) || OverwriteExisting) - { - - Directory.CreateDirectory(Path.GetDirectoryName(path)); - - Log.G().LogInformation($"Writing new {description} in {path}."); - - var templatePath = GetTemplatePath(template); - - - if (model == null) - { - var rendered = new TemplateUtil().RawTemplateFromFile(templatePath); - Log.G().LogInformation($"Loaded raw template {templatePath}"); - - File.WriteAllText(path, rendered); - } - else - { - var t = new TemplateUtil().TemplateFromFile(templatePath); - - Log.G().LogInformation($"Loaded template {templatePath}"); - - var rendered = t.Render(model); - File.WriteAllText(path, rendered); - } - - } - else - { - Log.G().LogInformation($"Refusing to overwrite existing {description} in {path}"); - } - } -} -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs deleted file mode 100644 index 54c0a23..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Target/ITarget.cs +++ /dev/null @@ -1,20 +0,0 @@ -using CodeQLToolkit.Shared.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Target -{ - public abstract class ITarget - { - public string Base { get; set; } - public abstract void Run(); - - public void DieWithError(string message) - { - ProcessUtils.DieWithError(message); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs b/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs deleted file mode 100644 index 402fcac..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Target/ScaffoldTarget.cs +++ /dev/null @@ -1,51 +0,0 @@ -using CodeQLToolkit.Shared.Logging; -using CodeQLToolkit.Shared.Template; -using CodeQLToolkit.Shared.Utils; -using Microsoft.Extensions.Logging; - -namespace CodeQLToolkit.Shared.Target -{ - public abstract class ScaffoldTarget : ITarget - { - - public string Name { get; set; } - public LanguageType Language { get; set; } - public bool OverwriteExisting { get; set; } - public string FeatureName { get; set; } - - - - public string GetTemplatePathForLanguage(string templateName) - { - var languagePath = Language; - - return Path.Combine("Templates", FeatureName, Language.ToDirectory(), templateName + ".liquid"); - } - - - - public string GetTemplatePath(string templateName) - { - return Path.Combine("Templates", FeatureName, "all", templateName + ".liquid"); - } - - public void WriteTemplateIfOverwriteOrNotExists(string template, string path, string description, object model) - { - if (!File.Exists(path) || OverwriteExisting) - { - Log.G().LogInformation($"Writing new {description} in {path}."); - - var t = new TemplateUtil().TemplateFromFile(GetTemplatePathForLanguage(template)); - - var rendered = t.Render(model); - - File.WriteAllText(path, rendered); - } - else - { - Log.G().LogInformation($"Refusing to overwrite existing {description} in {path}"); - } - } - - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs b/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs deleted file mode 100644 index 5bc1a58..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Template/TemplateUtil.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Scriban; - -namespace CodeQLToolkit.Shared.Template -{ - public class TemplateUtil - { - public string TemplatePath { get; set; } = Utils.FileUtils.GetExecutingDirectory().FullName; - - public Scriban.Template TemplateFromFile(string templateFile) - { - var templateFilePath = Path.Combine(TemplatePath, templateFile); - - var data = File.ReadAllText(templateFilePath); - - var template = Scriban.Template.ParseLiquid(data); - - return template; - } - - public string RawTemplateFromFile(string templateFile) - { - var templateFilePath = Path.Combine(TemplatePath, templateFile); - - var data = File.ReadAllText(templateFilePath); - - return data; - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs deleted file mode 100644 index a67d6c5..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationFeatureFinder.cs +++ /dev/null @@ -1,46 +0,0 @@ -using CodeQLToolkit.Shared.Feature; -using CodeQLToolkit.Shared.Target; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Types -{ - public class AutomationFeatureFinder - { - public static T FindTargetForAutomationType(AutomationType automationType) - { - var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - - foreach (var assembly in assemblies) - { - var types = assembly.GetTypes(); - - foreach (var type in types) - { - // restrict this to just things that are subtypes - // of targets - if (!type.IsSubclassOf(typeof(ITarget)) || !type.IsSubclassOf(typeof(T))) - { - continue; - } - - var attributes = type.GetCustomAttributes(typeof(AutomationTypeAttribute), true); - - // match the first thing with the automation type attribute - foreach (var attribute in attributes) - { - if (((AutomationTypeAttribute)attribute).AutomationType == automationType) - { - return (T)Activator.CreateInstance(type); - } - } - } - } - throw new NotImplementedException(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs deleted file mode 100644 index ab4aeb0..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationType.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Types -{ - public enum AutomationType - { - ANY, - ACTIONS - } - - public static class AutomationTypeMethods - { - public static AutomationType FromString(this AutomationType automationType, string value) - { - if (value.ToLower().Equals("actions")) - { - return AutomationType.ACTIONS; - } - - throw new NotImplementedException(); - } - - public static string ToDirectory(this AutomationType automationType) - { - if(automationType == AutomationType.ANY) - { - return "Any"; - } - - if(automationType == AutomationType.ACTIONS) - { - return "Actions"; - } - - throw new NotImplementedException(); - } - - } - - - public class AutomationTypeHelper - { - public static AutomationType AutomationTypeFromString(string automationType) - { - return new AutomationType().FromString(automationType); - } - - public static string AutomationTypeToString(AutomationType automationType) - { - return automationType.ToDirectory(); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs b/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs deleted file mode 100644 index a57592d..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Types/AutomationTypeAttribute.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Types -{ - - [AttributeUsage(AttributeTargets.Class | - AttributeTargets.Struct) - ] - public class AutomationTypeAttribute : Attribute - { - public AutomationType AutomationType { get; set; } - public AutomationTypeAttribute(AutomationType automationType) - { - AutomationType = automationType; - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs deleted file mode 100644 index 4f6d013..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Utils/FileUtils.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Utils -{ - public class FileUtils - { - public static DirectoryInfo GetExecutingDirectory() - { - var location = new Uri(Assembly.GetEntryAssembly().GetName().CodeBase); - return new FileInfo(location.AbsolutePath).Directory; - } - - public static string CreateTempDirectory() - { - return CreateTempDirectory(Path.GetTempPath()); - } - - public static string CreateTempDirectory(string baseDir) - { - string tempDirectory = Path.Combine(baseDir, Path.GetRandomFileName()); - Directory.CreateDirectory(tempDirectory); - return tempDirectory; - } - - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs deleted file mode 100644 index ea17bd2..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Utils/Language.cs +++ /dev/null @@ -1,239 +0,0 @@ -using CodeQLToolkit.Shared.Types; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Utils -{ - public enum LanguageType - { - C, - CPP, - JAVASCRIPT, - GO, - RUBY, - PYTHON, - JAVA, - CSHARP - } - - public static class LanguageTypeMethods - { - public static LanguageType FromOptionString(this LanguageType LanguageType, string value) - { - if (value.ToLower().Equals("c")) - { - return LanguageType.C; - } - - if (value.ToLower().Equals("cpp")) - { - return LanguageType.CPP; - } - - if (value.ToLower().Equals("javascript")) - { - return LanguageType.JAVASCRIPT; - } - - if (value.ToLower().Equals("go")) - { - return LanguageType.GO; - } - - if (value.ToLower().Equals("ruby")) - { - return LanguageType.RUBY; - } - - if (value.ToLower().Equals("java")) - { - return LanguageType.JAVA; - } - - if (value.ToLower().Equals("csharp")) - { - return LanguageType.CSHARP; - } - - throw new NotImplementedException(); - } - - - public static string ToOptionString(this LanguageType LanguageType) - { - if (LanguageType == LanguageType.C) - { - return "c"; - } - - if (LanguageType == LanguageType.CPP) - { - return "cpp"; - } - - if (LanguageType == LanguageType.JAVASCRIPT) - { - return "javascript"; - } - if (LanguageType == LanguageType.GO) - { - return "go"; - } - if (LanguageType == LanguageType.RUBY) - { - return "ruby"; - } - if (LanguageType == LanguageType.PYTHON) - { - return "python"; - } - if (LanguageType == LanguageType.JAVA) - { - return "java"; - } - if (LanguageType == LanguageType.CSHARP) - { - return "csharp"; - } - - throw new NotImplementedException(); - } - - - public static string ToDirectory(this LanguageType LanguageType) - { - if (LanguageType == LanguageType.C) - { - return "cpp"; - } - - if (LanguageType == LanguageType.CPP) - { - return "cpp"; - } - - if (LanguageType == LanguageType.JAVASCRIPT) - { - return "javascript"; - } - if (LanguageType == LanguageType.GO) - { - return "go"; - } - if (LanguageType == LanguageType.RUBY) - { - return "ruby"; - } - if (LanguageType == LanguageType.PYTHON) - { - return "python"; - } - if (LanguageType == LanguageType.JAVA) - { - return "java"; - } - if (LanguageType == LanguageType.CSHARP) - { - return "csharp"; - } - - throw new NotImplementedException(); - } - - public static string ToImport(this LanguageType LanguageType) - { - if (LanguageType == LanguageType.C) - { - return "cpp"; - } - - if (LanguageType == LanguageType.CPP) - { - return "cpp"; - } - - if (LanguageType == LanguageType.JAVASCRIPT) - { - return "javascript"; - } - if (LanguageType == LanguageType.GO) - { - return "go"; - } - if (LanguageType == LanguageType.RUBY) - { - return "ruby"; - } - if (LanguageType == LanguageType.PYTHON) - { - return "python"; - } - if (LanguageType == LanguageType.JAVA) - { - return "java"; - } - if (LanguageType == LanguageType.CSHARP) - { - return "csharp"; - } - - throw new NotImplementedException(); - } - - - public static string ToExtension(this LanguageType LanguageType) - { - if (LanguageType == LanguageType.C) - { - return "c"; - } - - if(LanguageType == LanguageType.CPP) - { - return "cpp"; - } - - if(LanguageType == LanguageType.JAVASCRIPT) - { - return "js"; - } - if(LanguageType == LanguageType.GO) - { - return "go"; - } - if(LanguageType == LanguageType.RUBY) - { - return "rb"; - } - if(LanguageType == LanguageType.PYTHON) - { - return "py"; - } - if(LanguageType == LanguageType.JAVA) - { - return "java"; - } - if (LanguageType == LanguageType.CSHARP) - { - return "cs"; - } - - - throw new NotImplementedException(); - } - - } - - - public class LanguageTypeHelper - { - public static LanguageType LanguageTypeFromOptionString(string LanguageType) - { - return new LanguageType().FromOptionString(LanguageType); - } - } - -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs deleted file mode 100644 index bffa245..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Utils/ProcessUtils.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Utils -{ - public class ProcessUtils - { - public static void DieWithError(string message) - { - Console.Error.WriteLine(message); - Environment.Exit(1); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs deleted file mode 100644 index a209548..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs +++ /dev/null @@ -1,46 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Utils -{ - public class QLTConfig - { - public string CodeQLCLI { get; set; } - public string CodeQLStandardLibrary { get; set; } - public string CodeQLCLIBundle { get; set; } - - public string CodeQLStandardLibraryIdent { - get { - return CodeQLStandardLibrary.Replace("/", "_"); - } - } - - - [JsonIgnore] - public string Base { get; set; } - - [JsonIgnore] - public string CodeQLConfigFilePath - { - get - { - return Path.Combine(Base, "qlt.conf.json"); - } - } - - public QLTConfig FromFile() { - var data = File.ReadAllText(CodeQLConfigFilePath); - return JsonConvert.DeserializeObject(data); - } - - public void ToFile() - { - var data = JsonConvert.SerializeObject(this, Formatting.Indented); - File.WriteAllText(CodeQLConfigFilePath, data); - } - } -} diff --git a/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs b/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs deleted file mode 100644 index 9f035a3..0000000 --- a/src_backup/src/CodeQLToolkit.Shared/Utils/Query.cs +++ /dev/null @@ -1,114 +0,0 @@ - using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CodeQLToolkit.Shared.Utils -{ - public class Query - { - public string Base { get; set; } - public LanguageType Language { get; set; } - public string QueryPackName { get; set; } - public string Scope { get; set; } - public string Name { get; set; } - - public string QuerySrcDir - { - get - { - return Path.Combine(Base, Language.ToDirectory(), QueryPackName, "src"); - } - } - - public string QueryFileDir - { - get - { - return Path.Combine(QuerySrcDir, Name); - } - } - - public string QueryFilePath - { - get - { - return Path.Combine(QueryFileDir, $"{Name}.ql"); - } - } - - public string QueryPackPath - { - get - { - return Path.Combine(QuerySrcDir, "qlpack.yml"); - - } - } - - // - public string QueryTestDir - { - get - { - return Path.Combine(Base, Language.ToDirectory(), QueryPackName, "test"); - } - } - - public string QueryFileTestDir - { - get - { - return Path.Combine(QueryTestDir, Name); - } - } - - public string QueryFileTestPath - { - get - { - return Path.Combine(QueryFileTestDir, $"{Name}.{Language.ToExtension()}"); - } - } - - public string QueryFileQLRefPath - { - get - { - return Path.Combine(QueryFileTestDir, $"{Name}.qlref"); - } - } - - public string QueryPackTestPath - { - get - { - return Path.Combine(QueryTestDir, "qlpack.yml"); - - } - } - - public string QueryTestExpectedFile - { - get - { - return Path.Combine(QueryFileTestDir, $"{Name}.expected"); - - } - } - - public string QueryTestPackName - { - get - { - return $"{QueryPackName}-tests"; - } - } - - public string GetLanguageImportForLangauge() - { - return Language.ToImport(); - } - } -} From 8062963dcfe10d0fb3f035d7a006e865f03ddaef Mon Sep 17 00:00:00 2001 From: "John L. Singleton" Date: Wed, 29 Nov 2023 16:29:23 -0500 Subject: [PATCH 5/5] adding metadata validation --- .../CodeQLToolkit.Features.csproj | 6 +- .../Actions/validate-query-metadata.liquid | 86 +++++++++++++++++++ .../Targets/Actions/InitLifecycleTarget.cs | 2 + .../Targets/CheckQueriesCommandTarget.cs | 81 +++++++++++++++++ .../Commands/ValidationCommandFeature.cs | 35 ++++---- .../Lifecycle/BaseLifecycleTarget.cs | 14 +++ .../Targets/Actions/InitLifecycleTarget.cs | 48 +++++++++++ .../Lifecycle/ValidationLifecycleFeature.cs | 75 ++++++++++++++++ .../Validation/ValidationFeatureMain.cs | 6 ++ 9 files changed, 335 insertions(+), 18 deletions(-) create mode 100644 src/CodeQLToolkit.Features/Templates/Validation/Actions/validate-query-metadata.liquid create mode 100644 src/CodeQLToolkit.Features/Validation/Commands/Targets/CheckQueriesCommandTarget.cs create mode 100644 src/CodeQLToolkit.Features/Validation/Lifecycle/BaseLifecycleTarget.cs create mode 100644 src/CodeQLToolkit.Features/Validation/Lifecycle/Targets/Actions/InitLifecycleTarget.cs create mode 100644 src/CodeQLToolkit.Features/Validation/Lifecycle/ValidationLifecycleFeature.cs diff --git a/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj index e458176..269a128 100644 --- a/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj +++ b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj @@ -12,9 +12,8 @@ - - + @@ -72,6 +71,9 @@ Always + + Always + diff --git a/src/CodeQLToolkit.Features/Templates/Validation/Actions/validate-query-metadata.liquid b/src/CodeQLToolkit.Features/Templates/Validation/Actions/validate-query-metadata.liquid new file mode 100644 index 0000000..97e9a09 --- /dev/null +++ b/src/CodeQLToolkit.Features/Templates/Validation/Actions/validate-query-metadata.liquid @@ -0,0 +1,86 @@ +name: ⚙️ CodeQL - Validate Queries ({{language}}) +{% raw %} +on: + push: + branches: + - '**' + pull_request: + branches: + - '**' + workflow_dispatch: + +jobs: + create-matrix: + name: Create CodeQL Test Matrix + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.export-test-matrix.outputs.matrix }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + id: install-qlt + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true +{% endraw %} + - name: Export test matrix + id: export-test-matrix + run: | + qlt test run get-matrix --os-version {{ use_runner }} +{% raw %} + validate-queries: + name: Validate Queries + needs: create-matrix + + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: ${{ fromJSON(needs.create-matrix.outputs.matrix) }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install QLT + uses: ./.github/actions/install-qlt + with: + qlt-version: 'latest' + add-to-path: true + + - name: Install CodeQL + uses: ./.github/actions/install-codeql + with: + codeql-cli-version: ${{ matrix.codeql_cli }} + codeql-stdlib-version: ${{ matrix.codeql_standard_library }} + add-to-path: true + + - name: Verify Versions of Tooling + shell: bash + run: | + echo "CodeQL Home: ${{ steps.install-codeql.outputs.codeql-home }}" + echo -e "Checking CodeQL Version:" + codeql --version + + echo -e "Checking QLT Version:" + echo "QLT Home: ${{ steps.install-qlt.outputs.qlt-home }}" + qlt version + + - name: Install QL Packs + shell: bash + run: | + qlt query run install-packs + + - name: Run validation tests + shell: bash + run: > +{% endraw %} + # run a copy for pretty printing + qlt validation run check-queries --pretty-print + --language {{ language }} + + # run this version to influence the outcome of the run. + qlt validation run check-queries + --language {{ language }} diff --git a/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs index b505101..b300412 100644 --- a/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs +++ b/src/CodeQLToolkit.Features/Test/Lifecycle/Targets/Actions/InitLifecycleTarget.cs @@ -55,6 +55,8 @@ runner with the `--use-runner` argument. (Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; + Log.G().LogInformation(message); + } } diff --git a/src/CodeQLToolkit.Features/Validation/Commands/Targets/CheckQueriesCommandTarget.cs b/src/CodeQLToolkit.Features/Validation/Commands/Targets/CheckQueriesCommandTarget.cs new file mode 100644 index 0000000..cda273e --- /dev/null +++ b/src/CodeQLToolkit.Features/Validation/Commands/Targets/CheckQueriesCommandTarget.cs @@ -0,0 +1,81 @@ +using CodeQLToolkit.Features.Query.Commands.Targets; +using CodeQLToolkit.Features.Validation.Models; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Commands.Targets +{ + public class CheckQueriesCommandTarget : CommandTarget + { + + public bool PrettyPrint { get; set; } + + + public override void Run() + { + Log.G().LogInformation($"Validating query metadata for {Language}..."); + + using (Process process = new Process()) + { + process.StartInfo.FileName = "codeql"; + process.StartInfo.UseShellExecute = false; + process.StartInfo.WorkingDirectory = Base; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardError = false; + process.StartInfo.Arguments = $"query compile --format json -n {Language}"; + process.Start(); + + var output = process.StandardOutput.ReadToEnd(); + + process.WaitForExit(); + + if (process.ExitCode != 0) + { + DieWithError($"Fatal error. Please check error output."); + } + + var results = JsonConvert.DeserializeObject>(output); + + bool shouldFail = false; + + if (results != null) + { + foreach (var r in results) + { + foreach (var message in r.messages) + { + if (message.severity == "WARNING" || message.severity == "ERROR") + { + shouldFail = true; + + if (PrettyPrint) + { + Console.WriteLine($"❌ [{message.severity}] {message.message}: {message.position.fileName}:{message.position.line},{message.position.column}-{message.position.endColumn},{message.position.endColumn}"); + } + else + { + Log.G().LogWarning($"[{message.severity}] {message.message}: {message.position.fileName}:{message.position.line},{message.position.column}-{message.position.endColumn},{message.position.endColumn}"); + } + + } + } + } + } + + if(shouldFail && !PrettyPrint ) + { + DieWithError("One or more validation errors found."); + } + + + + } + + } + } +} diff --git a/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs b/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs index 2e8db6d..b5d8450 100644 --- a/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs +++ b/src/CodeQLToolkit.Features/Validation/Commands/ValidationCommandFeature.cs @@ -1,4 +1,5 @@ -using CodeQLToolkit.Shared.Utils; +using CodeQLToolkit.Features.Validation.Commands.Targets; +using CodeQLToolkit.Shared.Utils; using System.CommandLine; namespace CodeQLToolkit.Features.Test.Commands @@ -29,27 +30,29 @@ public void Register(Command parentCommand) var runCommand = new Command("run", "Functions pertaining running validation commands."); parentCommand.Add(runCommand); - var getMatrixTestCommand = new Command("check-metadsata", "Checks the query metadata for the specified queries."); + var checkQueryQueriesCommand = new Command("check-queries", "Checks the query metadata for the specified language."); var languageOption = new Option("--language", $"The language to run tests for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); - var matrixOSVersion = new Option("--os-version", () => "ubuntu-latest", "A comma-seperated list of operating systems to use. Example: `ubuntu-latest`.") { IsRequired = true }; - getMatrixTestCommand.Add(matrixOSVersion); - - runCommand.Add(getMatrixTestCommand); + var prettyPrintOption = new Option("--pretty-print", () => false, "Pretty prints error output in a pretty compact format.") { IsRequired = true }; + checkQueryQueriesCommand.Add(languageOption); + checkQueryQueriesCommand.Add(prettyPrintOption); - getMatrixTestCommand.SetHandler(() => - { - Log.G().LogInformation("Executing validate-unit-tests command..."); - - //new ValidateUnitTestsCommand() - //{ - // ResultsDirectory = resultsDirectory, - // PrettyPrint = prettyPrint - //}.Run(); + runCommand.Add(checkQueryQueriesCommand); - }); + checkQueryQueriesCommand.SetHandler((language, basePath, prettyPrint) => + { + Log.G().LogInformation("Executing check-query-metadata command..."); + + new CheckQueriesCommandTarget() + { + Base = basePath, + Language = language, + PrettyPrint = prettyPrint, + }.Run(); + + }, languageOption, Globals.BasePathOption, prettyPrintOption); } public int Run() diff --git a/src/CodeQLToolkit.Features/Validation/Lifecycle/BaseLifecycleTarget.cs b/src/CodeQLToolkit.Features/Validation/Lifecycle/BaseLifecycleTarget.cs new file mode 100644 index 0000000..649b3c0 --- /dev/null +++ b/src/CodeQLToolkit.Features/Validation/Lifecycle/BaseLifecycleTarget.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Lifecycle +{ + abstract internal class BaseLifecycleTarget : ILifecycleTarget + { + public string UseRunner { get; set; } + + } +} \ No newline at end of file diff --git a/src/CodeQLToolkit.Features/Validation/Lifecycle/Targets/Actions/InitLifecycleTarget.cs b/src/CodeQLToolkit.Features/Validation/Lifecycle/Targets/Actions/InitLifecycleTarget.cs new file mode 100644 index 0000000..34fd7ce --- /dev/null +++ b/src/CodeQLToolkit.Features/Validation/Lifecycle/Targets/Actions/InitLifecycleTarget.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Lifecycle.Targets.Actions +{ + [AutomationType(AutomationType.ACTIONS)] + internal class InitLifecycleTarget : BaseLifecycleTarget + { + public InitLifecycleTarget() + { + AutomationType = AutomationType.ACTIONS; + } + + public override void Run() + { + Log.G().LogInformation("Running init command..."); + + // temporarily disable the language resolution + var tmpLanguage = Language; + Language = null; + + WriteTemplateIfOverwriteOrNotExists("validate-query-metadata", Path.Combine(Base, ".github", "workflows", $"validate-codeql-queries-{tmpLanguage}.yml"), $"Validate CodeQL Queries ({Language})", new + { + useRunner = UseRunner, + language = tmpLanguage, + }); + + Language = tmpLanguage; + + var message = @"------------------------------------------ +Your repository now has CodeQL Query Validation installed in `.github/workflows/`. Please ensure to initialize CodeQL +testing before using this workflow with `qlt test init`. + +Note that, by default, your runner the `ubuntu-latest` runner. + +You can modify default runner by adjusting the `--use-runner` argument. + +In addition to using QLT to generate your files you can also directly edit this file to fine tune its settings. + +(Hint: If you'd like to regenerate your files, you can use the `--overwrite-existing` option to overwrite the files that are in place now.)"; + + Log.G().LogInformation(message); + } + } +} diff --git a/src/CodeQLToolkit.Features/Validation/Lifecycle/ValidationLifecycleFeature.cs b/src/CodeQLToolkit.Features/Validation/Lifecycle/ValidationLifecycleFeature.cs new file mode 100644 index 0000000..ea3714b --- /dev/null +++ b/src/CodeQLToolkit.Features/Validation/Lifecycle/ValidationLifecycleFeature.cs @@ -0,0 +1,75 @@ +using CodeQLToolkit.Features.Test.Lifecycle; +using CodeQLToolkit.Shared.Utils; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Validation.Lifecycle +{ + internal class ValidationLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public ValidationLifecycleFeature() + { + FeatureName = "Validation"; + } + + public override LanguageType[] SupportedLangauges + { + get => new LanguageType[] { + LanguageType.C, + LanguageType.CPP, + LanguageType.CSHARP, + LanguageType.JAVA, + LanguageType.JAVASCRIPT, + LanguageType.GO, + LanguageType.RUBY, + LanguageType.PYTHON + }; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering lifecycle submodule."); + + var initCommand = new Command("init", "Initialize validation checking in this repository."); + + var overwriteExistingOption = new Option("--overwrite-existing", () => false, "Overwrite exiting files (if they exist)."); + var languageOption = new Option("--language", $"The language to generate automation for.") { IsRequired = true }.FromAmong(SupportedLangauges.Select(x => x.ToOptionString()).ToArray()); + var useRunnerOption = new Option("--use-runner", () => "ubuntu-latest", "The runner(s) to use. Should be a comma-seperated list of actions runners."); + + initCommand.AddOption(overwriteExistingOption); + initCommand.AddOption(languageOption); + initCommand.AddOption(useRunnerOption); + + parentCommand.Add(initCommand); + + initCommand.SetHandler((basePath, automationType, overwriteExisting, language, useRunner) => + { + Log.G().LogInformation("Executing init command..."); + + // + // dispatch at runtime to the correct automation type + // + var featureTarget = AutomationFeatureFinder.FindTargetForAutomationType(AutomationTypeHelper.AutomationTypeFromString(automationType)); + + // setup common params + featureTarget.FeatureName = FeatureName; + featureTarget.Base = basePath; + featureTarget.UseRunner = useRunner; + featureTarget.OverwriteExisting = overwriteExisting; + featureTarget.Language = language; + featureTarget.Run(); + + }, Globals.BasePathOption, Globals.AutomationTypeOption, overwriteExistingOption, languageOption, useRunnerOption); + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs b/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs index 1f8367f..27e24e4 100644 --- a/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs +++ b/src/CodeQLToolkit.Features/Validation/ValidationFeatureMain.cs @@ -1,4 +1,5 @@ using CodeQLToolkit.Features.Test.Commands; +using CodeQLToolkit.Features.Validation.Lifecycle; using System.CommandLine; namespace CodeQLToolkit.Features.Validation @@ -7,6 +8,7 @@ public class ValidationFeatureMain : IToolkitFeature { readonly ValidationCommandFeature commandFeature; + readonly ValidationLifecycleFeature validationLifecycleFeature; readonly static ValidationFeatureMain instance; static ValidationFeatureMain() @@ -17,6 +19,7 @@ static ValidationFeatureMain() private ValidationFeatureMain() { commandFeature = new ValidationCommandFeature(); + validationLifecycleFeature = new ValidationLifecycleFeature(); } public static ValidationFeatureMain Instance { get { return instance; } } @@ -28,6 +31,9 @@ public void Register(Command parentCommand) Log.G().LogInformation("Registering command submodule."); commandFeature.Register(validationCommand); + Log.G().LogInformation("Registering lifecycle submodule."); + validationLifecycleFeature.Register(validationCommand); + } public int Run()