Giter Club home page Giter Club logo

simple-yaml's Introduction

Simple YAML

Latest version Build Status

This Java API provides an easy-to-use way to store data and provide configurations using the YAML format.

ko-fi

What is YAML?

YAML is a human-readable data-oriented serialization language.

Serialization is the process of translating data structures or object state into a format that can be stored and reconstructed later in the same or another computer environment.

You can learn more about YAML language here. Specifically, if you're interested to learn about the YAML syntax you can go to the Chapter 2 of the YAML specification.

Filename extensions: .yaml, .yml

What is Simple-YAML?

Simple-YAML is a library designed to create configuration files for your programs, tools and plugins.

The API is a port from Bukkit configuration wrapper with some features added, so you can use this library wherever you want without Bukkit dependency.

Simplicity is added with the YamlFile class, which has everything you need with easy use for creation, management and serialization of yaml files. It is an extension of YamlConfiguration.

Furthermore, you can optionally save your files with comments in mind. You can write your comments with a text editor as usual. In addition, not only you can preserve your comments but also with this API you can read and add comments programmatically to your configuration. Sounds good, right?

How to install

To use this API all you need is to download the latest Simple-Yaml.jar and put it as a dependency on your project.

Maven

If you are using Maven you do not need to download the jar. Instead, add this repository and dependency to your pom.xml:

<repositories>
    <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
    </repository>
</repositories>
Yaml + Configuration
<dependency>
    <groupId>com.github.Carleslc.Simple-YAML</groupId>
    <artifactId>Simple-Yaml</artifactId>
    <version>1.8.4</version>
</dependency>

You can also use me.carleslc.Simple-YAML as the groupId.

Configuration only
<dependency>
    <groupId>com.github.Carleslc.Simple-YAML</groupId>
    <artifactId>Simple-Configuration</artifactId>
    <version>1.8.4</version>
</dependency>

You can also use me.carleslc.Simple-YAML as the groupId.

Gradle

If you are using Gradle you do not need to download the jar. Instead, add this repository and dependency to your build file:

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
Yaml + Configuration
dependencies {
  implementation 'com.github.Carleslc.Simple-YAML:Simple-Yaml:1.8.4'
}
Configuration only
dependencies {
  implementation 'com.github.Carleslc.Simple-YAML:Simple-Configuration:1.8.4'
}

How to use

The best way to learn how to use this API is through some examples.

You can find some examples to test here.

  • YamlExample: An example to create YAML files, save or delete values and move through the file configuration.
  • YamlCommentsExample: An example to load and save YAML files keeping comments and also how to read and add comments programmatically.
  • YamlCommentsFormatExample: An example to format header and comments with custom prefixes, suffixes and blank lines.
  • YamlEncodingExample: A minimal example to check your encoding with Unicode characters.
  • YamlSerializationExample: An example for saving complex objects using serialization.
  • Person: An example of class for complex objects used in the previous file. Here you can see how to serialize and deserialize objects.

Find the example .yml files here.

For more information and methods see the Javadoc:

Dependencies

This API uses SnakeYAML underneath. It is already included in the latest Simple-Yaml.jar and with the maven or gradle dependencies.

Looking for other file type configurations?

Have a look to these repositories:

These projects are using the Simple-Configuration module, but they are not related directly with Simple-YAML.

simple-yaml's People

Contributors

akramlz avatar alessiodp avatar blackbaroness avatar carleslc avatar foodcans avatar melainegerard avatar portlek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simple-yaml's Issues

.save() error

When i call the yamlFile.save(); method i always get this error:

java.lang.NoClassDefFoundError: com/google/common/io/Files
at org.simpleyaml.configuration.file.FileConfiguration.save(FileConfiguration.java:100)
at org.simpleyaml.configuration.file.YamlFile.save(YamlFile.java:78)

Licensing issue

Give credit where credit is due. You pretty much copy pasted half the classes (if not more) from Bukkit.

