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 2.2.4 to 2.3.0

4

CHANGELOG.md
# Changelog
## [2.3.0] 2020-09-05
- Support absolute paths in classpath with argument `useAbsoluteClassPaths` and classPath as array of strings ([#12](https://github.com/nvuillam/node-java-caller/pull/12), by [Dan Gowans](https://github.com/dangowans))
## [2.2.3] 2020-09-05

@@ -4,0 +8,0 @@

@@ -0,0 +0,0 @@ #! /usr/bin/env node

@@ -0,0 +0,0 @@ #! /usr/bin/env node

50

lib/java-caller.js

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

classPath = ".";
useAbsoluteClassPaths = false;
mainClass;

@@ -38,3 +39,4 @@ output = "none"; // can be none or console

* @param {string} [opts.jar] - Path to executable jar file
* @param {string} [opts.classPath] - If jar parameter is not set, classpath to use. Use : as separator (it will be converted if runned on Windows)
* @param {string | string[]} [opts.classPath] - If jar parameter is not set, classpath to use. Use : as separator (it will be converted if runned on Windows), or use a string array
* @param {boolean} [opts.useAbsoluteClassPaths] - Set to true if classpaths should not be based on the rootPath
* @param {string} [opts.mainClass] - If classPath set, main class to call

@@ -51,2 +53,3 @@ * @param {number} [opts.minimumJavaVersion] - Minimum java version to be used to call java command. If the java version found on machine is lower, java-caller will try to install and use the appropriate one

this.classPath = opts.classPath || this.classPath;
this.useAbsoluteClassPaths = opts.useAbsoluteClassPaths || this.useAbsoluteClassPaths;
this.mainClass = opts.mainClass || this.mainClass;

@@ -79,3 +82,3 @@ this.minimumJavaVersion = opts.minimumJavaVersion || this.minimumJavaVersion;

if (javaExe.toLowerCase().includes(".exe") && !javaExe.includes(`'`)) {
// Java executable has been overriden by caller : use it
// Java executable has been overridden by caller : use it
javaExe = `"${path.resolve(javaExe)}"`;

@@ -87,6 +90,4 @@ } else {

const classPathStr = this.classPath
.split(":")
.map(classPathElt => path.resolve(this.rootPath + path.sep + classPathElt))
.join(path.delimiter);
const classPathStr = this.buildClasspathStr();
const javaArgs = this.buildArguments(classPathStr, (userArguments || []).concat(this.additionalJavaArgs));

@@ -96,3 +97,3 @@ let stdout = "";

let child;
const prom = new Promise(resolve => {
const prom = new Promise((resolve) => {
// Spawn java command line

@@ -106,3 +107,3 @@ debug(`Java command: ${javaExe} ${javaArgs.join(" ")}`);

windowsHide: true,
windowsVerbatimArguments: true
windowsVerbatimArguments: true,
};

@@ -116,6 +117,6 @@ if (javaExe.includes(" ")) {

if (spawnOptions.stdio === "pipe") {
child.stdout.on("data", data => {
child.stdout.on("data", (data) => {
stdout += data;
});
child.stderr.on("data", data => {
child.stderr.on("data", (data) => {
stderr += data;

@@ -126,3 +127,3 @@ });

// Catch error
child.on("error", data => {
child.on("error", (data) => {
this.status = 666;

@@ -134,3 +135,3 @@ stderr += "Java spawn error: " + data;

// Catch status code
child.on("close", code => {
child.on("close", (code) => {
this.status = code;

@@ -148,3 +149,3 @@ resolve();

// Detached mode: Just wait a little amount of time in case you want to check a command error
await new Promise(resolve =>
await new Promise((resolve) =>
setTimeout(() => {

@@ -163,3 +164,3 @@ resolve();

stdout: stdout,
stderr: stderr
stderr: stderr,
};

@@ -177,2 +178,19 @@ if (child) {

// Translate the classpath from a string or string array into a string
buildClasspathStr() {
let classPathList = [];
if (typeof this.classPath === "string") {
classPathList = this.classPath.split(":");
} else {
classPathList = this.classPath;
}
if (!this.useAbsoluteClassPaths) {
classPathList = classPathList.map((classPathElt) => path.resolve(this.rootPath + path.sep + classPathElt));
}
return classPathList.join(path.delimiter);
}
// Set first java arguments, then jar || classpath, then jar/class user arguments

@@ -236,3 +254,3 @@ buildArguments(classPathStr, userArgs) {

version: "1.0.0",
description: "Java installations by java-caller (https://github.com/nvuillam/node-java-caller)"
description: "Java installations by java-caller (https://github.com/nvuillam/node-java-caller)",
};

@@ -308,3 +326,3 @@ await fse.writeFile(packageJson, JSON.stringify(packageJsonContent), "utf8");

let isFirst = true;
const dirContentFiltered = dirContent.filter(file => {
const dirContentFiltered = dirContent.filter((file) => {
if (!fse.statSync(path.join(javaInstallsTopDir, file)).isDirectory()) {

@@ -311,0 +329,0 @@ return false;

{
"name": "java-caller",
"version": "2.2.4",
"version": "2.3.0",
"description": "Library to easily call java from node sources. Automatically installs java if not present",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

<!-- markdownlint-disable MD033 -->
# Java Caller for Node.js
[![Version](https://img.shields.io/npm/v/java-caller.svg)](https://npmjs.org/package/node-java-caller)
[![Version](https://img.shields.io/npm/v/java-caller.svg)](https://www.npmjs.com/package/java-caller)
[![Downloads/week](https://img.shields.io/npm/dw/java-caller.svg)](https://npmjs.org/package/java-caller)
[![Downloads/total](https://img.shields.io/npm/dt/java-caller.svg)](https://npmjs.org/package/java-caller)
[![CircleCI](https://circleci.com/gh/nvuillam/node-java-caller/tree/master.svg?style=shield)](https://circleci.com/gh/nvuillam/node-java-caller/tree/master)
[![Mega-Linter](https://github.com/nvuillam/node-java-caller/workflows/Mega-Linter/badge.svg)](https://github.com/nvuillam/mega-linter#readme)
[![codecov](https://codecov.io/gh/nvuillam/node-java-caller/branch/master/graph/badge.svg)](https://codecov.io/gh/nvuillam/node-java-caller)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2f74d43c38764caab0c6f76a7a668df3)](https://www.codacy.com/manual/nvuillam/node-java-caller?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=nvuillam/node-java-caller&amp;utm_campaign=Badge_Grade)
[![GitHub contributors](https://img.shields.io/github/contributors/nvuillam/node-java-caller.svg)](https://gitHub.com/nvuillam/node-java-caller/graphs/contributors/)

@@ -42,14 +42,16 @@ [![GitHub stars](https://img.shields.io/github/stars/nvuillam/node-java-caller?label=Star&maxAge=2592000)](https://GitHub.com/nvuillam/node-java-caller/stargazers/)

| Parameter | Description | Default value | Example |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|------------------------------------------|
| jar | Path to executable jar file | | `"myfolder/myjar.jar"` |
| classPath | If jar parameter is not set, classpath to use<br/>Use `:` as separator (it will be converted if runned on Windows) | `.` (current folder) | `"java/myJar.jar:java/myOtherJar.jar"` |
| mainClass | If classPath set, main class to call | | `"com.example.MyClass"` |
| rootPath | If classPath elements are not relative to the current folder, you can define a root path. <br/> You may use `__dirname` if you classes / jars are in your module folder | `.` (current folder) | `"/home/my/folder/containing/jars"` |
| minimumJavaVersion | Minimum java version to be used to call java command.<br/> If the java version found on machine is lower, java-caller will try to install and use the appropriate one | `8` | `11` |
| maximumJavaVersion | Maximum java version to be used to call java command.<br/> If the java version found on machine is upper, java-caller will try to install and use the appropriate one <br/> Can be equal to minimumJavaVersion | | `10` |
| javaType | jre or jdk (if not defined and installation is required, jre will be installed) | | `"jre"` |
| additionalJavaArgs | Additional parameters for JVM that will be added in every JavaCaller instance runs | | `["-Xms256m","-Xmx2048m"]` |
| javaExecutable | You can force to use a defined java executable, instead of letting java-caller find/install one | | `"/home/some-java-version/bin/java.exe"` |
| Parameter | Description | Default value | Example |
| --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------- |
| jar | Path to executable jar file | | `"myfolder/myjar.jar"` |
| classPath | If jar parameter is not set, classpath to use<br/>Use `:` as separator (it will be converted if runned on Windows), or use a string array. | `.` (current folder) | `"java/myJar.jar:java/myOtherJar.jar"` |
| useAbsoluteClassPaths | Set to true if classpaths should not be based on the rootPath | `false` | `true` |
| mainClass | If classPath set, main class to call | | `"com.example.MyClass"` |
| rootPath | If classPath elements are not relative to the current folder, you can define a root path. <br/> You may use `__dirname` if you classes / jars are in your module folder | `.` (current folder) | `"/home/my/folder/containing/jars"` |
| minimumJavaVersion | Minimum java version to be used to call java command.<br/> If the java version found on machine is lower, java-caller will try to install and use the appropriate one | `8` | `11` |
| maximumJavaVersion | Maximum java version to be used to call java command.<br/> If the java version found on machine is upper, java-caller will try to install and use the appropriate one <br/> Can be equal to minimumJavaVersion | | `10` |
| javaType | jre or jdk (if not defined and installation is required, jre will be installed) | | `"jre"` |
| additionalJavaArgs | Additional parameters for JVM that will be added in every JavaCaller instance runs | | `["-Xms256m","-Xmx2048m"]` |
| javaExecutable | You can force to use a defined java executable, instead of letting java-caller find/install one | | `"/home/some-java-version/bin/java.exe"` |
### JAVA_ARGUMENTS

@@ -84,2 +86,12 @@

Call a class with multiple folders in the classPath
```javascript
const java = new JavaCaller({
classPath: ['C:\\pathA\\test\\java\\dist', 'C:\\pathB\\test\\java\\dist'],
mainClass: 'com.nvuillam.javacaller.JavaCallerTester'
});
const { status, stdout, stderr } = await java.run();
```
Call a class located in classpath with java and custom arguments

@@ -86,0 +98,0 @@

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