use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MessageUpdaterTest method shouldPerformNewerMigrations.
@Test
public void shouldPerformNewerMigrations() throws IOException {
// given
File messagesFile = temporaryFolder.newFile();
Files.copy(TestHelper.getJarFile(TestHelper.PROJECT_ROOT + "message/messages_test2.yml"), messagesFile);
// when
boolean wasChanged = messageUpdater.migrateAndSave(messagesFile, DEFAULT_MESSAGES_FILE, DEFAULT_MESSAGES_FILE);
// then
assertThat(wasChanged, equalTo(true));
PropertyReader reader = new YamlFileReader(messagesFile);
assertThat(reader.getString(MessageKey.TWO_FACTOR_CREATE.getKey()), equalTo("Old 2fa create text"));
// from pre-5.5 key
assertThat(reader.getString(MessageKey.WRONG_PASSWORD.getKey()), equalTo("test2 - wrong password"));
// from messages_en.yml
assertThat(reader.getString(MessageKey.SECOND.getKey()), equalTo("second"));
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class SettingsTest method mockPropertyResourceAndReader.
private static PropertyResource mockPropertyResourceAndReader() {
PropertyReader reader = mock(PropertyReader.class, RETURNS_DEEP_STUBS);
given(reader.getList(anyString())).willReturn(Collections.emptyList());
PropertyResource resource = mock(PropertyResource.class);
given(resource.createReader()).willReturn(reader);
return resource;
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MessageUpdater method migrateAndSave.
/**
* Performs the migration.
*
* @param userFile the file to verify and migrate
* @param jarMessageSource jar message source to get texts from if missing
* @return true if the file has been migrated and saved, false if it is up-to-date
*/
private boolean migrateAndSave(File userFile, JarMessageSource jarMessageSource) {
// YamlConfiguration escapes all special characters when saving, making the file hard to use, so use ConfigMe
MessageKeyConfigurationData configurationData = createConfigurationData();
PropertyResource userResource = new MigraterYamlFileResource(userFile);
PropertyReader reader = userResource.createReader();
configurationData.initializeValues(reader);
// Step 1: Migrate any old keys in the file to the new paths
boolean movedOldKeys = migrateOldKeys(reader, configurationData);
// Step 2: Perform newer migrations
boolean movedNewerKeys = migrateKeys(reader, configurationData);
// Step 3: Take any missing messages from the message files shipped in the AuthMe JAR
boolean addedMissingKeys = addMissingKeys(jarMessageSource, configurationData);
if (movedOldKeys || movedNewerKeys || addedMissingKeys) {
backupMessagesFile(userFile);
userResource.exportProperties(configurationData);
logger.debug("Successfully saved {0}", userFile);
return true;
}
return false;
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class MessagesFileWriter method performWrite.
private void performWrite() {
// Initialize ConfigMe classes
MessageKeyConfigurationData configurationData = MessageUpdater.createConfigurationData();
YamlFileResource resource = new MigraterYamlFileResource(file);
PropertyReader reader = resource.createReader();
configurationData.initializeValues(reader);
// Store initial comments so we can add them back later
List<String> initialComments = getInitialUserComments(configurationData);
// Create property resource with new defaults, save with ConfigMe for proper sections & comments
addMissingMessagesWithCommentMarker(reader, configurationData);
resource.exportProperties(configurationData);
// Go through the newly saved file and replace texts with comment marker to actual YAML comments
// and add initial comments back to the file
rewriteToFileWithComments(initialComments);
}
use of ch.jalu.configme.resource.PropertyReader in project AuthMeReloaded by AuthMe.
the class TranslationsGatherer method processMessagesFile.
private void processMessagesFile(String code, File file) {
PropertyReader reader = new YamlFileReader(file);
int availableMessages = 0;
for (MessageKey key : MessageKey.values()) {
if (reader.contains(key.getKey())) {
++availableMessages;
}
}
translationInfo.add(new TranslationInfo(code, (double) availableMessages / MessageKey.values().length));
}
Aggregations