Moreover, their license does not allow you to use it as it currently is used:

  • There's no license and no copyright notice of their code
  • You need to state what you've changed
  • The project would have to be licensed as GPL v3

(Velocity dependency clash) java.lang.NoSuchMethodError

java.lang.NoSuchMethodError: 'void org.yaml.snakeyaml.DumperOptions.setIndentWithIndicator(boolean)'
at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.configure(SnakeYamlImplementation.java:192) ~[?:?]
at org.simpleyaml.configuration.implementation.SimpleYamlImplementation.configure(SimpleYamlImplementation.java:149) ~[?:?]
at org.simpleyaml.configuration.file.YamlConfiguration.setImplementation(YamlConfiguration.java:62) ~[?:?]
at org.simpleyaml.configuration.file.YamlConfiguration.(YamlConfiguration.java:52) ~[?:?]
at org.simpleyaml.configuration.file.YamlConfiguration.(YamlConfiguration.java:47) ~[?:?]
at org.simpleyaml.configuration.file.YamlFile.(YamlFile.java:49) ~[?:?]
at org.simpleyaml.configuration.file.YamlFile.(YamlFile.java:76) ~[?:?]
at lv.exosmium.exodomainmanager.Main.setupConfig(Main.java:57) ~[?:?]
at lv.exosmium.exodomainmanager.Main.onProxyInitialization(Main.java:41) ~[?:?]
at lv.exosmium.exodomainmanager.Lmbda$1.execute(Unknown Source) ~[?:?]
at com.velocitypowered.proxy.event.UntargetedEventHandler$VoidHandler.lambda$buildHandler$0(UntargetedEventHandler.java:47) ~[velocity.jar:3.1.2-SNAPSHOT (git-7d77bfb5-b184)]
at com.velocitypowered.proxy.event.VelocityEventManager.fire(VelocityEventManager.java:598) ~[velocity.jar:3.1.2-SNAPSHOT (git-7d77bfb5-b184)]
at com.velocitypowered.proxy.event.VelocityEventManager.lambda$fire$5(VelocityEventManager.java:479) ~[velocity.jar:3.1.2-SNAPSHOT (git-7d77bfb5-b184)]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
at java.lang.Thread.run(Thread.java:833) ~[?:?]

Duplicate class found

Hi, thank you for your Simple-YAML module. I am trying to use this in my app but run into gradle dependency issues as follows:

  • I have included this in my build.gradle file:
    implementation 'me.carleslc.Simple-YAML:Simple-Yaml:1.7.2'
  • when I build the app, I receive this:
    Duplicate class org.simpleyaml.configuration.Configuration found in modules jetified-Simple-Configuration-1.7.2 (me.carleslc.Simple-YAML:Simple-Configuration:1.7.2) and jetified-Simple-Yaml-1.7.2 (me.carleslc.Simple-YAML:Simple-Yaml:1.7.2)

I am not familiar enough with gradle to know how to exclude such a duplicate class.

Any help would be much appreciated. Thank you.

Comments buggy

Last comments just decide to vanish after loading this config.yml file:

autoplug-backup-config:

  #######################################################################################################################
  # SERVER-FILES BACKUP
  #######################################################################################################################
  #Backups your server.jar and all setting files before startup to /autoplug-backups/server/...zip
  server-files-backup:
    enable: false

    #Set max-days to 0 if you want to keep your backups forever.
    max-days: 7

  #######################################################################################################################
  # WORLDS BACKUP
  #######################################################################################################################
  #Backups all folders starting with "world" to /autoplug-backups/worlds/...zip
  worlds-backup:
    enable: false

    #Set max-days to 0 if you want to keep your backups forever.
    max-days: 7

  #######################################################################################################################
  # PLUGINS BACKUP
  #######################################################################################################################
  #Backups your plugins folder before startup to /autoplug-backups/plugins/...zip
  plugins-backup:
    enable: true

    #Set max-days to 0 if you want to keep your backups forever.
    max-days: 7

This is what I get after loading the file:

autoplug-backup-config:

  #######################################################################################################################
  # SERVER-FILES BACKUP
  #######################################################################################################################
  #Backups your server.jar and all setting files before startup to /autoplug-backups/server/...zip
  server-files-backup:
    enable: false

    #Set max-days to 0 if you want to keep your backups forever.
    max-days: 7

  #######################################################################################################################
  # WORLDS BACKUP
  #######################################################################################################################
  #Backups all folders starting with "world" to /autoplug-backups/worlds/...zip
  worlds-backup:
    enable: false

    #Set max-days to 0 if you want to keep your backups forever.
    max-days: 7
  plugins-backup:
    enable: true
    max-days: 7

This is the java code handling the loading:

public class BackupConfig {

    public BackupConfig(){
        AutoPlugLogger.newClassDebug("BackupConfig");
    }
    
    private final YamlFile config = new YamlFile("autoplug-backup-config.yml");

    public void create(){

        // Load the YAML file if is already created or create new one otherwise
        try {
            if (!config.exists()) {
                AutoPlugLogger.info(" - autoplug-backup-config.yml not found! Creating new one...");
                config.createNewFile(true);
                AutoPlugLogger.debug("create", "Created file at: " + config.getFilePath());
            }
            else {
                AutoPlugLogger.info(" - Loading autoplug-backup-config.yml...");
            }
            config.load(); // Loads the entire file
        } catch (Exception e) {
            AutoPlugLogger.warn("Failed to load autoplug-backup-config.yml...");
            e.printStackTrace();
        }

        // Insert defaults
        insertDefaults();

        // Makes settings globally accessible
        setUserOptions();

        // Validates options
        validateOptions();

        //Finally save the file
        save();

    }

    private void insertDefaults(){

        config.addDefault("autoplug-backup-config.server-files-backup.enable", false);
        config.addDefault("autoplug-backup-config.server-files-backup.max-days", (int)7);

        config.addDefault("autoplug-backup-config.worlds-backup.enable", false);
        config.addDefault("autoplug-backup-config.worlds-backup.max-days", (int)7);

        config.addDefault("autoplug-backup-config.plugins-backup.enable", true);
        config.addDefault("autoplug-backup-config.plugins-backup.max-days", (int)7);

    }

    //User configuration
    public static boolean backup_server;
    public static int backup_server_max_days;

    public static boolean backup_worlds;
    public static int backup_worlds_max_days;

    public static boolean backup_plugins;
    public static int backup_plugins_max_days;

    private void setUserOptions(){

        AutoPlugLogger.debug("setUserOptions", "Applying values for autoplug-backup-config.yml");

        //SERVER JAR BACKUP
        backup_server = config.getBoolean("autoplug-backup-config.server-files-backup.enable");
        debugConfig("backup_server", String.valueOf(backup_server));
        backup_server_max_days = config.getInt("autoplug-backup-config.server-files-backup.max-days");
        debugConfig("backup_server_max_days", String.valueOf(backup_server_max_days));

        //WORLDS BACKUP
        backup_worlds = config.getBoolean("autoplug-backup-config.worlds-backup.enable");
        debugConfig("backup_worlds", String.valueOf(backup_worlds));
        backup_worlds_max_days = config.getInt("autoplug-backup-config.worlds-backup.max-days");
        debugConfig("backup_worlds_max_days", String.valueOf(backup_worlds_max_days));

        //PLUGINS BACKUP
        backup_plugins = config.getBoolean("autoplug-backup-config.plugins-backup.enable");
        debugConfig("backup_plugins", String.valueOf(backup_plugins));
        backup_plugins_max_days = config.getInt("autoplug-backup-config.plugins-backup.max-days");
        debugConfig("backup_plugins_max_days", String.valueOf(backup_plugins_max_days));

    }

