Skip to content

Commit 65f3b68

Browse files
Meakknoclone
andauthored
Java example test (#2782)
--------- Co-authored-by: Jean Fechter <[email protected]>
1 parent 6838c62 commit 65f3b68

24 files changed

+156
-65
lines changed

.github/actions/generic-ci/action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ runs:
335335
cmake --install . --component configuration
336336
cmake --install . --component colormaps
337337
338+
- name: Install Mesa Windows in install
339+
if: runner.os == 'Windows'
340+
uses: f3d-app/install-mesa-windows-action@v2
341+
with:
342+
path: ${{github.workspace}}\install\bin
343+
338344
- name: Build and configure python externally
339345
if: |
340346
inputs.optional_deps_label == 'optional-deps' &&
@@ -428,12 +434,6 @@ runs:
428434
shell: bash
429435
run: echo "F3D_BIN_PATH=./bin/f3d" >> $GITHUB_ENV
430436

431-
- name: Install Mesa Windows in install
432-
if: runner.os == 'Windows'
433-
uses: f3d-app/install-mesa-windows-action@v2
434-
with:
435-
path: ${{github.workspace}}\install\bin
436-
437437
# Grid rendering has artifacts in macOS arm64 CI
438438
# https://github.com/f3d-app/f3d/issues/1276
439439
- name: Check F3D_PLUGINS_PATH using plugin example

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ F3D (pronounced `/fɛd/`) is a fast and minimalist 3D viewer desktop application
1010

1111
It is fully controllable from the command line and support configuration files. It can provide thumbnails, support interactive hotkeys, drag&drop and integration into file managers.
1212

13-
F3D also contains the libf3d, a simple library to render meshes, with a C++17 API, C, Python and Javascript Bindings, and experimental Java bindings.
13+
F3D also contains the libf3d, a simple library to render meshes, with a C++17 API, C, Python, Java and Javascript Bindings.
1414

1515
<img src="https://media.githubusercontent.com/media/f3d-app/f3d-website/refs/heads/main/static/images/typical.png" width="640" />
1616

doc/dev/04-BUILD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Some modules, plugins and language bindings depending on external libraries can
6060
- `F3D_PLUGIN_BUILD_VDB`: Support for VDB file format. Requires that VTK has been built with `IOOpenVDB` module (and `OpenVDB`). Disabled by default.
6161
- `F3D_BINDINGS_PYTHON`: Generate python bindings (requires `Python` and `pybind11`). Disabled by default.
6262
- `F3D_BINDINGS_PYTHON_GENERATE_STUBS`: Generate python stubs (requires `Python` and `pybind11_stubgen`). Disabled by default.
63-
- `F3D_BINDINGS_JAVA`: Generate java bindings (requires `Java` and `JNI`). Disabled by default.
63+
- `F3D_BINDINGS_JAVA`: Generate java bindings (requires `Java` >= 17 and `JNI`). Disabled by default.
6464

6565
Some dependencies are provided internally, eg: ImGui, dmon and others. Use `F3D_USE_EXTERNAL_*` to use an external version of these libraries.
6666

doc/dev/07-ARCHITECTURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This architecture is reflected by the directories organisation.
1515
- **vtkext**: extensions to VTK and related tests, see below
1616
- c: [c bindings](../libf3d/04-LANGUAGE_BINDINGS.md#c) and tests
1717
- python: [python bindings](../libf3d/04-LANGUAGE_BINDINGS.md#python) and tests
18-
- java: [java bindings](../libf3d/04-LANGUAGE_BINDINGS.md#java-experimental) and tests
18+
- java: [java bindings](../libf3d/04-LANGUAGE_BINDINGS.md#java) and tests
1919
- webassembly: [webassembly/javascript bindings](../libf3d/04-LANGUAGE_BINDINGS.md#javascript) and tests
2020
- winshellext: shell extension for Windows, provide [thumbnails for Windows](../user/11-DESKTOP_INTEGRATION.md#windows)
2121

doc/libf3d/04-LANGUAGE_BINDINGS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ Some advanced libf3d API are not bound yet, here's the exhaustive list:
150150
- `f3d::interactor`: bindings related functions
151151
- `f3d::interactor`: `playInteraction` and `recordInteraction`
152152

153-
## Java (experimental)
153+
## Java
154154

155-
If the Java bindings have been generated using the `F3D_BINDINGS_JAVA` CMake option, the libf3d can be used directly from Java.
155+
If the Java bindings have been generated using the `F3D_BINDINGS_JAVA` CMake option, the libf3d can be used directly from Java >= 17.
156156
You can import the `f3d.jar` package and use the provided Java classes directly.
157157
Make sure to set `java.library.path` to the path where the JNI library is built.
158158
Here is an example showing how to use libf3d Java bindings:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22

33
add_subdirectory(interactive-app)
4+
5+
if (BUILD_TESTING)
6+
add_subdirectory(tests)
7+
endif ()

examples/libf3d/java/interactive-app/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ find_file(F3D_JAR
1919

2020
message(STATUS "Found f3d.jar: ${F3D_JAR}")
2121

22+
file(COPY ${F3D_JAR} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
23+
2224
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.MF"
2325
"Manifest-Version: 1.0\n"
2426
"Main-Class: InteractiveApp\n"
25-
"Class-Path: ${F3D_JAR}\n"
27+
"Class-Path: f3d.jar\n"
2628
)
2729

28-
set(CMAKE_JAVA_COMPILE_FLAGS -source 8 -target 8)
30+
set(CMAKE_JAVA_COMPILE_FLAGS --release 17)
2931
add_jar(interactive-app-java
3032
InteractiveApp.java
3133
INCLUDE_JARS ${F3D_JAR}

examples/libf3d/java/interactive-app/InteractiveApp.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import app.f3d.F3D.*;
2-
import java.util.Timer;
3-
import java.util.TimerTask;
42

53
public class InteractiveApp {
64

5+
// On Windows, try to load opengl32 from Java path
6+
// It's only useful in order to force Mesa software OpenGL
77
static {
8-
if (System.getProperty("os.name").startsWith("Windows")) {
9-
System.loadLibrary("opengl32");
8+
if (System.getProperty("os.name").startsWith("Windows"))
9+
{
10+
try {
11+
System.loadLibrary("opengl32");
12+
} catch (UnsatisfiedLinkError e) {
13+
// Ignore if opengl32 is not available
14+
}
1015
}
1116
}
1217

@@ -48,15 +53,7 @@ public static void main(String[] args) {
4853
if (args.length > 1) {
4954
// For testing purposes, stop after timeout seconds
5055
int timeout = Integer.parseInt(args[1]);
51-
Timer timer = new Timer();
52-
timer.schedule(new TimerTask() {
53-
@Override
54-
public void run() {
55-
interactor.requestStop();
56-
timer.cancel();
57-
}
58-
}, timeout * 1000L);
59-
interactor.start();
56+
interactor.start(timeout, () -> interactor.stop());
6057
} else {
6158
interactor.start();
6259
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
3+
get_filename_component(F3D_JAVA_LIBRARY_DIR "${f3d_DIR}/../.." ABSOLUTE)
4+
5+
set(java_test_args "--enable-native-access=ALL-UNNAMED")
6+
if (WIN32)
7+
set(F3D_JAVA_LIBRARY_DIR "${F3D_JAVA_LIBRARY_DIR}/../bin")
8+
endif()
9+
if(APPLE)
10+
list(APPEND java_test_args "-XstartOnFirstThread")
11+
endif()
12+
13+
# interactive-app
14+
add_test(NAME test_interactive-app-java
15+
WORKING_DIRECTORY "${F3D_JAVA_LIBRARY_DIR}"
16+
COMMAND ${Java_JAVA_EXECUTABLE}
17+
-Djava.library.path=${F3D_JAVA_LIBRARY_DIR}
18+
${java_test_args}
19+
-jar $<SHELL_PATH:$<TARGET_PROPERTY:interactive-app-java,JAR_FILE>>
20+
"${CMAKE_CURRENT_SOURCE_DIR}/data/cow.vtp" 1)
21+
set_tests_properties(test_interactive-app-java PROPERTIES TIMEOUT 60)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:d5aa4901d186902f90e17bf3b5917541cb6cb8cf223bfeea736631df4c047652
3+
size 60449

0 commit comments

Comments
 (0)