Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

npm-groovy-lint

Package Overview
Dependencies
Maintainers
1
Versions
204
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npm-groovy-lint - npm Package Compare versions

Comparing version 3.0.0-beta.1 to 3.0.0-beta.2

jdeploy-bundle/lib/com/nvuillam/CodeNarcServer$_initialize_closure3$_closure7.class

115

jdeploy-bundle/groovy-lint.js

@@ -27,2 +27,3 @@ #! /usr/bin/env node

jdeployFile;
jdeployFilePlanB;
jdeployRootPath;

@@ -48,2 +49,3 @@ parseOptions;

fixer;
execTimeout = 120000;

@@ -59,2 +61,3 @@ bar;

this.jdeployFile = internalOpts.jdeployFile || process.env.JDEPLOY_FILE || "originaljdeploy.js";
this.jdeployFilePlanB = internalOpts.jdeployFilePlanB || process.env.JDEPLOY_FILE_PLAN_B || "originaljdeployPlanB.js";
this.jdeployRootPath = internalOpts.jdeployRootPath || process.env.JDEPLOY_ROOT_PATH || __dirname;

@@ -109,3 +112,13 @@ this.parseOptions = internalOpts.parseOptions !== false;

if (this.options.version) {
console.info("v3.0.0");
let v = process.env.npm_package_version;
if (!v) {
try {
v = require("package.json").version;
} catch {
v = "3.0.0-beta.1";
}
}
const vLabel = "npm-groovy-lint v" + v;
console.info(vLabel);
this.nglOutputString = vLabel;
return false;

@@ -125,2 +138,28 @@ }

// Kill running CodeNarcServer
if (this.options.killserver) {
const serverUri = this.getCodeNarcServerUri() + "/kill";
try {
const parsedBody = await rp({
method: "POST",
uri: serverUri,
timeout: 5000,
json: true
});
if (parsedBody.status === "killed") {
this.nglOutputString = "CodeNarcServer terminated";
} else {
this.nglOutputString = "Error killing CodeNarcServer";
}
} catch (e) {
if (e.message.includes("socket hang up")) {
this.nglOutputString = "CodeNarcServer terminated";
} else {
this.nglOutputString = "CodeNarcServer was not running";
}
}
console.info(this.nglOutputString);
return false;
}
////////////////////////////

@@ -210,3 +249,8 @@ // Build codenarc options //

