diff --git a/doc/news/2019-11-26_0.9.1.md b/doc/news/2019-11-26_0.9.1.md index de077b802d8..0cf2721b2dd 100644 --- a/doc/news/2019-11-26_0.9.1.md +++ b/doc/news/2019-11-26_0.9.1.md @@ -248,8 +248,8 @@ you up to date with the multi-language support provided by Elektra. ### Java - Completely overhauled the Java binding to be able to use Elektra plugins directly. A new PluginLoader can load Elektra plugins or a native implemented Java plugin. - All Plugins now implement the new [Plugin](../../src/bindings/jna/libelektra5j/src/main/java/org/libelektra/Plugin.java) interface. - For an example see the [test case](../../src/bindings/jna/libelektra5j/src/test/java/org/libelektra/PluginLoaderIT.java). _(Michael Zronek)_ + All Plugins now implement the new [Plugin](../../src/bindings/jna/libelektra/src/main/java/org/libelektra/Plugin.java) interface. + For an example see the [test case](../../src/bindings/jna/libelektra/src/test/java/org/libelektra/PluginLoaderIT.java). _(Michael Zronek)_ - Upgraded maven dependencies for Java binding _(Michael Zronek)_ - The Java binding now supports the [error codes](../decisions/error_codes.md) in a native way. All exceptions contain the necessary information. _(Michael Zronek)_ - Further improved the Java binding such as wording and documentation. _(Michael Zronek)_ diff --git a/doc/tutorials/java-kdb.md b/doc/tutorials/java-kdb.md index e4c66a711ae..3b952e3e663 100644 --- a/doc/tutorials/java-kdb.md +++ b/doc/tutorials/java-kdb.md @@ -14,7 +14,7 @@ After that you can start loading a `KDB` object as follows: ```java Key key = Key.create("user:/kdbsession/javabinding"); try (KDB kdb = KDB.open(key)) { - //Your code to manipulate keys + // Your code to manipulate keys } catch (KDB.KDBException e) { e.printStackTrace(); } @@ -54,7 +54,7 @@ The method call would return `it_works!`. ```java String str = set.lookup("user:/my/test").getString() -System.out.println(str) //prints "it works!" +System.out.println(str) // prints "it works!" ``` ## Saving Keys @@ -64,7 +64,7 @@ Next I will show you how to save a new key into the database. First we need need ```java KeySet set = KeySet.create(); Key namespace = Key.create("user:/"); -kdb.get(set, namespace); //Fetch all keys for the namespace +kdb.get(set, namespace); // Fetch all keys for the namespace set.append(Key.create("user:/somekey", "myValue")); kdb.set(set, key); ``` @@ -83,12 +83,12 @@ environments though as it is not intended for productive systems. Key key = Key.create("user:/errors"); try (KDB kdb = KDB.open(key)) { KeySet set = KeySet.create(); - Key namespace = Key.create("user:/"); //Select a namespace from which all keys should be fetched - kdb.get(set, namespace); //Fetch all keys into the set object - for (int i = 0; i < set.length(); i++) { //Traverse the set + Key namespace = Key.create("user:/"); // Select a namespace from which all keys should be fetched + kdb.get(set, namespace); // Fetch all keys into the set object + for (int i = 0; i < set.length(); i++) { // Traverse the set String keyAndValue = String.format("%s: %s", - set.at(i).getName(), //Fetch the key's name - set.at(i).getString()); //Fetch the key's value + set.at(i).getName(), // Fetch the key's name + set.at(i).getString()); // Fetch the key's value System.out.println(keyAndValue); } } catch (KDB.KDBException e) { diff --git a/src/bindings/jna/CMakeLists.txt b/src/bindings/jna/CMakeLists.txt index 318b9f299b5..ad6a59eb1b7 100644 --- a/src/bindings/jna/CMakeLists.txt +++ b/src/bindings/jna/CMakeLists.txt @@ -1,15 +1,6 @@ -find_program (MAVEN_EXECUTABLE mvn) find_program (GRADLE_EXECUTABLE gradle) -#find_program(GRADLE_EXECUTABLE NAMES gradle PATHS $ENV{GRADLE_HOME}/bin NO_CMAKE_FIND_ROOT_PATH) find_package (Java QUIET) -macro (test_needs_plugin test plugin) - list (FIND REMOVED_PLUGINS ${plugin} plugin_index) - if (plugin_index GREATER -1) - string (APPEND MAVEN_TEST_EXCLUDES "**/${test}") - endif (plugin_index GREATER -1) -endmacro (test_needs_plugin test plugin) - macro (java_test_needs_plugin test plugin) list (FIND REMOVED_PLUGINS ${plugin} plugin_index) if (plugin_index GREATER -1) @@ -45,28 +36,17 @@ if (Java_JAVAC_EXECUTABLE) file (MAKE_DIRECTORY libelektra) - set (MAVEN_TEST_EXCLUDES "") - test_needs_plugin (GOptsTest.java gopts) + # generate test exclusions based on specific plugins set (GRADLE_TEST_EXCLUDES "") java_test_needs_plugin (GOptsTest gopts) - # first fill the elektra version in the pom file @ONLY to avoid replacing pom.xml placeholders which also use the - # format ${} - configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/libelektra/pom.xml.in" - "${CMAKE_CURRENT_BINARY_DIR}/libelektra/pom.xml" @ONLY) + # first fill the elektra version in the pom file @ONLY to avoid replacing pom.xml placeholders which also use the format ${} configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/version-settings.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/version-settings.gradle" @ONLY) configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/libelektra/test-exclusion.gradle.in" "${CMAKE_CURRENT_BINARY_DIR}/libelektra/test-exclusion.gradle" @ONLY) - # required to have a recognizable name for the pom upon installation in case other software installs a pom to the - # target directory and calls it pom.xml - file ( - GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libelektra/libelektra-${KDB_VERSION}.pom.xml" - INPUT "${CMAKE_CURRENT_BINARY_DIR}/libelektra/pom.xml") - - # The build system calls Maven to recompile the binding, if we change any of the following source files. + # the build system calls Gradle to recompile the binding, if we change any of the following source files. set (JNA_BINDING_PREFIX libelektra) set (JNA_BINDING_NAMESPACE java/org/libelektra) set (JNA_BINDING_SOURCE_DIRECTORY ${JNA_BINDING_PREFIX}/src/main/${JNA_BINDING_NAMESPACE}) @@ -114,24 +94,33 @@ if (Java_JAVAC_EXECUTABLE) ${JNA_BINDING_SOURCE_DIRECTORY_TEST}/KeyTest.java ${JNA_BINDING_SOURCE_DIRECTORY_TEST}/PluginLoaderIT.java ${JNA_BINDING_PREFIX}/build.gradle - ${JNA_BINDING_PREFIX}/gradle.properties - ${JNA_BINDING_PREFIX}/java-library.gradle - ${JNA_BINDING_PREFIX}/java-shared.gradle - ${JNA_BINDING_PREFIX}/maven-publish.gradle - ${JNA_BINDING_PREFIX}/settings.gradle) - - # Compile the source files and build the jar. We copy the source files into the build folder as that is the easiest - # way to handle the integration between CMake and Maven. + ${JNA_BINDING_PREFIX}/dependencies.gradle + build.gradle + gradle.properties + java-library.gradle + java-shared.gradle + maven-publish.gradle + settings.gradle) + + # compile the source files and build the jar. We copy the source files into the build folder as that is the easiest + # way to handle the integration between CMake and Gradle. add_custom_command ( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}.jar" - COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/libelektra" - "${CMAKE_CURRENT_BINARY_DIR}/libelektra" - COMMAND ${MAVEN_EXECUTABLE} -q -B -DskipTests=true package - WORKING_DIRECTORY libelektra - DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libelektra/pom.xml" ${JNA_BINDING_SOURCE_FILES}) - # TODO add changes in variable replaced build files to dependencies + "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}-javadoc.jar" + "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}-sources.jar" + "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/publications/libelektra/libelektra-${KDB_VERSION}.pom.xml" + COMMAND ${CMAKE_COMMAND} ARGS -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}" + "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND ${GRADLE_EXECUTABLE} -q assemble + #WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libelektra/test-exclusion.gradle" + "${CMAKE_CURRENT_BINARY_DIR}/version-settings.gradle" + ${JNA_BINDING_SOURCE_FILES}) create_lib_symlink (libelektra-${KDB_VERSION}.jar libelektra.jar java-elektra JAVA) + create_lib_symlink (libelektra-${KDB_VERSION}-javadoc.jar libelektra-javadoc.jar java-elektra JAVA) + create_lib_symlink (libelektra-${KDB_VERSION}-sources.jar libelektra-sources.jar java-elektra JAVA) create_lib_symlink (libelektra-${KDB_VERSION}.pom.xml libelektra.pom.xml java-elektra JAVA) add_custom_target (jna ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}.jar") @@ -141,31 +130,32 @@ if (Java_JAVAC_EXECUTABLE) "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}-javadoc.jar" "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/libs/libelektra-${KDB_VERSION}-sources.jar" "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/publications/libelektra/libelektra-${KDB_VERSION}.pom.xml" - "${CMAKE_CURRENT_BINARY_DIR}/libelektra/build/publications/libelektra/libelektra-${KDB_VERSION}.module.json" DESTINATION "share/java" COMPONENT java-elektra) # and add maven test to execute with ctest in the testing phase - if ((CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND NOT (CMAKE_SYSTEM_VERSION VERSION_LESS 15)) - - # we cannot set DYLD_LIBRARY_PATH on new macOS versions, making the kdb tests fail if its not installed in - # the system - set (MAVEN_TEST_ENV "env-test-without-kdb") - else () - set (MAVEN_TEST_ENV "env-test") - endif () - - if (NOT ENABLE_ASAN) - add_test ( - NAME testjna_maven - COMMAND - ${MAVEN_EXECUTABLE} -q -B -e -P ${MAVEN_TEST_ENV} test - WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/libelektra") - - set_property (TEST testjna_maven PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib") - - set_property (TEST testjna_maven PROPERTY LABELS kdbtests bindings memleak) - endif (NOT ENABLE_ASAN) + ##if ((CMAKE_SYSTEM_NAME STREQUAL "Darwin") AND NOT (CMAKE_SYSTEM_VERSION VERSION_LESS 15)) + ## + ## # we cannot set DYLD_LIBRARY_PATH on new macOS versions, making the kdb tests fail if its not installed in + ## # the system + ## set (MAVEN_TEST_ENV "env-test-without-kdb") + ##else () + ## set (MAVEN_TEST_ENV "env-test") + ##endif () + ## + ##if (NOT ENABLE_ASAN) + ## add_test ( + ## NAME testjna_maven + ## COMMAND + ## ${MAVEN_EXECUTABLE} -q -B -e -P ${MAVEN_TEST_ENV} test + ## WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/libelektra") + ## + ## set_property (TEST testjna_maven PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib") + ## + ## set_property (TEST testjna_maven PROPERTY LABELS kdbtests bindings memleak) + ##endif (NOT ENABLE_ASAN) + # TODO test execution + else (GRADLE_EXECUTABLE) exclude_binding (jna "Gradle not found, but required to build the jna bindings") endif (GRADLE_EXECUTABLE) @@ -176,5 +166,4 @@ else (Java_JAVAC_EXECUTABLE) exclude_binding (jna "javac (java compiler) not found, which is only included in a jdk") endif (Java_JAVAC_EXECUTABLE) -mark_as_advanced (MAVEN_EXECUTABLE) mark_as_advanced (GRADLE_EXECUTABLE) diff --git a/src/bindings/jna/libelektra/build.gradle b/src/bindings/jna/libelektra/build.gradle index 3bb970dce19..fec93c14dd8 100644 --- a/src/bindings/jna/libelektra/build.gradle +++ b/src/bindings/jna/libelektra/build.gradle @@ -51,3 +51,6 @@ publishing { signing { sign publishing.publications.libelektra } + +assemble.dependsOn generateMetadataFileForLibelektraPublication +assemble.dependsOn generatePomFileForLibelektraPublication diff --git a/src/bindings/jna/maven-publish.gradle b/src/bindings/jna/maven-publish.gradle index 4ad2f842ecc..2973c718b4f 100644 --- a/src/bindings/jna/maven-publish.gradle +++ b/src/bindings/jna/maven-publish.gradle @@ -32,6 +32,12 @@ publishing { } } +tasks.withType(GenerateMavenPom).all { + def matcher = name =~ /generatePomFileFor(\w+)Publication/ + def publicationName = matcher[0][1].toLowerCase() + destination = "$buildDir/publications/${publicationName}/${publicationName}-${version}.pom.xml" +} + // configure signing signing { required { project.isReleaseVersion && gradle.taskGraph.hasTask("publish") }