@@ -132,26 +132,6 @@ interface BqrsDecodeOptions {
132132 */
133133export class CodeQLCliServer implements Disposable {
134134
135- /**
136- * CLI version where --kind=DIL was introduced
137- */
138- private static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer ( '2.3.0' ) ;
139-
140- /**
141- * CLI version where languages are exposed during a `codeql resolve database` command.
142- */
143- private static CLI_VERSION_WITH_LANGUAGE = new SemVer ( '2.4.1' ) ;
144-
145- /**
146- * CLI version where `codeql resolve upgrades` supports
147- * the `--allow-downgrades` flag
148- */
149- private static CLI_VERSION_WITH_DOWNGRADES = new SemVer ( '2.4.4' ) ;
150-
151- /**
152- * CLI version where the `codeql resolve qlref` command is available.
153- */
154- public static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer ( '2.5.1' ) ;
155135
156136 /** The process for the cli server, or undefined if one doesn't exist yet */
157137 process ?: child_process . ChildProcessWithoutNullStreams ;
@@ -168,6 +148,8 @@ export class CodeQLCliServer implements Disposable {
168148 /** Path to current codeQL executable, or undefined if not running yet. */
169149 codeQlPath : string | undefined ;
170150
151+ cliConstraints = new CliVersionConstraint ( this ) ;
152+
171153 /**
172154 * When set to true, ignore some modal popups and assume user has clicked "yes".
173155 */
@@ -716,7 +698,7 @@ export class CodeQLCliServer implements Disposable {
716698 const args = [ '--additional-packs' , searchPath . join ( path . delimiter ) , '--dbscheme' , dbScheme ] ;
717699 if ( targetDbScheme ) {
718700 args . push ( '--target-dbscheme' , targetDbScheme ) ;
719- if ( allowDowngradesIfPossible && await this . supportsDowngrades ( ) ) {
701+ if ( allowDowngradesIfPossible && await this . cliConstraints . supportsDowngrades ( ) ) {
720702 args . push ( '--allow-downgrades' ) ;
721703 }
722704 }
@@ -769,7 +751,7 @@ export class CodeQLCliServer implements Disposable {
769751 }
770752
771753 async generateDil ( qloFile : string , outFile : string ) : Promise < void > {
772- const extraArgs = await this . supportsDecompileDil ( )
754+ const extraArgs = await this . cliConstraints . supportsDecompileDil ( )
773755 ? [ '--kind' , 'dil' , '-o' , outFile , qloFile ]
774756 : [ '-o' , outFile , qloFile ] ;
775757 await this . runCodeQlCliCommand (
@@ -786,22 +768,6 @@ export class CodeQLCliServer implements Disposable {
786768 return this . _version ;
787769 }
788770
789- private async supportsDecompileDil ( ) {
790- return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_DECOMPILE_KIND_DIL ) >= 0 ;
791- }
792-
793- public async supportsLanguageName ( ) {
794- return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_LANGUAGE ) >= 0 ;
795- }
796-
797- public async supportsDowngrades ( ) {
798- return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_DOWNGRADES ) >= 0 ;
799- }
800-
801- public async supportsResolveQlref ( ) {
802- return ( await this . getVersion ( ) ) . compare ( CodeQLCliServer . CLI_VERSION_WITH_RESOLVE_QLREF ) >= 0 ;
803- }
804-
805771 private async refreshVersion ( ) {
806772 const distribution = await this . distributionProvider . getDistribution ( ) ;
807773 switch ( distribution . kind ) {
@@ -1030,3 +996,60 @@ export function shouldDebugQueryServer() {
1030996 && process . env . QUERY_SERVER_JAVA_DEBUG !== '0'
1031997 && process . env . QUERY_SERVER_JAVA_DEBUG ?. toLocaleLowerCase ( ) !== 'false' ;
1032998}
999+
1000+ export class CliVersionConstraint {
1001+
1002+ /**
1003+ * CLI version where --kind=DIL was introduced
1004+ */
1005+ public static CLI_VERSION_WITH_DECOMPILE_KIND_DIL = new SemVer ( '2.3.0' ) ;
1006+
1007+ /**
1008+ * CLI version where languages are exposed during a `codeql resolve database` command.
1009+ */
1010+ public static CLI_VERSION_WITH_LANGUAGE = new SemVer ( '2.4.1' ) ;
1011+
1012+ /**
1013+ * CLI version where `codeql resolve upgrades` supports
1014+ * the `--allow-downgrades` flag
1015+ */
1016+ public static CLI_VERSION_WITH_DOWNGRADES = new SemVer ( '2.4.4' ) ;
1017+
1018+ /**
1019+ * CLI version where the `codeql resolve qlref` command is available.
1020+ */
1021+ public static CLI_VERSION_WITH_RESOLVE_QLREF = new SemVer ( '2.5.1' ) ;
1022+
1023+ /**
1024+ * CLI version where database registration was introduced
1025+ */
1026+ public static CLI_VERSION_WITH_DB_REGISTRATION = new SemVer ( '2.4.1' ) ;
1027+
1028+ constructor ( private readonly cli : CodeQLCliServer ) {
1029+ /**/
1030+ }
1031+
1032+ private async isVersionAtLeast ( v : SemVer ) {
1033+ return ( await this . cli . getVersion ( ) ) . compare ( v ) >= 0 ;
1034+ }
1035+
1036+ public async supportsDecompileDil ( ) {
1037+ return this . isVersionAtLeast ( CliVersionConstraint . CLI_VERSION_WITH_DECOMPILE_KIND_DIL ) ;
1038+ }
1039+
1040+ public async supportsLanguageName ( ) {
1041+ return this . isVersionAtLeast ( CliVersionConstraint . CLI_VERSION_WITH_LANGUAGE ) ;
1042+ }
1043+
1044+ public async supportsDowngrades ( ) {
1045+ return this . isVersionAtLeast ( CliVersionConstraint . CLI_VERSION_WITH_DOWNGRADES ) ;
1046+ }
1047+
1048+ public async supportsResolveQlref ( ) {
1049+ return this . isVersionAtLeast ( CliVersionConstraint . CLI_VERSION_WITH_RESOLVE_QLREF ) ;
1050+ }
1051+
1052+ async supportsDatabaseRegistration ( ) {
1053+ return this . isVersionAtLeast ( CliVersionConstraint . CLI_VERSION_WITH_DB_REGISTRATION ) ;
1054+ }
1055+ }
0 commit comments