Skip to content

Commit

Permalink
code for enabling and disabling and checking on status of custom bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
jsinglet committed Jan 19, 2024
1 parent a920756 commit 5b407d4
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 4 deletions.
4 changes: 3 additions & 1 deletion example/qlt.conf.json
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 3 additions & 0 deletions src/CodeQLToolkit.Core/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CodeQLToolkit.Features.Test;
using CodeQLToolkit.Features.Pack;
using CodeQLToolkit.Features.Validation;
using CodeQLToolkit.Features.Bundle;

namespace CodeQLDevelopmentLifecycleToolkit.Core
{
Expand Down Expand Up @@ -49,6 +50,8 @@ public static async Task<int> 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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CodeQLToolkit.Core/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
52 changes: 52 additions & 0 deletions src/CodeQLToolkit.Features/Bundle/BundleFeatureMain.cs
Original file line number Diff line number Diff line change
@@ -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<BundleFeatureMain>.G().LogInformation("Registering command submodule.");
commandFeature.Register(bundleFeatureCommand);

Log<BundleFeatureMain>.G().LogInformation("Registering lifecycle submodule.");
lifecycleFeature.Register(bundleFeatureCommand);

}

public int Run()
{
return 0;
}
}
}
68 changes: 68 additions & 0 deletions src/CodeQLToolkit.Features/Bundle/Commands/BundleCommandFeature.cs
Original file line number Diff line number Diff line change
@@ -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<BundleCommandFeature>.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<string>("--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<BundleCommandFeature>.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();
}
}
}
19 changes: 19 additions & 0 deletions src/CodeQLToolkit.Features/Bundle/Lifecycle/BaseLifecycleTarget.cs
Original file line number Diff line number Diff line change
@@ -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; }



}
}
100 changes: 100 additions & 0 deletions src/CodeQLToolkit.Features/Bundle/Lifecycle/BundleLifecycleFeature.cs
Original file line number Diff line number Diff line change
@@ -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<BundleLifecycleFeature>.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<CodeQLLifecycleFeature>.G().LogInformation("Executing enable command...");

new SetEnableCustomCodeQLBundlesLifecycleTarget()
{
Base = basePath
}.Run();

}, Globals.BasePathOption);
}

{
disableCommand.SetHandler((basePath) =>
{
Log<CodeQLLifecycleFeature>.G().LogInformation("Executing get enabled command...");

new SetDisableCustomCodeQLBundlesLifecycleTarget()
{
Base = basePath
}.Run();

}, Globals.BasePathOption);
}


{
getEnabledCommand.SetHandler((basePath) =>
{
Log<CodeQLLifecycleFeature>.G().LogInformation("Executing disable command...");

new GetEnabledCustomCodeQLBundlesLifecycleTarget()
{
Base = basePath
}.Run();

}, Globals.BasePathOption);
}


}

public int Run()
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<GetEnabledCustomCodeQLBundlesLifecycleTarget>.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.)");

}
}
}
Original file line number Diff line number Diff line change
@@ -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<SetDisableCustomCodeQLBundlesLifecycleTarget>.G().LogInformation("Running set command...");

var c = new QLTConfig()
{
Base = Base
};

var config = c.FromFile();

config.EnableCustomCodeQLBundles = false;

config.ToFile();

Log<SetDisableCustomCodeQLBundlesLifecycleTarget>.G().LogInformation("Wrote to file...");

}
}
}
Original file line number Diff line number Diff line change
@@ -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<SetEnableCustomCodeQLBundlesLifecycleTarget>.G().LogInformation("Running set command...");

var c = new QLTConfig()
{
Base = Base
};

var config = c.FromFile();

config.EnableCustomCodeQLBundles = true;

config.ToFile();

Log<SetEnableCustomCodeQLBundlesLifecycleTarget>.G().LogInformation("Wrote to file...");

}
}
}
3 changes: 3 additions & 0 deletions src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</ItemGroup>

<ItemGroup>
<Folder Include="Bundle\Commands\Targets\" />
<Folder Include="Bundle\Lifecycle\Targets\Actions\" />
<Folder Include="Bundle\Models\" />
<Folder Include="CodeQL\" />
<Folder Include="Pack\" />
<Folder Include="Templates\Validation\Actions\" />
Expand Down
Loading

0 comments on commit 5b407d4

Please sign in to comment.