Merge pull request #74 from onixbyte/release/2.4.0

Release 2.4.0
This commit is contained in:
Zihlu Wang
2025-06-17 15:55:44 +08:00
committed by GitHub
32 changed files with 44 additions and 2517 deletions
+2 -1298
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,11 +1,11 @@
# JDevKit
# OnixByte Toolbox
![Static Badge](https://img.shields.io/badge/dynamic/xml?url=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fcom%2Fonixbyte%2Fdevkit-bom%2Fmaven-metadata.xml&query=%2F%2Fmetadata%2Fversioning%2Flatest&label=version)
![Static Badge](https://img.shields.io/badge/licence-Apache_2.0-green)
![Static Badge](https://img.shields.io/badge/JDK-%E2%89%A517-blue)
JDevKit is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
OnixByte Toolbox is a Java Development Kit that offers a set of convenient tools for writing code efficiently.
## Installation and Usage
+4 -10
View File
@@ -37,17 +37,13 @@ repositories {
dependencies {
constraints {
api("com.onixbyte:devkit-core:$artefactVersion")
api("com.onixbyte:devkit-utils:$artefactVersion")
api("com.onixbyte:guid:$artefactVersion")
api("com.onixbyte:key-pair-loader:$artefactVersion")
api("com.onixbyte:map-util-unsafe:$artefactVersion")
api("com.onixbyte:num4j:$artefactVersion")
api("com.onixbyte:simple-jwt-facade:$artefactVersion")
api("com.onixbyte:simple-jwt-authzero:$artefactVersion")
api("com.onixbyte:simple-jwt-spring-boot-starter:$artefactVersion")
api("com.onixbyte:property-guard-spring-boot-starter:$artefactVersion")
api("com.onixbyte:simple-serial-spring-boot-starter:$artefactVersion")
}
}
@@ -59,8 +55,8 @@ publishing {
version = artefactVersion
pom {
name = "DevKit BOM"
description = "Using BOM could use unified OnixByte JDevKit."
name = "OnixByte Version Catalogue"
description = "OnixByte DevKit BOM is designed to manage dependency versions centrally."
url = projectUrl
licenses {
@@ -71,8 +67,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/devkit-bom.git"
developerConnection = "scm:git:git://github.com:OnixByte/devkit-bom.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -93,8 +89,6 @@ publishing {
}
}
print(components)
from(components["javaPlatform"])
signing {
-5
View File
@@ -1,5 +0,0 @@
# Module `devkit-core`
## Introduction
This module serves as the basement of `JDevKit`. It provides some base exceptions that `JDevKit` might use.
-126
View File
@@ -1,126 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
import java.net.URI
plugins {
java
id("java-library")
id("maven-publish")
id("signing")
}
val artefactVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Jar> {
exclude("logback.xml")
}
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
tasks.test {
useJUnitPlatform()
}
publishing {
publications {
create<MavenPublication>("devkitCore") {
groupId = group.toString()
artifactId = "devkit-core"
version = artefactVersion
pom {
name = "DevKit - Core"
description = "The core module of JDevKit."
url = projectUrl
licenses {
license {
name = licenseName
url = licenseUrl
}
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
url = projectGithubUrl
}
developers {
developer {
id = "zihluwang"
name = "Zihlu Wang"
email = "really@zihlu.wang"
timezone = "Asia/Hong_Kong"
}
developer {
id = "siujamo"
name = "Siu Jam'o"
email = "jamo.siu@outlook.com"
timezone = "Asia/Shanghai"
}
}
}
from(components["java"])
signing {
sign(publishing.publications["devkitCore"])
}
}
repositories {
maven {
name = "sonatypeNexus"
url = URI(providers.gradleProperty("repo.maven-central.host").get())
credentials {
username = providers.gradleProperty("repo.maven-central.username").get()
password = providers.gradleProperty("repo.maven-central.password").get()
}
}
}
}
}
@@ -1,93 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.devkit.core.exceptions;
/**
* The {@code NotImplementedException} class is a custom runtime exception that represents a
* situation where a particular method or functionality is not implemented or is currently
* unavailable in the codebase.
* <p>
* This exception is typically thrown when developers need to indicate that a specific part of the
* code is incomplete or requires further implementation. It serves as a placeholder to highlight
* unfinished sections of the application during development and testing phases.
* <p>
* Usage Example:
* <pre>
* public void someMethod() {
* // Some code...
* throw new NotImplementedException("""
* This feature will be implemented in a future release.""");
* }
* </pre>
*
* @author Zihlu Wang
* @version 1.1.0
* @see RuntimeException
* @since 1.0.0
*/
public class NotImplementedException extends RuntimeException {
/**
* Creates a new {@code NotImplementedException} with no specific error message.
*/
public NotImplementedException() {
}
/**
* Creates a new {@code NotImplementedException} with the provided error message.
*
* @param message the error message associated with this exception
*/
public NotImplementedException(String message) {
super(message);
}
/**
* Creates a new {@code NotImplementedException} with the specified error message and a cause
* for this exception.
*
* @param message the error message associated with this exception
* @param cause the cause of this exception
*/
public NotImplementedException(String message, Throwable cause) {
super(message, cause);
}
/**
* Creates a new {@code NotImplementedException} with the specified cause.
*
* @param cause the cause of this exception
*/
public NotImplementedException(Throwable cause) {
super(cause);
}
/**
* Creates a new {@code NotImplementedException} with the specified error message, cause,
* suppression flag, and stack trace writable flag.
*
* @param message the error message associated with this
* exception
* @param cause the cause of this exception
* @param enableSuppression whether suppression is enabled or disabled
* @param writableStackTrace whether the stack trace should be writable
*/
public NotImplementedException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2024-2025 OnixByte.
~
~ 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
~
~ http://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.
-->
<configuration>
<property name="COLOURFUL_OUTPUT"
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
<property name="STANDARD_OUTPUT"
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${COLOURFUL_OUTPUT}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
@@ -1,46 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.devkit.core.exceptions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NotImplementationExceptionTest {
private final static Logger log = LoggerFactory.getLogger(NotImplementationExceptionTest.class);
@Test
public void testExceptionWithEmptyConstructor() {
try {
throw new NotImplementedException();
} catch (NotImplementedException e) {
log.error("NotImplementedException: ", e);
}
}
@Test
public void testExceptionWithStringConstructor() {
try {
throw new NotImplementedException("This function is not implemented yet, please contact developer for further information.");
} catch (NotImplementedException e) {
log.error("NotImplementedException: ", e);
}
}
}
+3 -4
View File
@@ -54,7 +54,6 @@ tasks.withType<Jar> {
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
@@ -71,7 +70,7 @@ publishing {
version = artefactVersion
pom {
name = "DevKit - Utils"
name = "OnixByte Common Toolbox"
description = "The utils module of JDevKit."
url = projectUrl
@@ -83,8 +82,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -17,10 +17,7 @@
package com.onixbyte.devkit.utils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.StandardCharsets;
+4 -4
View File
@@ -15,8 +15,8 @@
# limitations under the License.
#
artefactVersion=2.3.0
projectUrl=https://onixbyte.com/projects/java-dev-kit
projectGithubUrl=https://github.com/onixbyte/java-dev-kit
artefactVersion=2.4.0
projectUrl=https://onixbyte.com/projects/onixbyte-toolbox
projectGithubUrl=https://github.com/onixbyte/onixbyte-toolbox
licenseName=The Apache License, Version 2.0
licenseUrl=https://onixbyte.com/projects/java-dev-kit/LICENSE.txt
licenseUrl=https://onixbyte.com/projects/onixbyte-toolbox/LICENSE.txt
+1 -18
View File
@@ -1,23 +1,6 @@
#
# Copyright (C) 2024-2025 OnixByte.
#
# 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
#
# http://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.
#
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
+3 -4
View File
@@ -54,7 +54,6 @@ tasks.withType<Jar> {
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
@@ -71,7 +70,7 @@ publishing {
version = artefactVersion
pom {
name = "DevKit - GUID"
name = "OnixByte Identity Generator"
description = "The module for generating GUIDs of JDevKit."
url = projectUrl
@@ -83,8 +82,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
+3 -4
View File
@@ -54,7 +54,6 @@ tasks.withType<Jar> {
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
testImplementation(libs.jwt.core)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
@@ -75,7 +74,7 @@ publishing {
version = artefactVersion
pom {
name = "Key Pair Loader"
name = "OnixByte Crypto Toolbox"
description =
"This module can easily load key pairs from a PEM content."
url = projectUrl
@@ -88,8 +87,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -19,12 +19,10 @@ package com.onixbyte.security;
import com.onixbyte.security.exception.KeyLoadingException;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.ECPublicKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.KeySpec;
/**
* The {@code KeyLoader} class provides utility methods for loading keys pairs from PEM-formatted
-5
View File
@@ -1,5 +0,0 @@
# Map Util Unsafe
`map-util-unsafe` provides a set of more convenient utilities for converting Java bean to Map or Map to Java bean, but which are less safe than the `MapUtil` provided in `devkit-utils`.
This `MapUtil` is implemented with Reflect API, which might be removed in later JDKs.
-127
View File
@@ -1,127 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
import java.net.URI
plugins {
java
id("java-library")
id("maven-publish")
id("signing")
}
val artefactVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Jar> {
exclude("logback.xml")
}
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
tasks.test {
useJUnitPlatform()
}
publishing {
publications {
create<MavenPublication>("mapUtilUnsafe") {
groupId = group.toString()
artifactId = "map-util-unsafe"
version = artefactVersion
pom {
name = "Unsafe Map Util"
description =
"This module is a converter that can convert an object to a map with unsafe methods."
url = projectUrl
licenses {
license {
name = licenseName
url = licenseUrl
}
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
url = projectGithubUrl
}
developers {
developer {
id = "zihluwang"
name = "Zihlu Wang"
email = "really@zihlu.wang"
timezone = "Asia/Hong_Kong"
}
developer {
id = "siujamo"
name = "Siu Jam'o"
email = "jamo.siu@outlook.com"
timezone = "Asia/Shanghai"
}
}
}
from(components["java"])
signing {
sign(publishing.publications["mapUtilUnsafe"])
}
}
repositories {
maven {
name = "sonatypeNexus"
url = URI(providers.gradleProperty("repo.maven-central.host").get())
credentials {
username = providers.gradleProperty("repo.maven-central.username").get()
password = providers.gradleProperty("repo.maven-central.password").get()
}
}
}
}
}
@@ -1,250 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.devkit.utils.unsafe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
/**
* The {@link ReflectMapUtil} class provides utility methods for converting between objects and maps
* using reflection. This class allows for dynamic mapping of object fields to map entries and
* vice versa.
* <p>
* The utility methods in this class are useful for scenarios where objects need to be represented
* as maps for serialization, deserialization, or other purposes, and where the structure of the
* objects is not known at compile time.
* </p>
*
* <p><b>Example usage:</b></p>
* <pre>
* {@code
* public class User {
* private String name;
* private int age;
*
* // getters and setters
* }
*
* public class Example {
* public static void main(String[] args) throws IllegalAccessException {
* User user = new User();
* user.setName("John");
* user.setAge(30);
*
* // Convert object to map
* Map<String, Object> userMap = ReflectMapUtil.objectToMap(user);
* System.out.println(userMap); // Output: {name=John, age=30}
*
* // Convert map to object
* User newUser = ReflectMapUtil.mapToObject(userMap, User.class);
* System.out.println(newUser.getName()); // Output: John
* System.out.println(newUser.getAge()); // Output: 30
* }
* }
* }
* </pre>
*
* @author zihluwang
* @version 1.4.2
* @since 1.4.2
* @deprecated This utility class is no longer maintained and will be removed in a future release. If you still need to
* use {@link ReflectMapUtil}, please stick to the last available version (2.2.0).
*/
@Deprecated(forRemoval = true, since = "2.2.0")
public final class ReflectMapUtil {
private final static Logger log = LoggerFactory.getLogger(ReflectMapUtil.class);
/**
* Converts an object to a map by mapping the field names to their corresponding values.
*
* @param obj the object to be converted to a map
* @return a map representing the fields and their values of the object
* @throws IllegalAccessException if an error occurs while accessing the fields of the object
*/
public static Map<String, Object> objectToMap(Object obj) throws IllegalAccessException {
if (obj == null) {
return null;
}
var map = new HashMap<String, Object>();
var declaredFields = obj.getClass().getDeclaredFields();
for (var field : declaredFields) {
field.setAccessible(true);
var result = field.get(obj);
if (result != null) {
map.put(field.getName(), result);
}
}
return map;
}
/**
* Converts a map to an object of the specified type by setting the field values using the
* map entries.
*
* @param map the map representing the fields and their values
* @param requiredType the class of the object to be created
* @param <T> the type of the object to be created
* @return an object of the specified type with the field values set from the map
* @throws NoSuchMethodException if the constructor of the required type is not found
* @throws InvocationTargetException if an error occurs while invoking the constructor
* @throws InstantiationException if the required type is abstract or an interface
* @throws IllegalAccessException if an error occurs while accessing the fields of the object
*/
public static <T> T mapToObject(Map<String, Object> map, Class<T> requiredType)
throws NoSuchMethodException, InvocationTargetException, InstantiationException,
IllegalAccessException {
var bean = requiredType.getConstructor().newInstance();
if (map != null) {
for (var entry : map.entrySet()) {
try {
var entryValue = entry.getValue().toString();
// get the field by field name
var field = requiredType.getDeclaredField(entry.getKey());
var fieldType = field.getGenericType();
// convert field value by class
if (fieldType instanceof Class<?> fieldClass) {
if (fieldClass == Short.class || fieldClass == short.class) {
entry.setValue(Short.parseShort(entryValue));
} else if (fieldClass == Integer.class || fieldClass == int.class) {
entry.setValue(Integer.parseInt(entryValue));
} else if (fieldClass == Long.class || fieldClass == long.class) {
entry.setValue(Long.parseLong(entryValue));
} else if (fieldClass == Float.class || fieldClass == float.class) {
entry.setValue(Float.parseFloat(entryValue));
} else if (fieldClass == Double.class || fieldClass == double.class) {
entry.setValue(Double.parseDouble(entryValue));
} else if (fieldClass == Character.class || fieldClass == char.class) {
entry.setValue(entryValue.charAt(0));
} else if (fieldClass == Byte.class || fieldClass == byte.class) {
entry.setValue(Byte.parseByte(entryValue));
} else if (fieldClass == Boolean.class || fieldClass == boolean.class) {
entry.setValue(Boolean.parseBoolean(entryValue));
} else if (fieldClass == String.class) {
entry.setValue(entryValue);
} else {
log.error("Unable to determine the type of property {}.", field.getName());
continue;
}
}
setFieldValue(bean, entry.getKey(), entry.getValue());
} catch (Exception e) {
log.error("Map to Object failed.");
}
}
}
return bean;
}
/**
* Retrieves the value of a field from an object using reflection.
*
* @param obj the object from which to retrieve the field value
* @param fieldName the name of the field
* @param fieldType the class representing the type of the field value
* @param <T> the type of the field value
* @return the value of the field in the object, or null if the field does
* not exist or cannot be accessed
* @throws IllegalAccessException if an error occurs while accessing the field
* @throws InvocationTargetException if an error occurs while invoking the field getter method
* @throws NoSuchMethodException if the specified getter is not present
*/
public static <T> T getFieldValue(Object obj, String fieldName, Class<T> fieldType)
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
var methodName = getMethodName("get", fieldName);
var objectClass = obj.getClass();
var method = objectClass.getDeclaredMethod(methodName);
method.setAccessible(true);
return cast(method.invoke(obj), fieldType);
}
/**
* Sets the value of a field in an object using reflection.
*
* @param obj the object in which to set the field value
* @param fieldName the name of the field
* @param fieldValue the value to be set
* @throws InvocationTargetException if an error occurs while invoking the field setter method
* @throws IllegalAccessException if an error occurs while accessing the field
* @throws NoSuchMethodException if the specific setter is not present
*/
public static void setFieldValue(Object obj, String fieldName, Object fieldValue)
throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
var objectClass = obj.getClass();
var methodName = getMethodName("set", fieldName);
var method = objectClass.getDeclaredMethod(methodName, fieldValue.getClass());
method.setAccessible(true);
method.invoke(obj, fieldValue);
}
/**
* Casts the specified value to the required type.
*
* @param value the value to be cast
* @param requiredType the type to which the value should be cast
* @param <T> the type to which the value should be cast
* @return the cast value, or null if the value cannot be cast to the required type
*/
public static <T> T cast(Object value, Class<T> requiredType) {
if (requiredType.isInstance(value)) {
return requiredType.cast(value);
}
return null;
}
/**
* Constructs a method name based on the given prefix and field name.
*
* @param prefix the prefix to be added to the field name
* @param fieldName the name of the field
* @return the constructed method name
*/
private static String getMethodName(String prefix, String fieldName) {
return prefix + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
}
/**
* Returns the default string representation of the specified object.
*
* @param obj the object for which to return the default string representation
* @return the default string representation of the object
*/
private static String defaultObject(Object obj) {
if (obj == null) {
return "";
} else {
return String.valueOf(obj);
}
}
/**
* Private constructor to prevent instantiation of this utility class.
*/
private ReflectMapUtil() {
}
}
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2024-2024 OnixByte.
~
~ 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
~
~ http://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.
-->
<configuration>
<property name="COLOURFUL_OUTPUT"
value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
<property name="STANDARD_OUTPUT"
value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${COLOURFUL_OUTPUT}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
+3 -4
View File
@@ -54,7 +54,6 @@ tasks.withType<Jar> {
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
}
@@ -71,7 +70,7 @@ publishing {
version = artefactVersion
pom {
name = "Num4j"
name = "OnixByte Math Toolbox"
description =
"This module is an easy-to-use util for mathematical calculations in Java."
url = projectUrl
@@ -84,8 +83,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
+1 -5
View File
@@ -15,19 +15,15 @@
* limitations under the License.
*/
rootProject.name = "JDevKit"
rootProject.name = "onixbyte-toolbox"
include(
"devkit-bom",
"devkit-core",
"devkit-utils",
"guid",
"key-pair-loader",
"map-util-unsafe",
"num4j",
"simple-jwt",
"simple-jwt-facade",
"simple-jwt-authzero",
"simple-jwt-spring-boot-starter",
"simple-serial-spring-boot-starter"
)
+3 -3
View File
@@ -78,7 +78,7 @@ publishing {
version = artefactVersion
pom {
name = "Simple JWT :: Auth0"
name = "OnixByte JWT Toolbox :: Auth0 Implementation"
description = "Simple JWT implemented with com.auth0:java-jwt."
url = projectUrl
@@ -90,8 +90,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -17,12 +17,6 @@
package com.onixbyte.simplejwt.authzero.test;
import com.onixbyte.simplejwt.authzero.AuthzeroTokenResolver;
import com.onixbyte.simplejwt.constants.TokenAlgorithm;
import org.junit.jupiter.api.Test;
import java.time.Duration;
/**
* TestAuthzeroTokenResolver
*
+3 -4
View File
@@ -55,7 +55,6 @@ dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
api(project(":devkit-core"))
api(project(":devkit-utils"))
api(project(":guid"))
@@ -75,7 +74,7 @@ publishing {
version = artefactVersion
pom {
name = "Simple JWT :: Facade"
name = "OnixByte JWT Toolbox :: Facade"
description = "Declaration of simple JWT module."
url = projectUrl
@@ -87,8 +86,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -87,7 +87,7 @@ publishing {
version = artefactVersion
pom {
name = "Simple JWT :: Spring Boot Starter"
name = "OnixByte JWT Toolbox :: Spring Boot Starter"
description = "Simple JWT all-in-one package for Spring Boot."
url = projectUrl
@@ -99,8 +99,8 @@ publishing {
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
connection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
developerConnection = "scm:git:git://github.com:onixbyte/onixbyte-toolbox.git"
url = projectGithubUrl
}
@@ -1,14 +0,0 @@
# Simple Serial
> Thanks to [@siujamo](https://github.com/siujamo)'s donation.
Simple Serial reuses the configuration of Redis connections to provide am easy-to-use serial
service.
## Configuration
Simple Serial reused the redis configuration of Spring Boot to provide redis support for the
service.
Besides, **Simple Serial** provides a configuration property `onixbyte.serial.start-serial` to
specify the start value of a serial, and default to `0`.
@@ -1,134 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
import java.net.URI
plugins {
java
id("java-library")
id("maven-publish")
id("signing")
}
val artefactVersion: String by project
val projectUrl: String by project
val projectGithubUrl: String by project
val licenseName: String by project
val licenseUrl: String by project
group = "com.onixbyte"
version = artefactVersion
repositories {
mavenCentral()
}
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
tasks.withType<Jar> {
exclude("logback.xml")
}
dependencies {
compileOnly(libs.slf4j)
implementation(libs.logback)
implementation(libs.jackson.databind)
implementation(libs.springBoot.autoconfigure)
implementation(libs.springBoot.starter.logging)
implementation(libs.springBoot.configurationProcessor)
implementation(libs.springBoot.starter.redis)
annotationProcessor(libs.springBoot.configurationProcessor)
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter)
testImplementation(libs.springBoot.starter.test)
}
tasks.test {
useJUnitPlatform()
}
publishing {
publications {
create<MavenPublication>("simpleSerialSpringBootStarter") {
groupId = group.toString()
artifactId = "simple-serial-spring-boot-starter"
version = artefactVersion
pom {
name = "Simple Serial :: Spring Boot Starter"
description = "A Redis based easy-to-use serial service."
url = projectUrl
licenses {
license {
name = licenseName
url = licenseUrl
}
}
scm {
connection = "scm:git:git://github.com:OnixByte/JDevKit.git"
developerConnection = "scm:git:git://github.com:OnixByte/JDevKit.git"
url = projectGithubUrl
}
developers {
developer {
id = "zihluwang"
name = "Zihlu Wang"
email = "really@zihlu.wang"
timezone = "Asia/Hong_Kong"
}
developer {
id = "siujamo"
name = "Siu Jam'o"
email = "jamo.siu@outlook.com"
timezone = "Asia/Shanghai"
}
}
}
from(components["java"])
signing {
sign(publishing.publications["simpleSerialSpringBootStarter"])
}
}
repositories {
maven {
name = "sonatypeNexus"
url = URI(providers.gradleProperty("repo.maven-central.host").get())
credentials {
username = providers.gradleProperty("repo.maven-central.username").get()
password = providers.gradleProperty("repo.maven-central.password").get()
}
}
}
}
}
@@ -1,57 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.serial;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
/**
* Redis Configuration provides redis templates for operations to serial.
*
* @author siujamo
*/
@AutoConfiguration
public class RedisConfig {
/**
* Redis auto configuration.
*/
public RedisConfig() {
}
/**
* RedisTemplate for serial service.
*
* @param redisConnectionFactory redis connection factory
* @return a configured redis template for serial service
*/
@Bean
public RedisTemplate<String, Long> serialRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
var redisTemplate = new RedisTemplate<String, Long>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(RedisSerializer.string());
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Long.class));
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
@@ -1,99 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.serial;
import com.onixbyte.serial.properties.SerialProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Optional;
/**
* {@code SerialService} provides simple serial operations.
*
* @author siujamo
*/
@Service
@EnableConfigurationProperties(SerialProperties.class)
public class SerialService {
private static final Logger log = LoggerFactory.getLogger(SerialService.class);
private final String appName;
private final RedisTemplate<String, Long> serialRedisTemplate;
private final SerialProperties serialProperties;
/**
* Default constructor.
*
* @param appName the name of this application
* @param serialRedisTemplate serial redis template
* @param serialProperties serial properties
*/
public SerialService(@Value("${spring.application.name}") String appName,
RedisTemplate<String, Long> serialRedisTemplate,
SerialProperties serialProperties) {
this.appName = appName;
this.serialRedisTemplate = serialRedisTemplate;
this.serialProperties = serialProperties;
}
/**
* Build a serial key.
*
* @param tag tag of the serial
* @return key of a serial
*/
public String buildKey(String tag) {
return appName + ":serial:" + tag;
}
/**
* Get the next available serial for specific tag.
*
* @param tag tag of the serial
* @return next available serial
*/
public Long nextSerial(String tag) {
var key = buildKey(tag);
var next = Optional.ofNullable(serialRedisTemplate.opsForValue().get(key))
.orElse(serialProperties.getStartSerial());
serialRedisTemplate.opsForValue().set(key, next + 1);
return next;
}
/**
* Reset all serial values.
*/
public void reset() {
var keys = serialRedisTemplate.keys(buildKey("*"));
var startSerial = serialProperties.getStartSerial();
if (!keys.isEmpty()) {
for (var key : keys) {
serialRedisTemplate.opsForValue().set(key, startSerial);
log.debug("Serial {} has been reset to {}", key, startSerial);
}
}
}
}
@@ -1,59 +0,0 @@
/*
* Copyright (C) 2024-2025 OnixByte.
*
* 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
*
* http://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.
*/
package com.onixbyte.serial.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* SerialProperties can modify the start value of a serial.
*
* @author siujamo
*/
@ConfigurationProperties(prefix = "onixbyte.serial")
public class SerialProperties {
/**
* The start of the serial, default to 0.
*/
private Long startSerial = 0L;
/**
* Get the start of the serial.
*
* @return start of the serial
*/
public Long getStartSerial() {
return startSerial;
}
/**
* Set the start of the serial.
*
* @param startSerial start of the serial
*/
public void setStartSerial(Long startSerial) {
this.startSerial = startSerial;
}
/**
* Default constructor.
*/
public SerialProperties() {
}
}
@@ -1,19 +0,0 @@
#
# Copyright (C) 2024-2025 OnixByte.
#
# 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
#
# http://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.
#
com.onixbyte.serial.RedisConfig
com.onixbyte.serial.SerialService
@@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2024-2025 OnixByte.
~
~ 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
~
~ http://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.
-->
<configuration>
<property name="COLOURFUL_OUTPUT" value="%black(%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK}) %highlight(%-5level) %black(---) %black([%10.10t]) %cyan(%-20.20logger{20}) %black(:) %msg%n"/>
<property name="STANDARD_OUTPUT" value="%date{'dd MMM, yyyy HH:mm:ss', Asia/Hong_Kong, en-UK} %-5level %black(---) [%10.10t] %-20.20logger{20} : %msg%n"/>
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${COLOURFUL_OUTPUT}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>