Skip to content

Commit 0ece4c2

Browse files
committed
yaml: Rewrite using event-based loading and saving
This allows us to capture more information as representation hints and to precisely control the output. We can also read comments events to properly round-trip comments in configuration files
1 parent 5695117 commit 0ece4c2

File tree

38 files changed

+5308
-149
lines changed

38 files changed

+5308
-149
lines changed

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.gradle.ext.ActionDelegationConfig
2+
13
import static org.eclipse.jgit.lib.Repository.shortenRefName
24

35
plugins {
@@ -8,10 +10,18 @@ plugins {
810
alias(libs.plugins.indra.sonatype)
911
alias(libs.plugins.indra.git)
1012
alias(libs.plugins.gitPublish)
13+
alias(libs.plugins.ideaExt)
1114
id 'java-base'
1215
id 'org.spongepowered.configurate.build.base'
1316
}
1417

18+
idea.project.settings {
19+
delegateActions {
20+
delegateBuildRunToGradle = false
21+
testRunner = ActionDelegationConfig.TestRunner.PLATFORM
22+
}
23+
}
24+
1525
tasks.named('aggregateJavadoc').configure {
1626
def gradleJdk = JavaVersion.current()
1727
// at least java 11, but not 12 (java 12 is broken for some reason :( )

core/src/main/java/org/spongepowered/configurate/util/UnmodifiableCollections.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private UnmodifiableCollections() {}
4848
*
4949
* @since 4.0.0
5050
*/
51-
public static <E> List<E> copyOf(final List<E> original) {
51+
public static <E> List<E> copyOf(final List<? extends E> original) {
5252
switch (original.size()) {
5353
case 0:
5454
return Collections.emptyList();
@@ -67,7 +67,7 @@ public static <E> List<E> copyOf(final List<E> original) {
6767
* @return a unmodifiable copy of the given {@link Set} instance
6868
* @since 4.0.0
6969
*/
70-
public static <E> Set<E> copyOf(final Set<E> original) {
70+
public static <E> Set<E> copyOf(final Set<? extends E> original) {
7171
switch (original.size()) {
7272
case 0:
7373
return Collections.emptySet();
@@ -87,12 +87,12 @@ public static <E> Set<E> copyOf(final Set<E> original) {
8787
* @return an unmodifiable copy of the given {@link Map} instance.
8888
* @since 4.1.0
8989
*/
90-
public static <K, V> Map<K, V> copyOf(final Map<K, V> original) {
90+
public static <K, V> Map<K, V> copyOf(final Map<? extends K, ? extends V> original) {
9191
switch (original.size()) {
9292
case 0:
9393
return Collections.emptyMap();
9494
case 1:
95-
final Map.Entry<K, V> entry = original.entrySet().iterator().next();
95+
final Map.Entry<? extends K, ? extends V> entry = original.entrySet().iterator().next();
9696
return Collections.singletonMap(entry.getKey(), entry.getValue());
9797
default:
9898
if (original instanceof LinkedHashMap<?, ?>) {

core/src/main/java10/org/spongepowered/configurate/util/UnmodifiableCollections.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private UnmodifiableCollections() {}
4242
* @return a unmodifiable copy of the given {@link List} instance
4343
* @since 4.0.0
4444
*/
45-
public static <E> List<E> copyOf(final List<E> original) {
45+
public static <E> List<E> copyOf(final List<? extends E> original) {
4646
return List.copyOf(original);
4747
}
4848

@@ -54,7 +54,7 @@ public static <E> List<E> copyOf(final List<E> original) {
5454
* @return a unmodifiable copy of the given {@link Set} instance
5555
* @since 4.0.0
5656
*/
57-
public static <E> Set<E> copyOf(final Set<E> original) {
57+
public static <E> Set<E> copyOf(final Set<? extends E> original) {
5858
return Set.copyOf(original);
5959
}
6060

extra/groovy/build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
plugins {
2+
id 'org.spongepowered.configurate.build.component'
3+
id 'groovy'
4+
}
5+
6+
tasks.processResources {
7+
inputs.property("version", project.version)
8+
expand version: project.version
9+
}
10+
11+
dependencies {
12+
api projects.core
13+
14+
[
15+
libs.groovy,
16+
libs.groovy.nio
17+
].each {
18+
implementation variantOf(it) { classifier('indy') }
19+
}
20+
21+
testImplementation variantOf(libs.groovy.test) { classifier('indy') }
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Configurate
3+
* Copyright (C) zml and Configurate contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.spongepowered.configurate.extra.groovy
18+
19+
import org.spongepowered.configurate.ScopedConfigurationNode;
20+
21+
class ConfigurationNodeExtensions {
22+
23+
static <N extends ScopedConfigurationNode<N>> N getAt(final ScopedConfigurationNode<N> self, Iterable<?> path) {
24+
return self.node(path)
25+
}
26+
27+
static <N extends ScopedConfigurationNode<N>> N getAt(final ScopedConfigurationNode<N> self, Object... path) {
28+
return self.node(path)
29+
}
30+
31+
static <N extends ScopedConfigurationNode<N>> boolean isCase(final ScopedConfigurationNode<N> self, Iterable<?> path) {
32+
return self.hasChild(path)
33+
}
34+
35+
static <N extends ScopedConfigurationNode<N>> boolean isCase(final ScopedConfigurationNode<N> self, Object... path) {
36+
return self.hasChild(path)
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Configurate
3+
* Copyright (C) zml and Configurate contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.spongepowered.configurate.extra.groovy
18+
19+
import org.spongepowered.configurate.ConfigurationNode
20+
import org.spongepowered.configurate.serialize.SerializationException
21+
import org.spongepowered.configurate.serialize.TypeSerializer
22+
23+
import java.lang.reflect.Type;
24+
25+
class GStringTypeSerializer implements TypeSerializer<GString> {
26+
27+
@Override
28+
GString deserialize(final Type type, final ConfigurationNode node) throws SerializationException {
29+
return GString.
30+
return null;
31+
}
32+
33+
@Override
34+
public void serialize(
35+
final Type type, final GString obj, final ConfigurationNode node) throws SerializationException {
36+
37+
}
38+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Configurate
3+
* Copyright (C) zml and Configurate contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.spongepowered.configurate.extra.groovy
18+
19+
import io.leangen.geantyref.GenericTypeReflector
20+
import org.spongepowered.configurate.objectmapping.FieldDiscoverer
21+
import org.spongepowered.configurate.serialize.SerializationException
22+
23+
import java.lang.reflect.AnnotatedType
24+
import java.lang.reflect.Field
25+
26+
class POGOFieldDiscoverer implements FieldDiscoverer<Map<String, Field>> {
27+
28+
@Override
29+
def <V> InstanceFactory<Map<String, Field>> discover(final AnnotatedType target, final FieldCollector<Map<String, Field>, V> collector)
30+
throws SerializationException {
31+
def clazz = GenericTypeReflector.erase(target.type)
32+
clazz.metaClass.properties
33+
}
34+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
moduleName=Extensions to configurate for compatibility with the Groovy environment
2+
moduleVersion=${version}
3+
extensionClasses=org.spongepowered.configurate.extra.groovy.ConfigurationNodeExtensions
4+
staticExtensionClasses=
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Configurate
3+
* Copyright (C) zml and Configurate contributors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.spongepowered.configurate.extra.groovy
18+
19+
import org.junit.jupiter.api.Test
20+
21+
class PogoFieldDiscovererTest {
22+
23+
@Test
24+
void testPogoFieldDiscoverer() {
25+
26+
}
27+
}

format/yaml/build.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'org.spongepowered.configurate.build.component'
33
alias(libs.plugins.shadow)
4+
id 'groovy' // for tests
45
}
56

67
description = "YAML format loader for Configurate"
@@ -12,9 +13,19 @@ configurations {
1213
testImplementation { extendsFrom shaded }
1314
}
1415

16+
configurate.useAutoValue()
1517
dependencies {
1618
api projects.core
1719
shaded "configurate.thirdparty:snakeyaml:version-from-submodule"
20+
21+
[
22+
libs.groovy,
23+
libs.groovy.nio,
24+
libs.groovy.test.junit5,
25+
libs.groovy.templates
26+
].each {
27+
testImplementation it
28+
}
1829
}
1930

2031
tasks {

format/yaml/src/main/java/org/spongepowered/configurate/yaml/NodeStyle.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,17 @@ static DumperOptions.FlowStyle asSnakeYaml(final @Nullable NodeStyle style) {
4747
return style == null ? DumperOptions.FlowStyle.AUTO : style.snake;
4848
}
4949

50+
static @Nullable NodeStyle fromSnakeYaml(final DumperOptions.FlowStyle style) {
51+
switch (style) {
52+
case AUTO:
53+
return null;
54+
case BLOCK:
55+
return BLOCK;
56+
case FLOW:
57+
return FLOW;
58+
default:
59+
throw new IllegalArgumentException("Unknown style " + style);
60+
}
61+
}
62+
5063
}

0 commit comments

Comments
 (0)