use of org.yaml.snakeyaml.Yaml in project mule by mulesoft.
the class DefaultConfigurationPropertiesProvider method createAttributesFromYamlObject.
protected void createAttributesFromYamlObject(String parentPath, Object parentYamlObject, Object yamlObject) {
if (yamlObject instanceof List) {
List list = (List) yamlObject;
if (list.get(0) instanceof Map) {
list.forEach(value -> createAttributesFromYamlObject(parentPath, yamlObject, value));
} else {
if (!(list.get(0) instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage("List of complex objects are not supported as property values. Offending key is " + parentPath), this);
}
String[] values = new String[list.size()];
list.toArray(values);
String value = join(",", list);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, value));
}
} else if (yamlObject instanceof Map) {
if (parentYamlObject instanceof List) {
throw new ConfigurationPropertiesException(createStaticMessage("Configuration properties does not support type a list of complex types. Complex type keys are: " + join(",", ((Map) yamlObject).keySet())), this);
}
Map<String, Object> map = (Map) yamlObject;
map.entrySet().stream().forEach(entry -> createAttributesFromYamlObject(createKey(parentPath, entry.getKey()), yamlObject, entry.getValue()));
} else {
if (!(yamlObject instanceof String)) {
throw new ConfigurationPropertiesException(createStaticMessage(format("YAML configuration properties only supports string values, make sure to wrap the value with \" so you force the value to be an string. Offending property is %s with value %s", parentPath, yamlObject)), this);
}
String resultObject = createValue(parentPath, (String) yamlObject);
configurationAttributes.put(parentPath, new DefaultConfigurationProperty(this, parentPath, resultObject));
}
}
use of org.yaml.snakeyaml.Yaml in project Essentials by EssentialsX.
the class Commandcreatekit method run.
// /createkit <name> <delay>
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length != 2) {
throw new NotEnoughArgumentsException();
}
// Command handler will auto fail if this fails.
long delay = Long.valueOf(args[1]);
String kitname = args[0];
ItemStack[] items = user.getBase().getInventory().getContents();
List<String> list = new ArrayList<>();
for (ItemStack is : items) {
if (is != null && is.getType() != null && is.getType() != Material.AIR) {
String serialized = ess.getItemDb().serialize(is);
list.add(serialized);
}
}
// Some users might want to directly write to config knowing the consequences. *shrug*
if (!ess.getSettings().isPastebinCreateKit()) {
ess.getKits().addKit(kitname, list, delay);
user.sendMessage(tl("createdKit", kitname, list.size(), delay));
} else {
ConfigurationSection config = new MemoryConfiguration();
config.set("kits." + kitname + ".delay", delay);
config.set("kits." + kitname + ".items", list);
final Yaml yaml = new Yaml(yamlConstructor, yamlRepresenter, yamlOptions);
String fileContents = "# Copy the kit code below into the kits section in your config.yml file\n";
fileContents += yaml.dump(config.getValues(false));
uploadPaste(user.getSource(), kitname, delay, fileContents);
}
}
use of org.yaml.snakeyaml.Yaml in project bboxdb by jnidzwetzki.
the class DistributionGroupMetadataHelper method writeMedatadataForGroup.
/**
* Write new metadata for a distribution group
* @param distributionGroupName
* @param distributionGroupMetadata
* @throws IOException
*/
public static void writeMedatadataForGroup(final String basedir, final String distributionGroupName, final DistributionGroupMetadata distributionGroupMetadata) throws IOException {
final Map<String, Object> data = new HashMap<>();
data.put("version", distributionGroupMetadata.getVersion());
final String filename = getFilename(basedir, distributionGroupName);
final File metadataFile = new File(filename);
logger.info("Writing metadata to {} ", metadataFile);
final FileWriter writer = new FileWriter(metadataFile);
final Yaml yaml = new Yaml();
yaml.dump(data, writer);
writer.close();
}
use of org.yaml.snakeyaml.Yaml in project bboxdb by jnidzwetzki.
the class BBoxDBConfigurationManager method loadConfiguration.
/**
* Load the configuration of the BBoxDB from the classpath
*/
public static void loadConfiguration() {
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
throw new IllegalArgumentException("Got null classloader");
}
final URL inputFile = classLoader.getResource(Const.CONFIG_FILE);
if (inputFile == null) {
configuration = new BBoxDBConfiguration();
logger.warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
logger.warn("!! No configuration file found, using default values !!");
logger.warn("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
try (final InputStream inputStream = inputFile.openStream()) {
logger.info("Loading configuration from: " + inputFile);
final Yaml yaml = new Yaml();
configuration = yaml.loadAs(inputStream, BBoxDBConfiguration.class);
} catch (IOException e) {
logger.error("Exception while loading configuration", e);
throw new RuntimeException(e);
}
}
use of org.yaml.snakeyaml.Yaml in project wildfly-swarm by wildfly-swarm.
the class ConfigReader method readConfig.
public MetadataList readConfig(InputStream configStream) {
Yaml yaml = new Yaml();
MetadataList config = yaml.loadAs(configStream, MetadataList.class);
log.info("Loaded config");
return config;
}
Aggregations