Skip to content

Commit 2c5ed60

Browse files
committed
Support upcoming PMD 7.0.0-rc1 release
1 parent a552efd commit 2c5ed60

File tree

8 files changed

+90
-1
lines changed

8 files changed

+90
-1
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ const downloadPmd = async function(version, token) {
3535

3636
const executePmd = async function(pmdInfo, fileListOrSourcePath, ruleset, reportFormat, reportFile) {
3737
let pmdExecutable = '/bin/run.sh pmd';
38+
if (isPmd7Cli(pmdInfo.version)) {
39+
pmdExecutable = '/bin/pmd.sh';
40+
}
3841
if (os.platform() === 'win32') {
3942
pmdExecutable = '\\bin\\pmd.bat';
4043
}
4144

45+
if (isPmd7Cli(pmdInfo.version)) {
46+
pmdExecutable += ' check';
47+
}
48+
4249
let sourceParameter = ['-d', fileListOrSourcePath];
4350
if (Array.isArray(fileListOrSourcePath)) {
4451
await writeFileList(fileListOrSourcePath);
@@ -69,6 +76,10 @@ function useNewArgsFormat(pmdVersion) {
6976
return semver.gte(pmdVersion, '6.41.0');
7077
}
7178

79+
function isPmd7Cli(pmdVersion) {
80+
return semver.gte(pmdVersion, '7.0.0-rc1');
81+
}
82+
7283
async function determinePmdRelease(pmdVersion, token) {
7384
core.debug(`determine release info for ${pmdVersion}`);
7485

tests/data/create-zips.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
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
55
zip -r pmd-bin-6.41.0.zip pmd-bin-6.41.0
6+
zip -r pmd-bin-7.0.0-rc1.zip pmd-bin-7.0.0-rc1

tests/data/pmd-bin-7.0.0-rc1.zip

1.01 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@echo off
2+
echo Running PMD 7.0.0-rc1 with: %*
3+
4+
(
5+
echo {
6+
echo "runs": [
7+
echo {
8+
echo "tool": {
9+
echo "driver": {
10+
echo "name": "PMD",
11+
echo "version": "7.0.0-rc1"
12+
echo }
13+
echo }
14+
echo }
15+
echo ]
16+
echo }
17+
)>"pmd-report.sarif"
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 7.0.0-rc1 with: $@"
4+
5+
echo '{
6+
"runs": [
7+
{
8+
"tool": {
9+
"driver": {
10+
"name": "PMD",
11+
"version": "7.0.0-rc1"
12+
}
13+
}
14+
}
15+
]
16+
}' > pmd-report.sarif
17+

tests/data/releases-7.0.0-rc1.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"id": "2",
3+
"name": "latest pmd release for test (7.0.0-rc1)",
4+
"tag_name": "pmd_releases/7.0.0-rc1",
5+
"assets": [
6+
{
7+
"browser_download_url": "https://github.com/pmd/pmd/releases/download/pmd_releases/7.0.0-rc1/pmd-bin-7.0.0-rc1.zip",
8+
"name": "pmd-bin-7.0.0-rc1.zip"
9+
}
10+
]
11+
}

tests/util.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const fs = require('fs').promises;
77
const exec = require('@actions/exec');
88
const util = require('../lib/util');
99
const github_utils = require('@actions/github/lib/utils')
10+
const semver = require('semver');
1011

1112
const cachePath = path.join(__dirname, 'CACHE')
1213
const tempPath = path.join(__dirname, 'TEMP')
@@ -403,6 +404,37 @@ describe('pmd-github-action-util', function () {
403404
expect(fileList).toStrictEqual(['src/main/java/AvoidCatchingThrowableSample.java', 'src/main/java2/NewFile.java', 'src/main/java/ChangedFile.java', 'README.md']
404405
.map(f => path.normalize(f)));
405406
})
407+
408+
test('can execute PMD 7 with correct parameters', async () => {
409+
nock('https://api.github.com')
410+
.get('/repos/pmd/pmd/releases/tags/pmd_releases%2F7.0.0-rc1')
411+
.replyWithFile(200, __dirname + '/data/releases-7.0.0-rc1.json', {
412+
'Content-Type': 'application/json',
413+
})
414+
nock('https://github.com')
415+
.get('/pmd/pmd/releases/download/pmd_releases/7.0.0-rc1/pmd-bin-7.0.0-rc1.zip')
416+
.replyWithFile(200, __dirname + '/data/pmd-bin-7.0.0-rc1.zip')
417+
418+
const pmdInfo = await util.downloadPmd('7.0.0-rc1', 'my_test_token');
419+
const execOutput = await util.executePmd(pmdInfo, ['src/file1.txt', 'src/file2.txt'], 'ruleset.xml', 'sarif', 'pmd-report.sarif');
420+
const pmdFilelist = path.join('.', 'pmd.filelist');
421+
await expect(fs.access(pmdFilelist)).resolves.toBe(undefined);
422+
const pmdFilelistContent = await fs.readFile(pmdFilelist, 'utf8');
423+
expect(pmdFilelistContent).toBe('src/file1.txt,src/file2.txt');
424+
expect(execOutput.exitCode).toBe(0);
425+
expect(execOutput.stdout.trim()).toBe('Running PMD 7.0.0-rc1 with: check --no-cache --file-list pmd.filelist -f sarif -R ruleset.xml -r pmd-report.sarif');
426+
await io.rmRF(pmdFilelist);
427+
await io.rmRF(path.join('.', 'pmd-report.sarif'));
428+
});
429+
430+
test('PMD 7 release candidates and final release version ordering', () => {
431+
// see method util#isPmd7Cli
432+
expect(semver.gte('6.55.0', '7.0.0-rc1')).toBe(false);
433+
expect(semver.gte('7.0.0-rc1', '7.0.0-rc1')).toBe(true);
434+
expect(semver.gte('7.0.0-rc2', '7.0.0-rc1')).toBe(true);
435+
expect(semver.gte('7.0.0-rc3', '7.0.0-rc1')).toBe(true);
436+
expect(semver.gte('7.0.0', '7.0.0-rc1')).toBe(true);
437+
});
406438
});
407439

408440
function setGlobal(key, value) {

0 commit comments

Comments
 (0)