Skip to content

Commit 8141cb4

Browse files
committed
Merge pull requets #22 from adangel:windows
Call pmd.bat under win32 #22 * pr-22: Call pmd.bat under win32
2 parents 3cd2913 + b033830 commit 8141cb4

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const github = require('@actions/github');
33
const tc = require('@actions/tool-cache');
44
const exec = require('@actions/exec');
55
const semver = require('semver');
6+
const os = require('os');
67

78
const downloadPmd = async function(version, token) {
89
let pmdVersion = version;
@@ -24,9 +25,12 @@ const downloadPmd = async function(version, token) {
2425
}
2526

2627
const executePmd = async function(pmdInfo, sourcePath, ruleset, reportFormat, reportFile) {
27-
const execOutput = await exec.getExecOutput(`${pmdInfo.path}/bin/run.sh`,
28+
let pmdExecutable = '/bin/run.sh pmd';
29+
if (os.platform() === 'win32') {
30+
pmdExecutable = '\\bin\\pmd.bat';
31+
}
32+
const execOutput = await exec.getExecOutput(`${pmdInfo.path}${pmdExecutable}`,
2833
[
29-
'pmd',
3034
useNewArgsFormat(pmdInfo.version) ? '--no-cache' : '-no-cache',
3135
'-d', sourcePath,
3236
'-f', reportFormat,

tests/util.test.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const nock = require('nock');
44
const io = require('@actions/io');
55
const os = require('os');
66
const fs = require('fs');
7+
const exec = require('@actions/exec');
78
const util = require('../lib/util');
89

910
const cachePath = path.join(__dirname, 'CACHE')
@@ -13,19 +14,26 @@ process.env['RUNNER_TEMP'] = tempPath
1314
process.env['RUNNER_TOOL_CACHE'] = cachePath
1415

1516
describe('pmd-github-action-util', function () {
16-
beforeAll(function () {
17+
let platformMock;
18+
let execMock;
19+
20+
beforeAll(function() {
1721
setGlobal('TEST_DOWNLOAD_TOOL_RETRY_MIN_SECONDS', 0)
1822
setGlobal('TEST_DOWNLOAD_TOOL_RETRY_MAX_SECONDS', 0)
1923
})
2024

2125
beforeEach(async function () {
26+
platformMock = jest.spyOn(os, 'platform');
27+
execMock = jest.spyOn(exec, 'getExecOutput');
2228
await io.rmRF(cachePath)
2329
await io.rmRF(tempPath)
2430
await io.mkdirP(cachePath)
2531
await io.mkdirP(tempPath)
2632
})
2733

2834
afterEach(function () {
35+
platformMock.mockRestore();
36+
execMock.mockRestore();
2937
})
3038

3139
afterAll(async function () {
@@ -136,11 +144,38 @@ describe('pmd-github-action-util', function () {
136144
.reply(503, 'Test Internal Server Error');
137145

138146
expect(() => util.downloadPmd('latest', 'my_test_token')).rejects.toThrow();
139-
});
147+
})
140148

141149
it('failure while executing PMD', async () => {
142150
expect(() => util.executePmd({ path: 'non-existing-pmd-path' }, '.', 'ruleset.xml', 'sarif', 'pmd-report.sarif')).rejects.toThrow();
143-
});
151+
})
152+
153+
it('can execute PMD win32', async () => {
154+
platformMock.mockReturnValueOnce('win32');
155+
execMock.mockReturnValueOnce({ exitCode: 0, stdout: '', stderr: '' });
156+
nock('https://api.github.com')
157+
.get('/repos/pmd/pmd/releases/latest')
158+
.replyWithFile(200, __dirname + '/data/releases-latest.json', {
159+
'Content-Type': 'application/json',
160+
})
161+
nock('https://github.com')
162+
.get('/pmd/pmd/releases/download/pmd_releases/6.40.0/pmd-bin-6.40.0.zip')
163+
.replyWithFile(200, __dirname + '/data/pmd-bin-6.40.0.zip')
164+
165+
const pmdInfo = await util.downloadPmd('latest', 'my_test_token');
166+
await util.executePmd(pmdInfo, '.', 'ruleset.xml', 'sarif', 'pmd-report.sarif');
167+
168+
expect(execMock).toBeCalledWith(`${pmdInfo.path}\\bin\\pmd.bat`, [
169+
'-no-cache',
170+
'-d', '.',
171+
'-f', 'sarif',
172+
'-R', 'ruleset.xml',
173+
'-r', 'pmd-report.sarif',
174+
],
175+
{
176+
ignoreReturnCode: true
177+
});
178+
})
144179
});
145180

146181
function setGlobal(key, value) {

0 commit comments

Comments
 (0)