java-caller 3.1.2-beta202311191629.0 → 3.1.3-beta202311251749.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/README.md +11 -41
- package/lib/java-caller.js +17 -10
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -52,25 +52,25 @@ const {status, stdout, stderr} = java.run(JAVA_ARGUMENTS,JAVA_CALLER_RUN_OPTIONS
|
|
|
52
52
|
| additionalJavaArgs | Additional parameters for JVM that will be added in every JavaCaller instance runs | | `["-Xms256m","-Xmx2048m"]` |
|
|
53
53
|
| javaExecutable | You can force to use a defined java executable, instead of letting java-caller find/install one. Can also be defined with env var `JAVA_CALLER_JAVA_EXECUTABLE` | | `"/home/some-java-version/bin/java.exe"` |
|
|
54
54
|
|
|
55
|
-
|
|
56
55
|
### JAVA_ARGUMENTS
|
|
57
56
|
|
|
58
57
|
The list of arguments can contain both arguments types together:
|
|
59
58
|
|
|
60
|
-
- Java arguments (**-X
|
|
59
|
+
- Java arguments (**-X***, **-D***). ex: `"-Xms256m"`, `"-Xmx2048m"`
|
|
61
60
|
- Main class arguments (sent to `public static void main method`). ex: `"--someflag"` , `"--someflagwithvalue myVal"` , `"-c"`
|
|
62
61
|
|
|
63
62
|
Example: `["-Xms256m", "--someflagwithvalue myVal", "-c"]`
|
|
64
63
|
|
|
65
64
|
### JAVA_CALLER_RUN_OPTIONS
|
|
66
65
|
|
|
67
|
-
| Parameter
|
|
68
|
-
|
|
69
|
-
| [detached](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options)
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
66
|
+
| Parameter | Description | Default | Example |
|
|
67
|
+
|-----------|-------------|---------|---------|
|
|
68
|
+
| [detached](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | If set to true, node will node wait for the java command to be completed.<br/>In that case, `childJavaProcess` property will be returned, but `stdout` and `stderr` may be empty, except if an error is triggered at command execution | `false` | `true`
|
|
69
|
+
| [stdoutEncoding](https://nodejs.org/api/stream.html#readablesetencodingencoding) | Adds control on spawn process stdout | `utf8` | `ucs2` |
|
|
70
|
+
| waitForErrorMs | If detached is true, number of milliseconds to wait to detect an error before exiting JavaCaller run | `500` | `2000` |
|
|
71
|
+
| [cwd](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | You can override cwd of spawn called by JavaCaller runner | `process.cwd()` | `some/other/cwd/folder` |
|
|
72
|
+
| javaArgs | List of arguments for JVM only, not the JAR or the class | `[]` | `['--add-opens=java.base/java.lang=ALL-UNNAMED']` |
|
|
73
|
+
| [windowsVerbatimArguments](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options) | No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to true automatically when shell is specified and is CMD. | `true` | `false` |
|
|
74
74
|
|
|
75
75
|
## Examples
|
|
76
76
|
|
|
@@ -153,38 +153,8 @@ java-caller Java command: java -Xms256m -Xmx2048m -cp C:\Work\gitPerso\node-java
|
|
|
153
153
|
|
|
154
154
|
Contributions are very welcome !
|
|
155
155
|
|
|
156
|
-
Please follow [Contribution instructions](
|
|
156
|
+
Please follow [Contribution instructions](CONTRIBUTING.md)
|
|
157
157
|
|
|
158
158
|
## RELEASE NOTES
|
|
159
159
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
- Fix Java 8 detection ([#101@npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint/issues/101))
|
|
163
|
-
|
|
164
|
-
### [2.2.0] 2020-08-29
|
|
165
|
-
|
|
166
|
-
- Fix CLASSPATH on windows in case there are spaces in paths
|
|
167
|
-
- Update License to MIT
|
|
168
|
-
|
|
169
|
-
### [2.1.0] 2020-08-12
|
|
170
|
-
|
|
171
|
-
- Allow to use java-caller to build your own CLI embedding java sources
|
|
172
|
-
- Example projects using module and CLI
|
|
173
|
-
|
|
174
|
-
### [2.0.0] 2020-08-11
|
|
175
|
-
|
|
176
|
-
- Big refactoring to simplify and enhance performances of code checking/installing java version
|
|
177
|
-
- Replace use of deprecated package [node-jre](https://github.com/schreiben/node-jre) by [njre](https://github.com/raftario/njre)
|
|
178
|
-
- Compliance with JDK & JRE from 8 to 14 ([AdoptOpenJdk](https://adoptopenjdk.net/) releases)
|
|
179
|
-
|
|
180
|
-
### [1.1.0] 2020-08-10
|
|
181
|
-
|
|
182
|
-
- Return `javaChildProcess` when `detached` is true, so it can be used to be killed later
|
|
183
|
-
|
|
184
|
-
### [1.0.0] 2020-08-10
|
|
185
|
-
|
|
186
|
-
- Initial version
|
|
187
|
-
|
|
188
|
-
____
|
|
189
|
-
|
|
190
|
-
See complete [CHANGELOG](https://github.com/nvuillam/node-java-caller/blob/master/CHANGELOG.md)
|
|
160
|
+
See complete [CHANGELOG](CHANGELOG.md)
|
package/lib/java-caller.js
CHANGED
|
@@ -71,13 +71,15 @@ class JavaCaller {
|
|
|
71
71
|
* @param {number} [runOptions.waitForErrorMs = 500] - If detached is true, number of milliseconds to wait to detect an error before exiting JavaCaller run
|
|
72
72
|
* @param {string} [runOptions.cwd = .] - You can override cwd of spawn called by JavaCaller runner
|
|
73
73
|
* @param {string} [runOptions.javaArgs = []] - You can override cwd of spawn called by JavaCaller runner
|
|
74
|
-
|
|
74
|
+
* @param {string} [runOptions.windowsVerbatimArguments = true] - No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to true automatically when shell is specified and is CMD.
|
|
75
|
+
* @return {Promise<{status:number, stdout:string, stderr:string, childJavaProcess:ChildProcess}>} - Command result (status, stdout, stderr, childJavaProcess)
|
|
75
76
|
*/
|
|
76
77
|
async run(userArguments, runOptions = {}) {
|
|
77
|
-
runOptions.detached = runOptions.detached
|
|
78
|
-
runOptions.waitForErrorMs = runOptions.waitForErrorMs
|
|
79
|
-
runOptions.cwd = runOptions.cwd
|
|
80
|
-
runOptions.stdoutEncoding = runOptions.stdoutEncoding
|
|
78
|
+
runOptions.detached = typeof runOptions.detached === "undefined" ? false : runOptions.detached;
|
|
79
|
+
runOptions.waitForErrorMs = typeof runOptions.waitForErrorMs === "undefined" ? 500 : runOptions.waitForErrorMs;
|
|
80
|
+
runOptions.cwd = typeof runOptions.cwd === "undefined" ? process.cwd() : runOptions.cwd;
|
|
81
|
+
runOptions.stdoutEncoding = typeof runOptions.stdoutEncoding === "undefined" ? "utf8" : runOptions.stdoutEncoding;
|
|
82
|
+
runOptions.windowsVerbatimArguments = typeof runOptions.windowsVerbatimArguments === "undefined" ? true : runOptions.windowsVerbatimArguments;
|
|
81
83
|
this.commandJavaArgs = (runOptions.javaArgs || []).concat(this.additionalJavaArgs);
|
|
82
84
|
|
|
83
85
|
let javaExe = this.javaExecutable;
|
|
@@ -104,7 +106,7 @@ class JavaCaller {
|
|
|
104
106
|
env: Object.assign({}, process.env),
|
|
105
107
|
stdio: this.output === "console" ? "inherit" : runOptions.detached ? "ignore" : "pipe",
|
|
106
108
|
windowsHide: true,
|
|
107
|
-
windowsVerbatimArguments:
|
|
109
|
+
windowsVerbatimArguments: runOptions.windowsVerbatimArguments,
|
|
108
110
|
};
|
|
109
111
|
if (javaExe.includes(" ")) {
|
|
110
112
|
spawnOptions.shell = true;
|
|
@@ -146,7 +148,7 @@ class JavaCaller {
|
|
|
146
148
|
await new Promise((resolve) =>
|
|
147
149
|
setTimeout(() => {
|
|
148
150
|
resolve();
|
|
149
|
-
}, runOptions.waitForErrorMs)
|
|
151
|
+
}, runOptions.waitForErrorMs),
|
|
150
152
|
);
|
|
151
153
|
} else {
|
|
152
154
|
// Not detached mode: wait for Promise to be resolved
|
|
@@ -188,7 +190,7 @@ class JavaCaller {
|
|
|
188
190
|
}
|
|
189
191
|
|
|
190
192
|
// Set first java arguments, then jar || classpath, then jar/class user arguments
|
|
191
|
-
buildArguments(classPathStr, userArgs) {
|
|
193
|
+
buildArguments(classPathStr, userArgs, windowsVerbatimArguments) {
|
|
192
194
|
let javaArgs = [];
|
|
193
195
|
let programArgs = [];
|
|
194
196
|
for (const arg of userArgs) {
|
|
@@ -201,9 +203,14 @@ class JavaCaller {
|
|
|
201
203
|
let allArgs = [];
|
|
202
204
|
allArgs.push(...javaArgs);
|
|
203
205
|
if (this.jar) {
|
|
204
|
-
allArgs.push(
|
|
206
|
+
allArgs.push(
|
|
207
|
+
...[
|
|
208
|
+
"-jar",
|
|
209
|
+
os.platform() === "win32" && windowsVerbatimArguments ? `"${this.rootPath}/${this.jar}"` : `${this.rootPath}/${this.jar}`,
|
|
210
|
+
],
|
|
211
|
+
);
|
|
205
212
|
} else {
|
|
206
|
-
allArgs.push(...["-cp", os.platform() === "win32" ? `"${classPathStr}"` : classPathStr, this.mainClass]);
|
|
213
|
+
allArgs.push(...["-cp", os.platform() === "win32" && windowsVerbatimArguments ? `"${classPathStr}"` : classPathStr, this.mainClass]);
|
|
207
214
|
}
|
|
208
215
|
allArgs.push(...programArgs);
|
|
209
216
|
return allArgs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "java-caller",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3-beta202311251749.0",
|
|
4
4
|
"description": "Library to easily call java from node sources. Automatically installs java if not present",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"eslint": "^8.27.0",
|
|
46
46
|
"mocha": "^10.1.0",
|
|
47
47
|
"nyc": "^15.1.0",
|
|
48
|
+
"prettier": "^3.1.0",
|
|
48
49
|
"which": "^4.0.0"
|
|
49
50
|
},
|
|
50
51
|
"engines": {
|