    private void validateOptions() {
    }

    //Shortcut for easier logging
    private void debugConfig(String config_name, String config_value){
        AutoPlugLogger.debug("debugConfig", "Setting value "+config_name+": "+config_value+"");
    }
    
    
    private void save() {

        // Finally, save changes!
        try {
            config.saveWithComments();
        } catch (IOException e) {
            e.printStackTrace();
            AutoPlugLogger.warn("Issues while saving config.yml");
        }

        AutoPlugLogger.info(" - Configuration file loaded!");

    }

}

'void org.yaml.snakeyaml.DumperOptions.setIndentWithIndicator(boolean)'

I tried using Simple-Yaml library with a plugin for Velocity (https://velocitypowered.com) which is a minecraft proxy, but the issue is it gives out this error:

[22:47:11 ERROR]: Couldn't pass ProxyInitializeEvent to eris
java.lang.NoSuchMethodError: 'void org.yaml.snakeyaml.DumperOptions.setIndentWithIndicator(boolean)'
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.configure(SnakeYamlImplementation.java:182) ~[?:?]
        at org.simpleyaml.configuration.implementation.SimpleYamlImplementation.configure(SimpleYamlImplementation.java:149) ~[?:?]
        at org.simpleyaml.configuration.file.YamlConfiguration.setImplementation(YamlConfiguration.java:62) ~[?:?]
        at org.simpleyaml.configuration.file.YamlConfiguration.<init>(YamlConfiguration.java:52) ~[?:?]
        at org.simpleyaml.configuration.file.YamlConfiguration.<init>(YamlConfiguration.java:47) ~[?:?]
        at org.simpleyaml.configuration.file.YamlFile.<init>(YamlFile.java:49) ~[?:?]
        at org.simpleyaml.configuration.file.YamlFile.<init>(YamlFile.java:89) ~[?:?]
        at ir.ciph3r.eris.storage.yml.model.YMLModel.createFile(YMLModel.java:28) ~[?:?]
        at ir.ciph3r.eris.storage.yml.Config.<init>(Config.java:13) ~[?:?]
        at ir.ciph3r.eris.Eris.onProxyInitialization(Eris.java:40) ~[?:?]
        at ir.ciph3r.eris.Lmbda$1.execute(Unknown Source) ~[?:?]
        at com.velocitypowered.proxy.event.UntargetedEventHandler$VoidHandler.lambda$buildHandler$0(UntargetedEventHandler.java:47) ~[velocity-3.1.1-98.jar:3.1.1]
        at com.velocitypowered.proxy.event.VelocityEventManager.fire(VelocityEventManager.java:598) ~[velocity-3.1.1-98.jar:3.1.1]
        at com.velocitypowered.proxy.event.VelocityEventManager.lambda$fire$5(VelocityEventManager.java:479) ~[velocity-3.1.1-98.jar:3.1.1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:833) [?:?]

If you need any code from the project
here is my YML model class: https://github.com/Ciph3r-Zer0/Eris/blob/master/src/main/java/ir/ciph3r/eris/storage/yml/model/YMLModel.java
and here is the Config class: https://github.com/Ciph3r-Zer0/Eris/blob/master/src/main/java/ir/ciph3r/eris/storage/yml/Config.java

Enhancement/Feature Request - addDefault() enforce quote style

It would be great if we could use this same syntax for addDefault()
yamlFile.set("quotes.custom", "This is double quote style", QuoteStyle.DOUBLE);

I could not find any documentation on how to get this to work, looking at the code we might have to modify MemoryConfiguration.

A workaround would be combining isSet() and set() but that does not look like a great idea.

Is it possible to separate YAML library?

Is it possible to separate SnakeYAML into a new module like;

  • simple-configuration > includes all common stuffs like;

utils package
exceptions package
configuration package
configuration/comments
configuration/file(without yaml classes)
configuration/serialization

  • simple-yaml > includes just snakeyaml dependency and all the yaml classes.

configuration/file(just YAML classes)

I just want to separate the configuration module and YAML module that's using the configuration module.
I will make a p.r. about that. I hope the point will be more understandable.

Resetting lists

I have a data.yml file that contains some questions with their answers, etc.
The answers are in a list, but I've noticed that whenever a question gets picked, some weird behavior happens.

image

What I do with this is:
1- check if get questions.1.used is false (continue), else return
2- get questions.1.question and store in a variable
3- getList questions.1.answers and store in another variable
4- get questions.1.extra and store in another variable
5- set questions.1.used true
6- The rest is just java code

Here the only thing I'm setting is questions.1.used but it turns into this:

image

Two unexpected things happened:
1- questions.1.answers changed to an empty list, without me setting it to anything or changing it.
2- questions.1.extra is reformatted a little, this is not major and doesn't affect anything though.

This is not because of the IDE I'm using or anything, I've tried on different devices and it acts the same.

Could not find artifact me.carleslc.Simple-YAML:Simple-Configuration:jar:1.8.3 in central (https://repo1.maven.org/maven2)

Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact me.carleslc.Simple-YAML:Simple-Configuration:jar:1.8.3 in central (https://repo1.maven.org/maven2)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve (DefaultArtifactResolver.java:425)
at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts (DefaultArtifactResolver.java:229)
at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveDependencies (DefaultRepositorySystem.java:340)
at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve (DefaultProjectDependenciesResolver.java:207)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies (LifecycleDependencyResolver.java:243)
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies (LifecycleDependencyResolver.java:147)
at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved (MojoExecutor.java:401)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:347)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact me.carleslc.Simple-YAML:Simple-Configuration:jar:1.8.3 in central (https://repo1.maven.org/maven2)
at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed (ArtifactTransportListener.java:48)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run (BasicRepositoryConnector.java:369)
at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run (RunnableErrorForwarder.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1136)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:635)
at java.lang.Thread.run (Thread.java:833)

more https://github.com/ImNotSoftik/ToastDionysus/actions/runs/3803802898/jobs/6470469741

Add a method for ConfigurationSection.

I think a method that parse configuration section's key-values with just primitive types should be useful.
The problem with getValues() method that is including ConfigurationSection object instead a map.

Formatting MapList indent

My code:

        Config config = new PluginConfig(this, "config.yml");

        if (config.getConfig().isSet("test-path"))
            config.getConfig().getMapList("test-path").forEach(map -> map.forEach((o, o2) -> System.out.println(o + ": " + o2)));

        List<Map<String, Object>> mapList = new ArrayList<>();

        Map<String, Object> map1 = new HashMap<>();
        map1.put("1", "test1");
        map1.put("2", "test2");
        map1.put("3", "test3");
        mapList.add(map1);
        Map<String, Object> map2 = new HashMap<>();
        map2.put("4", "test1");
        map2.put("5", "test2");
        map2.put("6", "test3");
        mapList.add(map2);
        Map<String, Object> map3 = new HashMap<>();
        map3.put("7", "test1");
        map3.put("8", "test2");
        map3.put("9", "test3");
        mapList.add(map3);
        config.getConfig().set("test-path", mapList);

        config.saveConfig();
  • When running this code, the file will be saved like this
test-path:
  -
  '1': test1
  '2': test2
  '3': test3
  -
  '4': test1
  '5': test2
  '6': test3
  -
  '7': test1
  '8': test2
  '9': test3
  • Instead of
test-path:
- '1': test1
  '2': test2
  '3': test3
- '4': test1
  '5': test2
  '6': test3
- '7': test1
  '8': test2
  '9': test3
  • A simple fix for this is to remove this line

Comments being inserted twice

Original file:
original
After saving it with comments:
with-comments
The comments are inserted twice, this also means the commentsWritten value is increased twice meaning the last comment of the file won't be saved as "commentsWritten < n" is false. I solved this issue by removing the comment from the comments list after it's inserted once but this won't work for everyone.

Error saving a serializable List

Saving a serializable List will generate a corrupted yml file.

For example, editing this test over here
https://github.com/Carleslc/Simple-YAML/blob/master/Simple-Yaml/src/test/java/org/simpleyaml/examples/YamlSerializationExample.java#L41-L46

to this:

// Write an object to the YAML file
final Person p = new Person("12345678A", "John", 1990);
final Person p2 = new Person("12345678B", "Maria", 1990);

yamlFile.set("test.people." + p.getDni(), p);

yamlFile.set("test.peoples", Arrays.asList(
        p, p2
));

// Don't forget to save the file!
yamlFile.save();

Will result in this yml.file

test:
  people:
    12345678A: &id001
      ==: org.simpleyaml.examples.Person
      dni: 12345678A
      name: John
      birthYear: 1990
      isAlive: true
  peoples:
    - *id001
    -
    ==: org.simpleyaml.examples.Person
    dni: 12345678B
    name: Maria
    birthYear: 1990
    isAlive: true

Which is not a valid YAMLfile! Its missing indentation on it.
It should be something like this:

...
  peoples:
    - *id001
    -
      ==: org.simpleyaml.examples.Person
      dni: 12345678B
      name: Maria
      birthYear: 1990
      isAlive: true

From what i tested, loading a serializable list after manully fixing this identation problem works normaly.

Add comments programmatically?

Is there a way of doing this with simple-yaml directly?
Like the addDefault() method adds a new value the addComment() method could add comments.

NoSuchMethodError when registering config

I am trying to create a config file using the following method:
YamlFile yamlFile = new YamlFile("config.yml");

but I get an error on that line, telling me that there is a missing method from snakeyml. I am using the latest version of Simple-YAML with maven, and Velocity.

imagen

How can I parse/save header/comment correctly?

Suppose I have a yaml config:

# Example Config
# Generated by {version}

# check update
check_update: true

# another option
option: 1

yaml.option().header() will return:

# Example Config
# Generated by {version}

# check update

This is obviously not what I need 🤔

yaml.getComment("check_update") also returns

# Example Config
# Generated by {version}

# check update

Is there any way to separate them?

Invalid configuration caused by the library itself?

I don't write the yaml file manually, I use the library to do all that. But, for some reason, the configuration is still wrong?
image
that's the line where the error is.
image
and that's the error. What's the issue here? Keep in mind, this is a List that contains all these elements that I injected into '1'

Load YamlConfiguration Error

When i do this: https://pastebin.com/ixXuxmEc

I have this error:

[11:47:27 INFO]: [PTC] Enabling PTC v1.0
[11:47:27 ERROR]: Error occurred while enabling PTC v1.0 (Is it up to date?)
java.lang.NoSuchMethodError: org.yaml.snakeyaml.Yaml.<init>(Lorg/yaml/snakeyaml/constructor/BaseConstructor;Lorg/yaml/snakeyaml/representer/Representer;Lorg/yaml/snakeyaml/DumperOptions;Lorg/yaml/snakeyaml/LoaderOptions;Lorg/yaml/snakeyaml/resolver/Resolver;)V
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.setYaml(SnakeYamlImplementation.java:61) ~[?:?]
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.setYaml(SnakeYamlImplementation.java:48) ~[?:?]
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.<init>(SnakeYamlImplementation.java:44) ~[?:?]
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.<init>(SnakeYamlImplementation.java:40) ~[?:?]
        at org.simpleyaml.configuration.implementation.snakeyaml.SnakeYamlImplementation.<init>(SnakeYamlImplementation.java:36) ~[?:?]
        at org.simpleyaml.configuration.file.YamlConfiguration.<init>(YamlConfiguration.java:43) ~[?:?]
        at org.simpleyaml.configuration.file.YamlConfiguration.<init>(YamlConfiguration.java:33) ~[?:?]
        at org.kayteam.api.simple.yaml.SimpleYaml.reloadYamlFile(SimpleYaml.java:98) ~[?:?]
        at org.kayteam.api.simple.yaml.SimpleYaml.registerYamlFile(SimpleYaml.java:71) ~[?:?]
        at org.kayteam.ptc.PTC.registerFiles(PTC.java:51) ~[?:?]
        at org.kayteam.ptc.PTC.onEnable(PTC.java:34) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[patched_1.8.8.jar:git-PaperSpigot-445]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [patched_1.8.8.jar:git-PaperSpigot-445]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:407) [patched_1.8.8.jar:git-PaperSpigot-445]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:359) [patched_1.8.8.jar:git-PaperSpigot-445]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:318) [patched_1.8.8.jar:git-PaperSpigot-445]
        at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:408) [patched_1.8.8.jar:git-PaperSpigot-445]
        at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:372) [patched_1.8.8.jar:git-PaperSpigot-445]
        at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:327) [patched_1.8.8.jar:git-PaperSpigot-445]
        at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:267) [patched_1.8.8.jar:git-PaperSpigot-445]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:563) [patched_1.8.8.jar:git-PaperSpigot-445]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_312]
[11:47:27 INFO]: [PTC] Disabling PTC v1.0

[Question] String length limit! Can it be disabled?

It seems that when a line is too long, the dump process will "split" it into several lines to keep ir "readable" (?)

I would like to know if its possible to disable it (or change it), or this feature has something to do with performance?

I asks about the perforamance reaseon because a few years ago i had to split myself a giant string into a List because the yaml file was getting laggy to be readen.

image

file.getName();

When ever I try to get a File name with file.getName(); it returns nothing.

There is a bug when i set the list

so basically I used the library for a few days, and I found out that when I have a list already and try to add an element to it, something weird happens, so I create the List first by using config.set("key", ArrayList<String>("")) so first I want to create empty list.
but in the YML file it's not empty, so the bug is when I try to add an element like this:

List<String> list = ArrayList<String>(config.getStringList("key"), ("newElement"));

config.set("key", list);
config.save()

it displayed in the file like this

-  - 'newElement'
- 'oldElements'

it's so weird bug...

Can't properly set comments on nested options

I am using this code to set comments:

this.path(it).comment(comment, YamlCommentFormat.BLANK_LINE)

But the first line comment is not placed correctly: (sync.sync-config)

# This is a configuration file synchronization feature, you can configure RikkaAC on one server, and
# then use "/rikka sync" to synchronize to all RikkaAC connected to the same database, this is very
# convenient for some large networks
sync:
# Whether the sync feature should sync config.yml
  # (!) Note that this will override the storage setting
  # (!) Better to not change storage setting if you want to sync
  sync-config: true

