Skip to content

Commit

Permalink
Update for stable release of Configurate 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 committed Nov 15, 2020
1 parent d618236 commit ac5124f
Show file tree
Hide file tree
Showing 24 changed files with 79 additions and 77 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ dependencies {
applaunchConfig("org.spongepowered:plugin-spi:$pluginSpiVersion")
applaunchConfig("org.apache.logging.log4j:log4j-api:2.11.2")
applaunchConfig("com.google.guava:guava:$guavaVersion")
applaunchConfig(platform("org.spongepowered:configurate-bom:4.0.0-SNAPSHOT"))
applaunchConfig(platform("org.spongepowered:configurate-bom:4.0.0"))
applaunchConfig("org.spongepowered:configurate-core") {
exclude(group = "org.checkerframework", module = "checker-qual") // We use our own version
}
Expand Down Expand Up @@ -560,8 +560,8 @@ project("SpongeVanilla") {
add(vanillaLaunch.implementationConfigurationName, vanillaMinecraftConfig)

vanillaInstallerConfig("com.google.code.gson:gson:2.8.0")
vanillaInstallerConfig("org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT")
vanillaInstallerConfig("org.spongepowered:configurate-core:4.0.0-SNAPSHOT")
vanillaInstallerConfig("org.spongepowered:configurate-hocon:4.0.0")
vanillaInstallerConfig("org.spongepowered:configurate-core:4.0.0")
vanillaInstallerConfig("net.sf.jopt-simple:jopt-simple:5.0.3")
vanillaInstallerConfig("org.apache.logging.log4j:log4j-api:2.11.2")
vanillaInstallerConfig("org.apache.logging.log4j:log4j-core:2.11.2")
Expand All @@ -581,7 +581,7 @@ project("SpongeVanilla") {
vanillaAppLaunchConfig("org.apache.logging.log4j:log4j-core:2.11.2")
vanillaAppLaunchConfig("com.zaxxer:HikariCP:2.6.3")
vanillaAppLaunchConfig("org.apache.logging.log4j:log4j-slf4j-impl:2.11.2")
vanillaAppLaunchConfig(platform("org.spongepowered:configurate-bom:4.0.0-SNAPSHOT"))
vanillaAppLaunchConfig(platform("org.spongepowered:configurate-bom:4.0.0"))
vanillaAppLaunchConfig("org.spongepowered:configurate-core") {
exclude(group = "org.checkerframework", module = "checker-qual")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.serialize.SerializationException;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* dimension-specific configurations, each which only need to contain values that are different to the ones in their parent. By visiting each
* configuration before it's saved, any unnecessary values can be removed.
*/
class DuplicateRemovalVisitor implements ConfigurationVisitor.Safe<AtomicReference<ConfigurationNode>, Void> {
final class DuplicateRemovalVisitor implements ConfigurationVisitor.Safe<AtomicReference<ConfigurationNode>, Void> {
private static final DuplicateRemovalVisitor INSTANCE = new DuplicateRemovalVisitor();

private DuplicateRemovalVisitor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
import com.google.common.collect.ImmutableSet;
import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.loader.ConfigurationLoader;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.spongepowered.configurate.transformation.NodePath;

import java.util.Set;

/**
* A transformation that moves a set of entries from the loaded file into another file.
*/
public class FileMovingConfigurationTransformation implements ConfigurationTransformation {
public final class FileMovingConfigurationTransformation implements ConfigurationTransformation {
private final Set<NodePath> paths;
private final ConfigurationLoader<?> destinationLoader;
private final boolean override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.common.applaunch.config.inheritable.BaseConfig;

import java.io.IOException;
import java.util.function.Consumer;
import java.util.function.Function;

public class InheritableConfigHandle<T extends BaseConfig> extends ConfigHandle<T> {
public final class InheritableConfigHandle<T extends BaseConfig> extends ConfigHandle<T> {

/**
* The parent configuration - values are inherited from this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@
import org.spongepowered.plugin.PluginKeys;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

/**
* Common utility methods for sponge configurations and necessary helpers for early init.
*/
public class SpongeConfigs {
public final class SpongeConfigs {

public static final Blackboard.Key<Boolean> IS_VANILLA_PLATFORM = Blackboard.Key.of("is_vanilla", Boolean.class);

Expand All @@ -65,8 +64,6 @@ public class SpongeConfigs {

static final ConfigurationOptions OPTIONS = ConfigurationOptions.defaults()
.header(HEADER)
.shouldCopyDefaults(true)
.implicitInitialization(true)
.serializers(collection -> collection.register(TokenHoldingString.SERIALIZER)
.registerAnnotatedObjects(OBJECT_MAPPERS));

Expand Down Expand Up @@ -178,4 +175,7 @@ public static InheritableConfigHandle<WorldConfig> createDetached() {
return new InheritableConfigHandle<>(new WorldConfig(), SpongeConfigs.getGlobalInheritable());
}

private SpongeConfigs() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/**
* Holder for a string value that is parsed for environment variables.
*/
public class TokenHoldingString {
public final class TokenHoldingString {

static final ScalarSerializer<TokenHoldingString> SERIALIZER = new Serializer();

Expand Down Expand Up @@ -124,7 +124,7 @@ public String getParsed() {
return this.parsedValue;
}

static class Serializer extends ScalarSerializer<TokenHoldingString> {
static final class Serializer extends ScalarSerializer<TokenHoldingString> {

Serializer() {
super(TokenHoldingString.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
*/
package org.spongepowered.common.applaunch.config.inheritable;

import org.spongepowered.configurate.ScopedConfigurationNode;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.objectmapping.meta.Comment;
import org.spongepowered.configurate.objectmapping.meta.Setting;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.common.applaunch.config.core.Config;
import org.spongepowered.configurate.transformation.NodePath;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
package org.spongepowered.common.applaunch.config.inheritable;

import com.google.common.collect.ImmutableSet;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.common.applaunch.config.core.FileMovingConfigurationTransformation;
import org.spongepowered.common.applaunch.config.core.SpongeConfigs;
import org.spongepowered.common.applaunch.config.common.CommonConfig;
import org.spongepowered.configurate.transformation.NodePath;
import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;

import java.util.Set;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package org.spongepowered.common.bridge.data;

import com.google.common.collect.ImmutableList;
import com.google.common.reflect.TypeToken;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import org.spongepowered.api.ResourceKey;
Expand All @@ -44,6 +43,7 @@
import org.spongepowered.common.data.persistence.NbtTranslator;
import org.spongepowered.common.util.Constants;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -60,7 +60,7 @@ static void serializeCustomData(final DataCompoundHolder object) {

final DataManipulator.Mutable manipulator = ((CustomDataHolderBridge) object).bridge$getManipulator();
final DataHolder dataHolder = (DataHolder) object;
final TypeToken<? extends DataHolder> dataHolderType = TypeToken.of(dataHolder.getClass());
final Type dataHolderType = dataHolder.getClass();

final Set<DataStore> dataStores = manipulator.getKeys().stream()
.map(key -> SpongeDataManager.getDatastoreRegistry().getDataStore(key, dataHolderType))
Expand Down Expand Up @@ -109,7 +109,7 @@ static void deserializeCustomData(final DataCompoundHolder object) {
.stream().map(CustomDataHolderBridge::updateDataViewForDataManipulator).collect(Collectors.toList());
spongeData.set(Constants.Sponge.CUSTOM_MANIPULATOR_LIST, updatedDataViews);

final TypeToken<? extends DataHolder> typeToken = TypeToken.of((Class<? extends DataHolder>)object.getClass());
final Class<? extends DataHolder> typeToken = object.getClass().asSubclass(DataHolder.class);
// Find DataStores
final List<DataStore> dataStores = new ArrayList<>();
final ImmutableList.Builder<DataView> failed = ImmutableList.builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
public final class DataSerializableTypeSerializer implements TypeSerializer<DataSerializable> {
private static final Class<DataSerializable> TYPE = DataSerializable.class;

public static Predicate<Type> predicate() {
return x -> GenericTypeReflector.isSuperType(DataSerializableTypeSerializer.TYPE, x)
public static boolean accepts(final Type x) {
return GenericTypeReflector.isSuperType(DataSerializableTypeSerializer.TYPE, x)
&& !GenericTypeReflector.isSuperType(CatalogTypeTypeSerializer.TYPE, x);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class PluginConfigManager implements ConfigManager {
.register(CatalogType.class, catalogSerializer)
// We have a separate type serializer for CatalogTypes, so we explicitly discount them here.
// See https://github.com/SpongePowered/SpongeCommon/issues/1348
.register(DataSerializableTypeSerializer.predicate(), dataSerializableSerializer)
.register(DataSerializableTypeSerializer::accepts, dataSerializableSerializer)
// TODO: register DataTranslators?
.registerAll(SpongeAdventure.CONFIGURATE.serializers())
.build();
Expand Down Expand Up @@ -90,8 +90,6 @@ public WatchServiceListener getWatchServiceListener() {

public static ConfigurationOptions getOptions(final TypeSerializerCollection serializers) {
return ConfigurationOptions.defaults()
.implicitInitialization(true)
.shouldCopyDefaults(true)
.serializers(serializers);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
/**
* SpongeCommon configurations that need to interact with game state
*/
public class SpongeGameConfigs {
public final class SpongeGameConfigs {

static final Logger LOGGER = LogManager.getLogger();

Expand All @@ -63,7 +63,7 @@ public class SpongeGameConfigs {

public static CompletableFuture<CommentedConfigurationNode> savePluginsInMetricsConfig(final Map<String, Tristate> entries) {
return SpongeConfigs.getCommon().updateSetting("metrics.plugin-states", entries,
new TypeToken<Map<String, Tristate>>() { private static final long serialVersionUID = -1L;});
new TypeToken<Map<String, Tristate>>() {});
}

public static ConfigHandle<CustomDataConfig> getCustomData() {
Expand Down Expand Up @@ -102,7 +102,7 @@ public static InheritableConfigHandle<WorldConfig> createWorld(final @Nullable D
Files.createDirectories(configPath.getParent());
Files.move(legacyPath, configPath);
final Path legacyParent = legacyPath.getParent();
try (DirectoryStream<Path> str = Files.newDirectoryStream(legacyParent)) {
try (final DirectoryStream<Path> str = Files.newDirectoryStream(legacyParent)) {
if (!str.iterator().hasNext()) {
Files.delete(legacyParent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/
package org.spongepowered.common.config.metrics;

import org.spongepowered.configurate.NodePath;
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
import org.spongepowered.configurate.objectmapping.meta.Comment;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.common.applaunch.config.core.Config;
import org.spongepowered.common.applaunch.config.core.SpongeConfigs;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import org.spongepowered.configurate.transformation.NodePath;
import org.spongepowered.plugin.PluginContainer;

import java.util.Collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.spongepowered.common.util.Constants;
import org.spongepowered.plugin.PluginContainer;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -322,10 +323,10 @@ public void registerCustomDataRegistration(SpongeDataRegistration registration)
private <V extends Value<E>, E> void registerCustomDataProviderForKey(final SpongeDataRegistration registration, final Key<V> key) {
final Collection<DataProvider<V, E>> providers = registration.getProvidersFor(key);

final Set<TypeToken<? extends DataHolder>> dataStoreSupportedTokens = new HashSet<>();
this.dataStoreRegistry.getDataStores(key).stream().map(DataStore::getSupportedTokens).forEach(dataStoreSupportedTokens::addAll);
final Set<Type> dataStoreSupportedTokens = new HashSet<>();
this.dataStoreRegistry.getDataStores(key).stream().map(DataStore::getSupportedTypes).forEach(dataStoreSupportedTokens::addAll);

for (DataProvider<V, E> provider : providers) {
for (final DataProvider<V, E> provider : providers) {
this.dataProviderRegistry.register(provider);
dataStoreSupportedTokens.removeIf(provider::isSupported);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.reflect.TypeToken;
import io.leangen.geantyref.GenericTypeReflector;
import io.leangen.geantyref.TypeToken;
import org.spongepowered.api.data.DataHolder;
import org.spongepowered.api.data.Key;
import org.spongepowered.api.data.persistence.DataStore;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -54,13 +56,17 @@ public Collection<DataStore> getDataStores(Key<?> key) {
return this.dataStores.get(key);
}

public DataStore getDataStore(Key<?> key, TypeToken<? extends DataHolder> typeToken) {
public DataStore getDataStore(final Key<?> key, final TypeToken<? extends DataHolder> typeToken) {
return this.getDataStore(key, typeToken.getType());
}

public DataStore getDataStore(final Key<?> key, final Type typeToken) {
return this.dataStoreCache.computeIfAbsent(new LookupKey(typeToken, key), this::loadDataStore);
}

private DataStore loadDataStore(LookupKey lookupKey) {
private DataStore loadDataStore(final LookupKey lookupKey) {
final List<DataStore> dataStores = this.dataStores.get(lookupKey.key).stream()
.filter(ds -> ds.getSupportedTokens().stream().anyMatch(token -> token.isSupertypeOf(lookupKey.holderType)))
.filter(ds -> ds.getSupportedTypes().stream().anyMatch(token -> GenericTypeReflector.isSuperType(token, lookupKey.holderType)))
.collect(Collectors.toList());
if (dataStores.size() > 1) {
throw new IllegalStateException("Multiple data-stores registered for the same key (" + lookupKey.key.getKey() + ") and data-holder " + lookupKey.holderType.toString());
Expand All @@ -73,10 +79,10 @@ private DataStore loadDataStore(LookupKey lookupKey) {

private static class LookupKey {

private final TypeToken<?> holderType;
private final Type holderType;
private final Key<?> key;

public LookupKey(final TypeToken<?> holderType, final Key<?> key) {
public LookupKey(final Type holderType, final Key<?> key) {
this.holderType = holderType;
this.key = key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public boolean isEmpty() {
return this.serializers.isEmpty();
}

public List<TypeToken<? extends DataHolder>> getDataHolderTypes() {
public List<Type> getDataHolderTypes() {
return this.dataHolderTypes;
}

Expand Down
Loading

0 comments on commit ac5124f

Please sign in to comment.