diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index af983c75..fcca0a88 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -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 diff --git a/.vscode/settings.json b/.vscode/settings.json index 4f164947..8b4e243e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "clazzclazz", "Ferner", "jarray", + "javac", "jboolean", "jbyte", "jchar", diff --git a/README.md b/README.md index 4be0944a..6dde09c1 100644 --- a/README.md +++ b/README.md @@ -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._ @@ -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 ``` @@ -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 @@ -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 diff --git a/binding.gyp b/binding.gyp index 5629c01f..25fa488c 100644 --- a/binding.gyp +++ b/binding.gyp @@ -13,13 +13,13 @@ 'target_arch': 's390' }], ['OS=="win"', { - 'javahome%': '&2 exit 1 @@ -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."* ]] diff --git a/postInstall.js b/scripts/postInstall.js similarity index 95% rename from postInstall.js rename to scripts/postInstall.js index 7a61dec3..50d3ec95 100644 --- a/postInstall.js +++ b/scripts/postInstall.js @@ -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))) : '""' ); } diff --git a/testRunner.js b/scripts/testRunner.js similarity index 84% rename from testRunner.js rename to scripts/testRunner.js index 92031fe7..0f1c0261 100644 --- a/testRunner.js +++ b/scripts/testRunner.js @@ -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 @@ -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)); @@ -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); diff --git a/scripts/update-commons-lang.sh b/scripts/update-commons-lang.sh new file mode 100755 index 00000000..d3e2d92e --- /dev/null +++ b/scripts/update-commons-lang.sh @@ -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!" diff --git a/src/java.cpp b/src-cpp/java.cpp similarity index 100% rename from src/java.cpp rename to src-cpp/java.cpp diff --git a/src/java.h b/src-cpp/java.h similarity index 100% rename from src/java.h rename to src-cpp/java.h diff --git a/src/javaObject.cpp b/src-cpp/javaObject.cpp similarity index 100% rename from src/javaObject.cpp rename to src-cpp/javaObject.cpp diff --git a/src/javaObject.h b/src-cpp/javaObject.h similarity index 100% rename from src/javaObject.h rename to src-cpp/javaObject.h diff --git a/src/javaScope.cpp b/src-cpp/javaScope.cpp similarity index 100% rename from src/javaScope.cpp rename to src-cpp/javaScope.cpp diff --git a/src/javaScope.h b/src-cpp/javaScope.h similarity index 100% rename from src/javaScope.h rename to src-cpp/javaScope.h diff --git a/src/methodCallBaton.cpp b/src-cpp/methodCallBaton.cpp similarity index 100% rename from src/methodCallBaton.cpp rename to src-cpp/methodCallBaton.cpp diff --git a/src/methodCallBaton.h b/src-cpp/methodCallBaton.h similarity index 100% rename from src/methodCallBaton.h rename to src-cpp/methodCallBaton.h diff --git a/src/nodeJavaBridge.cpp b/src-cpp/nodeJavaBridge.cpp similarity index 100% rename from src/nodeJavaBridge.cpp rename to src-cpp/nodeJavaBridge.cpp diff --git a/src/node_NodeDynamicProxyClass.h b/src-cpp/node_NodeDynamicProxyClass.h similarity index 100% rename from src/node_NodeDynamicProxyClass.h rename to src-cpp/node_NodeDynamicProxyClass.h diff --git a/src/utils.cpp b/src-cpp/utils.cpp similarity index 100% rename from src/utils.cpp rename to src-cpp/utils.cpp diff --git a/src/utils.h b/src-cpp/utils.h similarity index 100% rename from src/utils.h rename to src-cpp/utils.h diff --git a/commons-lang.jarjar.rules b/src-java/commons-lang.jarjar.rules similarity index 100% rename from commons-lang.jarjar.rules rename to src-java/commons-lang.jarjar.rules diff --git a/commons-lang3-node-java.jar b/src-java/commons-lang3-node-java.jar similarity index 100% rename from commons-lang3-node-java.jar rename to src-java/commons-lang3-node-java.jar diff --git a/jarjar-1.4.jar b/src-java/jarjar-1.4.jar similarity index 100% rename from jarjar-1.4.jar rename to src-java/jarjar-1.4.jar diff --git a/src-java/node/CastingUtils.class b/src-java/node/CastingUtils.class index de535982..a449276b 100644 Binary files a/src-java/node/CastingUtils.class and b/src-java/node/CastingUtils.class differ diff --git a/src-java/node/MethodCallBaton.class b/src-java/node/MethodCallBaton.class index 9cc4e4df..efb946b6 100644 Binary files a/src-java/node/MethodCallBaton.class and b/src-java/node/MethodCallBaton.class differ diff --git a/src-java/node/NodeDynamicProxyClass.class b/src-java/node/NodeDynamicProxyClass.class index 9eed5b23..95373a4b 100644 Binary files a/src-java/node/NodeDynamicProxyClass.class and b/src-java/node/NodeDynamicProxyClass.class differ diff --git a/src-java/node/NodeJsException.class b/src-java/node/NodeJsException.class index a19d4db4..1697d05e 100644 Binary files a/src-java/node/NodeJsException.class and b/src-java/node/NodeJsException.class differ diff --git a/src-java/node/VarArgs.class b/src-java/node/VarArgs.class index ecd67e02..6f990ec7 100644 Binary files a/src-java/node/VarArgs.class and b/src-java/node/VarArgs.class differ diff --git a/lib/nodeJavaBridge.js b/src-node/nodeJavaBridge.js similarity index 99% rename from lib/nodeJavaBridge.js rename to src-node/nodeJavaBridge.js index cfbbfec9..ca379d36 100644 --- a/lib/nodeJavaBridge.js +++ b/src-node/nodeJavaBridge.js @@ -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) { diff --git a/test/ListenerInterface.class b/test/ListenerInterface.class index c93ba7b9..88929b2c 100644 Binary files a/test/ListenerInterface.class and b/test/ListenerInterface.class differ diff --git a/test/ListenerTester.class b/test/ListenerTester.class index f47674d6..0fe29fa5 100644 Binary files a/test/ListenerTester.class and b/test/ListenerTester.class differ diff --git a/test/RunInterface$1.class b/test/RunInterface$1.class index 968bfc78..12eae837 100644 Binary files a/test/RunInterface$1.class and b/test/RunInterface$1.class differ diff --git a/test/RunInterface$Interface0Arg.class b/test/RunInterface$Interface0Arg.class index 1f5d02e1..907fdae8 100644 Binary files a/test/RunInterface$Interface0Arg.class and b/test/RunInterface$Interface0Arg.class differ diff --git a/test/RunInterface$Interface1Arg.class b/test/RunInterface$Interface1Arg.class index 5be2e13d..2008751c 100644 Binary files a/test/RunInterface$Interface1Arg.class and b/test/RunInterface$Interface1Arg.class differ diff --git a/test/RunInterface$InterfaceWithReturn.class b/test/RunInterface$InterfaceWithReturn.class index ae8a20a8..6257cc81 100644 Binary files a/test/RunInterface$InterfaceWithReturn.class and b/test/RunInterface$InterfaceWithReturn.class differ diff --git a/test/RunInterface.class b/test/RunInterface.class index c0d30e95..1404e1a2 100644 Binary files a/test/RunInterface.class and b/test/RunInterface.class differ diff --git a/test/Test$Enum.class b/test/Test$Enum.class index 4e9a1d61..5f851f69 100644 Binary files a/test/Test$Enum.class and b/test/Test$Enum.class differ diff --git a/test/Test$StaticEnum.class b/test/Test$StaticEnum.class index d63e7f54..a474b9f7 100644 Binary files a/test/Test$StaticEnum.class and b/test/Test$StaticEnum.class differ diff --git a/test/Test$SubClass.class b/test/Test$SubClass.class index e2f79c68..dba56514 100644 Binary files a/test/Test$SubClass.class and b/test/Test$SubClass.class differ diff --git a/test/Test$SuperClass.class b/test/Test$SuperClass.class index 35b83864..f3004faf 100644 Binary files a/test/Test$SuperClass.class and b/test/Test$SuperClass.class differ diff --git a/test/Test.class b/test/Test.class index 1559c37a..87fd03f1 100644 Binary files a/test/Test.class and b/test/Test.class differ diff --git a/test/TestExceptions.class b/test/TestExceptions.class index 3db31837..4d30c505 100644 Binary files a/test/TestExceptions.class and b/test/TestExceptions.class differ diff --git a/test/TestLambda$IntegerMath.class b/test/TestLambda$IntegerMath.class index 715fed7d..44893917 100644 Binary files a/test/TestLambda$IntegerMath.class and b/test/TestLambda$IntegerMath.class differ diff --git a/test/TestLambda.class b/test/TestLambda.class index a56ab0ac..60c082be 100644 Binary files a/test/TestLambda.class and b/test/TestLambda.class differ diff --git a/testAsyncOptions/allThreeSuffix.test.js b/testAsyncOptions/allThreeSuffix.test.js index f9f7cafc..d39c74a9 100644 --- a/testAsyncOptions/allThreeSuffix.test.js +++ b/testAsyncOptions/allThreeSuffix.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/asyncSuffixSyncDefault.test.js b/testAsyncOptions/asyncSuffixSyncDefault.test.js index dfd93544..96187991 100644 --- a/testAsyncOptions/asyncSuffixSyncDefault.test.js +++ b/testAsyncOptions/asyncSuffixSyncDefault.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/defacto.test.js b/testAsyncOptions/defacto.test.js index 5bcebd4d..ec4cd660 100644 --- a/testAsyncOptions/defacto.test.js +++ b/testAsyncOptions/defacto.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/defactoPlusPromise.test.js b/testAsyncOptions/defactoPlusPromise.test.js index 346dd9e4..07b0cbcf 100644 --- a/testAsyncOptions/defactoPlusPromise.test.js +++ b/testAsyncOptions/defactoPlusPromise.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/default.test.js b/testAsyncOptions/default.test.js index 581ee824..b322e444 100644 --- a/testAsyncOptions/default.test.js +++ b/testAsyncOptions/default.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/noAsync.test.js b/testAsyncOptions/noAsync.test.js index 569d69fc..2af3f847 100644 --- a/testAsyncOptions/noAsync.test.js +++ b/testAsyncOptions/noAsync.test.js @@ -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(); @@ -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"); diff --git a/testAsyncOptions/syncDefaultPlusPromise.test.js b/testAsyncOptions/syncDefaultPlusPromise.test.js index 8b0d9f81..7fe9403d 100644 --- a/testAsyncOptions/syncDefaultPlusPromise.test.js +++ b/testAsyncOptions/syncDefaultPlusPromise.test.js @@ -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(); @@ -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"); diff --git a/testHelpers.js b/testHelpers.js index 93e8fa0b..6bf05615 100644 --- a/testHelpers.js +++ b/testHelpers.js @@ -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 ?? { diff --git a/update-commons-lang.sh b/update-commons-lang.sh deleted file mode 100755 index 29250f57..00000000 --- a/update-commons-lang.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -ex - -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 ../../jarjar-1.4.jar process ../../commons-lang.jarjar.rules target/commons-lang3*-SNAPSHOT.jar ../../commons-lang3-node-java.jar -