-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1307 from forcedotcom/d/W-14689342
CHANGE (Other): @W-14689342@: Add environment variable to output to an internal outfile
- Loading branch information
Showing
21 changed files
with
521 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {AnyJson} from "@salesforce/ts-types"; | ||
|
||
/** | ||
* Container to hold the json return value for the --json flag used by some of the cli commands | ||
*/ | ||
export class JsonReturnValueHolder { | ||
private jsonReturnValue: AnyJson; | ||
|
||
public set(jsonReturnValue: AnyJson): void { | ||
this.jsonReturnValue = jsonReturnValue; | ||
} | ||
|
||
public get(): AnyJson { | ||
return this.jsonReturnValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {ResultsProcessor} from "./ResultsProcessor"; | ||
import {Results} from "./Results"; | ||
import {OutputFormat} from "./OutputFormat"; | ||
import {FormattedOutput} from "../../types"; | ||
import {FileHandler} from "../util/FileHandler"; | ||
|
||
/** | ||
* Processes results to produce an output file | ||
*/ | ||
export class OutfileResultsProcessor implements ResultsProcessor { | ||
private readonly outputFormat: OutputFormat; | ||
private readonly outfile: string; | ||
private readonly verboseViolations: boolean; | ||
public constructor(format:OutputFormat, outfile: string, verboseViolations: boolean) { | ||
this.outputFormat = format; | ||
this.outfile = outfile; | ||
this.verboseViolations = verboseViolations; | ||
} | ||
|
||
public async processResults(results: Results): Promise<void> { | ||
const fileContents: FormattedOutput = await results.toFormattedOutput(this.outputFormat, this.verboseViolations); | ||
(new FileHandler()).writeFileSync(this.outfile, fileContents as string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {Results} from "./Results"; | ||
|
||
/** | ||
* Interface to process run results | ||
*/ | ||
export interface ResultsProcessor { | ||
processResults(results: Results): Promise<void>; | ||
} | ||
|
||
/** | ||
* A composite results processor | ||
*/ | ||
export class CompositeResultsProcessor implements ResultsProcessor { | ||
private readonly delegates: ResultsProcessor[]; | ||
|
||
public constructor(delegateResultsProcessors: ResultsProcessor[]) { | ||
this.delegates = delegateResultsProcessors; | ||
} | ||
|
||
async processResults(results: Results): Promise<void> { | ||
for (const delegate of this.delegates) { | ||
await delegate.processResults(results); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Display} from "../Display"; | ||
import {JsonReturnValueHolder} from "./JsonReturnValueHolder"; | ||
import {RunOutputOptions, RunResultsProcessor} from "./RunResultsProcessor"; | ||
import {CompositeResultsProcessor, ResultsProcessor} from "./ResultsProcessor"; | ||
import {ENV_VAR_NAMES} from "../../Constants"; | ||
import {inferFormatFromInternalOutfile, OutputFormat} from "./OutputFormat"; | ||
import {OutfileResultsProcessor} from "./OutfileResultsProcessor"; | ||
|
||
/** | ||
* Interface for creating a ResultsProcessor | ||
*/ | ||
export interface ResultsProcessorFactory { | ||
createResultsProcessor(display: Display, runOutputOptions: RunOutputOptions, | ||
jsonReturnValueHolder: JsonReturnValueHolder): ResultsProcessor | ||
} | ||
|
||
/** | ||
* Runtime implementation of the ResultsProcessorFactory interface | ||
*/ | ||
export class ResultsProcessorFactoryImpl implements ResultsProcessorFactory { | ||
public createResultsProcessor(display: Display, runOutputOptions: RunOutputOptions, | ||
jsonReturnValueHolder: JsonReturnValueHolder): ResultsProcessor { | ||
const resultsProcessors: ResultsProcessor[] = [new RunResultsProcessor(display, runOutputOptions, jsonReturnValueHolder)]; | ||
this.addProcessorForInternalOutfileIfNeeded(resultsProcessors, runOutputOptions.verboseViolations); | ||
return new CompositeResultsProcessor(resultsProcessors); | ||
} | ||
|
||
private addProcessorForInternalOutfileIfNeeded(resultsProcessors: ResultsProcessor[], verboseViolations: boolean): void { | ||
const internalOutfile: string = process.env[ENV_VAR_NAMES.SCANNER_INTERNAL_OUTFILE]; | ||
if (internalOutfile && internalOutfile.length > 0) { | ||
const internalOutputFormat: OutputFormat = inferFormatFromInternalOutfile(internalOutfile); | ||
resultsProcessors.push(new OutfileResultsProcessor(internalOutputFormat, internalOutfile, verboseViolations)); | ||
} | ||
} | ||
} |
Oops, something went wrong.