diff --git a/pom.xml b/pom.xml
index de8e289b..820517ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.baidu.hugegraph
hugegraph-common
- 1.8.4
+ 1.8.5
hugegraph-common
https://github.com/hugegraph/hugegraph-common
@@ -266,7 +266,7 @@
- 1.8.4.0
+ 1.8.5.0
diff --git a/src/main/java/com/baidu/hugegraph/config/ConfigListConvOption.java b/src/main/java/com/baidu/hugegraph/config/ConfigListConvOption.java
index 8162500c..151fbf92 100644
--- a/src/main/java/com/baidu/hugegraph/config/ConfigListConvOption.java
+++ b/src/main/java/com/baidu/hugegraph/config/ConfigListConvOption.java
@@ -60,7 +60,7 @@ protected boolean forList() {
}
@Override
- protected List parse(Object value) {
+ protected List parse(String value) {
return ConfigListOption.convert(value, part -> {
return this.parse(part, this.elemClass);
});
diff --git a/src/main/java/com/baidu/hugegraph/config/ConfigListOption.java b/src/main/java/com/baidu/hugegraph/config/ConfigListOption.java
index 565e9c71..ef6e3249 100644
--- a/src/main/java/com/baidu/hugegraph/config/ConfigListOption.java
+++ b/src/main/java/com/baidu/hugegraph/config/ConfigListOption.java
@@ -56,7 +56,7 @@ protected boolean forList() {
}
@Override
- protected List parse(Object value) {
+ protected List parse(String value) {
return convert(value, part -> this.parse(part, this.elemClass));
}
diff --git a/src/main/java/com/baidu/hugegraph/config/HugeConfig.java b/src/main/java/com/baidu/hugegraph/config/HugeConfig.java
index 5a8d345c..ed5da5a5 100644
--- a/src/main/java/com/baidu/hugegraph/config/HugeConfig.java
+++ b/src/main/java/com/baidu/hugegraph/config/HugeConfig.java
@@ -151,7 +151,7 @@ private Object validateOption(String key, Object value) {
"Invalid value for key '%s': %s", key, value);
TypedOption, ?> option = OptionSpace.get(key);
- return option.parseConvert(value);
+ return option.parseConvert((String) value);
}
private void checkRequiredOptions() {
diff --git a/src/main/java/com/baidu/hugegraph/config/TypedOption.java b/src/main/java/com/baidu/hugegraph/config/TypedOption.java
index 57d77c6f..2aa50e3f 100644
--- a/src/main/java/com/baidu/hugegraph/config/TypedOption.java
+++ b/src/main/java/com/baidu/hugegraph/config/TypedOption.java
@@ -50,6 +50,7 @@ public class TypedOption {
Double.class,
String.class,
String[].class,
+ Class.class,
List.class
);
@@ -112,20 +113,27 @@ public R defaultValue() {
return this.convert(this.defaultValue);
}
- public R parseConvert(Object value) {
+ public R parseConvert(String value) {
T parsed = this.parse(value);
this.check(parsed);
return this.convert(parsed);
}
@SuppressWarnings("unchecked")
- protected T parse(Object value) {
+ protected T parse(String value) {
return (T) this.parse(value, this.dataType);
}
- protected Object parse(Object value, Class> dataType) {
+ protected Object parse(String value, Class> dataType) {
if (dataType.equals(String.class)) {
return value;
+ } else if (dataType.equals(Class.class)) {
+ try {
+ return Class.forName(value);
+ } catch (ClassNotFoundException e) {
+ throw new ConfigException(
+ "Failed to parse Class from String '%s'", e, value);
+ }
} else if (List.class.isAssignableFrom(dataType)) {
E.checkState(this.forList(),
"List option can't be registered with class %s",
diff --git a/src/main/java/com/baidu/hugegraph/version/CommonVersion.java b/src/main/java/com/baidu/hugegraph/version/CommonVersion.java
index ad6cd2cb..34c07fbe 100644
--- a/src/main/java/com/baidu/hugegraph/version/CommonVersion.java
+++ b/src/main/java/com/baidu/hugegraph/version/CommonVersion.java
@@ -27,5 +27,5 @@ public class CommonVersion {
// The second parameter of Version.of() is for all-in-one JAR
public static final Version VERSION = Version.of(CommonVersion.class,
- "1.8.4");
+ "1.8.5");
}
diff --git a/src/test/java/com/baidu/hugegraph/unit/config/HugeConfigTest.java b/src/test/java/com/baidu/hugegraph/unit/config/HugeConfigTest.java
index 9744a32c..e6c8ac8b 100644
--- a/src/test/java/com/baidu/hugegraph/unit/config/HugeConfigTest.java
+++ b/src/test/java/com/baidu/hugegraph/unit/config/HugeConfigTest.java
@@ -75,6 +75,8 @@ public void testOptionDataType() {
Assert.assertEquals(Double.class, TestOptions.double1.dataType());
Assert.assertEquals(Boolean.class, TestOptions.bool.dataType());
+ Assert.assertEquals(Class.class, TestOptions.clazz.dataType());
+
Assert.assertEquals(List.class, TestOptions.list.dataType());
Assert.assertEquals(List.class, TestOptions.map.dataType());
@@ -110,6 +112,8 @@ public void testOptionsToString() {
TestOptions.double1.toString());
Assert.assertEquals("[Boolean]group1.bool=true",
TestOptions.bool.toString());
+ Assert.assertEquals("[Class]group1.class=class java.lang.Object",
+ TestOptions.clazz.toString());
Assert.assertEquals("[List]group1.list=[list-value1, list-value2]",
TestOptions.list.toString());
Assert.assertEquals("[List]group1.map=[key1:value1, key2:value2]",
@@ -208,6 +212,15 @@ public void testOptionWithError() {
);
});
+ Assert.assertThrows(ConfigException.class, () -> {
+ new ConfigOption<>(
+ "group1.class",
+ "description of group1.class",
+ input -> input != null && input.equals(Long.class),
+ Integer.class
+ );
+ });
+
Assert.assertThrows(ConfigException.class, () -> {
new ConfigListOption<>(
"group1.list",
@@ -265,6 +278,14 @@ public void testHugeConfig() throws Exception {
Assert.assertEquals(true, config.get(TestOptions.bool));
+ Assert.assertEquals(Object.class, config.get(TestOptions.clazz));
+ Assert.assertThrows(ConfigException.class, () -> {
+ config.setProperty(TestOptions.clazz.name(),
+ "com.baidu.hugegraph.HugeGraph");
+ }, e -> {
+ Assert.assertTrue(e.getCause() instanceof ClassNotFoundException);
+ });
+
Assert.assertEquals(Arrays.asList("list-value1", "list-value2"),
config.get(TestOptions.list));
@@ -299,6 +320,8 @@ public void testHugeConfigWithFile() throws Exception {
Assert.assertEquals(false, config.get(TestOptions.bool));
+ Assert.assertEquals(String.class, config.get(TestOptions.clazz));
+
Assert.assertEquals(Arrays.asList("file-v1", "file-v2", "file-v3"),
config.get(TestOptions.list));
@@ -477,6 +500,14 @@ public static synchronized TestOptions instance() {
true
);
+ public static final ConfigOption> clazz =
+ new ConfigOption<>(
+ "group1.class",
+ "description of group1.class",
+ disallowEmpty(),
+ Object.class
+ );
+
public static final ConfigConvOption weekday =
new ConfigConvOption<>(
"group1.weekday",
diff --git a/src/test/java/com/baidu/hugegraph/unit/config/test.conf b/src/test/java/com/baidu/hugegraph/unit/config/test.conf
index bd2ea2a8..9ee10b0a 100644
--- a/src/test/java/com/baidu/hugegraph/unit/config/test.conf
+++ b/src/test/java/com/baidu/hugegraph/unit/config/test.conf
@@ -12,6 +12,8 @@ group1.double1=66
group1.bool=false
+group1.class=java.lang.String
+
group1.list=[file-v1, file-v2, file-v3]
group1.map=[key1:value1, key3:value3]