Skip to content

Commit af9b544

Browse files
Try to get tests passing
Co-authored by: Marc Jaramillo mnj.webdeveloper@gmail.com Co-authored by: Musab Guma'a mgsium@github.com
1 parent 0f2e3d8 commit af9b544

4 files changed

Lines changed: 33 additions & 32 deletions

File tree

extensions/ql-vscode/src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ export class CliVersionConstraint {
10861086
/**
10871087
* CLI version where the `database unbundle` subcommand was introduced.
10881088
*/
1089-
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.4');
1089+
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
10901090

10911091
constructor(private readonly cli: CodeQLCliServer) {
10921092
/**/

extensions/ql-vscode/src/databaseFetcher.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ import { tmpDir } from './run-queries';
2929
* @param storagePath where to store the unzipped database.
3030
*/
3131
export async function promptImportInternetDatabase(
32-
cli: CodeQLCliServer,
3332
databaseManager: DatabaseManager,
3433
storagePath: string,
3534
progress: ProgressCallback,
3635
token: CancellationToken,
36+
cli?: CodeQLCliServer
3737
): Promise<DatabaseItem | undefined> {
3838
const databaseUrl = await window.showInputBox({
3939
prompt: 'Enter URL of zipfile of database to download',
@@ -45,12 +45,12 @@ export async function promptImportInternetDatabase(
4545
validateHttpsUrl(databaseUrl);
4646

4747
const item = await databaseArchiveFetcher(
48-
cli,
4948
databaseUrl,
5049
databaseManager,
5150
storagePath,
5251
progress,
53-
token
52+
token,
53+
cli
5454
);
5555

5656
if (item) {
@@ -70,11 +70,11 @@ export async function promptImportInternetDatabase(
7070
* @param storagePath where to store the unzipped database.
7171
*/
7272
export async function promptImportLgtmDatabase(
73-
cli: CodeQLCliServer,
7473
databaseManager: DatabaseManager,
7574
storagePath: string,
7675
progress: ProgressCallback,
77-
token: CancellationToken
76+
token: CancellationToken,
77+
cli?: CodeQLCliServer
7878
): Promise<DatabaseItem | undefined> {
7979
progress({
8080
message: 'Choose project',
@@ -93,12 +93,12 @@ export async function promptImportLgtmDatabase(
9393
const databaseUrl = await convertToDatabaseUrl(lgtmUrl, progress);
9494
if (databaseUrl) {
9595
const item = await databaseArchiveFetcher(
96-
cli,
9796
databaseUrl,
9897
databaseManager,
9998
storagePath,
10099
progress,
101-
token
100+
token,
101+
cli
102102
);
103103
if (item) {
104104
await commands.executeCommand('codeQLDatabases.focus');
@@ -120,21 +120,21 @@ export async function promptImportLgtmDatabase(
120120
* @param storagePath where to store the unzipped database.
121121
*/
122122
export async function importArchiveDatabase(
123-
cli: CodeQLCliServer,
124123
databaseUrl: string,
125124
databaseManager: DatabaseManager,
126125
storagePath: string,
127126
progress: ProgressCallback,
128127
token: CancellationToken,
128+
cli?: CodeQLCliServer,
129129
): Promise<DatabaseItem | undefined> {
130130
try {
131131
const item = await databaseArchiveFetcher(
132-
cli,
133132
databaseUrl,
134133
databaseManager,
135134
storagePath,
136135
progress,
137-
token
136+
token,
137+
cli
138138
);
139139
if (item) {
140140
await commands.executeCommand('codeQLDatabases.focus');
@@ -162,12 +162,12 @@ export async function importArchiveDatabase(
162162
* @param token cancellation token
163163
*/
164164
async function databaseArchiveFetcher(
165-
cli: CodeQLCliServer,
166165
databaseUrl: string,
167166
databaseManager: DatabaseManager,
168167
storagePath: string,
169168
progress: ProgressCallback,
170-
token: CancellationToken
169+
token: CancellationToken,
170+
cli?: CodeQLCliServer,
171171
): Promise<DatabaseItem> {
172172
progress({
173173
message: 'Getting database',
@@ -181,9 +181,9 @@ async function databaseArchiveFetcher(
181181
const unzipPath = await getStorageFolder(storagePath, databaseUrl);
182182

183183
if (isFile(databaseUrl)) {
184-
await readAndUnzip(cli, databaseUrl, unzipPath, progress);
184+
await readAndUnzip(databaseUrl, unzipPath, cli, progress);
185185
} else {
186-
await fetchAndUnzip(cli, databaseUrl, unzipPath, progress);
186+
await fetchAndUnzip(databaseUrl, unzipPath, cli, progress);
187187
}
188188

189189
progress({
@@ -255,9 +255,9 @@ function validateHttpsUrl(databaseUrl: string) {
255255
}
256256

257257
async function readAndUnzip(
258-
cli: CodeQLCliServer,
259258
zipUrl: string,
260259
unzipPath: string,
260+
cli?: CodeQLCliServer,
261261
progress?: ProgressCallback
262262
) {
263263
// TODO: Providing progress as the file is unzipped is currently blocked
@@ -268,7 +268,7 @@ async function readAndUnzip(
268268
step: 9,
269269
message: `Unzipping into ${path.basename(unzipPath)}`
270270
});
271-
if(await cli.cliConstraints.supportsDatabaseUnbundle()) {
271+
if (cli !== undefined && await cli.cliConstraints.supportsDatabaseUnbundle()) {
272272
// Use the `database unbundle` command if the installed cli version supports it
273273
await cli.databaseUnbundle(zipFile, unzipPath);
274274
} else {
@@ -281,9 +281,9 @@ async function readAndUnzip(
281281
}
282282

283283
async function fetchAndUnzip(
284-
cli: CodeQLCliServer,
285284
databaseUrl: string,
286285
unzipPath: string,
286+
cli?: CodeQLCliServer,
287287
progress?: ProgressCallback
288288
) {
289289
// Although it is possible to download and stream directly to an unzipped directory,
@@ -312,8 +312,9 @@ async function fetchAndUnzip(
312312
.on('finish', resolve)
313313
.on('error', reject)
314314
);
315-
316-
await readAndUnzip(cli, Uri.file(archivePath).toString(true), unzipPath, progress);
315+
if (cli && await cli.cliConstraints.supportsDatabaseUnbundle()) {
316+
await readAndUnzip(Uri.file(archivePath).toString(true), unzipPath, cli, progress);
317+
}
317318

318319
// remove archivePath eagerly since these archives can be large.
319320
await fs.remove(archivePath);

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,11 @@ export class DatabaseUI extends DisposableObject {
458458
throw new Error('Query server not started');
459459
}
460460
return await promptImportInternetDatabase(
461-
this.queryServer.cliServer,
462461
this.databaseManager,
463462
this.storagePath,
464463
progress,
465-
token
464+
token,
465+
this.queryServer.cliServer
466466
);
467467
};
468468

@@ -474,11 +474,11 @@ export class DatabaseUI extends DisposableObject {
474474
throw new Error('Query server not started');
475475
}
476476
return await promptImportLgtmDatabase(
477-
this.queryServer.cliServer,
478477
this.databaseManager,
479478
this.storagePath,
480479
progress,
481-
token
480+
token,
481+
this.queryServer.cliServer
482482
);
483483
};
484484

@@ -588,12 +588,12 @@ export class DatabaseUI extends DisposableObject {
588588
// Assume user has selected an archive if the file has a .zip extension
589589
if (uri.path.endsWith('.zip')) {
590590
await importArchiveDatabase(
591-
this.queryServer.cliServer,
592591
uri.toString(true),
593592
this.databaseManager,
594593
this.storagePath,
595594
progress,
596-
token
595+
token,
596+
this.queryServer.cliServer
597597
);
598598
} else {
599599
await this.setCurrentDatabase(progress, token, uri);
@@ -725,12 +725,12 @@ export class DatabaseUI extends DisposableObject {
725725
// we are selecting a database archive. Must unzip into a workspace-controlled area
726726
// before importing.
727727
return await importArchiveDatabase(
728-
this.queryServer.cliServer,
729728
uri.toString(true),
730729
this.databaseManager,
731730
this.storagePath,
732731
progress,
733-
token
732+
token,
733+
this.queryServer.cliServer
734734
);
735735
}
736736
}

extensions/ql-vscode/src/vscode-tests/cli-integration/databases.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ describe('Databases', function() {
1919

2020
const LGTM_URL = 'https://lgtm.com/projects/g/aeisenberg/angular-bind-notifier/';
2121

22-
let cli: CodeQLCliServer;
2322
let databaseManager: DatabaseManager;
2423
let sandbox: sinon.SinonSandbox;
2524
let inputBoxStub: sinon.SinonStub;
25+
let cli: CodeQLCliServer;
2626
let progressCallback: ProgressCallback;
2727

2828
beforeEach(async () => {
@@ -55,7 +55,7 @@ describe('Databases', function() {
5555
it('should add a database from a folder', async () => {
5656
const progressCallback = sandbox.spy() as ProgressCallback;
5757
const uri = Uri.file(dbLoc);
58-
let dbItem = await importArchiveDatabase(cli, uri.toString(true), databaseManager, storagePath, progressCallback, {} as CancellationToken);
58+
let dbItem = await importArchiveDatabase(uri.toString(true), databaseManager, storagePath, progressCallback, {} as CancellationToken, cli);
5959
expect(dbItem).to.be.eq(databaseManager.currentDatabaseItem);
6060
expect(dbItem).to.be.eq(databaseManager.databaseItems[0]);
6161
expect(dbItem).not.to.be.undefined;
@@ -66,7 +66,7 @@ describe('Databases', function() {
6666

6767
it('should add a database from lgtm with only one language', async () => {
6868
inputBoxStub.resolves(LGTM_URL);
69-
let dbItem = await promptImportLgtmDatabase(cli, databaseManager, storagePath, progressCallback, {} as CancellationToken);
69+
let dbItem = await promptImportLgtmDatabase(databaseManager, storagePath, progressCallback, {} as CancellationToken, cli);
7070
expect(dbItem).not.to.be.undefined;
7171
dbItem = dbItem!;
7272
expect(dbItem.name).to.eq('aeisenberg_angular-bind-notifier_106179a');
@@ -76,7 +76,7 @@ describe('Databases', function() {
7676
it('should add a database from a url', async () => {
7777
inputBoxStub.resolves(DB_URL);
7878

79-
let dbItem = await promptImportInternetDatabase(cli, databaseManager, storagePath, progressCallback, {} as CancellationToken);
79+
let dbItem = await promptImportInternetDatabase(databaseManager, storagePath, progressCallback, {} as CancellationToken, cli);
8080
expect(dbItem).not.to.be.undefined;
8181
dbItem = dbItem!;
8282
expect(dbItem.name).to.eq('db');

0 commit comments

Comments
 (0)