Native Libraries: added API version to:

- test whether native library matches the JAR (bad builds could e.g. ship a newer JAR with an older incompatible native library)
- invoke a method (to get API version) to check whether native library works correctly

if API version do not match, or method could not invoked correctly, disable usage of FlatLaf native library

Windows and macOS binaries built and signed locally in clean workspace
Linux binary built by GitHub Actions
This commit is contained in:
Karl Tauber
2024-03-24 13:40:47 +01:00
parent 4e1f092b98
commit 32d102dbc9
19 changed files with 229 additions and 16 deletions

View File

@@ -21,7 +21,10 @@ plugins {
}
flatlafJniHeaders {
headers = listOf( "com_formdev_flatlaf_ui_FlatNativeLinuxLibrary.h" )
headers = listOf(
"com_formdev_flatlaf_ui_FlatNativeLibrary.h",
"com_formdev_flatlaf_ui_FlatNativeLinuxLibrary.h"
)
}
library {

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2024 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <jni.h>
#include "com_formdev_flatlaf_ui_FlatNativeLibrary.h"
/**
* @author Karl Tauber
*/
// increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeLinuxLibrary
#define API_VERSION_LINUX 3001
//---- JNI methods ------------------------------------------------------------
extern "C"
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
( JNIEnv* env, jclass cls )
{
return API_VERSION_LINUX;
}

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_formdev_flatlaf_ui_FlatNativeLibrary */
#ifndef _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#define _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_formdev_flatlaf_ui_FlatNativeLibrary
* Method: getApiVersion
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -26,7 +26,10 @@ plugins {
}
flatlafJniHeaders {
headers = listOf( "com_formdev_flatlaf_ui_FlatNativeMacLibrary.h" )
headers = listOf(
"com_formdev_flatlaf_ui_FlatNativeLibrary.h",
"com_formdev_flatlaf_ui_FlatNativeMacLibrary.h"
)
}
library {

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_formdev_flatlaf_ui_FlatNativeLibrary */
#ifndef _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#define _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_formdev_flatlaf_ui_FlatNativeLibrary
* Method: getApiVersion
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2024 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <jni.h>
#include "com_formdev_flatlaf_ui_FlatNativeLibrary.h"
/**
* @author Karl Tauber
*/
// increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeMacLibrary
#define API_VERSION_MACOS 2001
//---- JNI methods ------------------------------------------------------------
extern "C"
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
( JNIEnv* env, jclass cls )
{
return API_VERSION_MACOS;
}

View File

@@ -22,6 +22,7 @@ plugins {
flatlafJniHeaders {
headers = listOf(
"com_formdev_flatlaf_ui_FlatNativeLibrary.h",
"com_formdev_flatlaf_ui_FlatNativeWindowsLibrary.h",
"com_formdev_flatlaf_ui_FlatWindowsNativeWindowBorder.h",
"com_formdev_flatlaf_ui_FlatWindowsNativeWindowBorder_WndProc.h"

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2024 FormDev Software GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <jni.h>
#include "com_formdev_flatlaf_ui_FlatNativeLibrary.h"
/**
* @author Karl Tauber
*/
// increase this version if changing API or functionality of native library
// also update version in Java class com.formdev.flatlaf.ui.FlatNativeWindowsLibrary
#define API_VERSION_WINDOWS 1001
//---- JNI methods ------------------------------------------------------------
extern "C"
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
( JNIEnv* env, jclass cls )
{
return API_VERSION_WINDOWS;
}

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_formdev_flatlaf_ui_FlatNativeLibrary */
#ifndef _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#define _Included_com_formdev_flatlaf_ui_FlatNativeLibrary
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_formdev_flatlaf_ui_FlatNativeLibrary
* Method: getApiVersion
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_formdev_flatlaf_ui_FlatNativeLibrary_getApiVersion
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif