Search in sources :

Example 1 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class SettingsProvider method get.

/**
     * Loads the plugin's settings.
     *
     * @return the settings instance, or null if it could not be constructed
     */
@Override
public Settings get() {
    File configFile = new File(dataFolder, "config.yml");
    if (!configFile.exists()) {
        FileUtils.create(configFile);
    }
    PropertyResource resource = new YamlFileResource(configFile);
    ConfigurationData configurationData = AuthMeSettingsRetriever.buildConfigurationData();
    return new Settings(dataFolder, resource, migrationService, configurationData);
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) ConfigurationData(ch.jalu.configme.configurationdata.ConfigurationData) File(java.io.File) Settings(fr.xephi.authme.settings.Settings)

Example 2 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class GenerateCommandsYml method executeDefault.

@Override
public void executeDefault() {
    File file = new File(COMMANDS_YML_FILE);
    // Get the default
    CommandConfig commandConfig = CommandSettingsHolder.COMMANDS.getDefaultValue();
    // Export the value to the file
    SettingsManager settingsManager = new SettingsManager(new YamlFileResource(file), null, CommandSettingsHolder.class);
    settingsManager.setProperty(CommandSettingsHolder.COMMANDS, commandConfig);
    settingsManager.save();
    System.out.println("Updated " + COMMANDS_YML_FILE);
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) CommandConfig(fr.xephi.authme.settings.commandconfig.CommandConfig) SettingsManager(ch.jalu.configme.SettingsManager) File(java.io.File)

Example 3 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class CommandYmlConsistencyTest method shouldLoadWithNoMigrations.

@Test
public void shouldLoadWithNoMigrations() {
    // given
    File commandFile = TestHelper.getJarFile("/commands.yml");
    PropertyResource resource = new YamlFileResource(commandFile);
    // when
    boolean result = commandMigrationService.checkAndMigrate(resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
    // then
    assertThat(result, equalTo(false));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) Test(org.junit.Test)

Example 4 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class CommandMigrationServiceTest method shouldNotChangeCompleteFile.

@Test
public void shouldNotChangeCompleteFile() {
    // given
    File commandFile = TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "settings/commandconfig/commands.complete.yml");
    PropertyResource resource = new YamlFileResource(commandFile);
    // when
    boolean result = commandMigrationService.checkAndMigrate(resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
    // then
    assertThat(result, equalTo(false));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) Test(org.junit.Test)

Example 5 with YamlFileResource

use of ch.jalu.configme.resource.YamlFileResource in project AuthMeReloaded by AuthMe.

the class SettingsIntegrationTest method shouldLoadAndReadAllProperties.

@Test
public void shouldLoadAndReadAllProperties() throws IOException {
    // given
    PropertyResource resource = new YamlFileResource(copyFileFromResources(COMPLETE_FILE));
    // Pass another, non-existent file to check if the settings had to be rewritten
    File newFile = temporaryFolder.newFile();
    // when / then
    Settings settings = new Settings(testPluginFolder, resource, new PlainMigrationService(), CONFIG_DATA);
    Map<Property<?>, Object> expectedValues = ImmutableMap.<Property<?>, Object>builder().put(TestConfiguration.DURATION_IN_SECONDS, 22).put(TestConfiguration.SYSTEM_NAME, "Custom sys name").put(TestConfiguration.RATIO_ORDER, TestEnum.FIRST).put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia", "Burundi", "Colombia")).put(TestConfiguration.VERSION_NUMBER, 2492).put(TestConfiguration.SKIP_BORING_FEATURES, false).put(TestConfiguration.BORING_COLORS, Arrays.asList("beige", "gray")).put(TestConfiguration.DUST_LEVEL, 2).put(TestConfiguration.USE_COOL_FEATURES, true).put(TestConfiguration.COOL_OPTIONS, Arrays.asList("Dinosaurs", "Explosions", "Big trucks")).build();
    for (Map.Entry<Property<?>, Object> entry : expectedValues.entrySet()) {
        assertThat("Property '" + entry.getKey().getPath() + "' has expected value", settings.getProperty(entry.getKey()), equalTo(entry.getValue()));
    }
    assertThat(newFile.length(), equalTo(0L));
}
Also used : YamlFileResource(ch.jalu.configme.resource.YamlFileResource) PlainMigrationService(ch.jalu.configme.migration.PlainMigrationService) PropertyResource(ch.jalu.configme.resource.PropertyResource) File(java.io.File) TestHelper.getJarFile(fr.xephi.authme.TestHelper.getJarFile) Property(ch.jalu.configme.properties.Property) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

YamlFileResource (ch.jalu.configme.resource.YamlFileResource)13 File (java.io.File)13 PropertyResource (ch.jalu.configme.resource.PropertyResource)10 Test (org.junit.Test)9 TestHelper.getJarFile (fr.xephi.authme.TestHelper.getJarFile)5 SettingsManager (ch.jalu.configme.SettingsManager)3 PlainMigrationService (ch.jalu.configme.migration.PlainMigrationService)2 Property (ch.jalu.configme.properties.Property)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ConfigurationData (ch.jalu.configme.configurationdata.ConfigurationData)1 Settings (fr.xephi.authme.settings.Settings)1 CommandConfig (fr.xephi.authme.settings.commandconfig.CommandConfig)1 IOException (java.io.IOException)1 TagValueHolder (tools.utils.TagValueHolder)1