java-caller
Advanced tools
Comparing version 3.3.2-beta202404281910.0 to 4.0.1-beta202405081245.0
@@ -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.1-beta202405081245.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 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35962
437
Updatednjre@^1.2.1