Skip to content

Commit

Permalink
Merge pull request #141 from adangel:check-for-ruleset-problem
Browse files Browse the repository at this point in the history
Check for "Cannot load ruleset"
  • Loading branch information
adangel committed Sep 8, 2023
2 parents 140bd87 + 4dad7c9 commit a654d62
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 42 deletions.
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ assignees: ''
A clear and concise description of what the bug is.

**Apex PMD Output**
<!-- Please make sure "Show StdErr" and "Show StdOut" Settings are enabled -->
<!-- Copy the output of the output channel "Apex PMD" from the output view -->

**Apex PMD Settings**
<!-- Please provide the "EFFECTIVE" (check workspace & user) settings -->

- pmdPath:
- rulesetPath:
- pmdBinPath:
- rulesets:
- additionalClassPaths:

**Apex File**
<!-- The File you were running the tool on (if applicable)-->
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Check for "Cannot load ruleset" [#141](https://github.com/ChuckJonas/vscode-apex-pmd/pull/141) @adangel

### Changed

- Update README.md - Intro sentence to get the command palette opened [#137](https://github.com/ChuckJonas/vscode-apex-pmd/pull/137) @surfmuggle
- Update dependencies [#142](https://github.com/ChuckJonas/vscode-apex-pmd/pull/142) @adangel

### Removed

- remove settings `showErrors`, `showStdOut`, and `showStdErr`. Output from PMD execution is always
displayed in the output window. This helps to diagnose problems like ruleset loading errors.

### Fixed

- Static Analysis Failed - Cannot load ruleset [#140](https://github.com/ChuckJonas/vscode-apex-pmd/issues/140)

**Full Changelog**: https://github.com/ChuckJonas/vscode-apex-pmd/compare/v0.6.0...HEAD

## [0.6.0] - 2023-08-24
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To start the command you can click in the menu on `Help/Show All Commands` or pr
## System Requirements

- Must have JRE >= 1.8 installed and in path
- See [PMD System Requirements](https://pmd.github.io/pmd-6.11.0/pmd_userdocs_installation.html#requirements) for more details
- See [PMD System Requirements](https://docs.pmd-code.org/latest/pmd_userdocs_installation.html#requirements) for more details

## Configuration

Expand All @@ -47,15 +47,21 @@ Set `apexPMD.rulesets` string array to reference your custom rulesets. You can e

You can also mention the default ruleset in `apexPMD.rulesets`. To do this add `default` value to the array.

[Apex Ruleset Reference](https://pmd.github.io/pmd-6.11.0/pmd_rules_apex.html)
[Apex Ruleset Reference](https://docs.pmd-code.org/latest/pmd_rules_apex.html)

NOTE: If you move away from the default ruleset in an sfdx project, make sure to exclude the `.sfdx` generated classes by keeping this line:

`<exclude-pattern>.*/.sfdx/.*</exclude-pattern>`

### Using custom rules written in Java

If you want to use your own [custom rules](https://pmd.github.io/latest/pmd_userdocs_extending_writing_pmd_rules.html) from a jar file, then the jar file must be on the classpath. By default, the PMD folder and the workspace root folder are included in the classpath. You can add further folders using the `additionalClassPaths` setting. This ["Hello world"](https://github.com/andrewgilbertsagecom/pmd-custom-rule-sample) example is a good starting place for beginners.
If you want to use your own [custom rules](https://docs.pmd-code.org/latest/pmd_userdocs_extending_writing_pmd_rules.html) from a jar file, then the jar file must be on the classpath. By default, the PMD folder and the workspace root folder are included in the classpath. You can add further folders using the `additionalClassPaths` setting. This ["Hello world"](https://github.com/andrewgilbertsagecom/pmd-custom-rule-sample) example is a good starting place for beginners.

## Troubleshooting

The plugin creates an own output channel "Apex PMD" in the output view. This shows the output of the PMD command that is executed in the background.
In case of any problem, this output channel might contain the underlying error. When reporting an issue, please include any error messages from
this output channel.

## Developing/Contributing

Expand Down
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,6 @@
"default": 3,
"description": "Determines at what priority level 'warnings' will be added. Anything less will be a hint"
},
"apexPMD.showErrors": {
"type": "boolean",
"default": true,
"description": "Show errors in output window"
},
"apexPMD.showStdOut": {
"type": "boolean",
"default": false,
"description": "Show showStdOut in output window"
},
"apexPMD.showStdErr": {
"type": "boolean",
"default": true,
"description": "Show showStdErr in output window"
},
"apexPMD.enableCache": {
"type": "boolean",
"default": false,
Expand Down
19 changes: 11 additions & 8 deletions src/lib/apexPmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ApexPmd {
} catch (e) {
AppStatus.getInstance().errors();
vscode.window.showErrorMessage(`Static Analysis Failed. Error Details: ${e}`);
this.outputChannel.show(true);
// should this throw e for promise catch?
}
}
Expand Down Expand Up @@ -117,10 +118,7 @@ export class ApexPmd {
enableCache,
pmdBinPath,
additionalClassPaths,
showStdOut,
showStdErr,
commandBufferSize,
showErrors,
} = this.config;

// -R Comma-separated list of ruleset or rule references.
Expand Down Expand Up @@ -148,7 +146,7 @@ export class ApexPmd {

const cmd = `${path.join(pmdBinPath, 'bin', 'pmd')} check ${pmdKeys}`;

if (showStdOut) this.outputChannel.appendLine('PMD Command: ' + cmd);
this.outputChannel.appendLine('PMD Command: ' + cmd);

const pmdCmd = ChildProcess.exec(cmd, {
env: env,
Expand All @@ -161,26 +159,31 @@ export class ApexPmd {
});

let stdout = '';
let stderr = '';
const pmdPromise = new Promise<string>((resolve, reject) => {
pmdCmd.addListener('error', (e) => {
if (showErrors) this.outputChannel.appendLine('error:' + e);
this.outputChannel.appendLine('error:' + e);
reject(e);
});
pmdCmd.addListener('exit', (e) => {
if (e !== 0 && e !== 4) {
this.outputChannel.appendLine(`Failed Exit Code: ${e}`);
if (stderr.includes('Cannot load ruleset')) {
reject('PMD Command Failed! There is a problem with the ruleset. Check the plugin output for details.')
}
if (!stdout) {
reject('PMD Command Failed! Enable "Show StdErr" setting for more info.');
reject('PMD Command Failed! Check the plugin output for details.');
}
}
resolve(stdout);
});
pmdCmd.stdout.on('data', (m: string) => {
if (showStdOut) this.outputChannel.appendLine('stdout:' + m);
this.outputChannel.appendLine('stdout:' + m);
stdout += m;
});
pmdCmd.stderr.on('data', (m: string) => {
if (showStdErr) this.outputChannel.appendLine('stderr:' + m);
this.outputChannel.appendLine('stderr:' + m);
stderr += m;
});
});
return pmdPromise;
Expand Down
6 changes: 0 additions & 6 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export class Config {
public runOnFileSave: boolean;
public runOnFileChange: boolean;
public onFileChangeDebounce: number;
public showErrors: boolean;
public showStdOut: boolean;
public showStdErr: boolean;
public enableCache: boolean;
public additionalClassPaths: string[];
public commandBufferSize: number;
Expand Down Expand Up @@ -46,9 +43,6 @@ export class Config {
this.runOnFileSave = config.get('runOnFileSave');
this.runOnFileChange = config.get('runOnFileChange');
this.onFileChangeDebounce = config.get('onFileChangeDebounce');
this.showErrors = config.get('showErrors');
this.showStdOut = config.get('showStdOut');
this.showStdErr = config.get('showStdErr');
this.enableCache = config.get('enableCache');
this.additionalClassPaths = config.get('additionalClassPaths');
this.commandBufferSize = config.get('commandBufferSize');
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pmdCsvParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function parsePmdCsv(csv: string): Array<PmdResult> {
results = parser(csv, parseOpts);
} catch (e) {
throw new Error(
'Failed to parse PMD Results. Enable please logging (STDOUT & STDERROR) and submit an issue if this problem persists.'
'Failed to parse PMD Results. Please submit an issue with the output from the "Apex PMD" output channel if this problem persists.'
);
}
vscode.window.showWarningMessage('Failed to read all PMD problems!');
Expand Down
6 changes: 0 additions & 6 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ suite('Extension Tests', () => {
config.rulesets = [RULESET_PATH, INVALID_RULESET_PATH];
config.priorityErrorThreshold = 3;
config.priorityWarnThreshold = 1;
config.showErrors = false;
config.showStdOut = false;
config.showStdErr = false;
config.additionalClassPaths = [];

const pmd = new ApexPmd(outputChannel, config);
Expand All @@ -52,9 +49,6 @@ suite('Extension Tests', () => {
config.rulesets = [RULESET_PATH];
config.priorityErrorThreshold = 3;
config.priorityWarnThreshold = 1;
config.showErrors = false;
config.showStdOut = false;
config.showStdErr = false;
config.workspaceRootPath = '';
config.additionalClassPaths = [];
config.commandBufferSize = 64000000;
Expand Down

0 comments on commit a654d62

Please sign in to comment.