Skip to content

Commit

Permalink
Merge pull request #137 from forcedotcom/release-1.2.0
Browse files Browse the repository at this point in the history
RELEASE @W-16608399@: Conducting v1.2.0 release
  • Loading branch information
jag-j authored Sep 24, 2024
2 parents 5ccd634 + a5068f2 commit 84dcae5
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 161 deletions.
2 changes: 1 addition & 1 deletion SHA256.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ make sure that their SHA values match the values in the list below.
shasum -a 256 <location_of_the_downloaded_file>

3. Confirm that the SHA in your output matches the value in this list of SHAs.
172c7b2973ea3d66feaae5017e7eae0de384340a137d59305ef3c1bc4114a04f ./extensions/sfdx-code-analyzer-vscode-1.0.0.vsix
f668893331860e3b8bc89357c4bfe2cac9840ee05acd1b0d67de5a8c37518b87 ./extensions/sfdx-code-analyzer-vscode-1.1.0.vsix
4. Change the filename extension for the file that you downloaded from .zip to
.vsix.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"color": "#ECECEC",
"theme": "light"
},
"version": "1.1.0",
"version": "1.2.0",
"publisher": "salesforce",
"license": "BSD-3-Clause",
"engines": {
Expand Down Expand Up @@ -152,7 +152,7 @@
"codeAnalyzer.scanner.engines": {
"type": "string",
"default": "pmd,retire-js,eslint-lwc",
"description": "The engines to run. Specify multiple values as a comma-separated list. Possible values are pmd, retire-js, eslint, eslint-lwc, and eslint-typescript."
"description": "The engines to run. Specify multiple values as a comma-separated list. Possible values are pmd, pmd-appexchange, retire-js, eslint, eslint-lwc, and eslint-typescript."
},
"codeAnalyzer.normalizeSeverity.enabled": {
"type": "boolean",
Expand Down
22 changes: 18 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import * as Constants from './lib/constants';
import * as path from 'path';
import { SIGKILL } from 'constants';
import * as ApexGuruFunctions from './apexguru/apex-guru-service'
import * as os from 'os';
import * as fs from 'fs';

export type RunInfo = {
diagnosticCollection?: vscode.DiagnosticCollection;
Expand All @@ -38,6 +40,8 @@ let customCancellationToken: vscode.CancellationTokenSource | null = null;

let outputChannel: vscode.LogOutputChannel;

let sfgeCachePath: string = null;

/**
* This method is invoked when the extension is first activated (this is currently configured to be when a sfdx project is loaded).
* The activation trigger can be changed by changing activationEvents in package.json
Expand Down Expand Up @@ -136,6 +140,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
}
});

sfgeCachePath = path.join(createTempDirectory(), 'sfca-graph-engine-cache.json');
const runDfaOnWorkspaceCmd = vscode.commands.registerCommand(Constants.COMMAND_RUN_DFA, async () => {
await _runDfa(context);
});
Expand Down Expand Up @@ -167,6 +172,16 @@ export async function activate(context: vscode.ExtensionContext): Promise<vscode
return Promise.resolve(context);
}

export function createTempDirectory(): string {
const tempFolderPrefix = path.join(os.tmpdir(), Constants.EXTENSION_PACK_ID);
try {
const folder = fs.mkdtempSync(tempFolderPrefix);
return folder;
} catch (err) {
throw new Error('Failed to create temporary directory');
}
}

async function _runDfa(context: vscode.ExtensionContext) {
if (violationsCacheExists()) {
const choice = await vscode.window.showQuickPick(
Expand Down Expand Up @@ -212,14 +227,13 @@ async function runDfaOnWorkspace(context: vscode.ExtensionContext) {
// We only have one project loaded on VSCode at once. So, projectDir should have only one entry and we use
// the root directory of that project as the projectDir argument to run DFA.
return _runAndDisplayDfa(context, {
commandName: Constants.COMMAND_RUN_DFA_ON_SELECTED_METHOD
commandName: Constants.COMMAND_RUN_DFA
}, customCancellationToken, null, targeting.getProjectDir());
});
}

function violationsCacheExists() {
// Returns true for now. Actual cache check will be performed as part of W-15639759.
return true;
return fs.existsSync(sfgeCachePath);
}

export function _removeDiagnosticsInRange(uri: vscode.Uri, range: vscode.Range, diagnosticCollection: vscode.DiagnosticCollection) {
Expand Down Expand Up @@ -364,7 +378,7 @@ export async function _runAndDisplayDfa(context:vscode.ExtensionContext ,runInfo
const startTime = Date.now();
try {
await verifyPluginInstallation();
const results = await new ScanRunner().runDfa([methodLevelTarget], projectDir, context);
const results = await new ScanRunner().runDfa([methodLevelTarget], projectDir, context, sfgeCachePath);
if (results.length > 0) {
const panel = vscode.window.createWebviewPanel(
'dfaResults',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class DiagnosticManager {
),
new vscode.DiagnosticRelatedInformation(
new vscode.Location(vscode.Uri.parse(violation.url), range),
`\n// ApexGuru Suggestions: \n${apexGuruViolation.suggestedCode}`
`/*\n//ApexGuru Suggestions: \n${apexGuruViolation.suggestedCode}\n*/`
)
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/fixer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ export class _ApexGuruFixGenerator extends FixGenerator {

const edit = new vscode.WorkspaceEdit();
const range = this.diagnostic.range; // Assuming the range is the location of the existing code in the document
const oneLineAbove = new vscode.Position(range.start.line > 1 ? range.start.line - 1 : 0, range.start.character);
edit.insert(document.uri, oneLineAbove, suggestedCode + '\n');
const diagnosticStartLine = new vscode.Position(range.start.line, range.start.character);
edit.insert(document.uri, diagnosticStartLine, suggestedCode + '\n');

// Assign the edit to the action
action.edit = edit;
Expand Down
12 changes: 9 additions & 3 deletions src/lib/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ScanRunner {
* @param targets A list of files to be targeted by the scan
* @returns The results of the scan
*/

public async run(targets: string[]): Promise<RuleResult[]> {
// Create the arg array.
const args: string[] = await this.createPathlessArgArray(targets);
Expand All @@ -39,9 +40,9 @@ export class ScanRunner {
* @param projectDir The directory containing all files in the project to be scanned.
* @returns The HTML-formatted scan results, or an empty string if no violations were found.
*/
public async runDfa(targets: string[], projectDir: string, context: vscode.ExtensionContext): Promise<string> {
public async runDfa(targets: string[], projectDir: string, context: vscode.ExtensionContext, cacheFilePath?: string): Promise<string> {
// Create the arg array.
const args: string[] = this.createDfaArgArray(targets, projectDir);
const args: string[] = this.createDfaArgArray(targets, projectDir, cacheFilePath);

// Invoke the scanner.
const executionResult: ExecutionResult = await this.invokeDfaAnalyzer(args, context);
Expand All @@ -55,7 +56,7 @@ export class ScanRunner {
* @param targets The files/methods to be targeted.
* @param projectDir The root of the project to be scanned.
*/
private createDfaArgArray(targets: string[], projectDir: string): string[] {
private createDfaArgArray(targets: string[], projectDir: string, cacheFilePath?: string): string[] {
const args: string[] = [
'scanner', 'run', 'dfa',
`--projectdir`, projectDir,
Expand All @@ -73,6 +74,11 @@ export class ScanRunner {
args.push('--target', `${targets.join(',')}`);
}

if (cacheFilePath) {
args.push('--cachepath', cacheFilePath);
args.push('--enablecaching');
}

// There are a number of custom settings that we need to check too.
// First we should check whether warning violations are disabled.
if (SettingsManager.getGraphEngineDisableWarningViolations()) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/suite/fixer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ suite('fixer.ts', () => {
expect(fixes).to.have.lengthOf(1, 'One fix should be offered');
const fix = fixes[0].edit.get(fileUri)[0];
expect(fix.newText).to.equal('apex guru suggested code\n', 'The suppression code should match the suggestion');
expect(fix.range.start.line).to.equal(6, 'The suppression should be added one line above the diagnostic line');
expect(fix.range.start.line).to.equal(7, 'The suppression should be added at the diagnostic line');
});

test('Should not generate a suppression fix if line is already processed', async () => {
Expand Down Expand Up @@ -605,7 +605,7 @@ suite('fixer.ts', () => {

// Validate results.
expect(fix.edit.get(fileUri)[0].newText).to.equal('apex guru suggested code\n', 'The suppression code should match the suggestion');
expect(fix.edit.get(fileUri)[0].range.start.line).to.equal(6, 'The suppression should be added one line above the diagnostic line');
expect(fix.edit.get(fileUri)[0].range.start.line).to.equal(7, 'The suppression should be added at the diagnostic line');
});
});
});
Expand Down
21 changes: 21 additions & 0 deletions src/test/suite/scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,27 @@ suite('ScanRunner', () => {
expect(args[10]).to.equal('--sfgejvmargs', 'Wrong arg');
expect(args[11]).to.equal(jvmArgs, 'Wrong arg');
});

test('Enable caching and include cache path', () => {
// ===== SETUP =====
Sinon.stub(SettingsManager, 'getGraphEngineDisableWarningViolations').returns(false);
Sinon.stub(SettingsManager, 'getGraphEngineThreadTimeout').returns(null);
Sinon.stub(SettingsManager, 'getGraphEnginePathExpansionLimit').returns(null);
Sinon.stub(SettingsManager, 'getGraphEngineJvmArgs').returns(null);
const emptyTargets = [];

// ===== TEST =====
// Call the test method helper.
const scanner: ScanRunner = new ScanRunner();
const args: string[] = (scanner as any).createDfaArgArray(emptyTargets, projectDir, 'some/path/file.json');

// ===== ASSERTIONS =====
// Verify that the right arguments were created.
expect(args).to.have.lengthOf(11, 'Wrong number of args');
expect(args[8]).to.equal('--cachepath', 'Wrong arg');
expect(args[9]).to.equal('some/path/file.json', 'Wrong arg');
expect(args[10]).to.equal('--enablecaching', 'Wrong arg');
});
});
});

Expand Down
Loading

0 comments on commit 84dcae5

Please sign in to comment.