Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated parser to support new license detection format #629

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
281 changes: 228 additions & 53 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@typescript-eslint/parser": "^6.9.1",
"@vercel/webpack-asset-relocator-loader": "^1.7.3",
"css-loader": "^6.8.1",
"electron": "^28.1.0",
"electron": "^28.2.0",
"electron-builder": "^24.9.1",
"eslint": "^8.53.0",
"eslint-plugin-css-import-order": "^1.1.0",
Expand All @@ -60,9 +60,9 @@
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"node-loader": "^2.0.0",
"style-loader": "^3.3.3",
"style-loader": "^3.3.4",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.0",
"ts-loader": "^9.5.1",
"typescript": "~5.2.2"
},
"dependencies": {
Expand Down Expand Up @@ -100,11 +100,11 @@
"react-router-dom": "^6.18.0",
"react-scroll": "^1.9.0",
"react-select": "^5.7.7",
"react-toastify": "^9.1.3",
"react-toastify": "^10.0.4",
"react-tooltip": "^5.22.0",
"scroll-into-view-if-needed": "^3.1.0",
"sequelize": "^6.34.0",
"sqlite3": "^5.1.6",
"sequelize": "^6.35.2",
"sqlite3": "^5.1.7",
"url-loader": "^4.1.1"
},
"overrides": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const MatchLicenseExpressionRenderer = (
])
);
newParsedComponents = parseTokensFromExpression(
matchInfo.match.license_expression_spdx
matchInfo.match.spdx_license_expression
).map((token) => {
const tokenInfo = licenseExpressionSpdxKeysMap.get(token);
if (tokenInfo) {
Expand Down
28 changes: 24 additions & 4 deletions src/components/LicenseEntity/LicenseMatchesTable.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import React from "react";
import { Button, OverlayTrigger, Popover, Table } from "react-bootstrap";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import {
LicenseClueMatch,
LicenseDetectionMatch,
} from "../../services/importedJsonTypes";
import { Button, OverlayTrigger, Popover, Table } from "react-bootstrap";
import MatchedTextRenderer from "./LicenseMatchCells/MatchedText";
import MatchLicenseExpressionRenderer from "./LicenseMatchCells/MatchLicenseExpression";
import { MatchedTextProvider } from "./MatchedTextContext";
import MatchRuleDetails from "./MatchRuleDetails";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import CoreLink from "../CoreLink/CoreLink";
import { useWorkbenchDB } from "../../contexts/dbContext";

interface LicenseMatchProps {
showLIcenseText?: boolean;
matches: LicenseClueMatch[] | LicenseDetectionMatch[];
}
const LicenseMatchesTable = (props: LicenseMatchProps) => {
const { matches, showLIcenseText } = props;
const { goToFileInTableView } = useWorkbenchDB();

return (
<MatchedTextProvider>
Expand All @@ -40,7 +42,7 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
/>
</td>
</tr>
{match.license_expression_spdx && (
{match.spdx_license_expression && (
<tr>
<td colSpan={2}>License Expression SPDX</td>
<td colSpan={7}>
Expand All @@ -53,6 +55,18 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
</td>
</tr>
)}
{match.from_file && (
<tr>
<td colSpan={2}>Matched file</td>
AyanSinhaMahapatra marked this conversation as resolved.
Show resolved Hide resolved
<td colSpan={7}>
<CoreLink
onClick={() => goToFileInTableView(match.from_file)}
>
{match.from_file}
</CoreLink>
</td>
</tr>
)}
{showLIcenseText && (
<tr className="matched-text-row">
<td colSpan={2}>Matched Text</td>
Expand All @@ -66,6 +80,12 @@ const LicenseMatchesTable = (props: LicenseMatchProps) => {
</td>
</tr>
)}
<tr>
<td colSpan={2}>Start Line</td>
<td colSpan={3}>{match.start_line}</td>
<td colSpan={2}>End Line</td>
<td colSpan={2}>{match.end_line}</td>
</tr>
<tr>
<td colSpan={2}>Matched length</td>
<td colSpan={3}>{match.matched_length}</td>
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/dbContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,11 @@ The SQLite file is invalid. Try re-importing the ScanCode JSON file and creating
}

function removeIpcListeners() {
ipcRenderer.removeAllListeners(NAVIGATION_CHANNEL);
ipcRenderer.removeAllListeners(IMPORT_REPLY_CHANNEL.JSON);
ipcRenderer.removeAllListeners(IMPORT_REPLY_CHANNEL.SQLITE);
ipcRenderer.removeAllListeners(SAVE_REPLY_CHANNEL.SQLITE);
ipcRenderer.removeAllListeners(NAVIGATION_CHANNEL);
ipcRenderer.removeAllListeners(UTIL_CHANNEL.CLOSE_FILE);
}

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { GENERAL_ACTIONS } from "./constants/IpcConnection";
import "./styles/index.css";
import "./styles/colors.css";

// Setup general actions
// Setup general action event listeners
ipcRenderer.on(GENERAL_ACTIONS.ZOOM_IN, () => {
webFrame.setZoomLevel(webFrame.getZoomLevel() + 0.5);
});
Expand Down
25 changes: 23 additions & 2 deletions src/services/importedJsonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { LicenseDetectionAttributes } from "./models/licenseDetections";
import { LicenseReferenceAttributes } from "./models/licenseReference";
import { LicenseRuleReferenceAttributes } from "./models/licenseRuleReference";

export interface LicenseExpressionKey {
key: string;
Expand All @@ -18,7 +20,8 @@ export interface LicenseMatch {
match_coverage: number;
matcher: string;
license_expression: string;
license_expression_spdx?: string;
spdx_license_expression?: string;
from_file?: string;
rule_identifier: string;
rule_relevance: number;
rule_url: string;
Expand All @@ -27,6 +30,9 @@ export interface LicenseMatch {
path?: string;
license_expression_keys?: LicenseExpressionKey[];
license_expression_spdx_keys?: LicenseExpressionSpdxKey[];

// Legacy output version fields
license_expression_spdx?: string;
}
export type LicenseDetectionMatch = LicenseMatch;
export type LicenseClueMatch = LicenseMatch;
Expand Down Expand Up @@ -64,10 +70,14 @@ export interface TopLevelLicenseDetection {
detection_count: number;
detection_log?: string[] | null;
file_regions?: LicenseFileRegion[];
matches?: LicenseDetectionMatch[];
reference_matches?: LicenseDetectionMatch[];

// Parser-added fields
matches?: LicenseDetectionMatch[]; // Also part of legacy output
AyanSinhaMahapatra marked this conversation as resolved.
Show resolved Hide resolved

// Legacy output version fields
count?: number;
sample_matches?: LicenseDetectionMatch[];
}
export interface ResourceLicenseDetection {
license_expression: string;
Expand All @@ -91,6 +101,17 @@ export interface RawTopLevelTodo {
detection: LicenseDetectionAttributes;
}

export interface RawTopLevelData {
headers: unknown[];
packages: unknown[];
dependencies: unknown[];
license_detections: unknown[];
license_references: LicenseReferenceAttributes[];
license_rule_references: LicenseRuleReferenceAttributes[];
license_policy: LicensePolicy[];
todo: RawTopLevelTodo[];
}

export interface Resource {
id?: number;
path: string;
Expand Down
2 changes: 1 addition & 1 deletion src/services/models/todo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Sequelize, DataTypes, Model } from "sequelize";
import { jsonDataType } from "./databaseUtils";

export interface TodoAttributes {
id: number;
id?: number;
AyanSinhaMahapatra marked this conversation as resolved.
Show resolved Hide resolved
detection_id: string;
issues: Record<string, string>;
}
Expand Down
Loading
Loading