本文整理汇总了Java中ch.jalu.configme.migration.PlainMigrationService类的典型用法代码示例。如果您正苦于以下问题:Java PlainMigrationService类的具体用法?Java PlainMigrationService怎么用?Java PlainMigrationService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PlainMigrationService类属于ch.jalu.configme.migration包,在下文中一共展示了PlainMigrationService类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateUserInfo
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
public String generateUserInfo() {
SettingsManager settingsManager = new SettingsManager(new YamlFileResource(configFile),
new PlainMigrationService(), ConfigurationDataBuilder.collectData(DemoSettings.class));
UserBase userBase = settingsManager.getProperty(DemoSettings.USER_BASE);
User richie = userBase.getRichie();
String savedLocationInfo = richie.getSavedLocations().entrySet().stream()
.map(entry -> entry.getKey() + " " + entry.getValue())
.collect(Collectors.joining(", "));
String info = "Saved locations of Richie: " + savedLocationInfo;
info += "\nNicknames of Bob: " + String.join(", ", userBase.getBobby().getNicknames());
Country country = settingsManager.getProperty(DemoSettings.COUNTRY);
info += "\nCountry '" + country.getName() + "' has neighbors: " + String.join(", ", country.getNeighbors());
return info;
}
示例2: shouldIncludeCommentFromAnnotation
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
@Test
public void shouldIncludeCommentFromAnnotation() throws IOException {
// given
PropertyResource resource = new YamlFileResource(file);
// when
new SettingsManager(resource, new PlainMigrationService(), GroupPropertyHolder.class);
// then
assertThat(Files.readAllLines(file.toPath()), contains(
"",
"# Group configuration number",
"default-gamemode: 'CREATIVE'",
"worlds: ",
"- 'world'"
));
}
示例3: shouldIncludeRootCommentFromSectionCommentsMethod
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
@Test
public void shouldIncludeRootCommentFromSectionCommentsMethod() throws IOException {
// given
PropertyResource resource = new YamlFileResource(file);
// when
new SettingsManager(resource, new PlainMigrationService(), TestConfig.class);
// then
assertThat(Files.readAllLines(file.toPath()), contains(
"",
"# Root comment",
"# 'some' Section",
"# Explanation for 'some'",
"some:",
" # Integer property",
" test: 4",
" # Other header",
" other:",
" property: 'hello'"
));
}
示例4: initSettings
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
/**
* Initializes the settings manager.
*
* @return the settings manager
*/
private SettingsManager initSettings() {
// Copy the demo/config.yml instead of using it directly so it doesn't get overridden
configFile = copyFileFromJar("/demo/config.yml");
PropertyResource resource = new YamlFileResource(configFile);
return new SettingsManager(resource, new PlainMigrationService(), TitleConfig.class);
}
示例5: Settings
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
/**
* Constructor.
*
* @param yamlFile the configuration file to load
*/
public Settings(File yamlFile) {
super(
new YamlFileResource(yamlFile),
new PlainMigrationService(),
PwiProperties.class);
}
示例6: shouldLoadAndReadAllProperties
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
@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));
}
示例7: shouldProperlyExportAnyValues
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
/** Verifies that "difficult cases" such as apostrophes in strings etc. are handled properly. */
@Test
public void shouldProperlyExportAnyValues() {
// given
File file = copyFileFromResources(DIFFICULT_FILE);
YamlFileResource resource = new YamlFileResource(file);
// Properties
List<Property<?>> properties = new ArrayList<>(Arrays.asList(
newProperty("more.string1", "it's a text with some \\'apostrophes'"),
newProperty("more.string2", "\tthis one\nhas some\nnew '' lines-test")));
properties.addAll(ConfigurationDataBuilder.collectData(TestConfiguration.class).getProperties());
ConfigurationData configData = new ConfigurationData(properties);
// when
new SettingsManager(resource, new PlainMigrationService(), configData);
// Save and load again
resource.exportProperties(configData);
resource.reload();
// then
assertThat(resource.getObject(TestConfiguration.DUST_LEVEL.getPath()), not(nullValue()));
Map<Property<?>, Object> expected = new HashMap<>();
expected.put(TestConfiguration.DURATION_IN_SECONDS, 20);
expected.put(TestConfiguration.SYSTEM_NAME, "A 'test' name");
expected.put(TestConfiguration.RATIO_ORDER, "FOURTH");
expected.put(TestConfiguration.RATIO_FIELDS, Arrays.asList("Australia\\", "\tBurundi'", "Colombia?\n''"));
expected.put(TestConfiguration.VERSION_NUMBER, -1337);
expected.put(TestConfiguration.SKIP_BORING_FEATURES, false);
expected.put(TestConfiguration.BORING_COLORS, Arrays.asList("it's a difficult string!", "gray\nwith new lines\n"));
expected.put(TestConfiguration.DUST_LEVEL, -1);
expected.put(TestConfiguration.USE_COOL_FEATURES, true);
expected.put(TestConfiguration.COOL_OPTIONS, Collections.EMPTY_LIST);
expected.put(properties.get(0), properties.get(0).getDefaultValue());
expected.put(properties.get(1), properties.get(1).getDefaultValue());
for (Map.Entry<Property<?>, Object> entry : expected.entrySet()) {
assertThat("Property '" + entry.getKey().getPath() + "' has expected value",
resource.getObject(entry.getKey().getPath()), equalTo(entry.getValue()));
}
}
示例8: createWithYamlFile
import ch.jalu.configme.migration.PlainMigrationService; //导入依赖的package包/类
/**
* Convenience method for creating a settings manager for the provided YAML file with defaults.
* Creates the YAML file if it doesn't exist. Uses the default migration service, checking that all
* properties are present in the YAML file.
*
* @param yamlFile the file to read from and write to
* @param settingsClasses classes whose Property fields make up all known properties
* @return the created settings manager
*/
@SafeVarargs
public static SettingsManager createWithYamlFile(File yamlFile,
Class<? extends SettingsHolder>... settingsClasses) {
Utils.createFileIfNotExists(yamlFile);
return new SettingsManager(new YamlFileResource(yamlFile), new PlainMigrationService(), settingsClasses);
}