Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:22

RUN apt-get update
RUN apt-get install -y openjdk-17-jdk gdb clang-format
RUN apt-get install -y openjdk-17-jdk maven gdb clang-format
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"clazzclazz",
"Ferner",
"jarray",
"javac",
"jboolean",
"jbyte",
"jchar",
Expand Down
19 changes: 3 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Notes:

* node-gyp requires python 2.x not python 3.x. See https://github.com/TooTallNate/node-gyp/issues/155 for more details.
* If you see an error such as "Call to 'node findJavaHome.js' returned exit status 1"
Try running `node findJavaHome.js` in the node-java directory to see the full failure message.
Try running `node ./scripts/findJavaHome.js` in the node-java directory to see the full failure message.
* If you are having problems finding 'jni.h'. Make sure you have the JDK installed not just the JRE. If you are using
OpenJDK you want the openjdk-7-jdk package, not openjdk-7-jre. _Mavericks users see [Issue #86](https://github.com/nearinfinity/node-java/issues/86) if you run into this._

Expand Down Expand Up @@ -62,7 +62,7 @@ GYP_DEFINES="armv7=0" CCFLAGS='-march=armv6' CXXFLAGS='-march=armv6' npm install
## Manual compile (Using node-gyp)

```bash
./compile-java-code.sh
./scripts/compile-java.sh
node-gyp configure build
npm test
```
Expand Down Expand Up @@ -104,19 +104,6 @@ Then run
node test.js
```

### Java 1.8 support

Manual compilation for Java 1.8 support requires additional steps:

```bash
./compile-java-code.sh
./compile-java8-code.sh
node-gyp configure build
npm test
```

Java 1.8 language features can be used in Java classes only if a Java 1.8 JRE is available. The script compile-java8-code.sh is used only to compile java classes used in the 'test8' unit tests, but these classes are checked into the test8/ directory. Note that unit tests in the test8/ directory will pass (by design) if run against a Java 1.7 JRE, provided that a java.lang.UnsupportedClassVersionError is caught with the message 'Unsupported major.minor version 52.0' (the expected behavior when Java 1.8 language features are used in an older JRE).

## Installation node-webkit

```bash
Expand Down Expand Up @@ -898,7 +885,7 @@ var value = Test.NestedEnum.name_alt; // OK

## Error: Cannot find module '../build/jvm_dll_path.json'

Either `postInstall.js` didn't run or there was a problem detecting java. Try running `postInstall.js` manually.
Either `./scripts/postInstall.js` didn't run or there was a problem detecting java. Try running `./scripts/postInstall.js` manually.

## Debugging

Expand Down
18 changes: 9 additions & 9 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
'target_arch': 's390'
}],
['OS=="win"', {
'javahome%': '<!(node findJavaHome.js)'
'javahome%': '<!(node ./scripts/findJavaHome.js)'
}],
['OS=="linux" or OS=="mac" or OS=="freebsd" or OS=="openbsd" or OS=="solaris" or OS=="zos"', {
'javahome%': '<!(node findJavaHome.js)'
'javahome%': '<!(node ./scripts/findJavaHome.js)'
}],
['OS=="linux" or OS=="mac" or OS=="freebsd" or OS=="openbsd" or OS=="solaris" or OS=="zos"', {
'javalibdir%': "<!(./find_java_libdir.sh <(target_arch) <(OS))"
'javalibdir%': "<!(./scripts/find_java_libdir.sh <(target_arch) <(OS))"
}],
['OS=="zos"', {
'nodever%': '<!(node -e "console.log(process.versions.node)" | cut -d"." -f1)'
Expand All @@ -30,12 +30,12 @@
{
'target_name': 'nodejavabridge_bindings',
'sources': [
'src/java.cpp',
'src/javaObject.cpp',
'src/javaScope.cpp',
'src/methodCallBaton.cpp',
'src/nodeJavaBridge.cpp',
'src/utils.cpp'
'src-cpp/java.cpp',
'src-cpp/javaObject.cpp',
'src-cpp/javaScope.cpp',
'src-cpp/methodCallBaton.cpp',
'src-cpp/nodeJavaBridge.cpp',
'src-cpp/utils.cpp'
],
'include_dirs': [
'<(javahome)/include',
Expand Down
13 changes: 0 additions & 13 deletions compile-java.sh

This file was deleted.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./lib/nodeJavaBridge");
module.exports = require("./src-node/nodeJavaBridge");
1 change: 0 additions & 1 deletion jarjar.rule

This file was deleted.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
},
"scripts": {
"install": "node-gyp rebuild",
"test": "node testRunner.js",
"postinstall": "node postInstall.js",
"clean": "rm -rf build",
"test": "node ./scripts/testRunner.js",
"postinstall": "node ./scripts/postInstall.js",
"lint": "eslint --ext js,ts,tsx --report-unused-disable-directives --max-warnings 0 .",
"format": "prettier --write .",
"format-cpp": "clang-format --version; find src/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i",
"format-cpp": "clang-format --version; find src-cpp/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i",
"precommit": "npm run format-cpp && npm run format && npm run lint && npm test"
},
"main": "./index.js"
Expand Down
17 changes: 17 additions & 0 deletions scripts/compile-java.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -eu

SCRIPT_DIR=$(dirname "$0")
cd "${SCRIPT_DIR}/.."

if [ -z "${JAVA_HOME:-}" ] && [ -e "/usr/libexec/java_home" ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
fi

echo "Using $(javac -version)."
set -x

javac -source 1.8 -target 1.8 src-java/node/*.java
javac -source 1.8 -target 1.8 test/*.java
javac -classpath src-java -h ./src-cpp src-java/node/NodeDynamicProxyClass.java
echo "complete!"
File renamed without changes.
6 changes: 4 additions & 2 deletions find_java_libdir.sh → scripts/find_java_libdir.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env bash

set -eu

SCRIPT_DIR=$(dirname "$0")
cd "${SCRIPT_DIR}/.."

error() {
echo "error: $*" >&2
exit 1
Expand All @@ -12,7 +14,7 @@ main () {
local os=$2

local java_home full_java_version java_version
java_home=$(node findJavaHome.js)
java_home=$(node ./scripts/findJavaHome.js)
full_java_version=$(${java_home}/bin/java -version 2>&1 | grep version | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q')

if [[ "${full_java_version}" = "1."* ]]
Expand Down
2 changes: 1 addition & 1 deletion postInstall.js → scripts/postInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require("find-java-home")((err, home) => {
const binary = dll ?? dylib ?? so;

fs.writeFileSync(
path.resolve(__dirname, "./build/jvm_dll_path.json"),
path.resolve(__dirname, "../build/jvm_dll_path.json"),
binary ? JSON.stringify(path.delimiter + path.dirname(path.resolve(home, binary))) : '""'
);
}
Expand Down
7 changes: 4 additions & 3 deletions testRunner.js → scripts/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const glob = require("glob");
const path = require("node:path");

const tests = glob
.sync(path.join("testAsyncOptions", "*.test.js"))
.sync("*.test.js", { cwd: path.join(__dirname, "..", "testAsyncOptions") })
.sort((a, b) => a.toLocaleLowerCase().localeCompare(b.toLocaleLowerCase()));

tests.unshift("test"); // Arrange to run the primary tests first, in a single process
Expand All @@ -19,7 +19,7 @@ function runTest(testArgs, done) {
const vitest = path.join("node_modules", ".bin", "vitest");
const cmd = testArgs === "test" ? `vitest --dir test` : `${vitest} ${testArgs}`;
console.log(`running "${cmd}"...`);
childProcess.exec(cmd, function (error, stdout, stderr) {
childProcess.exec(cmd, (error, stdout, stderr) => {
const errText = stderr.toString();
if (errText !== "") {
console.error(chalk.bold.red(errText));
Expand All @@ -30,7 +30,8 @@ function runTest(testArgs, done) {
});
}

async.eachSeries(tests, runTest, function (err) {
console.log('test to run', tests);
async.eachSeries(tests, runTest, (err) => {
if (err) {
console.error(chalk.bold.red(err));
process.exit(1);
Expand Down
20 changes: 20 additions & 0 deletions scripts/update-commons-lang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh
set -eu

SCRIPT_DIR=$(dirname "$0")
cd "${SCRIPT_DIR}/.."

if [ -d build/commons-lang ]; then
cd build/commons-lang
git pull
else
mkdir -p build
cd build
git clone --depth 1 git@github.com:apache/commons-lang.git
cd commons-lang
fi

mvn clean compile package -DskipTests
java -jar ../../src-java/jarjar-1.4.jar process ../../src-java/commons-lang.jarjar.rules target/commons-lang3*-SNAPSHOT.jar ../../src-java/commons-lang3-node-java.jar

echo "complete!"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified src-java/node/CastingUtils.class
Binary file not shown.
Binary file modified src-java/node/MethodCallBaton.class
Binary file not shown.
Binary file modified src-java/node/NodeDynamicProxyClass.class
Binary file not shown.
Binary file modified src-java/node/NodeJsException.class
Binary file not shown.
Binary file modified src-java/node/VarArgs.class
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/nodeJavaBridge.js → src-node/nodeJavaBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (!binaryPath) {
const bindings = require(binaryPath);

const java = (module.exports = new bindings.Java());
java.classpath.push(path.resolve(__dirname, "../commons-lang3-node-java.jar"));
java.classpath.push(path.resolve(__dirname, "../src-java/commons-lang3-node-java.jar"));
java.classpath.push(path.resolve(__dirname, __dirname, "../src-java"));
java.classpath.pushDir = function (dir) {
fs.readdirSync(dir).forEach(function (file) {
Expand Down
Binary file modified test/ListenerInterface.class
Binary file not shown.
Binary file modified test/ListenerTester.class
Binary file not shown.
Binary file modified test/RunInterface$1.class
Binary file not shown.
Binary file modified test/RunInterface$Interface0Arg.class
Binary file not shown.
Binary file modified test/RunInterface$Interface1Arg.class
Binary file not shown.
Binary file modified test/RunInterface$InterfaceWithReturn.class
Binary file not shown.
Binary file modified test/RunInterface.class
Binary file not shown.
Binary file modified test/Test$Enum.class
Binary file not shown.
Binary file modified test/Test$StaticEnum.class
Binary file not shown.
Binary file modified test/Test$SubClass.class
Binary file not shown.
Binary file modified test/Test$SuperClass.class
Binary file not shown.
Binary file modified test/Test.class
Binary file not shown.
Binary file modified test/TestExceptions.class
Binary file not shown.
Binary file modified test/TestLambda$IntegerMath.class
Binary file not shown.
Binary file modified test/TestLambda.class
Binary file not shown.
4 changes: 2 additions & 2 deletions testAsyncOptions/allThreeSuffix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("allThreeSuffix", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("allThreeSuffix", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.formatSync("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/asyncSuffixSyncDefault.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("asyncSuffixSyncDefault", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -75,7 +75,7 @@ describe("asyncSuffixSyncDefault", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.format("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/defacto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("defacto", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("defacto", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.formatSync("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/defactoPlusPromise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("defactoPlusPromise", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -77,7 +77,7 @@ describe("defactoPlusPromise", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.formatSync("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/default.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("default", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("default", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.formatSync("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/noAsync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("noAsync", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
const arrayList = new ArrayList();
Expand Down Expand Up @@ -86,7 +86,7 @@ describe("noAsync", () => {
});

test("sStaticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.formatSync("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
4 changes: 2 additions & 2 deletions testAsyncOptions/syncDefaultPlusPromise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("syncDefaultPlusPromise", () => {
});

test("importClass", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// This test verifies the import runs without error.
const ArrayList = java.import("java.util.ArrayList");
expect(ArrayList).toBeTruthy();
Expand Down Expand Up @@ -52,7 +52,7 @@ describe("syncDefaultPlusPromise", () => {
});

test("staticSyncCalls", () => {
// Note: java.import executes javascript code in lib/nodeJavaBridge that makes sync calls to java classes.
// Note: java.import executes javascript code in src-node/nodeJavaBridge that makes sync calls to java classes.
// Among other things, java.import creates Sync functions for static methods.
const String = java.import("java.lang.String");
expect(String.format("%s--%s", "hello", "world")).toBe("hello--world");
Expand Down
1 change: 0 additions & 1 deletion testHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ java.options.push("-Djava.awt.headless=true");

java.classpath.push("test/");
java.classpath.push("test/commons-lang3-3.1.jar");
java.classpath.push("test8/");

export function getJava(asyncOptions) {
java.asyncOptions = asyncOptions ?? {
Expand Down
15 changes: 0 additions & 15 deletions update-commons-lang.sh

This file was deleted.