-
Notifications
You must be signed in to change notification settings - Fork 122
CM H3 Java JNI whitelist plugin #3889
Changes from all commits
43035b1
b41edd1
14f99b0
9289fd2
fcf0a63
4bf1864
b35c6a2
083ec97
e8f5f0e
c2eb037
35d2a0e
f2b62f8
cbbcb7a
6259535
62157ca
2eb24e0
da42974
1e8586c
8f45067
d366ccf
0af1c9a
3f18960
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,16 @@ you up to date with the multi-language support provided by Elektra. | |
- Introduced `KeySet::remove(Key)` and `KeySet::remove(String)` | ||
- Removed `KeySet::lookup(Key, int)` and `KeySet::lookup(String, int)` as well as accompanying flag definitions `KeySet::KDB_O_NONE`, `KeySet::KDB_O_DEL` and `KeySet::KDB_O_POP`. Please use `KeySet::lookup(Key)` and `KeySet::lookup(String)` instead. Instead of `KeySet::KDB_O_DEL`, please consider using `Key::release`. The proper replacement for `KeySet::KDB_O_POP` is `KeySet::remove(Key)` or `KeySet::remove(String)`. | ||
- Native library proxy interface `Elektra` is now package private (previously was public). | ||
- Added example Java plugin `whitelist` (see [here](../../src/bindings/jna/plugins/whitelist/README.md)) | ||
- Changed `Key nextMeta()` to `Optional<Key> nextMeta ()` no longer throwing NoSuchElementException for non-exceptional behavior | ||
- Added support of binary valued keys: | ||
- Renamed `KeyBinaryTypeNotSupportedException` to `KeyStringValueException` | ||
- Introduced `KeyBinaryValueException` | ||
- Improved `Key` test coverage | ||
- Introduced `Key::getBinary()` and `Key::setBinary(byte[])` | ||
- Fixed example project in `examples/external/java/read-keys-example` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was fixed? A typo? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before it was not working at all... I will add a few words about that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
- now works with a standard installation of Elektra | ||
- updated code to work with current Java binding | ||
|
||
_(Michael Tucek)_ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,34 +85,51 @@ The _user_ namespace is accessible without special rights, but if you try to wri | |
|
||
### Traversing Keys in a `KeySet` | ||
|
||
First we create a new `KDB` handle and fetch all keys for the desired namespace, in this example the whole `user` namespace. Since all all keys are put in the passed `keySet` variable we can then iterate through it. | ||
The `at(int)` method returns a new `Key` object for the native key with the corresponding position within the `keySet`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually there is a new |
||
|
||
```java | ||
var keyNamespace = Key.create("user:/"); // select a namespace from which all keys should be fetched | ||
var keyNamespace = Key.create("user:/"); // select a namespace from which all keys should be fetched | ||
try (KDB kdb = KDB.open()) { | ||
var keySet = kdb.get(keyNamespace); // fetch all keys int new key set | ||
for (int i = 0; i < keySet.length(); i++) { // traverse the set | ||
var keySet = kdb.get(keyNamespace); // fetch all keys into a new key set | ||
for (int i = 0; i < keySet.length(); i++) { // traverse the set | ||
var currentKey = keySet.at(i); | ||
System.out.println(String.format("%s: %s", | ||
currentKey.getName(), // fetch the key's name | ||
currentKey.getString())); // fetch the key's value | ||
currentKey.getName(), // fetch the key's name | ||
currentKey.getString())); // fetch the key's value | ||
} | ||
} catch (KDB.KDBException e) { | ||
e.printStackTrace(); | ||
} | ||
``` | ||
|
||
First we create a new `KDB` session and fetch all keys for the desired namespace, in this example the whole `user` namespace. Since all all keys are put in the passed `keySet` variable we can then iterate through it. | ||
The `at(int)` method return a new `Key` object for the native key with the corresponding position within the `keySet`. | ||
`KeySet` also provides an iterator implementation: | ||
|
||
```java | ||
var keyNamespace = Key.create("user:/"); // select a namespace from which all keys should be fetched | ||
try (KDB kdb = KDB.open()) { | ||
var iter = kdb.get(keyNamespace).iterator(); // fetch all keys into a new key set | ||
while(iter.hasNext()) { // traverse the set | ||
var currentKey = iter.next(); | ||
System.out.println(String.format("%s: %s", | ||
currentKey.getName(), // fetch the key's name | ||
currentKey.getString())); // fetch the key's value | ||
} | ||
} catch (KDB.KDBException e) { | ||
e.printStackTrace(); | ||
} | ||
``` | ||
|
||
Of course, alternatively a for each loop can be used: | ||
|
||
```java | ||
var keyNamespace = Key.create("user:/"); // select a namespace from which all keys should be fetched | ||
var keyNamespace = Key.create("user:/"); // select a namespace from which all keys should be fetched | ||
try (KDB kdb = KDB.open()) { | ||
var keySet = kdb.get(keyNamespace); // fetch all keys int new key set | ||
for (var currentKey : keySet) { // traverse the set | ||
var keySet = kdb.get(keyNamespace); // fetch all keys into a new key set | ||
for (var currentKey : keySet) { // traverse the set | ||
System.out.println(String.format("%s: %s", | ||
currentKey.getName(), // fetch the key's name | ||
currentKey.getString())); // fetch the key's value | ||
currentKey.getName(), // fetch the key's name | ||
currentKey.getString())); // fetch the key's value | ||
} | ||
} catch (KDB.KDBException e) { | ||
e.printStackTrace(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ignore java class files | ||
*.class | ||
|
||
# ignore secret settings | ||
secret-settings.gradle | ||
|
||
# ignore gradle cache | ||
/.gradle | ||
|
||
# ignore eclipse project files | ||
.project | ||
.classpath | ||
bin | ||
target | ||
.settings |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
This is a fully working example for how to use Elektra with Maven or Gradle. | ||
This is a fully working example for how to use Elektra with Maven or Gradle for reading keys. | ||
|
||
Make sure Elektra and the JNA binding are installed correctly. | ||
First Make sure to install the Elektra Java binding to your local maven repository: | ||
|
||
See [JNA binding](../../../../src/bindings/jna/README.md) for more information. | ||
```sh | ||
cd ./src/bindings/jna | ||
./gradlew publishLibelektraPublicationToMavenLocal | ||
``` | ||
|
||
TODO add short intro how to build suing gradle or maven | ||
Alternatively change the `libelektra` dependency in `build.gradle` to a published version, fitting your Elektra installation. | ||
(See [JNA binding](../../../../src/bindings/jna/README.md) for more information.) | ||
|
||
Then change to the example app folder: | ||
|
||
```sh | ||
cd ../../../examples/external/java/read-keys-example | ||
``` | ||
|
||
Use a local Gradle installation to run the example app: | ||
|
||
```sh | ||
gradle run | ||
``` | ||
|
||
Alternatively use a local Maven installation to run the example app: | ||
|
||
```sh | ||
mvn compile exec:java | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,24 +57,6 @@ if (Java_JAVAC_EXECUTABLE) | |
set (GRADLE_TEST_EXCLUDES "") | ||
java_test_needs_plugin (GOptsTest gopts) | ||
|
||
if ((CMAKE_SYSTEM_NAME STREQUAL "Darwin") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this change related to the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, all tests have been explicitly added to not be executed on this mac os version. I took the opportunity to optimize the cmake file instead of adding more (new) tests to the exclusion list. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this basically exclude all related tests on all our CI macOS instances? Actually running some tests would be a requirement before merging this PR.
tucek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
AND NOT (CMAKE_SYSTEM_VERSION VERSION_LESS 15) | ||
OR (NOT BUILD_TESTING)) | ||
# we cannot set DYLD_LIBRARY_PATH on new macOS versions, making the kdb tests fail if its not | ||
# installed in the system | ||
java_exclude_test (ExceptionMapperIT) | ||
java_exclude_test (ExceptionMapperTest) | ||
java_exclude_test (GOptsTest) | ||
java_exclude_test (KDBExceptionTest) | ||
java_exclude_test (KDBTest) | ||
java_exclude_test (KeyNameIteratorTest) | ||
java_exclude_test (KeySetTest) | ||
java_exclude_test (KeyTest) | ||
java_exclude_test (PluginLoaderIT) | ||
java_exclude_test (ReturnTest) | ||
java_exclude_test (WarningEntryTest) | ||
endif () | ||
|
||
# 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" | ||
|
@@ -114,13 +96,14 @@ if (Java_JAVAC_EXECUTABLE) | |
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/InterfaceException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/InternalException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KDBClosedException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyBinaryTypeNotSupportedException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyBinaryValueException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyMetaException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyNameException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyReleasedException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeySetAppendException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeySetReleasedException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/KeyStringValueException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/LogicalException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/OutOfMemoryException.java | ||
${JNA_BINDING_SOURCE_DIRECTORY_EXCEPTION}/package-info.java | ||
|
@@ -141,6 +124,10 @@ if (Java_JAVAC_EXECUTABLE) | |
${JNA_BINDING_SOURCE_DIRECTORY_TEST_PLUGIN}/ReturnTest.java | ||
${JNA_BINDING_PREFIX}/build.gradle | ||
${JNA_BINDING_PREFIX}/dependencies.gradle | ||
plugins/build.gradle | ||
plugins/dependencies.gradle | ||
plugins/whitelist/src/main/java/org/libelektra/plugin/WhitelistPlugin.java | ||
plugins/whitelist/src/test/java/org/libelektra/plugin/WhitelistPluginTests.java | ||
build.gradle | ||
gradle.properties | ||
java-library.gradle | ||
|
@@ -180,8 +167,14 @@ if (Java_JAVAC_EXECUTABLE) | |
DESTINATION "share/java" | ||
COMPONENT java-elektra) | ||
|
||
# add gradle test to execute with ctest in the testing phase | ||
if (BUILD_TESTING AND NOT ENABLE_ASAN) | ||
# we cannot set DYLD_LIBRARY_PATH on new macOS versions, making the kdb tests fail if its not installed in | ||
# the system | ||
if (BUILD_TESTING | ||
AND NOT ENABLE_ASAN | ||
AND NOT | ||
((CMAKE_SYSTEM_NAME STREQUAL "Darwin") | ||
AND NOT (CMAKE_SYSTEM_VERSION VERSION_LESS 15) | ||
OR (NOT BUILD_TESTING))) | ||
add_test ( | ||
NAME testjna_gradle | ||
COMMAND ${GRADLE_EXECUTABLE} -q --console=plain test | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be probably directly after "Added support of binary valued keys:"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markus2330 I do not understand what you mean. What do you mean by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence "- Introduced
Key::getBinary()
andKey::setBinary(byte[])
" seems to be the most important feature for "Added support of binary valued keys:", so I would write it first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will reorder the affected lines of the release note in #4002