Skip to content

Commit a138e17

Browse files
committed
Fixed matches parser not working for prev toolkit versions (absence of detection.identifier)
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent bae4edb commit a138e17

File tree

7 files changed

+27
-124
lines changed

7 files changed

+27
-124
lines changed

src/constants/data.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
export const LEGEND_LIMIT = 8;
2-
export const NO_VALUE_DETECTED_LABEL = 'No Value detected';
2+
export const NO_VALUE_DETECTED_LABEL = 'No Value detected';
3+
4+
export const UNKNOWN_EXPRESSION = "unknown-license-reference";
5+
export const UNKNOWN_EXPRESSION_SPDX =
6+
"LicenseRef-scancode-unknown-license-reference";

src/index.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
<head>
44
<meta charset="UTF-8" />
55
<title>Scancode Workbench</title>
6-
<!-- @TODO: Experimental work-around needed to have script in Prod., but no longer required now :) -->
7-
<!-- <script defer="defer" src="index.js"></script> -->
8-
96
<!-- <link rel="stylesheet" href="lib/css/c3/c3.css" type="text/css"/> -->
107
</head>
118
<body>

src/mainMenu.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ function getTemplate() {
196196
},
197197
{
198198
label: 'Licensing Information',
199-
// // @TODO
200-
// click: () => showErrorDialog({
201-
// title: "Not implemented",
202-
// message: "This feature is yet to be discussed"
203-
// })
204199
click: () => {
205200
// @TODO - make react route instead
206201
let win = new BrowserWindow({frame: true});

src/pages/Packages/Packages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const Packages = () => {
179179
})
180180
});
181181
const parsedPackageWithDeps = Array.from(packageMapping.values());
182-
// @TODO
182+
// @TODO - What are qualifiers ?
183183
parsedPackageWithDeps.forEach(pkg => {
184184
if(Object.keys(pkg.qualifiers).length)
185185
console.log("Qualifying:", pkg);

src/pages/TableView/CustomCellRenderers/LicenseDetections/MatchLicenseExpressionRenderer.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { useMemo } from "react";
22
import { LICENSE_EXPRESSIONS_CONJUNCTIONS, parseTokensFromExpression } from "../../../../services/models/databaseUtils";
33

4-
// @TODO - Create SPDXLicenseExpressionParser too !!
4+
const DEBUG_URLS = false;
5+
56
interface LicenseExpressionRendererProps {
67
value: string;
78
spdxLicense?: boolean;
@@ -25,8 +26,6 @@ interface ParsedTokens {
2526
href?: string;
2627
}
2728

28-
const DEBUG_URLS = false;
29-
3029
const MatchLicenseExpressionRenderer = (
3130
props: LicenseExpressionRendererProps
3231
) => {

src/pages/TableView/TableView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ const TableView = () => {
228228
gridApi={gridApi}
229229
updateGridApi={setGridApi}
230230
onColumnMoved={(event: ColumnMovedEvent<any>) => {
231-
// @TODO
231+
// @TODO - Save order of columns when moved
232232
// console.log("Column moved", event);
233-
234233
}}
235234
columnDefs={columnDefs}
236235
tableData={tableData}

src/services/workbenchDB.ts

Lines changed: 18 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ import {
2828
} from "sequelize";
2929
import fs from "fs";
3030
import path from "path";
31+
import { toast } from "react-toastify";
3132
import JSONStream from "jsonstream";
33+
import { DataNode } from "rc-tree/lib/interface";
3234
import { DatabaseStructure, newDatabase } from "./models/database";
35+
3336
import {
3437
filterSpdxKeys,
3538
JSON_Type,
@@ -39,9 +42,8 @@ import {
3942
} from "./models/databaseUtils";
4043
import { DebugLogger } from "../utils/logger";
4144
import { FileAttributes } from "./models/file";
42-
import { DataNode } from "rc-tree/lib/interface";
4345
import { flattenFile } from "./models/flatFile";
44-
import { toast } from "react-toastify";
46+
import { UNKNOWN_EXPRESSION, UNKNOWN_EXPRESSION_SPDX } from "../constants/data";
4547

4648
/**
4749
* Manages the database created from a ScanCode JSON input.
@@ -91,27 +93,19 @@ export class WorkbenchDB {
9193
const password = config && config.dbPassword ? config.dbPassword : null;
9294
const storage = config && config.dbStorage ? config.dbStorage : ":memory:";
9395

94-
console.log("Sequelize DB details", {
95-
name,
96-
user,
97-
password,
98-
storage,
99-
});
96+
// console.log("Sequelize DB details", {
97+
// name,
98+
// user,
99+
// password,
100+
// storage,
101+
// });
100102

101103
this.sequelize = new Sequelize(name, user, password, {
102104
dialect: "sqlite",
103105
// dialectModule: { Database },
104106
// dialectOptions: {
105107
// sqlite3: Database,
106108
// },
107-
// dialectModule: BetterSqlite3,
108-
// dialectOptions: {
109-
// sqlite3: BetterSqlite3,
110-
// },
111-
// dialectModule: sqlite3,
112-
// dialectOptions: {
113-
// sqlite3
114-
// },
115109
storage: storage,
116110
logging: false,
117111
});
@@ -262,15 +256,12 @@ export class WorkbenchDB {
262256
let rootPath: string | null = null;
263257
let hasRootPath = false;
264258
const batchSize = 1000;
265-
let files: unknown[] = []; // @TODO
259+
let files: unknown[] = []; // @TODO - Define proper type for this
266260
let progress = 0;
267261
let promiseChain: Promise<void | DatabaseStructure | number> = this.sync;
268262

269263
console.log("JSON parse started (step 1)");
270264
console.time("json-parse-time");
271-
// @TODO - Remove this in next commit
272-
const DEBUG_MODE_MATCHES = true;
273-
const DEBUG_MATCH_FILE_NAME = "node_modules/rc/package.json";
274265

275266
return new Promise((resolve, reject) => {
276267
// eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -371,25 +362,17 @@ export class WorkbenchDB {
371362
const file_license_expressions_spdx_components = parseSubExpressions(
372363
file.detected_license_expression_spdx
373364
);
374-
const UNKNOWN_EXPRESSION = "unknown-license-reference";
375-
const UNKNOWN_EXPRESSION_SPDX =
376-
"LicenseRef-scancode-unknown-license-reference";
377-
378-
if (DEBUG_MODE_MATCHES && file.path.includes(DEBUG_MATCH_FILE_NAME))
379-
console.log("Sub", {
380-
detected: file.detected_license_expression,
381-
detectedspdx: file.detected_license_expression_spdx,
382-
detected_sub_license_expressions:
383-
file_license_expressions_components,
384-
detected_sub_license_expressions_spdx:
385-
file_license_expressions_spdx_components,
386-
});
365+
// Handle absence of detection.identifier in matches at file level in prev toolkit versions
366+
// upto v32.0.0rc2
367+
const for_license_detections: string[] = file.for_license_detections || [];
387368

388369
file?.license_detections?.forEach(
389370
(detection: any, detectionIdx: number) => {
390-
const targetLicenseDetection: any =
391-
TopLevelData.license_detections_map.get(detection.identifier);
371+
const detectionIdentifier = detection.identifier || for_license_detections[detectionIdx];
392372

373+
const targetLicenseDetection: any =
374+
TopLevelData.license_detections_map.get(detectionIdentifier);
375+
393376
if (!targetLicenseDetection) return;
394377
if (!targetLicenseDetection.file_regions)
395378
targetLicenseDetection.file_regions = [];
@@ -429,25 +412,6 @@ export class WorkbenchDB {
429412
correspondingFileLicenseExpressionSpdxComponent
430413
);
431414

432-
if (
433-
DEBUG_MODE_MATCHES &&
434-
file.path.includes(DEBUG_MATCH_FILE_NAME)
435-
)
436-
console.log(`Detection #${detectionIdx} in ${file.path}, `, {
437-
jsonDetection: detection,
438-
targetLicenseDetection,
439-
detection_le: detection.license_expression,
440-
detection_lespdx:
441-
file_license_expressions_spdx_components[
442-
file_license_expressions_components.findIndex(
443-
(val) => val === detection.license_expression
444-
)
445-
],
446-
detectionComponents: detectionLicenseExpressionComponents,
447-
detectionSpdxComponents:
448-
detectionSpdxLicenseExpressionComponents,
449-
});
450-
451415
let min_start_line = detection.matches[0].start_line;
452416
let max_end_line = detection.matches[0].end_line;
453417

@@ -495,33 +459,6 @@ export class WorkbenchDB {
495459
const parsedSpdxLicenseKeys = parseSubExpressions(
496460
match.license_expression_spdx
497461
);
498-
if (
499-
DEBUG_MODE_MATCHES &&
500-
file.path.includes(DEBUG_MATCH_FILE_NAME)
501-
)
502-
console.log(
503-
`Match details ${matchIdx}. ${match.license_expression}`,
504-
{
505-
license_expression: match.license_expression,
506-
license_expression_spdx: match.license_expression_spdx,
507-
parsedLicenseKeys,
508-
parsedLicenseSpdxKeys: parsedSpdxLicenseKeys,
509-
foundItemInLE: file_license_expressions_components.find(
510-
(val) => val === match.license_expression
511-
),
512-
foundItemInLEIdx:
513-
file_license_expressions_components.findIndex(
514-
(val) => val === match.license_expression
515-
),
516-
corresponding:
517-
file_license_expressions_spdx_components[
518-
file_license_expressions_components.findIndex(
519-
(val) => val === match.license_expression
520-
)
521-
],
522-
}
523-
);
524-
// console.log("Debug for match expression", match.license_expression_keys, match.license_expression_spdx_keys);
525462

526463
parsedLicenseKeys.forEach((key) => {
527464
const license_reference: any =
@@ -552,31 +489,9 @@ export class WorkbenchDB {
552489
start_line: min_start_line,
553490
end_line: max_end_line,
554491
});
555-
if (
556-
DEBUG_MODE_MATCHES &&
557-
file.path.includes(DEBUG_MATCH_FILE_NAME)
558-
)
559-
console.log(
560-
`(Matches: ${targetLicenseDetection.matches.length}) Prepared detection in ${file.path}`,
561-
detection,
562-
targetLicenseDetection
563-
);
564492
}
565493

566494
delete detection.matches; // Not required, adds extra memory usage
567-
568-
if (
569-
DEBUG_MODE_MATCHES &&
570-
file.path.includes(DEBUG_MATCH_FILE_NAME)
571-
) {
572-
console.log(
573-
"Final top level detection",
574-
targetLicenseDetection
575-
);
576-
console.log(
577-
"\n----------------------------------------------------------------\n"
578-
);
579-
}
580495
}
581496
);
582497

@@ -732,12 +647,6 @@ export class WorkbenchDB {
732647

733648
const flattenedFiles = files.map((file: unknown) => flattenFile(file));
734649

735-
// @DEBUG
736-
// flattenedFiles.forEach(file => {
737-
// if(file.path == 'samples/JGroups/EULA')
738-
// console.log("Flat File: ", file);
739-
// });
740-
741650
return this.db.FlatFile.bulkCreate(flattenedFiles as any, {
742651
logging: false,
743652
});

0 commit comments

Comments
 (0)