From 1f751113eae40f22feb1d3f590333dd30d83b9bc Mon Sep 17 00:00:00 2001 From: Jag Jayaprakash Date: Thu, 5 Sep 2024 09:12:52 -0700 Subject: [PATCH 1/3] NEW (Extension) @W-15639920@ CLI changes to pass java env variable to enable caching and path for delta runs --- src/commands/scanner/run/dfa.ts | 12 +++++++++++- src/lib/EngineOptionsFactory.ts | 10 +++++++++- src/lib/sfge/SfgeWrapper.ts | 21 ++++++++++++++++++++- src/types.ts | 2 ++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/commands/scanner/run/dfa.ts b/src/commands/scanner/run/dfa.ts index 05c0cb2b8..6e348f18f 100644 --- a/src/commands/scanner/run/dfa.ts +++ b/src/commands/scanner/run/dfa.ts @@ -69,7 +69,17 @@ export default class Dfa extends ScannerRunCommand { summary: getMessage(BundleName.RunDfa, 'flags.pathexplimitSummary'), description: getMessage(BundleName.RunDfa, 'flags.pathexplimitDescription'), env: 'SFGE_PATH_EXPANSION_LIMIT' - }) + }), + 'enablecaching': Flags.boolean({ + summary: '', + description: '', + env: 'SFGE_ENABLE_CACHING' + }), + 'cachepath': Flags.string({ + summary: '', + description: '', + env: 'SFGE_FILES_TO_ENTRIES_CACHE_LOCATION' + }), // END: Config-overrideable engine flags. }; diff --git a/src/lib/EngineOptionsFactory.ts b/src/lib/EngineOptionsFactory.ts index d159586a1..e4cfdcc2e 100644 --- a/src/lib/EngineOptionsFactory.ts +++ b/src/lib/EngineOptionsFactory.ts @@ -28,7 +28,9 @@ abstract class CommonEngineOptionsFactory implements EngineOptionsFactory { const options: Map = new Map(); if (this.shouldSfgeRun(inputs)) { const sfgeConfig: SfgeConfig = { - projectDirs: this.inputProcessor.resolveProjectDirPaths(inputs) + projectDirs: this.inputProcessor.resolveProjectDirPaths(inputs), + cachepath: inputs.cachepath, + enablecaching: inputs.enablecaching }; options.set(CUSTOM_CONFIG.SfgeConfig, JSON.stringify(sfgeConfig)); } @@ -114,6 +116,12 @@ export class RunDfaEngineOptionsFactory extends CommonEngineOptionsFactory { if (inputs['pathexplimit'] != null) { sfgeConfig.pathexplimit = inputs['pathexplimit'] as number; } + if (inputs['enablecaching'] != null) { + sfgeConfig.enablecaching = inputs['enablecaching'] as boolean; + } + if (inputs['cachepath'] != null) { + sfgeConfig.cachepath = inputs['cachepath'] as string; + } sfgeConfig.ruleDisableWarningViolation = getBooleanEngineOption(inputs, RULE_DISABLE_WARNING_VIOLATION_FLAG); engineOptions.set(CUSTOM_CONFIG.SfgeConfig, JSON.stringify(sfgeConfig)); diff --git a/src/lib/sfge/SfgeWrapper.ts b/src/lib/sfge/SfgeWrapper.ts index b9bb64871..4ec616f99 100644 --- a/src/lib/sfge/SfgeWrapper.ts +++ b/src/lib/sfge/SfgeWrapper.ts @@ -33,6 +33,8 @@ type SfgeWrapperOptions = { spinnerManager: SpinnerManager; jvmArgs?: string; pathExpLimit?: number; + enablecaching?: boolean; + cachepath?: string; } type SfgeCatalogOptions = SfgeWrapperOptions & { @@ -46,6 +48,8 @@ type SfgeExecuteOptions = SfgeWrapperOptions & { ruleThreadCount?: number; ruleThreadTimeout?: number; ruleDisableWarningViolation?: boolean; + enablecaching?: boolean; + cachepath?: string; } type SfgeTarget = { @@ -57,6 +61,8 @@ type SfgeInput = { targets: SfgeTarget[]; projectDirs: string[]; rulesToRun: string[]; + enablecaching?: boolean; + cachepath?: string; }; class SfgeSpinnerManager extends AsyncCreatable implements SpinnerManager { @@ -164,6 +170,7 @@ abstract class AbstractSfgeWrapper extends CommandLineSupport { } args.push(...this.getSupplementalFlags(), MAIN_CLASS, this.action, ...(await this.getSupplementalArgs())); this.logger.trace(`Preparing to execute sfge with command: "${command}", args: "${JSON.stringify(args)}"`); + console.log(`Preparing to execute sfge with command: "${command}", args: "${JSON.stringify(args)}"`); return [command, args]; } protected async execute(): Promise { @@ -209,6 +216,8 @@ export class SfgeExecuteWrapper extends AbstractSfgeWrapper { private ruleThreadCount: number; private ruleThreadTimeout: number; private ruleDisableWarningViolation: boolean; + private enablecaching: boolean; + private cachepath: string; constructor(options: SfgeExecuteOptions) { super(options); @@ -218,6 +227,8 @@ export class SfgeExecuteWrapper extends AbstractSfgeWrapper { this.ruleThreadCount = options.ruleThreadCount; this.ruleThreadTimeout = options.ruleThreadTimeout; this.ruleDisableWarningViolation = options.ruleDisableWarningViolation; + this.enablecaching = options.enablecaching; + this.cachepath = options.cachepath; } protected getSupplementalFlags(): string[] { @@ -231,6 +242,12 @@ export class SfgeExecuteWrapper extends AbstractSfgeWrapper { if (this.ruleDisableWarningViolation != null) { flags.push(`-DSFGE_RULE_DISABLE_WARNING_VIOLATION=${this.ruleDisableWarningViolation.toString()}`); } + if (this.enablecaching) { + flags.push(`-DSFGE_DISABLE_CACHING=false`); + } + if (this.cachepath != null) { + flags.push(`-DSFGE_FILES_TO_ENTRIES_CACHE_LOCATION=${this.cachepath}`); + } return flags; } @@ -291,7 +308,9 @@ export class SfgeExecuteWrapper extends AbstractSfgeWrapper { pathExpLimit: sfgeConfig.pathexplimit, ruleThreadCount: sfgeConfig.ruleThreadCount, ruleThreadTimeout: sfgeConfig.ruleThreadTimeout, - ruleDisableWarningViolation: sfgeConfig.ruleDisableWarningViolation + ruleDisableWarningViolation: sfgeConfig.ruleDisableWarningViolation, + cachepath: sfgeConfig.cachepath, + enablecaching: sfgeConfig.enablecaching }); return wrapper.execute(); } diff --git a/src/types.ts b/src/types.ts index 21d9da770..bec41e4f5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -204,4 +204,6 @@ export type SfgeConfig = { ruleDisableWarningViolation?: boolean; jvmArgs?: string; pathexplimit?: number; + enablecaching?: boolean; + cachepath?: string; }; From 1ab7f499db809f9c64ab62bb774fff5c024f40fd Mon Sep 17 00:00:00 2001 From: Jag Jayaprakash Date: Thu, 5 Sep 2024 10:02:24 -0700 Subject: [PATCH 2/3] NEW (Extension) @W-15639920@ CLI changes to pass java env variable to enable caching and path for delta runs - part 2 --- src/lib/EngineOptionsFactory.ts | 4 ++-- src/lib/sfge/SfgeWrapper.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/EngineOptionsFactory.ts b/src/lib/EngineOptionsFactory.ts index e4cfdcc2e..f6923863e 100644 --- a/src/lib/EngineOptionsFactory.ts +++ b/src/lib/EngineOptionsFactory.ts @@ -29,8 +29,8 @@ abstract class CommonEngineOptionsFactory implements EngineOptionsFactory { if (this.shouldSfgeRun(inputs)) { const sfgeConfig: SfgeConfig = { projectDirs: this.inputProcessor.resolveProjectDirPaths(inputs), - cachepath: inputs.cachepath, - enablecaching: inputs.enablecaching + cachepath: inputs.cachepath as string, + enablecaching: inputs.enablecaching as boolean }; options.set(CUSTOM_CONFIG.SfgeConfig, JSON.stringify(sfgeConfig)); } diff --git a/src/lib/sfge/SfgeWrapper.ts b/src/lib/sfge/SfgeWrapper.ts index 4ec616f99..e6434e690 100644 --- a/src/lib/sfge/SfgeWrapper.ts +++ b/src/lib/sfge/SfgeWrapper.ts @@ -242,7 +242,7 @@ export class SfgeExecuteWrapper extends AbstractSfgeWrapper { if (this.ruleDisableWarningViolation != null) { flags.push(`-DSFGE_RULE_DISABLE_WARNING_VIOLATION=${this.ruleDisableWarningViolation.toString()}`); } - if (this.enablecaching) { + if (this.enablecaching != null && this.enablecaching) { flags.push(`-DSFGE_DISABLE_CACHING=false`); } if (this.cachepath != null) { From 1bd5a1f6d7e96ed23e018233af97529983ed2dba Mon Sep 17 00:00:00 2001 From: Jag Jayaprakash Date: Thu, 5 Sep 2024 10:29:25 -0700 Subject: [PATCH 3/3] FIX (Extension) @W-15639920@ address review feedback --- src/commands/scanner/run/dfa.ts | 6 ++++-- src/lib/EngineOptionsFactory.ts | 4 +--- src/lib/sfge/SfgeWrapper.ts | 3 --- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/commands/scanner/run/dfa.ts b/src/commands/scanner/run/dfa.ts index 6e348f18f..fe3ef4584 100644 --- a/src/commands/scanner/run/dfa.ts +++ b/src/commands/scanner/run/dfa.ts @@ -73,12 +73,14 @@ export default class Dfa extends ScannerRunCommand { 'enablecaching': Flags.boolean({ summary: '', description: '', - env: 'SFGE_ENABLE_CACHING' + env: 'SFGE_ENABLE_CACHING', + hidden: true }), 'cachepath': Flags.string({ summary: '', description: '', - env: 'SFGE_FILES_TO_ENTRIES_CACHE_LOCATION' + env: 'SFGE_FILES_TO_ENTRIES_CACHE_LOCATION', + hidden: true }), // END: Config-overrideable engine flags. }; diff --git a/src/lib/EngineOptionsFactory.ts b/src/lib/EngineOptionsFactory.ts index f6923863e..45a6f84f5 100644 --- a/src/lib/EngineOptionsFactory.ts +++ b/src/lib/EngineOptionsFactory.ts @@ -28,9 +28,7 @@ abstract class CommonEngineOptionsFactory implements EngineOptionsFactory { const options: Map = new Map(); if (this.shouldSfgeRun(inputs)) { const sfgeConfig: SfgeConfig = { - projectDirs: this.inputProcessor.resolveProjectDirPaths(inputs), - cachepath: inputs.cachepath as string, - enablecaching: inputs.enablecaching as boolean + projectDirs: this.inputProcessor.resolveProjectDirPaths(inputs) }; options.set(CUSTOM_CONFIG.SfgeConfig, JSON.stringify(sfgeConfig)); } diff --git a/src/lib/sfge/SfgeWrapper.ts b/src/lib/sfge/SfgeWrapper.ts index e6434e690..7ab08294f 100644 --- a/src/lib/sfge/SfgeWrapper.ts +++ b/src/lib/sfge/SfgeWrapper.ts @@ -33,8 +33,6 @@ type SfgeWrapperOptions = { spinnerManager: SpinnerManager; jvmArgs?: string; pathExpLimit?: number; - enablecaching?: boolean; - cachepath?: string; } type SfgeCatalogOptions = SfgeWrapperOptions & { @@ -170,7 +168,6 @@ abstract class AbstractSfgeWrapper extends CommandLineSupport { } args.push(...this.getSupplementalFlags(), MAIN_CLASS, this.action, ...(await this.getSupplementalArgs())); this.logger.trace(`Preparing to execute sfge with command: "${command}", args: "${JSON.stringify(args)}"`); - console.log(`Preparing to execute sfge with command: "${command}", args: "${JSON.stringify(args)}"`); return [command, args]; } protected async execute(): Promise {