diff --git a/example/qlt.conf.json b/example/qlt.conf.json index a13745c..eb74899 100644 --- a/example/qlt.conf.json +++ b/example/qlt.conf.json @@ -1,5 +1,7 @@ { "CodeQLCLI": "2.11.6", "CodeQLStandardLibrary": "codeql-cli/v2.11.6", - "CodeQLCLIBundle": "codeql-bundle-20221211" + "CodeQLCLIBundle": "codeql-bundle-20221211", + "EnableCustomCodeQLBundles": false, + "CodeQLStandardLibraryIdent": "codeql-cli_v2.11.6" } \ No newline at end of file diff --git a/src/CodeQLToolkit.Core/Main.cs b/src/CodeQLToolkit.Core/Main.cs index fdb0f53..fda2c6a 100644 --- a/src/CodeQLToolkit.Core/Main.cs +++ b/src/CodeQLToolkit.Core/Main.cs @@ -10,6 +10,7 @@ using CodeQLToolkit.Features.Test; using CodeQLToolkit.Features.Pack; using CodeQLToolkit.Features.Validation; +using CodeQLToolkit.Features.Bundle; namespace CodeQLDevelopmentLifecycleToolkit.Core { @@ -49,6 +50,8 @@ public static async Task Main(string[] args) PackFeatureMain.Instance.Register(rootCommand); // Register the `Validation` feature ValidationFeatureMain.Instance.Register(rootCommand); + // Register the `Bundle` feature + BundleFeatureMain.Instance.Register(rootCommand); return await rootCommand.InvokeAsync(args); } diff --git a/src/CodeQLToolkit.Core/Properties/launchSettings.json b/src/CodeQLToolkit.Core/Properties/launchSettings.json index 9b17472..58a6cf3 100644 --- a/src/CodeQLToolkit.Core/Properties/launchSettings.json +++ b/src/CodeQLToolkit.Core/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "CodeQLToolkit.Core": { "commandName": "Project", - "commandLineArgs": " --base C:\\QLPACKTEST test init" + "commandLineArgs": "--base C:\\Projects\\codeql-development-lifecycle-toolkit\\example bundle set enable-custom-bundles" } } } \ No newline at end of file diff --git a/src/CodeQLToolkit.Features/Bundle/BundleFeatureMain.cs b/src/CodeQLToolkit.Features/Bundle/BundleFeatureMain.cs new file mode 100644 index 0000000..d55f223 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/BundleFeatureMain.cs @@ -0,0 +1,52 @@ +using CodeQLToolkit.Features.Test.Commands; +using CodeQLToolkit.Features.Validation.Lifecycle; +using CodeQLToolkit.Features.Validation; +using System; +using System.Collections.Generic; +using System.CommandLine; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CodeQLToolkit.Features.Bundle.Commands; +using CodeQLToolkit.Features.Bundle.Lifecycle; + +namespace CodeQLToolkit.Features.Bundle +{ + public class BundleFeatureMain : IToolkitFeature + + { + readonly BundleCommandFeature commandFeature; + readonly BundleLifecycleFeature lifecycleFeature; + readonly static BundleFeatureMain instance; + + static BundleFeatureMain() + { + instance = new BundleFeatureMain(); + } + + private BundleFeatureMain() + { + commandFeature = new BundleCommandFeature(); + lifecycleFeature = new BundleLifecycleFeature(); + } + public static BundleFeatureMain Instance { get { return instance; } } + + public void Register(Command parentCommand) + { + var bundleFeatureCommand = new Command("bundle", "Features related creation and usage of custom CodeQL bundles."); + parentCommand.Add(bundleFeatureCommand); + + Log.G().LogInformation("Registering command submodule."); + commandFeature.Register(bundleFeatureCommand); + + Log.G().LogInformation("Registering lifecycle submodule."); + lifecycleFeature.Register(bundleFeatureCommand); + + } + + public int Run() + { + return 0; + } + } +} diff --git a/src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs b/src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs new file mode 100644 index 0000000..e8b12ea --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs @@ -0,0 +1,68 @@ +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.Bundle.Commands +{ + public class BundleCommandFeature : 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 BundleCommandFeature() + { + FeatureName = "Bundle"; + } + + public void Register(Command parentCommand) + { + Log.G().LogInformation("Registering command submodule."); + + + var runCommand = new Command("run", "Functions pertaining running bundle commands."); + parentCommand.Add(runCommand); + + //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()); + + //checkQueryQueriesCommand.Add(languageOption); + + //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() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features/Bundle/Lifecycle/BaseLifecycleTarget.cs b/src/CodeQLToolkit.Features/Bundle/Lifecycle/BaseLifecycleTarget.cs new file mode 100644 index 0000000..04b4b17 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Lifecycle/BaseLifecycleTarget.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeQLToolkit.Features.Bundle.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/CodeQLToolkit.Features/Bundle/Lifecycle/BundleLifecycleFeature.cs b/src/CodeQLToolkit.Features/Bundle/Lifecycle/BundleLifecycleFeature.cs new file mode 100644 index 0000000..27611d2 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Lifecycle/BundleLifecycleFeature.cs @@ -0,0 +1,100 @@ +using CodeQLToolkit.Features.CodeQL.Lifecycle.Targets; +using CodeQLToolkit.Features.CodeQL.Lifecycle; +using CodeQLToolkit.Features.Test.Lifecycle.Targets; +using CodeQLToolkit.Features.Test.Lifecycle.Targets.Actions; +using CodeQLToolkit.Shared.Utils; +using System.CommandLine; +using System.Reflection; +using CodeQLToolkit.Features.Bundle.Lifecycle.Targets; + +namespace CodeQLToolkit.Features.Bundle.Lifecycle +{ + public class BundleLifecycleFeature : FeatureBase, IToolkitLifecycleFeature + { + public BundleLifecycleFeature() + { + FeatureName = "Bundle"; + } + + 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 setCommand = new Command("set", "Functions pertaining to setting variables related to custom CodeQL bundles."); + parentCommand.Add(setCommand); + + var enableCommand = new Command("enable-custom-bundles", "Enables custom CodeQL Bundles."); + setCommand.Add(enableCommand); + + var disableCommand = new Command("disable-custom-bundles", "Disables custom CodeQL Bundles."); + setCommand.Add(disableCommand); + + var getCommand = new Command("get", "Functions pertaining to getting variables related to CodeQL Bundles."); + parentCommand.Add(getCommand); + + var getEnabledCommand = new Command("enabled", "Determines if custom CodeQL Bundles are enabled."); + getCommand.Add(getEnabledCommand); + + { + enableCommand.SetHandler((basePath) => + { + Log.G().LogInformation("Executing enable command..."); + + new SetEnableCustomCodeQLBundlesLifecycleTarget() + { + Base = basePath + }.Run(); + + }, Globals.BasePathOption); + } + + { + disableCommand.SetHandler((basePath) => + { + Log.G().LogInformation("Executing get enabled command..."); + + new SetDisableCustomCodeQLBundlesLifecycleTarget() + { + Base = basePath + }.Run(); + + }, Globals.BasePathOption); + } + + + { + getEnabledCommand.SetHandler((basePath) => + { + Log.G().LogInformation("Executing disable command..."); + + new GetEnabledCustomCodeQLBundlesLifecycleTarget() + { + Base = basePath + }.Run(); + + }, Globals.BasePathOption); + } + + + } + + public int Run() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/GetEnabledCustomCodeQLBundlesLifecycleTarget.cs b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/GetEnabledCustomCodeQLBundlesLifecycleTarget.cs new file mode 100644 index 0000000..9e2e4d6 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/GetEnabledCustomCodeQLBundlesLifecycleTarget.cs @@ -0,0 +1,31 @@ +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.Bundle.Lifecycle.Targets +{ + public class GetEnabledCustomCodeQLBundlesLifecycleTarget : ILifecycleTarget + { + override public void Run() + { + Log.G().LogInformation("Running get enabled command..."); + + var c = new QLTConfig() + { + Base = Base + }; + + var config = c.FromFile(); + + Console.WriteLine($"---------current settings---------"); + Console.WriteLine($"CodeQL Custom Bundles Enabled: {config.EnableCustomCodeQLBundles}"); + Console.WriteLine($"----------------------------------"); + Console.WriteLine("(hint: use `qlt bundle set` to modify these values.)"); + + } + } +} diff --git a/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetDisableCustomCodeQLBundlesLifecycleTarget.cs b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetDisableCustomCodeQLBundlesLifecycleTarget.cs new file mode 100644 index 0000000..dee5072 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetDisableCustomCodeQLBundlesLifecycleTarget.cs @@ -0,0 +1,32 @@ +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.Bundle.Lifecycle.Targets +{ + public class SetDisableCustomCodeQLBundlesLifecycleTarget : ILifecycleTarget + { + override public void Run() + { + Log.G().LogInformation("Running set command..."); + + var c = new QLTConfig() + { + Base = Base + }; + + var config = c.FromFile(); + + config.EnableCustomCodeQLBundles = false; + + config.ToFile(); + + Log.G().LogInformation("Wrote to file..."); + + } + } +} diff --git a/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetEnableCustomCodeQLBundlesLifecycleTarget.cs b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetEnableCustomCodeQLBundlesLifecycleTarget.cs new file mode 100644 index 0000000..a59a1c7 --- /dev/null +++ b/src/CodeQLToolkit.Features/Bundle/Lifecycle/Targets/SetEnableCustomCodeQLBundlesLifecycleTarget.cs @@ -0,0 +1,32 @@ +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.Bundle.Lifecycle.Targets +{ + public class SetEnableCustomCodeQLBundlesLifecycleTarget : ILifecycleTarget + { + override public void Run() + { + Log.G().LogInformation("Running set command..."); + + var c = new QLTConfig() + { + Base = Base + }; + + var config = c.FromFile(); + + config.EnableCustomCodeQLBundles = true; + + config.ToFile(); + + Log.G().LogInformation("Wrote to file..."); + + } + } +} diff --git a/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj index 269a128..5ed572e 100644 --- a/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj +++ b/src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj @@ -11,6 +11,9 @@ + + + diff --git a/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs b/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs index a209548..7c8a1a9 100644 --- a/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs +++ b/src/CodeQLToolkit.Shared/Utils/QLTConfig.cs @@ -12,10 +12,16 @@ public class QLTConfig public string CodeQLCLI { get; set; } public string CodeQLStandardLibrary { get; set; } public string CodeQLCLIBundle { get; set; } + + public bool EnableCustomCodeQLBundles { get; set; } public string CodeQLStandardLibraryIdent { get { - return CodeQLStandardLibrary.Replace("/", "_"); + if (CodeQLStandardLibrary != null) + { + return CodeQLStandardLibrary.Replace("/", "_"); + } + return CodeQLStandardLibrary; } } @@ -34,7 +40,11 @@ public string CodeQLConfigFilePath public QLTConfig FromFile() { var data = File.ReadAllText(CodeQLConfigFilePath); - return JsonConvert.DeserializeObject(data); + QLTConfig c = JsonConvert.DeserializeObject(data); + + + c.Base = Base; + return c; } public void ToFile()