remove property settings loader by default
This commit is contained in:
parent
15a7273b17
commit
abe8e4adf8
10 changed files with 144 additions and 25 deletions
|
@ -1,9 +1,5 @@
|
|||
package org.xbib.config;
|
||||
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.settings.SettingsBuilder;
|
||||
import org.xbib.settings.SettingsLoader;
|
||||
import org.xbib.settings.SettingsLoaderService;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -23,6 +19,10 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.stream.Collectors;
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.settings.SettingsBuilder;
|
||||
import org.xbib.settings.SettingsLoader;
|
||||
import org.xbib.settings.SettingsLoaderService;
|
||||
|
||||
/**
|
||||
* A configuration loader for configuration files.
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.xbib.config;
|
||||
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.settings.datastructures.DatastructureSettings;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.sql.Connection;
|
||||
|
@ -10,6 +8,8 @@ import java.util.Arrays;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.settings.datastructures.DatastructureSettings;
|
||||
|
||||
public class ConfigParams implements Comparable<ConfigParams> {
|
||||
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
package org.xbib.config.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.config.ConfigLoader;
|
||||
import org.xbib.config.ConfigParams;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.config.ConfigLoader;
|
||||
import org.xbib.config.ConfigParams;
|
||||
import org.xbib.settings.Settings;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigLoaderTest {
|
||||
|
||||
|
|
|
@ -56,10 +56,19 @@ page at http://checkstyle.sourceforge.net/config.html -->
|
|||
<!-- Checks for out of order import statements. -->
|
||||
|
||||
<property name="severity" value="warning"/>
|
||||
<property name="groups" value="com,junit,net,org,java,javax"/>
|
||||
<!-- This ensures that static imports go first. -->
|
||||
<property name="option" value="top"/>
|
||||
<property name="tokens" value="STATIC_IMPORT, IMPORT"/>
|
||||
<!-- <property name="tokens" value="IMPORT, STATIC_IMPORT"/> -->
|
||||
<property name="separated" value="false"/>
|
||||
<property name="groups" value="*"/>
|
||||
<!-- <property name="option" value="above"/> -->
|
||||
<property name="sortStaticImportsAlphabetically" value="true"/>
|
||||
</module>
|
||||
|
||||
<module name="CustomImportOrder">
|
||||
<!-- <property name="customImportOrderRules" value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/> -->
|
||||
<!-- <property name="specialImportsRegExp" value="^javax\."/> -->
|
||||
<!-- <property name="standardPackageRegExp" value="^java\."/> -->
|
||||
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||
<property name="separateLineBetweenGroups" value="false"/>
|
||||
</module>
|
||||
|
||||
<!--
|
||||
|
|
|
@ -48,6 +48,7 @@ public abstract class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="AccessorClassGeneration"
|
||||
language="java"
|
||||
since="1.04"
|
||||
maximumLanguageVersion="10"
|
||||
message="Avoid instantiation through private constructors from outside of the constructor's class."
|
||||
|
@ -109,6 +110,7 @@ public class OuterClass {
|
|||
</rule>
|
||||
|
||||
<rule name="ArrayIsStoredDirectly"
|
||||
language="java"
|
||||
since="2.2"
|
||||
message="The user-supplied array ''{0}'' is stored directly."
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.ArrayIsStoredDirectlyRule"
|
||||
|
@ -168,6 +170,7 @@ class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="AvoidReassigningLoopVariables"
|
||||
language="java"
|
||||
since="6.11.0"
|
||||
message="Avoid reassigning the loop control variable ''{0}''"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidReassigningLoopVariablesRule"
|
||||
|
@ -216,6 +219,7 @@ public class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="AvoidReassigningParameters"
|
||||
language="java"
|
||||
since="1.0"
|
||||
message="Avoid reassigning parameters such as ''{0}''"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidReassigningParametersRule"
|
||||
|
@ -265,6 +269,7 @@ public class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="AvoidUsingHardCodedIP"
|
||||
language="java"
|
||||
since="4.1"
|
||||
message="Do not hard code the IP address ${variableName}"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidUsingHardCodedIPRule"
|
||||
|
@ -493,7 +498,7 @@ for (int i = 0, j = 0; i < 10; i++, j += 2) {
|
|||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Image='suite']]
|
||||
//ClassOrInterfaceBodyDeclaration[MethodDeclaration/MethodDeclarator[@Name='suite']]
|
||||
[MethodDeclaration/ResultType/Type/ReferenceType/ClassOrInterfaceType[pmd-java:typeIs('junit.framework.Test')]]
|
||||
[not(MethodDeclaration/Block//ClassOrInterfaceType[pmd-java:typeIs('junit.framework.JUnit4TestAdapter')])]
|
||||
]]>
|
||||
|
@ -535,7 +540,7 @@ public class GoodTest {
|
|||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceBodyDeclaration
|
||||
[MethodDeclaration/MethodDeclarator[@Image='tearDown']]
|
||||
[MethodDeclaration/MethodDeclarator[@Name='tearDown']]
|
||||
[count(Annotation//Name[
|
||||
pmd-java:typeIs('org.junit.After')
|
||||
or pmd-java:typeIs('org.junit.jupiter.api.AfterEach')
|
||||
|
@ -579,7 +584,7 @@ public class MyTest2 {
|
|||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceBodyDeclaration
|
||||
[MethodDeclaration/MethodDeclarator[@Image='setUp']]
|
||||
[MethodDeclaration/MethodDeclarator[@Name='setUp']]
|
||||
[count(Annotation//Name[
|
||||
pmd-java:typeIs('org.junit.Before')
|
||||
or pmd-java:typeIs('org.junit.jupiter.api.BeforeEach')
|
||||
|
@ -623,10 +628,10 @@ public class MyTest2 {
|
|||
<value>
|
||||
<![CDATA[
|
||||
//ClassOrInterfaceDeclaration[
|
||||
matches(@Image, $testClassPattern)
|
||||
matches(@SimpleName, $testClassPattern)
|
||||
or ExtendsList/ClassOrInterfaceType[pmd-java:typeIs('junit.framework.TestCase')]]
|
||||
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[MethodDeclaration[@Public=true()]/MethodDeclarator[starts-with(@Image, 'test')]]
|
||||
/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration[MethodDeclaration[@Public=true()]/MethodDeclarator[starts-with(@Name, 'test')]]
|
||||
[not(Annotation//Name[
|
||||
pmd-java:typeIs('org.junit.Test')
|
||||
or pmd-java:typeIs('org.junit.jupiter.api.Test') or pmd-java:typeIs('org.junit.jupiter.api.RepeatedTest')
|
||||
|
@ -656,6 +661,7 @@ public class MyTest {
|
|||
</rule>
|
||||
|
||||
<rule name="JUnitAssertionsShouldIncludeMessage"
|
||||
language="java"
|
||||
since="1.04"
|
||||
message="JUnit assertions should include a message"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitAssertionsShouldIncludeMessageRule"
|
||||
|
@ -734,6 +740,7 @@ public class MyTestCase extends TestCase {
|
|||
</rule>
|
||||
|
||||
<rule name="JUnitTestsShouldIncludeAssert"
|
||||
language="java"
|
||||
since="2.0"
|
||||
message="JUnit tests should include assert() or fail()"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitTestsShouldIncludeAssertRule"
|
||||
|
@ -758,6 +765,7 @@ public class Foo extends TestCase {
|
|||
</rule>
|
||||
|
||||
<rule name="JUnitUseExpected"
|
||||
language="java"
|
||||
since="4.0"
|
||||
message="In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.JUnitUseExpectedRule"
|
||||
|
@ -788,6 +796,7 @@ public class MyTest {
|
|||
</rule>
|
||||
|
||||
<rule name="LooseCoupling"
|
||||
language="java"
|
||||
since="0.7"
|
||||
message="Avoid using implementation types like ''{0}''; use the interface instead"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.LooseCouplingRule"
|
||||
|
@ -824,6 +833,7 @@ public class Bar {
|
|||
</rule>
|
||||
|
||||
<rule name="MethodReturnsInternalArray"
|
||||
language="java"
|
||||
since="2.2"
|
||||
message="Returning ''{0}'' may expose an internal array."
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.MethodReturnsInternalArrayRule"
|
||||
|
@ -848,6 +858,7 @@ public class SecureSystem {
|
|||
|
||||
|
||||
<rule name="MissingOverride"
|
||||
language="java"
|
||||
since="6.2.0"
|
||||
minimumLanguageVersion="1.5"
|
||||
message="The method ''{0}'' is missing an @Override annotation."
|
||||
|
@ -1000,6 +1011,7 @@ class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="PreserveStackTrace"
|
||||
language="java"
|
||||
since="3.7"
|
||||
message="New exception is thrown in catch block, original stack trace may be lost"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.PreserveStackTraceRule"
|
||||
|
@ -1217,6 +1229,7 @@ public class Foo {
|
|||
</rule>
|
||||
|
||||
<rule name="UnusedImports"
|
||||
language="java"
|
||||
since="1.0"
|
||||
message="Avoid unused imports such as ''{0}''"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.UnusedImportsRule"
|
||||
|
@ -1489,6 +1502,7 @@ public class MyTestCase extends TestCase {
|
|||
</rule>
|
||||
|
||||
<rule name="UseCollectionIsEmpty"
|
||||
language="java"
|
||||
since="3.9"
|
||||
message="Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()"
|
||||
class="net.sourceforge.pmd.lang.java.rule.bestpractices.UseCollectionIsEmptyRule"
|
||||
|
@ -1546,7 +1560,7 @@ public class Foo {
|
|||
][
|
||||
pmd-java:typeIs('java.lang.AutoCloseable')
|
||||
or
|
||||
../../PrimarySuffix/Arguments[@ArgumentCount = 1]//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
|
||||
../../PrimarySuffix/Arguments[@Size = 1]//PrimaryPrefix[pmd-java:typeIs('java.lang.AutoCloseable')]
|
||||
]]
|
||||
]]>
|
||||
</value>
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package org.xbib.settings.content.json;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.settings.Settings;
|
||||
import org.xbib.settings.SettingsLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class JsonSettingsTest {
|
||||
|
||||
@Test
|
||||
public void testMapForSettings() throws IOException {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("hello", "world");
|
||||
Map<String, Object> settingsMap = new HashMap<>();
|
||||
settingsMap.put("map", map);
|
||||
SettingsLoader settingsLoader = new JsonSettingsLoader();
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
.put(settingsLoader.load(settingsMap))
|
||||
.build();
|
||||
assertEquals("{map.hello=world}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapSettingsFromReader() throws IOException {
|
||||
Map<String, Object> map = Map.of("map", Map.of("hello", "world"));
|
||||
SettingsLoader settingsLoader = new JsonSettingsLoader();
|
||||
Settings settings = Settings.settingsBuilder()
|
||||
.put(settingsLoader.load(map))
|
||||
.build();
|
||||
assertEquals("{map.hello=world}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFromString() throws IOException {
|
||||
String json = "{\"Hello\":\"World\"}";
|
||||
SettingsLoader loader = new JsonSettingsLoader();
|
||||
Map<String, String> result = loader.load(json);
|
||||
assertEquals("{Hello=World}", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSettingsFromString() {
|
||||
String json = "{\"Hello\":\"World\"}";
|
||||
Settings settings = Settings.settingsBuilder().loadFromString(json).build();
|
||||
assertEquals("{Hello=World}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatLoader() throws IOException {
|
||||
String s = "{\"a\":{\"b\":\"c\"}}";
|
||||
SettingsLoader loader = new JsonSettingsLoader();
|
||||
Map<String, String> flatMap = loader.load(s);
|
||||
assertEquals("{a.b=c}", flatMap.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFromMap() throws IOException {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> code = new LinkedHashMap<>();
|
||||
code.put("a", "b");
|
||||
code.put("b", "c");
|
||||
Map<String, Object> name = new LinkedHashMap<>();
|
||||
name.put("a", "b");
|
||||
name.put("b", "c");
|
||||
List<String> list = Arrays.asList("a", "b");
|
||||
map.put("code", code);
|
||||
map.put("name", name);
|
||||
map.put("list", list);
|
||||
map.put("null", null);
|
||||
SettingsLoader loader = new JsonSettingsLoader();
|
||||
Map<String, String> result = loader.load(map);
|
||||
assertEquals("{code.a=b, code.b=c, name.a=b, name.b=c, list.0=a, list.1=b, null=null}", result.toString());
|
||||
}
|
||||
}
|
|
@ -38,6 +38,21 @@ public class JsonSettingsTest {
|
|||
assertEquals("{map.hello=world}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadFromString() throws IOException {
|
||||
String json = "{\"Hello\":\"World\"}";
|
||||
SettingsLoader loader = new JsonSettingsLoader();
|
||||
Map<String, String> result = loader.load(json);
|
||||
assertEquals("{Hello=World}", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadSettingsFromString() {
|
||||
String json = "{\"Hello\":\"World\"}";
|
||||
Settings settings = Settings.settingsBuilder().loadFromString(json).build();
|
||||
assertEquals("{Hello=World}", settings.getAsMap().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlatLoader() throws IOException {
|
||||
String s = "{\"a\":{\"b\":\"c\"}}";
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
org.xbib.settings.datastructures.json.JsonSettingsLoader
|
|
@ -229,8 +229,7 @@ public class DatastructureSettingsBuilder implements SettingsBuilder {
|
|||
public DatastructureSettingsBuilder loadFromString(String source) {
|
||||
SettingsLoader settingsLoader = settingsLoaderService.loaderFromString(source);
|
||||
try {
|
||||
Map<String, String> loadedSettings = settingsLoader.load(source);
|
||||
put(loadedSettings);
|
||||
put(settingsLoader.load(source));
|
||||
} catch (Exception e) {
|
||||
throw new SettingsException("failed to load settings from [" + source + "]", e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue