Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- removed maven dependency for JNI test
- re-enabled test
- TODO fix test
  • Loading branch information
Michael Tucek committed May 4, 2021
1 parent d6f2175 commit ef4715b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 89 deletions.
8 changes: 0 additions & 8 deletions scripts/cmake/ElektraClasspath.cmake

This file was deleted.

66 changes: 9 additions & 57 deletions src/bindings/jna/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ you enable the JNA bindings, e.g., with `cmake -DBINDINGS=jna`, see also
[COMPILE](/doc/COMPILE.md#bindings). Internally, Gradle will be used to
actually compile the plugin.

Please note that the [jni plugin](/src/plugins/jni) serves a different purpose. We
use the jni plugin to develop plugins for Elektra itself, whereas the JNA
bindings allow to use Elektra to access configuration in Java projects. The jni
Please note that the [JNI plugin](/src/plugins/jni) serves a different purpose. We
use the JNI plugin to develop plugins for Elektra itself, whereas the JNA
bindings allow to use Elektra to access configuration in Java projects. The JNI
plugin is _not_ required for the JNA bindings to work. But, to develop
jni plugins, JNA can be used. [Here](libelektra/plugin) are example
plugins, which need jni at runtime.
JNI plugins, JNA can be used. [Here](libelektra/plugin) are example
plugins, which need JNI at runtime.

### Command line

Expand Down Expand Up @@ -168,59 +168,11 @@ which can be used to save and load `.properties` files into Elektra.

### Command Line

You can run unit tests after importing jUnit, JNA and the libelektra java
library into a project (eclipse, netbeans, intelliJ, ...).
You can run unit tests by invoking:

Tested library versions are:

- JNA: 4.5.0
- jUnit: 4.12 [jUnit 3 is not supported]
- hamcrest-core: 1.13 (required by newer jUnit versions)

Tested JDK versions are:

- Oracle JDK 1.8.0_112 on macOS 10.12 Sierra
- OpenJDK 1.8.0_121 on Arch Linux
- OpenJDK 1.9 on Ubuntu
- Oracle JDK 1.9 build 9+181 on macOS 10.12 Sierra

Both libraries should work on version 4.0 too, though.

It should also be possible to run the tests by command line:

1. Compile the library and tests (run in root directory; make sure junit4 and
jna are installed and/or path is correct). Execute the following commands inside
the libelektra folder:

```sh
mkdir ./target (if it does not exist yet)
javac -cp <path to junit and jna and hamcrest*> -d \
./target src/main/java/org/libelektra/*.java \
src/main/java/org/libelektra/plugin/*.java \
src/test/java/org/libelektra/*.java
```

If you copied the jna.jar, junit.jar and hamcrest-core.jar directly to the
jna directory, the correct path would be `./jna.jar:./junit.jar:./hamcrest-core.jar`
(separated by : on Mac and Linux, by ; on Windows), otherwise specify the
appropriate locations.

For Linux users they are usually in `/usr/share/java/jna.jar:/usr/share/java/junit4.jar`

2. Run all jUnit tests (please note that the -cp parameter now also has to
include the target directory we created in the first step, where the compiled
classfiles are):

```sh
java -cp <path to target, junit, jna and hamcrest> org.junit.runner.JUnitCore org.libelektra.AllTests
```

Or run all tests on their own:

```sh
java -cp <path to target, junit, jna and hamcrest> org.junit.runner.JUnitCore org.libelektra.KeyTest
java -cp <path to target, junit, jna and hamcrest> org.junit.runner.JUnitCore org.libelektra.KeySetTest
```
```sh
./gradlew test
```

## Limitations

Expand Down
11 changes: 11 additions & 0 deletions src/bindings/jna/java-library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ apply plugin: 'java-library'

// apply common java project cofiguration
apply from: "$rootProject.projectDir/java-shared.gradle"

// add task to generate fat jar (includes all runtime dependencies)
// (primarily intended for using JNA binding for testing JNI plugin interface)
task fatJar(type: Jar) {
classifier = 'all'
from {
configurations.runtimeClasspath.filter{ it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
assemble.dependsOn fatJar
35 changes: 12 additions & 23 deletions src/plugins/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,18 @@ add_plugin (

if (ADDTESTING_PHASE)
check_binding_was_added ("jna" BINDING_WAS_ADDED)
find_program (MAVEN_EXECUTABLE mvn)

if (ENABLE_BROKEN_TESTS)
if (BUILD_TESTING
AND BINDING_WAS_ADDED
AND MAVEN_EXECUTABLE)
add_plugintest (jni MEMLEAK)
include_directories (${CMAKE_CURRENT_BINARY_DIR})
if (BUILD_TESTING AND BINDING_WAS_ADDED)
add_plugintest (jni MEMLEAK)
include_directories (${CMAKE_CURRENT_BINARY_DIR})

# Generate header file
set (LIBELEKTRA5J_PATH ${CMAKE_BINARY_DIR}/src/bindings/jna/libelektra)
add_custom_command (
COMMAND ${MAVEN_EXECUTABLE} ARGS dependency:build-classpath -q -Dmdep.outputFile=classpath.txt
COMMAND
${CMAKE_COMMAND} ARGS -D SOURCE_PATH=${CMAKE_CURRENT_SOURCE_DIR} -D
DESTINATION_PATH=${CMAKE_CURRENT_BINARY_DIR} -D LIBELEKTRA5J_PATH=${LIBELEKTRA5J_PATH} -D
KDB_VERSION=${KDB_VERSION} -P ${CMAKE_SOURCE_DIR}/scripts/cmake/ElektraClasspath.cmake
OUTPUT "${LIBELEKTRA5J_PATH}/classpath.txt" "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h"
WORKING_DIRECTORY ${LIBELEKTRA5J_PATH}
DEPENDS "${LIBELEKTRA5J_PATH}/pom.xml jna")
add_custom_target (jni_header DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h")
else ()
message (WARNING "jna bindings are required for testing, test deactivated")
endif ()
endif (ENABLE_BROKEN_TESTS)
# Generate header file
set (libelektra_jar_all ${CMAKE_BINARY_DIR}/src/bindings/jna/libelektra/build/libs/libelektra-${KDB_VERSION}-all.jar)
configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/testmod_jni.h.in" "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h")

add_custom_target (jni_header DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/testmod_jni.h")
message (INFO "JNI test activated.")
else ()
message (WARNING "JNA bindings are required for testing but binding was not enabled. JNI test deactivated.")
endif ()
endif ()
2 changes: 1 addition & 1 deletion src/plugins/jni/testmod_jni.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
#ifndef TESTMOD_JNI_H_IN
#define TESTMOD_JNI_H_IN

#define CLASSPATH "@jna@:@libelektra_jar@"
#define CLASSPATH "@libelektra_jar_all@"

#endif

0 comments on commit ef4715b

Please sign in to comment.