Skip to content

Commit

Permalink
Merge pull request #143 from adangel:issue-139-quote-classpath
Browse files Browse the repository at this point in the history
Quote classPath to deal with spaces in workspaceRootPath
  • Loading branch information
adangel committed Sep 8, 2023
2 parents a654d62 + 8149274 commit 7c3e317
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- 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
- Quote classPath to deal with spaces in workspaceRootPath [#143](https://github.com/ChuckJonas/vscode-apex-pmd/pull/143) @adangel

### Removed

Expand All @@ -22,7 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Static Analysis Failed - Cannot load ruleset [#140](https://github.com/ChuckJonas/vscode-apex-pmd/issues/140)
- Error executing PMD when project folder uses spaces [#139](https://github.com/ChuckJonas/vscode-apex-pmd/issues/139)
- 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

Expand Down
12 changes: 7 additions & 5 deletions src/lib/apexPmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ApexPmd {
progress?: vscode.Progress<{ message?: string; increment?: number }>,
token?: vscode.CancellationToken
): Promise<void> {
this.outputChannel.appendLine('###################################');
this.outputChannel.appendLine(`Analyzing ${targetPath}`);
AppStatus.getInstance().thinking();

Expand Down Expand Up @@ -138,18 +139,19 @@ export class ApexPmd {
...additionalClassPaths,
].join(CLASSPATH_DELM);

let env : NodeJS.ProcessEnv = {...process.env};
env["CLASSPATH"] = classPath;
let env : NodeJS.ProcessEnv = {};
env["CLASSPATH"] = `"${classPath}"`;
if (this.config.jrePath) {
env["PATH"] = `${path.join(this.config.jrePath, 'bin')}${path.delimiter}${process.env.PATH}`;
}

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

this.outputChannel.appendLine(`env: ${JSON.stringify(env)}`);
this.outputChannel.appendLine('PMD Command: ' + cmd);

const pmdCmd = ChildProcess.exec(cmd, {
env: env,
env: {...process.env, ...env},
maxBuffer: Math.max(commandBufferSize, 1) * 1024 * 1024,
});

Expand Down Expand Up @@ -178,11 +180,11 @@ export class ApexPmd {
resolve(stdout);
});
pmdCmd.stdout.on('data', (m: string) => {
this.outputChannel.appendLine('stdout:' + m);
this.outputChannel.append('stdout:' + m);
stdout += m;
});
pmdCmd.stderr.on('data', (m: string) => {
this.outputChannel.appendLine('stderr:' + m);
this.outputChannel.append('stderr:' + m);
stderr += m;
});
});
Expand Down
10 changes: 10 additions & 0 deletions test/assets/folder - with space/test.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// test case for https://github.com/ChuckJonas/vscode-apex-pmd/issues/139

// Test apex that should return a single error
public class Test{
public Test(){
while(true){
Account acc = [SELECT Id FROM Account];
}
}
}

0 comments on commit 7c3e317

Please sign in to comment.