未验证 提交 b47cba28 编写于 作者: L Liang Zhang 提交者: GitHub

Unify YAML to Yaml in class name (#5630)

* refactor package structure of yaml.engine

* unify YAML to Yaml in class name
上级 adf9c473
......@@ -15,16 +15,16 @@
* limitations under the License.
*/
package org.apache.shardingsphere.sharding.yaml.construct;
package org.apache.shardingsphere.sharding.yaml.engine.construct;
import org.apache.shardingsphere.sharding.yaml.config.strategy.YamlNoneShardingStrategyConfiguration;
import org.apache.shardingsphere.underlying.common.yaml.constructor.ShardingSphereYAMLConstruct;
import org.apache.shardingsphere.underlying.common.yaml.engine.constructor.ShardingSphereYamlConstruct;
import org.yaml.snakeyaml.nodes.Node;
/**
* YAML none sharding strategy configuration YAML construct.
*/
public final class NoneShardingStrategyConfigurationYAMLConstruct implements ShardingSphereYAMLConstruct {
public final class NoneShardingStrategyConfigurationYamlConstruct implements ShardingSphereYamlConstruct {
@Override
public Object construct(final Node node) {
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.sharding.yaml.representer.processor;
package org.apache.shardingsphere.sharding.yaml.engine.representer.processor;
import org.apache.shardingsphere.underlying.common.yaml.representer.processor.ShardingSphereYAMLTupleProcessor;
import org.apache.shardingsphere.underlying.common.yaml.engine.representer.processor.ShardingSphereYamlTupleProcessor;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.ScalarNode;
......@@ -26,7 +26,7 @@ import org.yaml.snakeyaml.nodes.Tag;
/**
* None YAML tuple processor.
*/
public final class NoneTupleProcessor implements ShardingSphereYAMLTupleProcessor {
public final class NoneYamlTupleProcessor implements ShardingSphereYamlTupleProcessor {
@Override
public String getTupleName() {
......
......@@ -132,7 +132,7 @@ public final class ConfigCenter {
}
}
YamlRootRuleConfigurations yamlRuleConfigurations = new YamlRootRuleConfigurations();
yamlRuleConfigurations.setRules(new YamlRuleConfigurationSwapperEngine().swapToYAMLConfigurations(configurations));
yamlRuleConfigurations.setRules(new YamlRuleConfigurationSwapperEngine().swapToYamlConfigurations(configurations));
repository.persist(node.getRulePath(shardingSchemaName), YamlEngine.marshal(yamlRuleConfigurations));
}
......
......@@ -44,7 +44,7 @@ public final class ConfigurationLogger {
*/
public static void log(final Collection<RuleConfiguration> ruleConfigurations) {
YamlRootRuleConfigurations yamlRuleConfigurations = new YamlRootRuleConfigurations();
yamlRuleConfigurations.setRules(new YamlRuleConfigurationSwapperEngine().swapToYAMLConfigurations(ruleConfigurations));
yamlRuleConfigurations.setRules(new YamlRuleConfigurationSwapperEngine().swapToYamlConfigurations(ruleConfigurations));
log("Rule configurations: ", YamlEngine.marshal(yamlRuleConfigurations));
}
......
......@@ -21,8 +21,8 @@ import com.google.common.base.Strings;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.underlying.common.yaml.config.YamlConfiguration;
import org.apache.shardingsphere.underlying.common.yaml.constructor.ShardingSphereYAMLConstructor;
import org.apache.shardingsphere.underlying.common.yaml.representer.ShardingSphereYAMLRepresenter;
import org.apache.shardingsphere.underlying.common.yaml.engine.constructor.ShardingSphereYamlConstructor;
import org.apache.shardingsphere.underlying.common.yaml.engine.representer.ShardingSphereYamlRepresenter;
import org.yaml.snakeyaml.Yaml;
import java.io.ByteArrayInputStream;
......@@ -55,7 +55,7 @@ public final class YamlEngine {
FileInputStream fileInputStream = new FileInputStream(yamlFile);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")
) {
return new Yaml(new ShardingSphereYAMLConstructor(classType)).loadAs(inputStreamReader, classType);
return new Yaml(new ShardingSphereYamlConstructor(classType)).loadAs(inputStreamReader, classType);
}
}
......@@ -70,7 +70,7 @@ public final class YamlEngine {
*/
public static <T extends YamlConfiguration> T unmarshal(final byte[] yamlBytes, final Class<T> classType) throws IOException {
try (InputStream inputStream = new ByteArrayInputStream(yamlBytes)) {
return new Yaml(new ShardingSphereYAMLConstructor(classType)).loadAs(inputStream, classType);
return new Yaml(new ShardingSphereYamlConstructor(classType)).loadAs(inputStream, classType);
}
}
......@@ -83,7 +83,7 @@ public final class YamlEngine {
* @return object from YAML
*/
public static <T> T unmarshal(final String yamlContent, final Class<T> classType) {
return new Yaml(new ShardingSphereYAMLConstructor(classType)).loadAs(yamlContent, classType);
return new Yaml(new ShardingSphereYamlConstructor(classType)).loadAs(yamlContent, classType);
}
/**
......@@ -113,6 +113,6 @@ public final class YamlEngine {
* @return YAML content
*/
public static String marshal(final Object value) {
return new Yaml(new ShardingSphereYAMLRepresenter()).dumpAsMap(value);
return new Yaml(new ShardingSphereYamlRepresenter()).dumpAsMap(value);
}
}
......@@ -15,14 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.constructor;
package org.apache.shardingsphere.underlying.common.yaml.engine.constructor;
import org.yaml.snakeyaml.constructor.Construct;
/**
* ShardingSphere YAML construct.
*/
public interface ShardingSphereYAMLConstruct extends Construct {
public interface ShardingSphereYamlConstruct extends Construct {
/**
* Get type.
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.constructor;
package org.apache.shardingsphere.underlying.common.yaml.engine.constructor;
import lombok.SneakyThrows;
import org.apache.shardingsphere.sharding.spi.ShardingSphereServiceLoader;
......@@ -31,19 +31,19 @@ import java.util.Map;
/**
* ShardingSphere YAML constructor.
*/
public final class ShardingSphereYAMLConstructor extends Constructor {
public final class ShardingSphereYamlConstructor extends Constructor {
static {
ShardingSphereServiceLoader.register(ShardingSphereYAMLConstruct.class);
ShardingSphereServiceLoader.register(ShardingSphereYamlConstruct.class);
}
private final Map<Class, Construct> typeConstructs = new HashMap<>();
@SneakyThrows
public ShardingSphereYAMLConstructor(final Class<?> rootClass) {
public ShardingSphereYamlConstructor(final Class<?> rootClass) {
super(rootClass);
ShardingSphereServiceLoader.newServiceInstances(ShardingSphereYAMLConstruct.class).forEach(each -> typeConstructs.put(each.getType(), each));
YamlRuleConfigurationSwapperEngine.getYAMLShortcuts().forEach((key, value) -> addTypeDescription(new TypeDescription(value, key)));
ShardingSphereServiceLoader.newServiceInstances(ShardingSphereYamlConstruct.class).forEach(each -> typeConstructs.put(each.getType(), each));
YamlRuleConfigurationSwapperEngine.getYamlShortcuts().forEach((key, value) -> addTypeDescription(new TypeDescription(value, key)));
}
@Override
......
......@@ -15,12 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.representer;
package org.apache.shardingsphere.underlying.common.yaml.engine.representer;
import lombok.SneakyThrows;
import org.apache.shardingsphere.sharding.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.underlying.common.yaml.representer.processor.DefaultYAMLTupleProcessor;
import org.apache.shardingsphere.underlying.common.yaml.representer.processor.ShardingSphereYAMLTupleProcessor;
import org.apache.shardingsphere.underlying.common.yaml.engine.representer.processor.DefaultYamlTupleProcessor;
import org.apache.shardingsphere.underlying.common.yaml.engine.representer.processor.ShardingSphereYamlTupleProcessor;
import org.apache.shardingsphere.underlying.common.yaml.swapper.YamlRuleConfigurationSwapperEngine;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.NodeTuple;
......@@ -30,25 +30,25 @@ import org.yaml.snakeyaml.representer.Representer;
/**
* ShardingSphere YAML representer.
*/
public final class ShardingSphereYAMLRepresenter extends Representer {
public final class ShardingSphereYamlRepresenter extends Representer {
static {
ShardingSphereServiceLoader.register(ShardingSphereYAMLTupleProcessor.class);
ShardingSphereServiceLoader.register(ShardingSphereYamlTupleProcessor.class);
}
@SneakyThrows
public ShardingSphereYAMLRepresenter() {
YamlRuleConfigurationSwapperEngine.getYAMLShortcuts().forEach((key, value) -> addClassTag(value, new Tag(key)));
public ShardingSphereYamlRepresenter() {
YamlRuleConfigurationSwapperEngine.getYamlShortcuts().forEach((key, value) -> addClassTag(value, new Tag(key)));
}
@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
for (ShardingSphereYAMLTupleProcessor each : ShardingSphereServiceLoader.newServiceInstances(ShardingSphereYAMLTupleProcessor.class)) {
for (ShardingSphereYamlTupleProcessor each : ShardingSphereServiceLoader.newServiceInstances(ShardingSphereYamlTupleProcessor.class)) {
if (property.getName().equals(each.getTupleName())) {
return each.process(nodeTuple);
}
}
return new DefaultYAMLTupleProcessor().process(nodeTuple);
return new DefaultYamlTupleProcessor().process(nodeTuple);
}
}
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.representer.processor;
package org.apache.shardingsphere.underlying.common.yaml.engine.representer.processor;
import org.yaml.snakeyaml.nodes.CollectionNode;
import org.yaml.snakeyaml.nodes.MappingNode;
......@@ -27,7 +27,7 @@ import org.yaml.snakeyaml.nodes.Tag;
/**
* Default YAML tuple processor.
*/
public final class DefaultYAMLTupleProcessor {
public final class DefaultYamlTupleProcessor {
/**
* Process node tuple.
......
......@@ -15,14 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.representer.processor;
package org.apache.shardingsphere.underlying.common.yaml.engine.representer.processor;
import org.yaml.snakeyaml.nodes.NodeTuple;
/**
* ShardingSphere YAML tuple processor.
*/
public interface ShardingSphereYAMLTupleProcessor {
public interface ShardingSphereYamlTupleProcessor {
/**
* Get tuple name.
......
......@@ -47,7 +47,7 @@ public final class YamlRuleConfigurationSwapperEngine {
* @return YAML rule configurations
*/
@SuppressWarnings("unchecked")
public Collection<YamlRuleConfiguration> swapToYAMLConfigurations(final Collection<RuleConfiguration> ruleConfigurations) {
public Collection<YamlRuleConfiguration> swapToYamlConfigurations(final Collection<RuleConfiguration> ruleConfigurations) {
Collection<YamlRuleConfiguration> result = new LinkedList<>();
for (Entry<RuleConfiguration, YamlRuleConfigurationSwapper> entry : OrderedSPIRegistry.getRegisteredServices(ruleConfigurations, YamlRuleConfigurationSwapper.class).entrySet()) {
result.add((YamlRuleConfiguration) entry.getValue().swap(entry.getKey()));
......@@ -88,7 +88,7 @@ public final class YamlRuleConfigurationSwapperEngine {
* @return YAML shortcuts
*/
@SneakyThrows
public static Map<String, Class<?>> getYAMLShortcuts() {
public static Map<String, Class<?>> getYamlShortcuts() {
Map<String, Class<?>> result = new HashMap<>();
for (YamlRuleConfigurationSwapper each : ShardingSphereServiceLoader.newServiceInstances(YamlRuleConfigurationSwapper.class)) {
Class<?> yamlRuleConfigurationClass = Class.forName(((ParameterizedType) each.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0].getTypeName());
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.constructor;
package org.apache.shardingsphere.underlying.common.yaml.engine.constructor;
import org.apache.shardingsphere.underlying.common.yaml.fixture.DefaultYamlRepresenterFixture;
import org.apache.shardingsphere.underlying.common.yaml.engine.fixture.DefaultYamlRepresenterFixture;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
......@@ -27,7 +27,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
public final class ShardingSphereYAMLConstructorTest {
public final class ShardingSphereYamlConstructorTest {
@Test
public void assertToObject() {
......@@ -40,7 +40,7 @@ public final class ShardingSphereYAMLConstructorTest {
+ " key2: value2\n"
+ "value: value\n"
+ "customClass:";
DefaultYamlRepresenterFixture actual = new Yaml(new ShardingSphereYAMLConstructor(DefaultYamlRepresenterFixture.class)).loadAs(yamlString, DefaultYamlRepresenterFixture.class);
DefaultYamlRepresenterFixture actual = new Yaml(new ShardingSphereYamlConstructor(DefaultYamlRepresenterFixture.class)).loadAs(yamlString, DefaultYamlRepresenterFixture.class);
assertThat(actual.getValue(), is("value"));
assertThat(actual.getCollection().size(), is(2));
Iterator<String> iterator = actual.getCollection().iterator();
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.fixture;
package org.apache.shardingsphere.underlying.common.yaml.engine.fixture;
import lombok.Getter;
import lombok.Setter;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.fixture;
package org.apache.shardingsphere.underlying.common.yaml.engine.fixture;
public final class FixtureCustomClass {
}
......@@ -15,12 +15,12 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.fixture;
package org.apache.shardingsphere.underlying.common.yaml.engine.fixture;
import org.apache.shardingsphere.underlying.common.yaml.constructor.ShardingSphereYAMLConstruct;
import org.apache.shardingsphere.underlying.common.yaml.engine.constructor.ShardingSphereYamlConstruct;
import org.yaml.snakeyaml.nodes.Node;
public final class FixtureTypeConstructor implements ShardingSphereYAMLConstruct {
public final class FixtureShardingSphereYamlConstruct implements ShardingSphereYamlConstruct {
@Override
public Object construct(final Node node) {
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package org.apache.shardingsphere.underlying.common.yaml.representer;
package org.apache.shardingsphere.underlying.common.yaml.engine.representer;
import org.apache.shardingsphere.underlying.common.yaml.fixture.DefaultYamlRepresenterFixture;
import org.apache.shardingsphere.underlying.common.yaml.engine.fixture.DefaultYamlRepresenterFixture;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
......@@ -30,12 +30,12 @@ import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public final class ShardingSphereYAMLRepresenterTest {
public final class ShardingSphereYamlRepresenterTest {
@Test
public void assertToYamlWithNull() {
DefaultYamlRepresenterFixture actual = new DefaultYamlRepresenterFixture();
assertThat(new Yaml(new ShardingSphereYAMLRepresenter()).dumpAsMap(actual), is("{}\n"));
assertThat(new Yaml(new ShardingSphereYamlRepresenter()).dumpAsMap(actual), is("{}\n"));
}
@Test
......@@ -44,7 +44,7 @@ public final class ShardingSphereYAMLRepresenterTest {
actual.setValue("");
actual.setCollection(Collections.emptyList());
actual.setMap(Collections.emptyMap());
assertThat(new Yaml(new ShardingSphereYAMLRepresenter()).dumpAsMap(actual), is("value: ''\n"));
assertThat(new Yaml(new ShardingSphereYamlRepresenter()).dumpAsMap(actual), is("value: ''\n"));
}
@Test
......@@ -56,7 +56,7 @@ public final class ShardingSphereYAMLRepresenterTest {
map.put("key1", "value1");
map.put("key2", "value2");
actual.setMap(map);
String expected = new Yaml(new ShardingSphereYAMLRepresenter()).dumpAsMap(actual);
String expected = new Yaml(new ShardingSphereYamlRepresenter()).dumpAsMap(actual);
assertThat(expected, containsString("collection:\n- value1\n- value2\n"));
assertThat(expected, containsString("map:\n key1: value1\n key2: value2\n"));
assertThat(expected, containsString("value: value\n"));
......
......@@ -15,4 +15,4 @@
# limitations under the License.
#
org.apache.shardingsphere.sharding.yaml.construct.NoneShardingStrategyConfigurationYAMLConstruct
org.apache.shardingsphere.underlying.common.yaml.engine.fixture.FixtureShardingSphereYamlConstruct
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册