Skip to content

Commit a0fcb83

Browse files
authored
feat(java): convert to named module (#120)
* feat(java): convert to named module * ci: build arm test container * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers * ci: build test containers
1 parent aea4d43 commit a0fcb83

File tree

19 files changed

+737
-836
lines changed

19 files changed

+737
-836
lines changed

.github/workflows/alpine-container.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/asan.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
pull_request:
88
workflow_dispatch:
99

10+
env:
11+
JAVA_VERSION: 21
12+
NODE_VERSION: 24
13+
1014
concurrency:
1115
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
1216
cancel-in-progress: true
@@ -35,14 +39,14 @@ jobs:
3539
- name: Setup node
3640
uses: actions/setup-node@v6
3741
with:
38-
node-version: 20
42+
node-version: ${{env.NODE_VERSION}}
3943
check-latest: true
4044
cache: 'npm'
41-
- name: Setup java 17
45+
- name: Setup java
4246
uses: actions/setup-java@v5
4347
with:
4448
distribution: 'temurin'
45-
java-version: '17'
49+
java-version: ${{env.JAVA_VERSION}}
4650

4751
- name: Rust Cache
4852
uses: Swatinem/rust-cache@v2.7.3

.github/workflows/test-container.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,19 @@ on:
1414

1515
env:
1616
REGISTRY: ghcr.io
17-
IMAGE_NAME: java-bridge-asan-testcontainer
17+
IMAGE_NAME: ghcr.io/markusjx/node-java-bridge/java-bridge-asan-testcontainer:latest
1818

1919
jobs:
2020
build:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- uses: actions/checkout@v4
25-
- name: Create dockerfile
26-
uses: edgardleal/mustache-template-action@v1.0.4
27-
env:
28-
DEBIAN_VERSION: ${{github.event.inputs.debian-version}}
29-
JDK_VERSION: ${{github.event.inputs.jdk-version}}
30-
NODE_VERSION: ${{github.event.inputs.node-version}}
31-
with:
32-
input: ./docker/Dockerfile-test-template.hbs
33-
output: Dockerfile
34-
35-
- name: Build image
36-
run: docker build . --file Dockerfile --tag $IMAGE_NAME
37-
38-
- name: Log into registry
24+
- uses: actions/checkout@v6
25+
- name: Docker login
3926
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
40-
- name: Push latest image
27+
- name: Build image
4128
run: |
42-
IMAGE_ID=$REGISTRY/${{ github.repository }}
43-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')/$IMAGE_NAME
44-
docker tag $IMAGE_NAME $IMAGE_ID:latest
45-
docker push $IMAGE_ID:latest
29+
docker build --push -f docker/Dockerfile.asan -t $IMAGE_NAME\
30+
--build-arg JDK_VERSION=${{github.event.inputs.jdk-version}} \
31+
--build-arg NODE_VERSION=${{github.event.inputs.node-version}} \
32+
--build-arg DEBIAN_VERSION=${{github.event.inputs.debian-version}} .

.github/workflows/test.yml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11+
DEBIAN_VERSION: trixie
12+
JAVA_VERSION: 21
1113

1214
concurrency:
1315
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.event.pull_request.number || github.ref }}
@@ -86,10 +88,18 @@ jobs:
8688
architecture: ${{matrix.arch}}
8789
- name: Setup java 17
8890
uses: actions/setup-java@v5
91+
if: ${{matrix.os == 'windows-latest'}}
8992
with:
9093
distribution: 'temurin'
9194
java-version: '17'
9295
architecture: ${{matrix.arch}}
96+
- name: Setup java
97+
uses: actions/setup-java@v5
98+
if: ${{matrix.os != 'windows-latest'}}
99+
with:
100+
distribution: 'temurin'
101+
java-version: ${{env.JAVA_VERSION}}
102+
architecture: ${{matrix.arch}}
93103
- name: Rust Cache
94104
uses: Swatinem/rust-cache@v2.7.3
95105
if: ${{matrix.os != 'ubuntu-latest' && matrix.os != 'ubuntu-20.04'}}
@@ -146,7 +156,7 @@ jobs:
146156
uses: actions/setup-java@v5
147157
with:
148158
distribution: 'temurin'
149-
java-version: '17'
159+
java-version: ${{env.JAVA_VERSION}}
150160
- name: Install rust toolchain
151161
uses: dtolnay/rust-toolchain@stable
152162
with:
@@ -171,19 +181,26 @@ jobs:
171181
run: npm install
172182
- name: Init qemu
173183
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
184+
- name: Docker login
185+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
186+
- name: Build test container
187+
run: |
188+
if docker manifest inspect ghcr.io/markusjx/node-java-bridge/test-arm:${{matrix.node-version}}-$JAVA_VERSION-$DEBIAN_VERSION;
189+
then
190+
echo "Docker container already exists"
191+
else
192+
docker build --push --platform linux/arm64 --build-arg NODE_VERSION=${{matrix.node-version}} \
193+
--build-arg DEBIAN_VERSION=$DEBIAN_VERSION \
194+
--build-arg JAVA_VERSION=$JAVA_VERSION -f docker/Dockerfile.arm \
195+
-t ghcr.io/markusjx/node-java-bridge/test-arm:${{matrix.node-version}}-$JAVA_VERSION-$DEBIAN_VERSION .
196+
fi
174197
- name: Run tests
175198
uses: addnab/docker-run-action@v3
176199
timeout-minutes: 180
177200
with:
178-
image: arm64v8/node:${{matrix.node-version}}-trixie
201+
image: ghcr.io/markusjx/node-java-bridge/test-arm:${{matrix.node-version}}-${{env.JAVA_VERSION}}-${{env.DEBIAN_VERSION}}
179202
options: -v ${{ github.workspace }}:/github/workspace -w /github/workspace --platform linux/arm64
180203
run: |
181-
apt-get update
182-
apt-get install ca-certificates-java -y
183-
apt-get install openjdk-21-jre-headless -y
184-
apt-get remove -y openjdk-11*
185-
npm config set cache /tmp --global
186-
export CI=true
187204
npm install
188205
npm run testOnly
189206
- name: Create test summary
@@ -209,20 +226,30 @@ jobs:
209226
fail-fast: false
210227
matrix:
211228
node-version: [20, 22]
212-
runs-on: ubuntu-24.04
229+
runs-on: ubuntu-latest
213230
steps:
214231
- uses: actions/checkout@v6
215232
- name: Rust Cache
216233
uses: Swatinem/rust-cache@v2.7.3
234+
- name: Docker login
235+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
236+
- name: Build test container
237+
run: |
238+
if docker manifest inspect ghcr.io/markusjx/node-java-bridge/test-alpine:${{matrix.node-version}}-$JAVA_VERSION;
239+
then
240+
echo "Docker container already exists"
241+
else
242+
docker build --push --build-arg NODE_VERSION=${{matrix.node-version}} \
243+
--build-arg JAVA_VERSION=$JAVA_VERSION -f docker/Dockerfile.alpine \
244+
-t ghcr.io/markusjx/node-java-bridge/test-alpine:${{matrix.node-version}}-$JAVA_VERSION .
245+
fi
217246
- name: Run tests
218247
uses: addnab/docker-run-action@v3
219248
timeout-minutes: 180
220249
with:
221-
image: ghcr.io/markusjx/node-java-bridge/java-bridge-node-alpine-build:node-${{matrix.node-version}}-jdk-17
250+
image: ghcr.io/markusjx/node-java-bridge/test-alpine:${{matrix.node-version}}-${{env.JAVA_VERSION}}
222251
options: -v ${{ github.workspace }}:/github/workspace -w /github/workspace
223252
run: |
224-
npm config set cache /tmp --global
225-
export CI=true
226253
npm ci
227254
npm test
228255
- name: Create test summary
@@ -254,7 +281,7 @@ jobs:
254281
- uses: actions/setup-java@v5
255282
with:
256283
distribution: 'temurin'
257-
java-version: '17'
284+
java-version: ${{env.JAVA_VERSION}}
258285
- name: Rust Cache
259286
uses: Swatinem/rust-cache@v2.7.3
260287
- name: Install

Cargo.lock

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ ensureJvm({
128128

129129
All threads will be attached as daemon threads, allowing the jvm to exit when the main
130130
thread exits.
131-
This behaviour can not be changed, as it may introduce undefined behaviour.
131+
This behavior can not be changed, as it may introduce undefined behaviour.
132132

133133
Important note on jvm options: Different arguments must be parsed as separate strings in
134134
the `opts` array.
@@ -266,7 +266,7 @@ await str.toString(); // 'Hello World'
266266

267267
When using asynchronous functions, by default, the number of threads used by these functions
268268
is determined by the number of physical CPUs available.
269-
In order to change this behaviour, set the `JAVA_BRIDGE_THREAD_POOL_SIZE` environment variable
269+
In order to change this behavior, set the `JAVA_BRIDGE_THREAD_POOL_SIZE` environment variable
270270
to the desired amount of threads.
271271

272272
Note: Setting this to a non-numeric value will cause an error to be thrown during startup.

crates/java-bridge/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2021"
33
name = "java"
4-
version = "2.8.0"
4+
version = "2.8.1"
55

66
[lib]
77
crate-type = ["cdylib"]
@@ -25,7 +25,7 @@ glob = "0.3.1"
2525
java-rs = { path = "../java-rs" }
2626
app-state = { git = "https://github.com/MarkusJx/app-state" }
2727
# TODO: remove this once the next version of napi-sys is released
28-
libloading = "0.8.6"
28+
libloading = "0.9.0"
2929
anyhow = "1.0.97"
3030
log = { version = "0.4.27", optional = true }
3131
log4rs = { version = "1.3.0", features = ["json_format"], optional = true }

crates/java-rs/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ version = "1.0.0"
44
edition = "2021"
55

66
[dependencies]
7-
libloading = "0.8"
7+
libloading = "0.9"
88
lazy_static = "1.4.0"
99
java-locator = "0.1.5"
1010
regex = { version = "1.11.1", optional = true }
1111
log = { version = "0.4.22", optional = true }
1212

1313
[build-dependencies]
14-
bindgen = "0.71.1"
14+
bindgen = "0.72.1"
1515
java-locator = "0.1.8"
16-
build-target = "0.4.0"
16+
build-target = "0.8.0"
1717

1818
[features]
1919
type_check = ["dep:regex"]

crates/java-rs/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ fn main() {
2121
.clang_arg(format!("-I{}", java_home.join(os_dir).as_path().to_str().unwrap()).as_str())
2222
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
2323

24-
if build_target::target_os().unwrap() == Os::Linux
25-
&& build_target::target_arch().unwrap() == Arch::AARCH64
26-
{
24+
if build_target::target_os() == Os::Linux && build_target::target_arch() == Arch::AArch64 {
2725
bindings = bindings.size_t_is_usize(false);
2826
}
2927

docker/Dockerfile-build-alpine.hbs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)