Skip to content

Commit 3cd2913

Browse files
committed
Merge pull request #17 from adangel:cli
Avoid using deprecated CLI options for PMD >= 6.41.0 #17 * pr-17: Avoid using deprecated CLI options for PMD >= 6.41.0
2 parents 080b184 + 255364f commit 3cd2913

File tree

12 files changed

+147
-56
lines changed

12 files changed

+147
-56
lines changed

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,25 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
709709
THE SOFTWARE.
710710

711711

712+
lru-cache
713+
ISC
714+
The ISC License
715+
716+
Copyright (c) Isaac Z. Schlueter and Contributors
717+
718+
Permission to use, copy, modify, and/or distribute this software for any
719+
purpose with or without fee is hereby granted, provided that the above
720+
copyright notice and this permission notice appear in all copies.
721+
722+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
723+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
724+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
725+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
726+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
727+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
728+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
729+
730+
712731
minimatch
713732
ISC
714733
The ISC License
@@ -986,3 +1005,22 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9861005
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
9871006
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
9881007
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1008+
1009+
1010+
yallist
1011+
ISC
1012+
The ISC License
1013+
1014+
Copyright (c) Isaac Z. Schlueter and Contributors
1015+
1016+
Permission to use, copy, modify, and/or distribute this software for any
1017+
purpose with or without fee is hereby granted, provided that the above
1018+
copyright notice and this permission notice appear in all copies.
1019+
1020+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1021+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1022+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1023+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1024+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1025+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
1026+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

lib/index.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ const annotations = require('./annotations');
88
const reportFormat = 'sarif';
99
const reportFile = 'pmd-report.sarif'
1010

11-
let pmdPath, exitCode, violations;
12-
1311
async function main() {
12+
let pmdInfo, execOutput, violations;
1413
try {
15-
pmdPath = await util.downloadPmd(
16-
validator.validateVersion(core.getInput('version', { required: true })),
17-
core.getInput('token', { required: true })
18-
);
19-
exitCode = await util.executePmd(pmdPath,
14+
pmdInfo = await util.downloadPmd(validator.validateVersion(core.getInput('version'), { required: true }));
15+
execOutput = await util.executePmd(pmdInfo,
2016
validator.validateSourcePath(core.getInput('sourcePath', { required: true })),
2117
validator.validateRulesets(core.getInput('rulesets', { required: true })),
2218
reportFormat, reportFile)
2319

24-
core.info(`PMD exited with ${exitCode}`);
20+
core.info(`PMD exited with ${execOutput.exitCode}`);
2521

2622
violations = sarif.countViolations(reportFile);
2723
core.setOutput('violations', violations);

lib/util.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const core = require('@actions/core');
22
const github = require('@actions/github');
33
const tc = require('@actions/tool-cache');
44
const exec = require('@actions/exec');
5+
const semver = require('semver');
56

67
const downloadPmd = async function(version, token) {
78
let pmdVersion = version;
@@ -16,14 +17,17 @@ const downloadPmd = async function(version, token) {
1617
}
1718

1819
core.info(`Using PMD ${pmdVersion} from cached path ${cachedPmdPath}`);
19-
return `${cachedPmdPath}/pmd-bin-${pmdVersion}`;
20+
return {
21+
version: pmdVersion,
22+
path: `${cachedPmdPath}/pmd-bin-${pmdVersion}`
23+
}
2024
}
2125

22-
const executePmd = async function(pmdPath, sourcePath, ruleset, reportFormat, reportFile) {
23-
const { exitCode, stdout, stderr } = await exec.getExecOutput(`${pmdPath}/bin/run.sh`,
26+
const executePmd = async function(pmdInfo, sourcePath, ruleset, reportFormat, reportFile) {
27+
const execOutput = await exec.getExecOutput(`${pmdInfo.path}/bin/run.sh`,
2428
[
2529
'pmd',
26-
'-no-cache',
30+
useNewArgsFormat(pmdInfo.version) ? '--no-cache' : '-no-cache',
2731
'-d', sourcePath,
2832
'-f', reportFormat,
2933
'-R', ruleset,
@@ -32,14 +36,18 @@ const executePmd = async function(pmdPath, sourcePath, ruleset, reportFormat, re
3236
{
3337
ignoreReturnCode: true
3438
});
35-
core.debug(`stdout: ${stdout}`);
36-
core.debug(`stderr: ${stderr}`);
37-
core.debug(`exitCode: ${exitCode}`);
38-
return exitCode;
39+
core.debug(`stdout: ${execOutput.stdout}`);
40+
core.debug(`stderr: ${execOutput.stderr}`);
41+
core.debug(`exitCode: ${execOutput.exitCode}`);
42+
return execOutput;
43+
}
44+
45+
function useNewArgsFormat(pmdVersion) {
46+
return semver.gte(pmdVersion, '6.41.0');
3947
}
4048

4149
async function determinePmdRelease(pmdVersion, token) {
42-
core.debug(`Determine release info for ${pmdVersion}`);
50+
core.debug(`determine release info for ${pmdVersion}`);
4351
const octokit = github.getOctokit(token);
4452
let release;
4553
if (pmdVersion === 'latest') {

lib/validator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const path = require('path');
2+
const semver = require('semver');
23

34
const validateVersion = function(version) {
45
if (typeof(version) === 'string'
5-
&& (version === 'latest' || version.match(/^\d+\.\d+\.\d+$/))) {
6+
&& (version === 'latest' || semver.valid(version) === version)) {
67
// valid
78
return version;
89
}

package-lock.json

Lines changed: 4 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"@actions/exec": "^1.1.0",
3030
"@actions/github": "^5.0.0",
3131
"@actions/tool-cache": "^1.7.1",
32-
"@octokit/rest": "^18.12.0"
32+
"@octokit/rest": "^18.12.0",
33+
"semver": "^7.3.5"
3334
},
3435
"devDependencies": {
3536
"@actions/io": "^1.1.1",

tests/data/create-zips.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
zip -r pmd-bin-6.39.0.zip pmd-bin-6.39.0
44
zip -r pmd-bin-6.40.0.zip pmd-bin-6.40.0
5+
zip -r pmd-bin-6.41.0.zip pmd-bin-6.41.0

tests/data/pmd-bin-6.41.0.zip

677 Bytes
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Running PMD 6.41.0 with: $@"
4+
5+
echo '{
6+
"runs": [
7+
{
8+
"tool": {
9+
"driver": {
10+
"name": "PMD",
11+
"version": "6.41.0"
12+
}
13+
}
14+
}
15+
]
16+
}' > pmd-report.sarif
17+

0 commit comments

Comments
 (0)