// Call either CodeNarc local server (better perfs), or java class if server not running
/* Order of attempts (supposed to work on every config):
- Call CodeNarcServer via Http (except if --noserver)
- Launch CodeNarcServer using com.nvuillam.CodeNarcServer, then call CodeNarcServer via Http (except if --noserver)
- Call CodeNarc using com.nvuillam.CodeNarcServer (without launching server) (originaljdeploy.js)
- Call CodeNarc using org.codenarc.CodeNarc (originaljdeployPlanB.js)
*/
async callCodeNarc() {

@@ -225,3 +269,3 @@ let serverSuccess = false;

// If use of --codenarcargs, get default values for CodeNarcServer host & port
const serverUri = this.getCodeNarcServerUi();
const serverUri = this.getCodeNarcServerUri();
// Remove "" around values because they won't get thru system command line parser

@@ -257,3 +301,5 @@ const codeNarcArgsForServer = this.codenarcArgs.map(codeNarcArg => {

) {
return await this.callCodeNarcServer();
if (this.serverStatus === "running") {
return await this.callCodeNarcServer();
}
}

@@ -269,6 +315,7 @@ this.serverStatus = "error";

// Call CodeNard java class from renamed jdeploy.js
async callCodeNarcJava() {
async callCodeNarcJava(secondAttempt = false) {
// Build jdeploy codenarc command (request to launch server for next call except if --noserver is sent)
const nodeExe = this.args[0] && this.args[0].includes("node") ? this.args[0] : "node";
const jDeployCommand = '"' + nodeExe + '" "' + this.jdeployRootPath.trim() + "/" + this.jdeployFile + '" ' + this.codenarcArgs.join(" ");
const jdeployFileToUse = secondAttempt ? this.jdeployFilePlanB : this.jdeployFile;
const jDeployCommand = '"' + nodeExe + '" "' + this.jdeployRootPath.trim() + "/" + jdeployFileToUse + '" ' + this.codenarcArgs.join(" ");

@@ -298,7 +345,13 @@ // Start progress bar

try {
execRes = await exec(jDeployCommand);
execRes = await exec(jDeployCommand, { timeout: this.execTimeout });
} catch (e) {
clearInterval(this.barTimer);
this.bar.stop();
throw new Error("NGL: CodeNarc crash: \n" + e.message);
// If failure (missing class com.nvuillam.CodeNarcServer for example, it can happen on Linux, let's try the original org.codenarc.CodeNarc class)
if (!secondAttempt) {
return await this.callCodeNarcJava(true);
} else {
this.codeNarcStdErr = e.stderr;
return;
}
}

@@ -317,29 +370,36 @@

this.serverStatus = "unknown";
const maxAttemptTimeMs = 2000;
let attempts = 1;
const nodeExe = this.args[0] && this.args[0].includes("node") ? this.args[0] : "node";
const jDeployCommand = '"' + nodeExe + '" "' + this.jdeployRootPath.trim() + "/" + this.jdeployFile + '" --server';
const serverPingUri = this.getCodeNarcServerUi() + "/ping";
const serverPingUri = this.getCodeNarcServerUri() + "/ping";
let interval;
try {
// Start server using java
exec(jDeployCommand);
exec(jDeployCommand, { timeout: this.execTimeout });
// Poll it until it is ready
const start = performance.now();
await new Promise((resolve, reject) => {
const interval = setInterval(() => {
interval = setInterval(() => {
request
.get(serverPingUri)
.on("response", response => {
if (response.statusCode === 200 && response.toJSON().status === "running") {
if (response.statusCode === 200) {
this.serverStatus = "running";
clearInterval(interval);
resolve();
} else if (this.serverStatus === "unknown" && performance.now() - start > 5000) {
clearInterval(interval);
reject("NGL: Unable to launch CodeNarc Server");
} else if (this.serverStatus === "unknown" && performance.now() - start > maxAttemptTimeMs) {
this.declareServerError(
{
message: "Timeout after " + maxAttemptTimeMs + "\nResponse: " + JSON.stringify(response.toJSON())
},
interval
);
reject();
}
})
.on("error", () => {
if (this.serverStatus === "unknown" && performance.now() - start > 5000) {
clearInterval(interval);
reject("NGL: Unable to launch CodeNarc Server");
.on("error", e => {
if (this.serverStatus === "unknown" && performance.now() - start > maxAttemptTimeMs) {
this.declareServerError(e, interval);
reject();
}

@@ -350,3 +410,3 @@ });

} catch (e) {
console.log("NGL: Error starting CodeNarc Server");
this.declareServerError(e, interval);
return false;

@@ -358,4 +418,15 @@ }

declareServerError(e, interval) {
this.serverStatus = "error";
if (interval) {
clearInterval(interval);
}
console.log("NGL: Unable to start CodeNarc Server. Use --noserver if you do not even want to try");
if (this.verbose && e) {
console.error(e.message);
}
}
// Return CodeNarc server URI
getCodeNarcServerUi() {
getCodeNarcServerUri() {
// If use of --codenarcargs, get default values for CodeNarcServer host & port

@@ -369,3 +440,3 @@ const serverOptions = optionsDefinition.parse({});

// CodeNarc error
if (this.codeNarcStdErr && this.codeNarcStdErr !== "Picked up _JAVA_OPTIONS: -Xmx512M\n") {
if (this.codeNarcStdErr && [null, "", undefined].includes(this.codeNarcStdOut)) {
this.status = 1;

@@ -372,0 +443,0 @@ console.error("NGL: Error running CodeNarc: \n" + this.codeNarcStdErr);

@@ -0,0 +0,0 @@ Copyright (c) 2002-2012, the original author or authors.

@@ -0,0 +0,0 @@ The person or persons who have associated work with this document (the

@@ -0,0 +0,0 @@ Copyright (c) 2006, Sun Microsystems, Inc.

@@ -0,0 +0,0 @@ Eclipse Public License - v 1.0

@@ -0,0 +0,0 @@ Eclipse Public License - v 2.0

@@ -0,0 +0,0 @@ Copyright (c) 2003-2006, Joe Walnes

@@ -78,3 +78,2 @@ /**

option: "verbose",
alias: "v",
type: "Boolean",

@@ -144,3 +143,3 @@ description: "More outputs in console, including performed fixes"

type: "String",
default: "http://localhost",
default: "http://" + require("ip").address(), //Usually localhost, but not always on CIs (Circle, Jenkins ...)
description: "If use of CodeNarc server, host where is the CodeNarc server (default: localhost)"

@@ -155,2 +154,7 @@ },

{
option: "killserver",
type: "Boolean",
description: "Terminate the CodeNarcServer if running"
},
{
option: "help",

@@ -160,2 +164,8 @@ alias: "h",

description: "Show help (npm-groovy-lint -help OPTIONNAME to see option detail)"
},
{
option: "version",
alias: "v",
type: "Boolean",
description: "Show version"
}

@@ -162,0 +172,0 @@ ],

8

package.json
{
"name": "npm-groovy-lint",
"version": "3.0.0-beta.1",
"version": "3.0.0-beta.2",
"description": "NPM CodeNarc wrapper to easily lint Groovy files",

@@ -12,2 +12,3 @@ "main": "index.js",

"postbuild": "node patch-jdeploy-after.js",
"groovy:run-server-from-source": "groovy -cp \"lib/CodeNarc-1.5.jar;lib/groovy-3.0.1/lib/groovy-3.0.1.jar;lib/groovy-3.0.1/lib/groovy-templates-3.0.1.jar;lib/groovy-3.0.1/lib/groovy-xml-3.0.1.jar;lib/groovy-3.0.1/lib/groovy-json-3.0.1.jar;lib/slf4j-api-1.7.9.jar;lib/log4j-slf4j-impl-2.13.0.jar;lib/log4j-api-2.13.0.jar;lib/log4j-core-2.13.0.jar;lib/GMetrics-0.7.jar\" groovy/src/main/com/nvuillam/CodeNarcServer.groovy --server",
"groovy:build": "groovyc -cp \"./lib/*\" --encoding utf-8 ./groovy/src/main/com/nvuillam/CodeNarcServer.groovy -d lib && jar -cvfm ./lib/CodeNarcServer.jar MANIFEST.txt lib/com/nvuillam/*.class ",

@@ -18,3 +19,4 @@ "test": "mocha \"test/**/*.test.js\"",

"publish:release": "npm run build && npm publish",
"publish:beta": "npm run build && npm publish --tag beta"
"publish:beta": "npm run build && npm publish --tag beta",
"lint-build-all": "npm run lint:fix && npm run groovy:build && npm run build"
},

@@ -50,2 +52,3 @@ "repository": {

"glob": "^7.1.6",
"ip": "^1.1.5",
"optionator": "^0.8.3",

@@ -77,2 +80,3 @@ "request": "^2.88.2",

"mainClass": "com.nvuillam.CodeNarcServer",
"mainClassPlanB": "org.codenarc.CodeNarc",
"classPath": "lib/CodeNarc-1.5.jar:lib/groovy-3.0.1/lib/groovy-3.0.1.jar:lib/groovy-3.0.1/lib/groovy-templates-3.0.1.jar:lib/groovy-3.0.1/lib/groovy-xml-3.0.1.jar:lib/groovy-3.0.1/lib/groovy-json-3.0.1.jar:lib/slf4j-api-1.7.9.jar:lib/log4j-slf4j-impl-2.13.0.jar:lib/log4j-api-2.13.0.jar:lib/log4j-core-2.13.0.jar:lib/GMetrics-0.7.jar:lib",

@@ -79,0 +83,0 @@ "files": [

@@ -53,2 +53,3 @@ # NPM GROOVY LINT (and FIX !)

| -h<br/> --help | Boolean | Show help (npm-groovy-lint -h OPTIONNAME to see option detail with examples)
# EXAMPLES

@@ -55,0 +56,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc