File tree 5 files changed +126
-0
lines changed
CodeQLToolkit.Features/Query/Commands/Targets
test/CodeQLToolkit.Shared.Tests/Utils
5 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 1
1
using CodeQLToolkit . Shared . CodeQL ;
2
+ using CodeQLToolkit . Shared . Utils ;
2
3
using Microsoft . VisualBasic ;
3
4
using System ;
4
5
using System . Collections . Generic ;
@@ -26,7 +27,35 @@ public override void Run()
26
27
27
28
installation . EnableCustomCodeQLBundles = UseBundle ;
28
29
30
+ //
29
31
installation . IsInstalledOrDie ( ) ;
32
+ //
33
+
34
+
35
+ // filter the packs that are part of a custom bundle if we are using bundles.
36
+ if ( UseBundle )
37
+ {
38
+ // load the config
39
+ var config = QLTConfig . LoadFromFile ( Base ) ;
40
+
41
+ Log < InstallQueryPacksCommandTarget > . G ( ) . LogInformation ( "In bundle mode so filtering bundled packs..." ) ;
42
+
43
+
44
+ foreach ( var pack in config . ExportedCustomizationPacks )
45
+ {
46
+ Log < InstallQueryPacksCommandTarget > . G ( ) . LogInformation ( $ "Pack { pack } will NOT installed because it is part of the bundle...") ;
47
+ }
48
+
49
+ files = files . Where ( f => ! config . ExportedCustomizationPacks . Any ( p => CodeQLPackReader . read ( f ) . Name == p ) ) . ToArray ( ) ;
50
+
51
+ Log < InstallQueryPacksCommandTarget > . G ( ) . LogInformation ( $ "Got { files . Length } packs after filtering...") ;
52
+
53
+ foreach ( var file in files )
54
+ {
55
+ Log < InstallQueryPacksCommandTarget > . G ( ) . LogInformation ( $ "Pack { CodeQLPackReader . read ( file ) . Name } in { file } will installed because it is not part of the bundle...") ;
56
+ }
57
+ }
58
+
30
59
31
60
foreach ( string file in files )
32
61
{
Original file line number Diff line number Diff line change 13
13
<PackageReference Include =" NLog.Extensions.Logging" Version =" 5.3.2" />
14
14
<PackageReference Include =" Scriban" Version =" 5.7.0" />
15
15
<PackageReference Include =" System.CommandLine" Version =" 2.0.0-beta4.22272.1" />
16
+ <PackageReference Include =" YamlDotNet" Version =" 15.1.2" />
16
17
</ItemGroup >
17
18
18
19
</Project >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+ using YamlDotNet . RepresentationModel ;
7
+
8
+ namespace CodeQLToolkit . Shared . Utils
9
+ {
10
+ public class CodeQLPack
11
+ {
12
+ public string Name { get ; set ; }
13
+ }
14
+ public class CodeQLPackReader
15
+ {
16
+ public static CodeQLPack read ( string path )
17
+ {
18
+ var pack = new CodeQLPack ( ) ;
19
+
20
+ using ( var reader = new StreamReader ( path ) )
21
+ {
22
+ var yaml = new YamlStream ( ) ;
23
+ yaml . Load ( reader ) ;
24
+
25
+ var root = ( YamlMappingNode ) yaml . Documents [ 0 ] . RootNode ;
26
+
27
+ foreach ( var e in root . Children )
28
+ {
29
+ if ( e . Key . ToString ( ) == "name" )
30
+ {
31
+ pack . Name = e . Value . ToString ( ) ;
32
+ }
33
+ }
34
+
35
+
36
+
37
+ }
38
+
39
+ return pack ;
40
+ }
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -52,5 +52,21 @@ public void ToFile()
52
52
var data = JsonConvert . SerializeObject ( this , Formatting . Indented ) ;
53
53
File . WriteAllText ( CodeQLConfigFilePath , data ) ;
54
54
}
55
+
56
+ public static QLTConfig ? LoadFromFile ( string baseDir )
57
+ {
58
+ var config = new QLTConfig ( )
59
+ {
60
+ Base = baseDir
61
+ } ;
62
+
63
+
64
+ if ( File . Exists ( config . CodeQLConfigFilePath ) )
65
+ {
66
+ return config . FromFile ( ) ;
67
+ }
68
+
69
+ return null ;
70
+ }
55
71
}
56
72
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace CodeQLToolkit . Shared . Tests . Utils
8
+ {
9
+ public class PackReaderTests
10
+ {
11
+ public string TestFile { get ; set ; }
12
+ [ SetUp ]
13
+ public void Setup ( )
14
+ {
15
+ var doc = @"
16
+ ---
17
+ library: true
18
+ name: qlt2/stuff2
19
+ version: 0.0.1
20
+ description: Default description
21
+ suites:
22
+ license:
23
+ dependencies:
24
+ codeql/cpp-all: ""0.12.2""
25
+ " ;
26
+
27
+ TestFile = Path . Combine ( Path . GetTempPath ( ) , "qlpack.yml" ) ;
28
+
29
+ File . WriteAllText ( TestFile , doc ) ;
30
+ }
31
+
32
+ [ Test ]
33
+ public void TestReadPackName ( )
34
+ {
35
+ Assert . AreEqual ( "qlt2/stuff2" , CodeQLPackReader . read ( TestFile ) . Name ) ;
36
+ }
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments