Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade snakeyaml to 2.0 #24636

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public static String marshal(final Object value) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setLineBreak(DumperOptions.LineBreak.getPlatformLineBreak());
if (value instanceof Collection) {
return new Yaml(new ShardingSphereYamlRepresenter(), dumperOptions).dumpAs(value, null, DumperOptions.FlowStyle.BLOCK);
return new Yaml(new ShardingSphereYamlRepresenter(dumperOptions), dumperOptions).dumpAs(value, null, DumperOptions.FlowStyle.BLOCK);
}
return new Yaml(new ShardingSphereYamlRepresenter(), dumperOptions).dumpAsMap(value);
return new Yaml(new ShardingSphereYamlRepresenter(dumperOptions), dumperOptions).dumpAsMap(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
*/
public final class ShardingSphereYamlRepresenter extends Representer {

public ShardingSphereYamlRepresenter() {
public ShardingSphereYamlRepresenter(final DumperOptions dumperOptions) {
super(dumperOptions);
Map<String, Class<?>> yamlShortcuts = new HashMap<>();
ShardingSphereServiceLoader.getServiceInstances(ShardingSphereYamlShortcuts.class).stream().map(ShardingSphereYamlShortcuts::getYamlShortcuts).forEach(yamlShortcuts::putAll);
yamlShortcuts.forEach((key, value) -> addClassTag(value, new Tag(key)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.apache.shardingsphere.infra.util.yaml.fixture.shortcuts.YamlShortcutsConfigurationFixture;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.constructor.ConstructorException;
import org.yaml.snakeyaml.composer.ComposerException;

import java.io.BufferedReader;
import java.io.File;
Expand Down Expand Up @@ -101,7 +101,7 @@ void assertUnmarshalInvalidYaml() throws IOException {
yamlContent.append(line).append(System.lineSeparator());
}
}
assertThrows(ConstructorException.class, () -> YamlEngine.unmarshal(yamlContent.toString(), Object.class));
assertThrows(ComposerException.class, () -> YamlEngine.unmarshal(yamlContent.toString(), Object.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.shardingsphere.infra.util.yaml.fixture.pojo.YamlConfigurationFixture;
import org.junit.jupiter.api.Test;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.ConstructorException;
import org.yaml.snakeyaml.composer.ComposerException;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -53,7 +53,7 @@ private void assertYamlObject(final YamlConfigurationFixture actual) {
@Test
void assertToObjectWithNotAcceptClass() throws IOException {
try (InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("yaml/accepted-class.yaml")) {
assertThrows(ConstructorException.class, () -> new Yaml(new ShardingSphereYamlConstructor(Object.class)).loadAs(inputStream, Object.class));
assertThrows(ComposerException.class, () -> new Yaml(new ShardingSphereYamlConstructor(Object.class)).loadAs(inputStream, Object.class));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class ShardingSphereYamlRepresenterTest {
@Test
void assertToYamlWithoutContent() {
YamlConfigurationFixture actual = new YamlConfigurationFixture();
assertThat(new Yaml(new ShardingSphereYamlRepresenter(), new DumperOptions()).dumpAsMap(actual), is("{}\n"));
DumperOptions dumperOptions = new DumperOptions();
assertThat(new Yaml(new ShardingSphereYamlRepresenter(dumperOptions), dumperOptions).dumpAsMap(actual), is("{}\n"));
}

@Test
Expand All @@ -53,7 +54,8 @@ void assertToYamlWithAllContents() {
actual.getEmbeddedMap().put("embedded_map_1", new LinkedHashMap<>());
actual.getEmbeddedMap().put("embedded_map_2", Collections.singletonMap("embedded_map_foo", "embedded_map_foo_value"));
actual.setCustomizedTag("customized_tag");
String expected = new Yaml(new ShardingSphereYamlRepresenter(), new DumperOptions()).dumpAsMap(actual);
DumperOptions dumperOptions = new DumperOptions();
String expected = new Yaml(new ShardingSphereYamlRepresenter(dumperOptions), dumperOptions).dumpAsMap(actual);
assertThat(expected, containsString("collection:\n- value1\n- value2\n"));
assertThat(expected, containsString("map:\n key1: value1\n key2: value2\n"));
assertThat(expected, not(containsString("embedded_map_1")));
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<transmittable-thread-local.version>2.14.2</transmittable-thread-local.version>

<antlr4.version>4.10.1</antlr4.version>
<snakeyaml.version>1.33</snakeyaml.version>
<snakeyaml.version>2.0</snakeyaml.version>
<gson.version>2.9.1</gson.version>
<jackson.version>2.14.0</jackson.version>
<groovy.version>4.0.10</groovy.version>
Expand Down