npm-groovy-lint 11.1.2-beta202310271757.0 → 11.1.2-beta202311021422.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codenarc-caller.js +48 -15
- package/lib/groovy-lint.js +10 -10
- package/lib/java/CodeNarcServer.jar +0 -0
- package/lib/java/groovy/lib/groovy-dateutil-3.0.9.jar +0 -0
- package/lib/java/logback-classic-1.4.9.jar +0 -0
- package/lib/java/logback-core-1.4.9.jar +0 -0
- package/lib/java/logback.xml +34 -0
- package/package.json +7 -7
- package/lib/java/slf4j-simple-2.0.9.jar +0 -0
package/lib/codenarc-caller.js
CHANGED
|
@@ -32,14 +32,14 @@ class CodeNarcCaller {
|
|
|
32
32
|
|
|
33
33
|
javaCallerOptions = {
|
|
34
34
|
codeNarcServer: {
|
|
35
|
-
minimumJavaVersion:
|
|
36
|
-
maximumJavaVersion:
|
|
35
|
+
minimumJavaVersion: 17,
|
|
36
|
+
maximumJavaVersion: 17,
|
|
37
37
|
rootPath: __dirname,
|
|
38
38
|
jar: "java/CodeNarcServer.jar"
|
|
39
39
|
},
|
|
40
40
|
codeNarcJava: {
|
|
41
|
-
minimumJavaVersion:
|
|
42
|
-
maximumJavaVersion:
|
|
41
|
+
minimumJavaVersion: 17,
|
|
42
|
+
maximumJavaVersion: 17,
|
|
43
43
|
rootPath: __dirname,
|
|
44
44
|
jar: "java/CodeNarcServer.jar"
|
|
45
45
|
}
|
|
@@ -108,6 +108,14 @@ class CodeNarcCaller {
|
|
|
108
108
|
}
|
|
109
109
|
// Cancelled codeNarcAction (duplicate)
|
|
110
110
|
else if (e.code && e.code === "ECONNRESET") {
|
|
111
|
+
// The server was shutdown just retry.
|
|
112
|
+
if (startServerTried === false && (await this.startCodeNarcServer()) && this.serverStatus === "running") {
|
|
113
|
+
return await this.callCodeNarcServer(true);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Should this really be cancelled, as the Groovy says it should return:
|
|
117
|
+
// respObj.status = 'cancelledByDuplicateRequest'
|
|
118
|
+
// respObj.statusCode = 444
|
|
111
119
|
return {
|
|
112
120
|
status: 9
|
|
113
121
|
};
|
|
@@ -255,7 +263,7 @@ class CodeNarcCaller {
|
|
|
255
263
|
// Start CodeNarc server so it can be called via Http just after
|
|
256
264
|
async startCodeNarcServer() {
|
|
257
265
|
this.serverStatus = "unknown";
|
|
258
|
-
const maxAttemptTimeMs =
|
|
266
|
+
const maxAttemptTimeMs = 10000;
|
|
259
267
|
const scriptArgs = ["--server"];
|
|
260
268
|
const serverPingUri = this.getCodeNarcServerUri() + "/ping";
|
|
261
269
|
|
|
@@ -266,18 +274,20 @@ class CodeNarcCaller {
|
|
|
266
274
|
javaCallerOpts.javaExecutable = this.javaExecutable;
|
|
267
275
|
javaCallerOpts.additionalJavaArgs = this.additionalJavaArgs;
|
|
268
276
|
const javaCaller = new JavaCaller(javaCallerOpts);
|
|
269
|
-
const
|
|
277
|
+
const javaResult = await javaCaller.run(scriptArgs, { detached: true, waitForErrorMs: 500 });
|
|
270
278
|
|
|
271
|
-
|
|
272
|
-
|
|
279
|
+
// Store the process so we can stop it later.
|
|
280
|
+
this.codeNarcProcess = javaResult.childJavaProcess;
|
|
281
|
+
|
|
282
|
+
trace(`javaResult: ${JSON.stringify(javaResult)}`);
|
|
283
|
+
|
|
284
|
+
if ([666, 1].includes(javaResult.status)) {
|
|
285
|
+
console.error(c.red(`Unable to start CodeNarc server: ${JSON.stringify(javaResult)}`));
|
|
273
286
|
console.error(c.grey(JSON.stringify(scriptArgs)));
|
|
274
287
|
this.serverStatus = "error";
|
|
275
288
|
return false;
|
|
276
289
|
}
|
|
277
290
|
|
|
278
|
-
// Store the process so we can stop it later.
|
|
279
|
-
this.codeNarcProcess = javaCallRes.childJavaProcess;
|
|
280
|
-
|
|
281
291
|
// Poll it until it is ready
|
|
282
292
|
const start = performance.now();
|
|
283
293
|
let notified = false;
|
|
@@ -325,9 +335,8 @@ class CodeNarcCaller {
|
|
|
325
335
|
if (this.serverStatus === "running") {
|
|
326
336
|
debug(c.green(`GroovyLint: Started CodeNarc Server`));
|
|
327
337
|
return true;
|
|
328
|
-
} else {
|
|
329
|
-
return false;
|
|
330
338
|
}
|
|
339
|
+
return false;
|
|
331
340
|
}
|
|
332
341
|
|
|
333
342
|
// Kill CodeNarc process if running.
|
|
@@ -364,9 +373,9 @@ class CodeNarcCaller {
|
|
|
364
373
|
}
|
|
365
374
|
|
|
366
375
|
// Process kill wasn't possible, so try sending a kill http request.
|
|
367
|
-
const
|
|
376
|
+
const killUri = this.getCodeNarcServerUri() + "/kill";
|
|
368
377
|
try {
|
|
369
|
-
const response = await axios.post(
|
|
378
|
+
const response = await axios.post(killUri, { timeout: 1000 });
|
|
370
379
|
if (response.data.status === "killed") {
|
|
371
380
|
outputString = "CodeNarcServer terminated";
|
|
372
381
|
} else {
|
|
@@ -381,6 +390,30 @@ class CodeNarcCaller {
|
|
|
381
390
|
outputString = `CodeNarcServer was not running`;
|
|
382
391
|
}
|
|
383
392
|
}
|
|
393
|
+
|
|
394
|
+
// Wait for the server to stop otherwise when we try to start it
|
|
395
|
+
// again it it's likely to fail due to an port in use error.
|
|
396
|
+
const serverPingUri = this.getCodeNarcServerUri() + "/ping";
|
|
397
|
+
|
|
398
|
+
let interval;
|
|
399
|
+
await new Promise(resolve => {
|
|
400
|
+
interval = setInterval(() => {
|
|
401
|
+
debug(`pinging CodeNarcServer at ${serverPingUri} serverStatus: ${this.serverStatus}`);
|
|
402
|
+
axios
|
|
403
|
+
.get(serverPingUri)
|
|
404
|
+
.then(response => {
|
|
405
|
+
debug(`ping response: ${response.status}`);
|
|
406
|
+
})
|
|
407
|
+
.catch(e => {
|
|
408
|
+
debug(`Ping code: ${e.code} message: ${e.message}`);
|
|
409
|
+
clearInterval(interval);
|
|
410
|
+
resolve();
|
|
411
|
+
});
|
|
412
|
+
}, 400);
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
trace(`killCodeNarcServer: ${outputString}`);
|
|
416
|
+
|
|
384
417
|
return outputString;
|
|
385
418
|
}
|
|
386
419
|
|
package/lib/groovy-lint.js
CHANGED
|
@@ -117,6 +117,9 @@ class NpmGroovyLint {
|
|
|
117
117
|
|
|
118
118
|
// Actions before call to CodeNarc
|
|
119
119
|
async preProcess() {
|
|
120
|
+
// Reset status so we don't get stale results.
|
|
121
|
+
this.status = 0;
|
|
122
|
+
|
|
120
123
|
// Manage when the user wants to use only codenarc args
|
|
121
124
|
if (Array.isArray(this.args) && this.args.includes("--codenarcargs")) {
|
|
122
125
|
this.codenarcArgs = this.args.slice(2).filter(userArg => userArg !== "--codenarcargs");
|
|
@@ -367,6 +370,7 @@ class NpmGroovyLint {
|
|
|
367
370
|
await newLinter.run();
|
|
368
371
|
// Merge new linter results in existing results
|
|
369
372
|
this.lintResult = this.mergeResults(this.lintResult, newLinter.lintResult);
|
|
373
|
+
this.status = newLinter.status;
|
|
370
374
|
}
|
|
371
375
|
|
|
372
376
|
// Fix again after fix because fixed rules contained triggersAgainAfterFix property (for the moment, only Indentation rule)
|
|
@@ -489,32 +493,28 @@ class NpmGroovyLint {
|
|
|
489
493
|
return;
|
|
490
494
|
}
|
|
491
495
|
|
|
492
|
-
const errorNb = this.lintResult.summary.
|
|
493
|
-
const warningNb = this.lintResult.summary.
|
|
494
|
-
const infoNb = this.lintResult.summary.
|
|
496
|
+
const errorNb = this.lintResult.summary.totalRemainingErrorNumber;
|
|
497
|
+
const warningNb = this.lintResult.summary.totalRemainingWarningNumber;
|
|
498
|
+
const infoNb = this.lintResult.summary.totalRemainingInfoNumber;
|
|
495
499
|
|
|
496
500
|
// Fail on error
|
|
497
501
|
if (failureLevel === "error" && errorNb > 0) {
|
|
498
502
|
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
499
|
-
console.error(`Failure: ${this.lintResult.summary
|
|
503
|
+
console.error(`Failure summary: ${JSON.stringify(this.lintResult.summary, null, 2)}`);
|
|
500
504
|
}
|
|
501
505
|
this.status = 1;
|
|
502
506
|
}
|
|
503
507
|
// Fail on warning
|
|
504
508
|
else if (failureLevel === "warning" && (errorNb > 0 || warningNb > 0)) {
|
|
505
509
|
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
506
|
-
console.error(
|
|
507
|
-
`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found`
|
|
508
|
-
);
|
|
510
|
+
console.error(`Failure summary: ${JSON.stringify(this.lintResult.summary, null, 2)}`);
|
|
509
511
|
}
|
|
510
512
|
this.status = 1;
|
|
511
513
|
}
|
|
512
514
|
// Fail on info
|
|
513
515
|
else if (failureLevel === "info" && (errorNb > 0 || warningNb > 0 || infoNb > 0)) {
|
|
514
516
|
if (!["json", "sarif", "stdout"].includes(this.outputType)) {
|
|
515
|
-
console.error(
|
|
516
|
-
`Failure: ${this.lintResult.summary.totalFoundErrorNumber} error(s) have been found \n ${this.lintResult.summary.totalFoundWarningNumber} warning(s) have been found \n ${this.lintResult.summary.totalFoundInfoNumber} info(s) have been found`
|
|
517
|
-
);
|
|
517
|
+
console.error(`Failure summary: ${JSON.stringify(this.lintResult.summary, null, 2)}`);
|
|
518
518
|
}
|
|
519
519
|
this.status = 1;
|
|
520
520
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<!DOCTYPE configuration>
|
|
3
|
+
|
|
4
|
+
<configuration>
|
|
5
|
+
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
|
6
|
+
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
|
7
|
+
|
|
8
|
+
<appender name="STDERR" class="ConsoleAppender">
|
|
9
|
+
<target>System.err</target>
|
|
10
|
+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
|
11
|
+
<level>${logging.appender.console.level:-INFO}</level>
|
|
12
|
+
</filter>
|
|
13
|
+
<encoder class="PatternLayoutEncoder">
|
|
14
|
+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n</pattern>
|
|
15
|
+
</encoder>
|
|
16
|
+
</appender>
|
|
17
|
+
|
|
18
|
+
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
|
19
|
+
<file>logback.log</file>
|
|
20
|
+
<append>true</append>
|
|
21
|
+
<immediateFlush>true</immediateFlush>
|
|
22
|
+
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
|
23
|
+
<level>${logging.appender.log.level:-OFF}</level>
|
|
24
|
+
</filter>
|
|
25
|
+
<encoder>
|
|
26
|
+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
|
27
|
+
</encoder>
|
|
28
|
+
</appender>
|
|
29
|
+
|
|
30
|
+
<root>
|
|
31
|
+
<appender-ref ref="FILE"/>
|
|
32
|
+
<appender-ref ref="STDERR"/>
|
|
33
|
+
</root>
|
|
34
|
+
</configuration>
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-groovy-lint",
|
|
3
|
-
"version": "11.1.2-
|
|
3
|
+
"version": "11.1.2-beta202311021422.0",
|
|
4
4
|
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint:fix": "eslint **/*.js --fix && prettier --write \"./lib/**/*.{js,jsx}\" --tab-width 4 --print-width 150",
|
|
8
|
-
"server:run-from-source": "npm run
|
|
9
|
-
"server:run": "npm run
|
|
8
|
+
"server:run-from-source": "npm run server:kill && groovy -cp \"lib/java/*\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
|
|
9
|
+
"server:run": "npm run server:kill && java -Xms256m -Xmx2048m -jar lib/java/CodeNarcServer.jar --server",
|
|
10
10
|
"server:build": "node scripts/build-server.js",
|
|
11
|
-
"
|
|
11
|
+
"server:kill": "npm-groovy-lint --killserver",
|
|
12
|
+
"test": "npm run server:kill && mocha \"test/**/*.test.js\"",
|
|
12
13
|
"test:coverage": "nyc npm run test",
|
|
13
|
-
"test:debug": "npm run
|
|
14
|
+
"test:debug": "npm run server:kill && mocha --reporter spec --inspect-brk \"test/**/*.test.js\"",
|
|
14
15
|
"build": "node scripts/build-config-all.js && cp -f README.md docs/index.md && cp -f CHANGELOG.md docs/CHANGELOG.md",
|
|
15
|
-
"dev:
|
|
16
|
-
"dev:lint-install-local": "npm run dev:kill-server && npm run lint:fix && npm link --force",
|
|
16
|
+
"dev:lint-install-local": "npm run server:kill && npm run lint:fix && npm link --force",
|
|
17
17
|
"dev:lint-install-local-copy-vscode": "npm run dev:lint-install-local && node scripts/deploy-in-vscode.js",
|
|
18
18
|
"dev:pre-commit": "npm-run-all lint:fix build server:build"
|
|
19
19
|
},
|
|
Binary file
|