Skip to content

Commit 4aa8fe5

Browse files
authored
Merge pull request #629 from nexB/update/license-detections-format
Updated parser to support new license detection format
2 parents c019c2f + 8399edc commit 4aa8fe5

File tree

11 files changed

+1709
-732
lines changed

11 files changed

+1709
-732
lines changed

package-lock.json

Lines changed: 228 additions & 53 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@typescript-eslint/parser": "^6.9.1",
5151
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
5252
"css-loader": "^6.8.1",
53-
"electron": "^28.1.0",
53+
"electron": "^28.2.0",
5454
"electron-builder": "^24.9.1",
5555
"eslint": "^8.53.0",
5656
"eslint-plugin-css-import-order": "^1.1.0",
@@ -60,9 +60,9 @@
6060
"jest": "^29.7.0",
6161
"jest-environment-jsdom": "^29.7.0",
6262
"node-loader": "^2.0.0",
63-
"style-loader": "^3.3.3",
63+
"style-loader": "^3.3.4",
6464
"ts-jest": "^29.1.1",
65-
"ts-loader": "^9.5.0",
65+
"ts-loader": "^9.5.1",
6666
"typescript": "~5.2.2"
6767
},
6868
"dependencies": {
@@ -100,11 +100,11 @@
100100
"react-router-dom": "^6.18.0",
101101
"react-scroll": "^1.9.0",
102102
"react-select": "^5.7.7",
103-
"react-toastify": "^9.1.3",
103+
"react-toastify": "^10.0.4",
104104
"react-tooltip": "^5.22.0",
105105
"scroll-into-view-if-needed": "^3.1.0",
106-
"sequelize": "^6.34.0",
107-
"sqlite3": "^5.1.6",
106+
"sequelize": "^6.35.2",
107+
"sqlite3": "^5.1.7",
108108
"url-loader": "^4.1.1"
109109
},
110110
"overrides": {

src/components/LicenseEntity/LicenseMatchCells/MatchLicenseExpression.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const MatchLicenseExpressionRenderer = (
4848
])
4949
);
5050
newParsedComponents = parseTokensFromExpression(
51-
matchInfo.match.license_expression_spdx
51+
matchInfo.match.spdx_license_expression
5252
).map((token) => {
5353
const tokenInfo = licenseExpressionSpdxKeysMap.get(token);
5454
if (tokenInfo) {

src/components/LicenseEntity/LicenseMatchesTable.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import React from "react";
2+
import { Button, OverlayTrigger, Popover, Table } from "react-bootstrap";
3+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
4+
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
25
import {
36
LicenseClueMatch,
47
LicenseDetectionMatch,
58
} from "../../services/importedJsonTypes";
6-
import { Button, OverlayTrigger, Popover, Table } from "react-bootstrap";
79
import MatchedTextRenderer from "./LicenseMatchCells/MatchedText";
810
import MatchLicenseExpressionRenderer from "./LicenseMatchCells/MatchLicenseExpression";
911
import { MatchedTextProvider } from "./MatchedTextContext";
1012
import MatchRuleDetails from "./MatchRuleDetails";
11-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
12-
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
1313
import CoreLink from "../CoreLink/CoreLink";
14+
import { useWorkbenchDB } from "../../contexts/dbContext";
1415

1516
interface LicenseMatchProps {
1617
showLIcenseText?: boolean;
1718
matches: LicenseClueMatch[] | LicenseDetectionMatch[];
1819
}
1920
const LicenseMatchesTable = (props: LicenseMatchProps) => {
2021
const { matches, showLIcenseText } = props;
22+
const { goToFileInTableView } = useWorkbenchDB();
2123

2224
return (
2325
<MatchedTextProvider>
@@ -40,7 +42,7 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
4042
/>
4143
</td>
4244
</tr>
43-
{match.license_expression_spdx && (
45+
{match.spdx_license_expression && (
4446
<tr>
4547
<td colSpan={2}>License Expression SPDX</td>
4648
<td colSpan={7}>
@@ -53,6 +55,18 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
5355
</td>
5456
</tr>
5557
)}
58+
{match.from_file && (
59+
<tr>
60+
<td colSpan={2}>From file</td>
61+
<td colSpan={7}>
62+
<CoreLink
63+
onClick={() => goToFileInTableView(match.from_file)}
64+
>
65+
{match.from_file}
66+
</CoreLink>
67+
</td>
68+
</tr>
69+
)}
5670
{showLIcenseText && (
5771
<tr className="matched-text-row">
5872
<td colSpan={2}>Matched Text</td>
@@ -66,6 +80,12 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
6680
</td>
6781
</tr>
6882
)}
83+
<tr>
84+
<td colSpan={2}>Start Line</td>
85+
<td colSpan={3}>{match.start_line}</td>
86+
<td colSpan={2}>End Line</td>
87+
<td colSpan={2}>{match.end_line}</td>
88+
</tr>
6989
<tr>
7090
<td colSpan={2}>Matched length</td>
7191
<td colSpan={3}>{match.matched_length}</td>

src/contexts/dbContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,11 @@ The SQLite file is invalid. Try re-importing the ScanCode JSON file and creating
386386
}
387387

388388
function removeIpcListeners() {
389+
ipcRenderer.removeAllListeners(NAVIGATION_CHANNEL);
389390
ipcRenderer.removeAllListeners(IMPORT_REPLY_CHANNEL.JSON);
390391
ipcRenderer.removeAllListeners(IMPORT_REPLY_CHANNEL.SQLITE);
391392
ipcRenderer.removeAllListeners(SAVE_REPLY_CHANNEL.SQLITE);
392-
ipcRenderer.removeAllListeners(NAVIGATION_CHANNEL);
393+
ipcRenderer.removeAllListeners(UTIL_CHANNEL.CLOSE_FILE);
393394
}
394395

395396
useEffect(() => {

src/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { GENERAL_ACTIONS } from "./constants/IpcConnection";
3434
import "./styles/index.css";
3535
import "./styles/colors.css";
3636

37-
// Setup general actions
37+
// Setup general action event listeners
3838
ipcRenderer.on(GENERAL_ACTIONS.ZOOM_IN, () => {
3939
webFrame.setZoomLevel(webFrame.getZoomLevel() + 0.5);
4040
});

src/services/importedJsonTypes.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { LicenseDetectionAttributes } from "./models/licenseDetections";
2+
import { LicenseReferenceAttributes } from "./models/licenseReference";
3+
import { LicenseRuleReferenceAttributes } from "./models/licenseRuleReference";
24

35
export interface LicenseExpressionKey {
46
key: string;
@@ -18,7 +20,8 @@ export interface LicenseMatch {
1820
match_coverage: number;
1921
matcher: string;
2022
license_expression: string;
21-
license_expression_spdx?: string;
23+
spdx_license_expression?: string;
24+
from_file?: string;
2225
rule_identifier: string;
2326
rule_relevance: number;
2427
rule_url: string;
@@ -27,6 +30,9 @@ export interface LicenseMatch {
2730
path?: string;
2831
license_expression_keys?: LicenseExpressionKey[];
2932
license_expression_spdx_keys?: LicenseExpressionSpdxKey[];
33+
34+
// Legacy output version fields
35+
license_expression_spdx?: string;
3036
}
3137
export type LicenseDetectionMatch = LicenseMatch;
3238
export type LicenseClueMatch = LicenseMatch;
@@ -64,10 +70,14 @@ export interface TopLevelLicenseDetection {
6470
detection_count: number;
6571
detection_log?: string[] | null;
6672
file_regions?: LicenseFileRegion[];
67-
matches?: LicenseDetectionMatch[];
73+
reference_matches?: LicenseDetectionMatch[];
74+
75+
// Parser-added fields
76+
matches?: LicenseDetectionMatch[]; // Also part of legacy output
6877

6978
// Legacy output version fields
7079
count?: number;
80+
sample_matches?: LicenseDetectionMatch[];
7181
}
7282
export interface ResourceLicenseDetection {
7383
license_expression: string;
@@ -91,6 +101,17 @@ export interface RawTopLevelTodo {
91101
detection: LicenseDetectionAttributes;
92102
}
93103

104+
export interface RawTopLevelData {
105+
headers: unknown[];
106+
packages: unknown[];
107+
dependencies: unknown[];
108+
license_detections: unknown[];
109+
license_references: LicenseReferenceAttributes[];
110+
license_rule_references: LicenseRuleReferenceAttributes[];
111+
license_policy: LicensePolicy[];
112+
todo: RawTopLevelTodo[];
113+
}
114+
94115
export interface Resource {
95116
id?: number;
96117
path: string;

0 commit comments

Comments
 (0)