How can I use defaults?

Hi,
I added some keys and values to the default map, but they have not been added to this file. So how can I use them for pre-set my yml file?
Sorry for my bad English :)

Nexus maven central is a good alternative to jitpack.

I think nexus is a good alternative to the jitpack.
Also, the dependency should be like that;

<dependency>
    <groupId>just.domain.name</groupId>
    <artifactId>Simple-Configuration</artifactId>
    <version>1.7</version>
</dependency>
<dependency>
    <groupId>just.domain.name</groupId>
    <artifactId>Simple-Yaml</artifactId>
    <version>1.7</version>
</dependency>

just.domain.name should be like for example io.github.portlek which's not including the Simple-YAML. In this case, the groupId should be me.carleslc and this will make the library more clear.
But I guess it's not allowed with the jitpack right?

"ö" turns into "\xf6"

When writing an "ö" in a config it turns into "\xf6";

My code for writing:

final File file = new File("config.yml");
try {
    final YamlFile yamlFile = new YamlFile(file);
    if (!yamlFile.exists()) {
        yamlFile.createNewFile(true);
    }
    yamlFile.loadWithComments();
    yamlFile.set("test", "ö");
    yamlFile.saveWithComments();
} catch (final IOException | InvalidConfigurationException exception) {
    exception.printStackTrace();
}

