@@ -28,8 +28,11 @@ import {
2828} from "sequelize" ;
2929import fs from "fs" ;
3030import path from "path" ;
31+ import { toast } from "react-toastify" ;
3132import JSONStream from "jsonstream" ;
33+ import { DataNode } from "rc-tree/lib/interface" ;
3234import { DatabaseStructure , newDatabase } from "./models/database" ;
35+
3336import {
3437 filterSpdxKeys ,
3538 JSON_Type ,
@@ -39,9 +42,8 @@ import {
3942} from "./models/databaseUtils" ;
4043import { DebugLogger } from "../utils/logger" ;
4144import { FileAttributes } from "./models/file" ;
42- import { DataNode } from "rc-tree/lib/interface" ;
4345import { 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