mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f97166192 | |||
| ccd239ad6b | |||
| 69b27476bc | |||
| 0651cac6b0 | |||
| 1a1efad283 | |||
| 3c1ba61b61 | |||
| 1a3e84a787 | |||
| 00228db2c4 |
+3
-1
@@ -5,12 +5,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyconfiguration-core</artifactId>
|
<artifactId>easyconfiguration-core</artifactId>
|
||||||
|
|||||||
@@ -50,6 +50,23 @@ public interface ConfigValueParser<T, R> {
|
|||||||
@Contract(pure = true)
|
@Contract(pure = true)
|
||||||
static <V> @NotNull ConfigValueParser<Object, V> castObject(Class<V> valueClass) {
|
static <V> @NotNull ConfigValueParser<Object, V> castObject(Class<V> valueClass) {
|
||||||
return (input, defaultValue) -> {
|
return (input, defaultValue) -> {
|
||||||
|
|
||||||
|
if (Number.class.isAssignableFrom(valueClass)) {
|
||||||
|
if (Long.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = longValue().parse(input, null);
|
||||||
|
} else if (Integer.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = intValue().parse(input, null);
|
||||||
|
} else if (Float.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = floatValue().parse(input, null);
|
||||||
|
} else if (Double.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = doubleValue().parse(input, null);
|
||||||
|
} else if (Byte.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = byteValue().parse(input, null);
|
||||||
|
} else if (Short.class.isAssignableFrom(valueClass)) {
|
||||||
|
input = shortValue().parse(input, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (valueClass.isInstance(input)) return valueClass.cast(input);
|
if (valueClass.isInstance(input)) return valueClass.cast(input);
|
||||||
else throw new IllegalArgumentException("Cannot cast value to " + valueClass.getName());
|
else throw new IllegalArgumentException("Cannot cast value to " + valueClass.getName());
|
||||||
};
|
};
|
||||||
|
|||||||
+4
-2
@@ -5,13 +5,15 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.1</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>easyconfiguration-json</artifactId>
|
<artifactId>easyconfiguration-json</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -28,7 +30,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
<version>2.9.1</version>
|
<version>2.10</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -5,13 +5,17 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.1</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|
||||||
|
<maven.deploy.skip>true</maven.deploy.skip>
|
||||||
</properties>
|
</properties>
|
||||||
<artifactId>easyconfiguration-sql</artifactId>
|
<artifactId>easyconfiguration-sql</artifactId>
|
||||||
|
|
||||||
@@ -24,8 +28,6 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
+4
-2
@@ -5,13 +5,15 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.1</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||||
<maven.compiler.target>${java.version}</maven.compiler.target>
|
<maven.compiler.target>${java.version}</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<artifactId>easyconfiguration-yaml</artifactId>
|
<artifactId>easyconfiguration-yaml</artifactId>
|
||||||
@@ -29,7 +31,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bspfsystems</groupId>
|
<groupId>org.bspfsystems</groupId>
|
||||||
<artifactId>yamlconfiguration</artifactId>
|
<artifactId>yamlconfiguration</artifactId>
|
||||||
<version>1.2.1</version>
|
<version>1.3.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,12 @@ public class DemoConfigTest {
|
|||||||
public static void testDemo() {
|
public static void testDemo() {
|
||||||
System.out.println("----------------------------------------------------");
|
System.out.println("----------------------------------------------------");
|
||||||
|
|
||||||
|
System.out.println("Test Number: ");
|
||||||
|
|
||||||
|
System.out.println("before: " + DemoConfiguration.TEST_NUMBER.get());
|
||||||
|
DemoConfiguration.TEST_NUMBER.set((long) (Long.MAX_VALUE * Math.random()));
|
||||||
|
System.out.println("after: " + DemoConfiguration.TEST_NUMBER.get());
|
||||||
|
|
||||||
System.out.println("> Test Value:");
|
System.out.println("> Test Value:");
|
||||||
System.out.println("before: " + DemoConfiguration.Sub.UUID_CONFIG_VALUE.get());
|
System.out.println("before: " + DemoConfiguration.Sub.UUID_CONFIG_VALUE.get());
|
||||||
DemoConfiguration.Sub.UUID_CONFIG_VALUE.set(UUID.randomUUID());
|
DemoConfiguration.Sub.UUID_CONFIG_VALUE.set(UUID.randomUUID());
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package config;
|
|
||||||
|
|
||||||
import config.offset.FieldOffset;
|
|
||||||
import config.offset.OffsetUtil;
|
|
||||||
import config.source.DemoConfiguration;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OffsetTest {
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
public void test() {
|
|
||||||
//
|
|
||||||
output(OffsetUtil.getClassMemberOffset(DemoConfiguration.class));
|
|
||||||
output(OffsetUtil.getClassMemberOffset(DemoConfiguration.Sub.class));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void output(List<FieldOffset> fieldOffsets) {
|
|
||||||
for (FieldOffset fieldOffset : fieldOffsets) {
|
|
||||||
System.out.println(fieldOffset.getOffsetValue() + " -> " + fieldOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,63 +1,63 @@
|
|||||||
package config.offset;
|
//package config.offset;
|
||||||
|
//
|
||||||
|
//
|
||||||
import sun.misc.Unsafe;
|
//import sun.misc.Unsafe;
|
||||||
|
//
|
||||||
import java.lang.reflect.Field;
|
//import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
//import java.lang.reflect.Modifier;
|
||||||
import java.util.Collections;
|
//import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
//import java.util.LinkedList;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* @author Chris2018998
|
// * @author Chris2018998
|
||||||
*/
|
// */
|
||||||
public class OffsetUtil {
|
//public class OffsetUtil {
|
||||||
private static Unsafe unsafe;
|
// private static Unsafe unsafe;
|
||||||
|
//
|
||||||
static {
|
// static {
|
||||||
try {
|
|
||||||
// 获取 Unsafe 内部的私有的实例化单例对象
|
|
||||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
|
||||||
// 无视权限
|
|
||||||
field.setAccessible(true);
|
|
||||||
unsafe = (Unsafe) field.get(null);
|
|
||||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
// try {
|
// try {
|
||||||
// unsafe = AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
|
// // 获取 Unsafe 内部的私有的实例化单例对象
|
||||||
// Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
// Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
// theUnsafe.setAccessible(true);
|
// // 无视权限
|
||||||
// return (Unsafe) theUnsafe.get(null);
|
// field.setAccessible(true);
|
||||||
// });
|
// unsafe = (Unsafe) field.get(null);
|
||||||
// } catch (Throwable e) {
|
// } catch (NoSuchFieldException | IllegalAccessException e) {
|
||||||
// System.err.println("Unable to load unsafe");
|
// e.printStackTrace();
|
||||||
// }
|
// }
|
||||||
}
|
//// try {
|
||||||
|
//// unsafe = AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
|
||||||
public static List<FieldOffset> getClassMemberOffset(Class<?> beanClass) {
|
//// Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
List<FieldOffset> offsetsList = new LinkedList<>();
|
//// theUnsafe.setAccessible(true);
|
||||||
for (Field field : beanClass.getDeclaredFields()) {
|
//// return (Unsafe) theUnsafe.get(null);
|
||||||
FieldOffset fieldOffset = new FieldOffset(field);
|
//// });
|
||||||
offsetsList.add(fieldOffset);
|
//// } catch (Throwable e) {
|
||||||
if (Modifier.isStatic(field.getModifiers()))
|
//// System.err.println("Unable to load unsafe");
|
||||||
fieldOffset.setOffsetValue(unsafe.staticFieldOffset(field));
|
//// }
|
||||||
else
|
// }
|
||||||
fieldOffset.setOffsetValue(unsafe.objectFieldOffset(field));
|
//
|
||||||
Class<?> fieldType = field.getType();
|
// public static List<FieldOffset> getClassMemberOffset(Class<?> beanClass) {
|
||||||
if (!fieldType.getName().startsWith("java")) {
|
// List<FieldOffset> offsetsList = new LinkedList<>();
|
||||||
Field[] subfields = fieldType.getDeclaredFields();
|
// for (Field field : beanClass.getDeclaredFields()) {
|
||||||
if (subfields.length > 0) {
|
// FieldOffset fieldOffset = new FieldOffset(field);
|
||||||
fieldOffset.setSubFieldOffsetList(getClassMemberOffset(fieldType));
|
// offsetsList.add(fieldOffset);
|
||||||
}
|
// if (Modifier.isStatic(field.getModifiers()))
|
||||||
}
|
// fieldOffset.setOffsetValue(unsafe.staticFieldOffset(field));
|
||||||
}
|
// else
|
||||||
|
// fieldOffset.setOffsetValue(unsafe.objectFieldOffset(field));
|
||||||
Collections.sort(offsetsList);
|
// Class<?> fieldType = field.getType();
|
||||||
return offsetsList;
|
// if (!fieldType.getName().startsWith("java")) {
|
||||||
}
|
// Field[] subfields = fieldType.getDeclaredFields();
|
||||||
|
// if (subfields.length > 0) {
|
||||||
|
// fieldOffset.setSubFieldOffsetList(getClassMemberOffset(fieldType));
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Collections.sort(offsetsList);
|
||||||
|
// return offsetsList;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ public class DemoConfiguration extends ConfigurationRoot {
|
|||||||
@ConfigPath(root = true)
|
@ConfigPath(root = true)
|
||||||
protected static final ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
protected static final ConfigValue<Double> VERSION = ConfiguredValue.of(Double.class, 1.0D);
|
||||||
|
|
||||||
|
@ConfigPath(root = true)
|
||||||
|
public static final ConfigValue<Long> TEST_NUMBER = ConfiguredValue.of(Long.class, 1000000L);
|
||||||
|
|
||||||
// 支持通过 Class<?> 变量标注子配置,一并注册。
|
// 支持通过 Class<?> 变量标注子配置,一并注册。
|
||||||
// 注意: 若对应类也有注解,则优先使用类的注解。
|
// 注意: 若对应类也有注解,则优先使用类的注解。
|
||||||
@ConfigPath("impl-test") //支持通过注解修改子配置的主路径,若不修改则以变量名自动生成。
|
@ConfigPath("impl-test") //支持通过注解修改子配置的主路径,若不修改则以变量名自动生成。
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<groupId>cc.carm.lib</groupId>
|
<groupId>cc.carm.lib</groupId>
|
||||||
<artifactId>easyconfiguration-parent</artifactId>
|
<artifactId>easyconfiguration-parent</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<version>3.2.0</version>
|
<version>3.2.1</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
<module>impl/yaml</module>
|
<module>impl/yaml</module>
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>3.2.2</version>
|
<version>3.3.0</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -224,7 +224,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.4.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
|||||||
Reference in New Issue
Block a user