The config:

test: "\xf6"

The code for reading (output: "?"):

final File file = new File("config.yml");
final YamlFile yamlFile = new YamlFile(file);
try {
    yamlFile.loadWithComments();
} catch (final InvalidConfigurationException | IOException exception) {
    exception.printStackTrace();
}
System.out.println(yamlFile.getString("test"));

Comments are broken

Error Message: while scanning a simple key
 in 'string', line 15, column 1:
    ys to 0 if you want to keep your ... 
    ^
could not find expected ':'
 in 'string', line 16, column 13:
        max-days: 7
                ^

Yaml file: (max-days duplicated itself and the # and half of the comment disappeared)

  plugins-backup:
    # Backups your plugins folder before startup to /autoplug-backups/plugins/...zip
    enable: true
    max-days: 7
ys to 0 if you want to keep your backups forever.
    max-days: 7

Comment support?

Hi, I don't have an issue at all I was just wondering if this API supports comments that are made in the YML file? I know that by default SnakeYAML doesn't handle these and I was wondering if this had been implemented into this API?

CI with travis.

This feature should be good when someone wants to create a pull request. the code reviewer can see what's the problem with the test.

Auto updates

Does this library automatically add nodes from the default resource to the existing yaml file if they're not currently present?

Header being duplicated when there is no comment on the root key

When there is no comment on the root-key, the header will be in both the options().header and in the roots.comment()

This will cause a duplication of the header on the next save.

Example!

image


How to Reproduce:

Under the YamlCommentsFormatExample.java

1 - Remove the comment on RootKey https://github.com/Carleslc/Simple-YAML/blob/master/Simple-Yaml/src/test/java/org/simpleyaml/examples/YamlCommentsFormatExample.java#L45

2 - Add this to the end of the test

        YamlFile yamlFile2 = new YamlFile(yamlFile.getConfigurationFile());
        yamlFile2.loadWithComments();
        yamlFile2.save("examples/test-comments-format-2.yml");

FileOutput:

image

Reliable and more powerful unit testing.

ATM, the testing is not safe so much. We should add official unit test with jupiter and it should work when we build the project.

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter</artifactId>
    <version>5.6.2</version>
    <scope>test</scope>
</dependency>

Also, need a plugin;

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
</plugin>

for automatic tests when the project is building.

Weird behavior of Side comments

I wrote a program to test the comment feature of YAML

  • The code
        // Create new YAML file with relative path
        saveResource("test.yml", true);
        final YamlFile yamlFile = new YamlFile(new File(getDataFolder(), "test.yml"));

        try {
            yamlFile.createOrLoadWithComments();
        } catch (final Exception e) {
            e.printStackTrace();
        }

        System.out.println("test-comment value: " + yamlFile.getString("test-comment"));
        System.out.println("test-comment side comment: " + yamlFile.getComment("test-comment", CommentType.SIDE));
        System.out.println("test-comment1 value: " + yamlFile.getString("test-comment1"));
        System.out.println("test-comment1 side comment: " + yamlFile.getComment("test-comment1", CommentType.SIDE));

        try {
            yamlFile.save();
        } catch (final IOException e) {
            e.printStackTrace();
        }
  • test.yml
test-comment: 'value' # comment
test-comment1: 'test# value2' # comment
  • Output
test-comment value: value
test-comment side comment: comment
test-comment1 value: test# value2
test-comment1 side comment: value2'comment
  • test.yml after running the code
test-comment: value # comment
test-comment1: test# value2# value2' # comment

The output was supposed to be

test-comment value: value
test-comment side comment: comment
test-comment1 value: test# value2
test-comment1 side comment: comment

And test.yml should not be changed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.