-
-
Notifications
You must be signed in to change notification settings - Fork 80
Add DataFixerUpper v7 support #572
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
Conversation
zml2008
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few surface-level things to look at, will look more as I have time
extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/package-info.java
Outdated
Show resolved
Hide resolved
|
not sure why ci build fails? I can't reproduce |
|
https://github.com/KyoriPowered/indra/wiki/indra#javaversions - cross-version testing only automatically runs on CI. And what do you think would happen if you tried to test a J17 module on J11 anyways? You should be able to access the test versions property on the indra extension as documented and remove older target versions. |
|
For anyone curious, diff of the v4 vs v7 modules: v4 vs v7 diffdiff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/CodecSerializer.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/CodecSerializer.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/CodecSerializer.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/CodecSerializer.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -24,6 +24,8 @@
import com.mojang.serialization.DynamicOps;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.serialize.TypeSerializer;
@@ -36,7 +38,7 @@
*/
final class CodecSerializer<V> implements TypeSerializer<V> {
- private static final LogWrapper LOGGER = LogWrapper.logger(CodecSerializer.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(CodecSerializer.class);
private static final ConfigurateOps DEFAULT_OPS = ConfigurateOps.builder().readWriteProtection(ConfigurateOps.Protection.NONE).build();
static DynamicOps<ConfigurationNode> opsFor(final ConfigurationNode node) {
@@ -59,7 +61,7 @@
@Override
public V deserialize(final @NonNull Type type, final @NonNull ConfigurationNode value) throws SerializationException {
final DataResult<Pair<V, ConfigurationNode>> result = this.codec.decode(opsFor(value), value);
- final DataResult./* @Nullable */ PartialResult<Pair<V, ConfigurationNode>> error = result.error().orElse(null);
+ final DataResult./* @Nullable */ Error<Pair<V, ConfigurationNode>> error = result.error().orElse(null);
if (error != null) {
LOGGER.debug("Unable to decode value using {} due to {}", this.codec, error.message());
throw new SerializationException(error.message());
@@ -71,7 +73,7 @@
public void serialize(final @NonNull Type type, final @Nullable V obj, final @NonNull ConfigurationNode value)
throws SerializationException {
final DataResult<ConfigurationNode> result = this.codec.encode(obj, opsFor(value), value);
- final DataResult./* @Nullable */ PartialResult<ConfigurationNode> error = result.error().orElse(null);
+ final DataResult./* @Nullable */ Error<ConfigurationNode> error = result.error().orElse(null);
if (error != null) {
LOGGER.debug("Unable to encode value using {} due to {}", this.codec, error.message());
throw new SerializationException(error.message());
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/ConfigurateOps.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/ConfigurateOps.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/ConfigurateOps.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/ConfigurateOps.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -92,7 +92,7 @@
* or (by default impl) a list of longs</dd>
* </dl>
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public final class ConfigurateOps implements DynamicOps<ConfigurationNode> {
@@ -109,7 +109,7 @@
* the default factory. The returned instance will not be compressed
*
* @return the shared instance
- * @since 4.0.0
+ * @since 4.3.0
*/
public static DynamicOps<ConfigurationNode> instance() {
return instance(false);
@@ -125,7 +125,7 @@
* @param compressed whether keys should be compressed in the output of
* this serializer
* @return the shared instance
- * @since 4.0.0
+ * @since 4.3.0
*/
public static DynamicOps<ConfigurationNode> instance(final boolean compressed) {
return compressed ? COMPRESSED : UNCOMPRESSED;
@@ -136,7 +136,7 @@
*
* @param collection collection to provide through created nodes' options
* @return ops instance
- * @since 4.0.0
+ * @since 4.3.0
*/
public static DynamicOps<ConfigurationNode> forSerializers(final TypeSerializerCollection collection) {
if (requireNonNull(collection, "collection").equals(TypeSerializerCollection.defaults())) {
@@ -153,7 +153,7 @@
*
* @param node the node to wrap
* @return a wrapped node
- * @since 4.0.0
+ * @since 4.3.0
*/
public static Dynamic<ConfigurationNode> wrap(final ConfigurationNode node) {
if (node.options().serializers().equals(TypeSerializerCollection.defaults())) {
@@ -168,7 +168,7 @@
*
* @param value the value type
* @return values
- * @since 4.0.0
+ * @since 4.3.0
*/
public static DynamicOps<ConfigurationNode> fromNode(final ConfigurationNode value) {
return builder().factoryFromNode(value).build();
@@ -178,7 +178,7 @@
* Create a new builder for an ops instance.
*
* @return builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public static ConfigurateOpsBuilder builder() {
return new ConfigurateOpsBuilder();
@@ -363,13 +363,13 @@
if (compressMaps()) {
final int result = input.getInt(Integer.MIN_VALUE);
if (result == Integer.MIN_VALUE) {
- return DataResult.error("Value is not a number");
+ return DataResult.error(() -> "Value is not a number");
}
return DataResult.success(result);
}
}
- return DataResult.error("Not a number: " + input);
+ return DataResult.error(() -> "Not a number: " + input);
}
/**
@@ -386,7 +386,7 @@
return DataResult.success(value);
}
- return DataResult.error("Not a string: " + input);
+ return DataResult.error(() -> "Not a string: " + input);
}
/**
@@ -436,7 +436,7 @@
@Override
public DataResult<ConfigurationNode> mergeToPrimitive(final ConfigurationNode prefix, final ConfigurationNode value) {
if (!prefix.empty()) {
- return DataResult.error("Cannot merge " + value + " into non-empty node " + prefix);
+ return DataResult.error(() -> "Cannot merge " + value + " into non-empty node " + prefix);
}
return DataResult.success(guardOutputRead(value));
}
@@ -457,7 +457,7 @@
return DataResult.success(ret);
}
- return DataResult.error("mergeToList called on a node which is not a list: " + input, input);
+ return DataResult.error(() -> "mergeToList called on a node which is not a list: " + input, input);
}
/**
@@ -478,7 +478,7 @@
return DataResult.success(ret);
}
- return DataResult.error("mergeToList called on a node which is not a list: " + input, input);
+ return DataResult.error(() -> "mergeToList called on a node which is not a list: " + input, input);
}
/**
@@ -500,7 +500,7 @@
return DataResult.success(copied);
}
- return DataResult.error("mergeToMap called on a node which is not a map: " + input, input);
+ return DataResult.error(() -> "mergeToMap called on a node which is not a map: " + input, input);
}
/**
@@ -521,7 +521,7 @@
guardOutputRead(entry.getValue()))));
}
- return DataResult.error("Not a map: " + input);
+ return DataResult.error(() -> "Not a map: " + input);
}
/**
@@ -538,7 +538,7 @@
if (input.empty() || input.isMap()) {
return DataResult.success(new NodeMaplike(this, input.options(), input.childrenMap()));
} else {
- return DataResult.error("Input node is not a map");
+ return DataResult.error(() -> "Input node is not a map");
}
}
@@ -566,7 +566,7 @@
}
});
} else {
- return DataResult.error("Input node is not a list");
+ return DataResult.error(() -> "Input node is not a list");
}
}
@@ -583,7 +583,7 @@
return DataResult.success(stream);
}
- return DataResult.error("Not a list: " + input);
+ return DataResult.error(() -> "Not a list: " + input);
}
/**
@@ -672,7 +672,7 @@
@Override
public DataResult<ConfigurationNode> get(final ConfigurationNode input, final String key) {
final ConfigurationNode ret = input.node(key);
- return ret.virtual() ? DataResult.error("No element " + key + " in the map " + input) : DataResult.success(guardOutputRead(ret));
+ return ret.virtual() ? DataResult.error(() -> "No element " + key + " in the map " + input) : DataResult.success(guardOutputRead(ret));
}
/**
@@ -689,7 +689,7 @@
@Override
public DataResult<ConfigurationNode> getGeneric(final ConfigurationNode input, final ConfigurationNode key) {
final ConfigurationNode ret = input.node(keyFrom(key));
- return ret.virtual() ? DataResult.error("No element " + key + " in the map " + input) : DataResult.success(guardOutputRead(ret));
+ return ret.virtual() ? DataResult.error(() -> "No element " + key + " in the map " + input) : DataResult.success(guardOutputRead(ret));
}
/**
@@ -773,7 +773,7 @@
/**
* Protection level for configuration node accesses through ops instance.
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public enum Protection {
/**
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/ConfigurateOpsBuilder.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/ConfigurateOpsBuilder.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/ConfigurateOpsBuilder.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/ConfigurateOpsBuilder.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -28,7 +28,7 @@
/**
* A builder for {@link ConfigurateOps} instances.
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public final class ConfigurateOpsBuilder {
@@ -48,7 +48,7 @@
* @param supplier source for new nodes created to store values in
* the {@code create*} methods
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder factory(final ConfigurationNodeFactory<? extends ConfigurationNode> supplier) {
this.nodeSupplier = requireNonNull(supplier, "nodeSupplier");
@@ -62,7 +62,7 @@
*
* @param collection type serializers to use for nodes.
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder factoryFromSerializers(final TypeSerializerCollection collection) {
requireNonNull(collection, "collection");
@@ -76,7 +76,7 @@
*
* @param node node to use
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder factoryFromNode(final ConfigurationNode node) {
final ConfigurationOptions options = requireNonNull(node, "node").options();
@@ -98,7 +98,7 @@
* @param compressed whether to compress values
* @return this builder
* @see ConfigurateOps#compressMaps() for more about what compression is
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder compressed(final boolean compressed) {
this.compressed = compressed;
@@ -115,7 +115,7 @@
*
* @param readProtection protection level
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder readProtection(final ConfigurateOps.Protection readProtection) {
this.readProtection = requireNonNull(readProtection, "readProtection");
@@ -132,7 +132,7 @@
*
* @param writeProtection protection level
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder writeProtection(final ConfigurateOps.Protection writeProtection) {
this.writeProtection = requireNonNull(writeProtection, "writeProtection");
@@ -148,7 +148,7 @@
* affects value reads
* @see #writeProtection(ConfigurateOps.Protection) for how this level
* affects value writes
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOpsBuilder readWriteProtection(final ConfigurateOps.Protection protection) {
requireNonNull(protection, "protection");
@@ -165,7 +165,7 @@
* valid state.
*
* @return the new instance
- * @since 4.0.0
+ * @since 4.3.0
*/
public ConfigurateOps build() {
return new ConfigurateOps(this.nodeSupplier, this.compressed, this.readProtection, this.writeProtection);
@@ -179,7 +179,7 @@
*
* @param node wrapped node
* @return new dynamic
- * @since 4.0.0
+ * @since 4.3.0
*/
public Dynamic<ConfigurationNode> buildWrapping(final ConfigurationNode node) {
return new Dynamic<>(build(), node);
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/DataFixerTransformation.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/DataFixerTransformation.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/DataFixerTransformation.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/DataFixerTransformation.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -40,7 +40,7 @@
* transformation works by explicitly providing a mapping between configurate
* node paths and DFU TypeReferences.</p>
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public final class DataFixerTransformation implements ConfigurationTransformation.Versioned {
@@ -53,7 +53,7 @@
* Create a builder that can work with any DFU DataFixer.
*
* @return the builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public static Builder dfuBuilder() {
return new Builder();
@@ -106,7 +106,7 @@
/**
* Builder for {@link DataFixerTransformation}.
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public static class Builder {
private NodePath versionPath = NodePath.path("dfu-version");
@@ -119,7 +119,7 @@
*
* @param fixer the fixer
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder dataFixer(final DataFixer fixer) {
this.fixer = requireNonNull(fixer);
@@ -132,7 +132,7 @@
*
* @param path the path
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder versionKey(final Object... path) {
this.versionPath = NodePath.of(requireNonNull(path, "path"));
@@ -145,7 +145,7 @@
*
* @param path the path
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder versionKey(final NodePath path) {
this.versionPath = requireNonNull(path, "path");
@@ -158,7 +158,7 @@
*
* @param targetVersion target version
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder targetVersion(final int targetVersion) {
this.targetVersion = targetVersion;
@@ -171,7 +171,7 @@
* @param type value type reference
* @param path target path
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder addType(final DSL.TypeReference type, final Object... path) {
return this.addType(type, NodePath.of(path));
@@ -183,7 +183,7 @@
* @param type value type reference
* @param path target path
* @return this builder
- * @since 4.0.0
+ * @since 4.3.0
*/
public Builder addType(final DSL.TypeReference type, final NodePath path) {
this.dataFixes.add(Pair.of(type, path));
@@ -194,7 +194,7 @@
* Create a new transformation based on the provided info.
*
* @return new transformation
- * @since 4.0.0
+ * @since 4.3.0
*/
public DataFixerTransformation build() {
requireNonNull(this.fixer, "A fixer must be provided!");
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/DfuSerializers.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/DfuSerializers.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/DfuSerializers.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/DfuSerializers.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -28,7 +28,7 @@
/**
* A bridge between Configurate and DataFixerUpper serialization types.
*
- * @since 4.0.0
+ * @since 4.3.0
*/
public final class DfuSerializers {
@@ -41,7 +41,7 @@
* @param codec codec to use for the serialization operation
* @param <V> value type
* @return a new serializer
- * @since 4.0.0
+ * @since 4.3.0
*/
public static <V> TypeSerializer<V> serializer(final Codec<V> codec) {
return new CodecSerializer<>(requireNonNull(codec, "codec"));
@@ -55,7 +55,7 @@
* @param <S> value type
* @return a codec for the type, or null if an appropriate
* {@link TypeSerializer} could not be found.
- * @since 4.0.0
+ * @since 4.3.0
*/
public static <S> @Nullable Codec<S> codec(final TypeToken<S> type) {
return codec(requireNonNull(type, "type"), TypeSerializerCollection.defaults());
@@ -69,7 +69,7 @@
* @param <V> value type
* @return a codec, or null if an appropriate {@link TypeSerializer}
* could not be found for the TypeToken.
- * @since 4.0.0
+ * @since 4.3.0
*/
public static <V> @Nullable Codec<V> codec(final TypeToken<V> type, final TypeSerializerCollection collection) {
final @Nullable TypeSerializer<V> serial = collection.get(requireNonNull(type, "type"));
Only in extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4: LogWrapper.java
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/NodeMaplike.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/NodeMaplike.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/NodeMaplike.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/NodeMaplike.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.MapLike;
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/TypeSerializerCodec.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/TypeSerializerCodec.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/TypeSerializerCodec.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/TypeSerializerCodec.java 2025-06-01 11:53:47
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import static java.util.Objects.requireNonNull;
@@ -23,13 +23,15 @@
import com.mojang.serialization.DataResult;
import com.mojang.serialization.DynamicOps;
import io.leangen.geantyref.TypeToken;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.serialize.TypeSerializer;
final class TypeSerializerCodec<V> implements Codec<V> {
- private static final LogWrapper LOGGER = LogWrapper.logger(TypeSerializerCodec.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(TypeSerializerCodec.class);
private final TypeToken<V> token;
private final TypeSerializer<V> serializer;
@@ -59,8 +61,8 @@
try {
return DataResult.success(Pair.of(this.serializer.deserialize(this.token.getType(), node), holder));
} catch (final SerializationException ex) {
- LOGGER.debug(() -> "Error decoding value of type " + this.token, ex);
- return DataResult.error(ex.getMessage());
+ LOGGER.debug("Error decoding value of type {}", this.token, ex);
+ return DataResult.error(ex::getMessage);
}
}
@@ -83,8 +85,8 @@
}
}
} catch (final SerializationException ex) {
- LOGGER.debug(() -> "Error encoding value of type " + this.token, ex);
- return DataResult.error(ex.getMessage());
+ LOGGER.debug("Error encoding value of type {}", this.token, ex);
+ return DataResult.error(ex::getMessage);
}
}
diff -ur extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/package-info.java extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/package-info.java
--- extra/dfu4/src/main/java/org/spongepowered/configurate/extra/dfu/v4/package-info.java 2023-04-25 21:00:14
+++ extra/dfu7/src/main/java/org/spongepowered/configurate/extra/dfu/v7/package-info.java 2025-06-01 11:53:47
@@ -17,13 +17,13 @@
/**
* Implementation of DataFixerUpper interfaces for Configurate types.
*
- * <p>This version of DataFixerUpper is used in Minecraft 1.16.2 onwards.</p>
+ * <p>This version of DataFixerUpper is used in Minecraft 1.20.6 onwards.</p>
*
- * <p>This module is also compatible with DataFixerUpper v5, since
+ * <p>This module is also compatible with DataFixerUpper v8, since
* there were no major API changes.</p>
*/
@DefaultQualifier(NonNull.class)
-package org.spongepowered.configurate.extra.dfu.v4;
+package org.spongepowered.configurate.extra.dfu.v7;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier; |
* Initial DataFixerUpper v7 support * use sfl4j `Logger` directly in DFU 7 module * Resolve changes requests * Filter older versions than target for tests
based on
extra-dfu4module