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

java-caller

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-caller - npm Package Compare versions

Comparing version 3.3.2-beta202404281910.0 to 4.0.0

63

lib/java-caller.js

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

"use strict";
minimumJavaVersion = 8;
minimumJavaVersion = os.platform() === "darwin" ? 11 : 8; // Mac starts at 11
maximumJavaVersion;

@@ -34,2 +34,3 @@ javaType;

javaBin;
javaExecutableFromNodeJavaCaller;

@@ -64,2 +65,3 @@ prevPath;

this.javaExecutable = opts.javaExecutable || process.env.JAVA_CALLER_JAVA_EXECUTABLE || this.javaExecutable;
this.javaExecutableFromNodeJavaCaller = null;
this.additionalJavaArgs = opts.additionalJavaArgs || this.additionalJavaArgs;

@@ -91,3 +93,3 @@ this.output = opts.output || this.output;

let javaExe = runOptions.windowless ? this.javaExecutableWindowless : this.javaExecutable;
if (javaExe.toLowerCase().includes(".exe") && !javaExe.includes(`'`)) {
if (javaExe.toLowerCase().includes(".exe") && javaExe.includes(" ") && !javaExe.includes(`'`)) {
// Java executable has been overridden by caller : use it

@@ -100,4 +102,4 @@ javaExe = `"${path.resolve(javaExe)}"`;

const javaExeToUse = this.javaExecutableFromNodeJavaCaller ?? javaExe;
const classPathStr = this.buildClasspathStr();
const javaArgs = this.buildArguments(classPathStr, (userArguments || []).concat(this.commandJavaArgs));

@@ -109,6 +111,6 @@ let stdout = "";

// Spawn java command line
debug(`Java command: ${javaExe} ${javaArgs.join(" ")}`);
debug(`Java command: ${javaExeToUse} ${javaArgs.join(" ")}`);
const spawnOptions = {
detached: runOptions.detached,
cwd: javaExe === "java" || javaExe === "javaw" ? runOptions.cwd : undefined,
cwd: javaExeToUse === "java" || javaExeToUse === "javaw" ? runOptions.cwd : undefined,
env: Object.assign({}, process.env),

@@ -119,6 +121,6 @@ stdio: this.output === "console" ? "inherit" : runOptions.detached ? "ignore" : "pipe",

};
if (javaExe.includes(" ")) {
if (javaExeToUse.includes(" ")) {
spawnOptions.shell = true;
}
child = spawn(javaExe, javaArgs, spawnOptions);
child = spawn(javaExeToUse, javaArgs, spawnOptions);

@@ -230,2 +232,6 @@ // Gather stdout and stderr if they must be returned

async manageJavaInstall() {
if (this.javaExecutable !== 'java' && this.javaExecutable !== 'javaw') {
// Do not search/install java if its path is sent as argument
return;
}
if (await this.getInstallInCache()) {

@@ -250,2 +256,3 @@ return;

await this.addJavaInPath();
this.setJavaExecutableFromNodeJavaCaller(this.javaBin);
return;

@@ -257,5 +264,4 @@ }

this.minimumJavaVersion !== this.maximumJavaVersion
? `Java ${this.javaType ? this.javaType : "jre or jdk"} between ${this.minimumJavaVersion} and ${
this.maximumJavaVersion
} is required `
? `Java ${this.javaType ? this.javaType : "jre or jdk"} between ${this.minimumJavaVersion} and ${this.maximumJavaVersion
} is required `
: `Java ${this.javaType ? this.javaType : "jre or jdk"} ${this.minimumJavaVersion} is required`;

@@ -301,2 +307,3 @@ console.log(requiredMsg);

await this.addJavaInPath();
this.setJavaExecutableFromNodeJavaCaller(this.javaBin);
return true;

@@ -341,14 +348,14 @@ }

items
.filter((item) => fse.statSync(path.join(javaInstallsTopDir, item)).isDirectory())
.map((folder) => {
const version = semver.coerce(folder)
return { version, folder }
})
.filter(({ version, folder }) => this.checkMatchingJavaVersion(version.major, folder))
.map(({ version, folder }) => {
const home = path.join(javaInstallsTopDir, folder);
const bin = path.join(home, this.getPlatformBinPath());
return { version, folder, home, bin }
})
.find(({ bin }) => fse.existsSync(bin))
.filter((item) => fse.statSync(path.join(javaInstallsTopDir, item)).isDirectory())
.map((folder) => {
const version = semver.coerce(folder)
return { version, folder }
})
.filter(({ version, folder }) => this.checkMatchingJavaVersion(version.major, folder))
.map(({ version, folder }) => {
const home = path.join(javaInstallsTopDir, folder);
const bin = path.join(home, this.getPlatformBinPath());
return { version, folder, home, bin }
})
.find(({ bin }) => fse.existsSync(bin))
)

@@ -360,4 +367,3 @@ .then((match) => {

debug(
`Found matching java bin: ${bin} for ${this.javaType ? this.javaType : "jre or jdk"} ${this.minimumJavaVersion}${
this.maximumJavaVersion && this.maximumJavaVersion !== this.minimumJavaVersion ? " -> " + this.maximumJavaVersion : "+"
`Found matching java bin: ${bin} for ${this.javaType ? this.javaType : "jre or jdk"} ${this.minimumJavaVersion}${this.maximumJavaVersion && this.maximumJavaVersion !== this.minimumJavaVersion ? " -> " + this.maximumJavaVersion : "+"
}`

@@ -431,2 +437,11 @@ );

setJavaExecutableFromNodeJavaCaller(javaBinPath) {
this.javaExecutableFromNodeJavaCaller = path.join(
javaBinPath,
os.platform() === "win32" ? "java.exe" : "java");
if (this.javaExecutableFromNodeJavaCaller.includes(" ") && !this.javaExecutableFromNodeJavaCaller.startsWith('"')) {
this.javaExecutableFromNodeJavaCaller = `"${path.resolve(this.javaExecutableFromNodeJavaCaller)}"`
}
}
fail(reason) {

@@ -433,0 +448,0 @@ console.error(reason);

{
"name": "java-caller",
"version": "3.3.2-beta202404281910.0",
"version": "4.0.0",
"description": "Library to easily call java from node sources. Automatically installs java if not present",

@@ -40,3 +40,3 @@ "main": "./lib/index.js",

"fs-extra": "^11.1.1",
"njre": "^1.1.0",
"njre": "^1.2.1",
"semver": "^7.5.4"

@@ -43,0 +43,0 @@ },

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