Git Product home page Git Product logo

boosted-yaml's Introduction

๐Ÿ”ผ BoostedYAML

A simple-to-use standalone (beneficial for cross-platform and multimodule projects) Java library delivering boosted experience while working with YAML documents. Work on this project started on Apr 8, 2021 with the target to build advanced, hence still easy-to-use library which would enable developers to manage documents and files with ease.

If you are developing plugins for Spigot/BungeeCord API, make sure to read the post at SpigotMC forums for more information regarding setup and other relevant useful information.

BoostedYAML is powered by Senior Hosting. Use code "YAML" for 10% off!

โ“ Why to use BoostedYAML over other libraries?

BoostedYAML is single of its kind, given the following advantages:

  1. SnakeYAML Engine based - built upon popular and trusted software.
  2. YAML 1.2 supported - allows to reliably parse JSON files
  3. Comments everywhere - no longer a headache for your customers, say bye to external documentation.
  4. File updater - upgrading to the latest version of your software? Adapt the configuration files easily, with one line of code.
  5. Beautiful structure management - makes your code cleaner and easier to read.
  6. Functional interfaces included - we've got something for everyone.
  7. Amazing features - automatic saving, updating, endless possibilities.
  8. Settings for everything - customize it to suite your needs just perfectly.
  9. Performant and well documented - just like a dream.
  10. Open source - if there's anything that can be improved, feel free to let me know, or contribute.
  11. TDD (test driven development) - don't worry about reliability, everything's verified automatically before production by more than 140 tests.

All of that with quick and kind support. Convinced? Let's get you onboard.

๐Ÿ”ง Quick setup

Setup takes only about 5 minutes. Example software built using this guide is available at https://github.com/dejvokep/boosted-yaml-example.

1. Add using Maven (Gradle):

BoostedYAML is hosted by Maven Central Repository. That means, you only need to add a dependency:

<dependency>
  <groupId>dev.dejvokep</groupId>
  <artifactId>boosted-yaml</artifactId>
  <version>1.3</version>
</dependency>

Add the following shading section to prevent class loader conflicts:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.2.4</version>
      <configuration>
        <relocations>
          <relocation>
            <pattern>dev.dejvokep.boostedyaml</pattern>
            <!-- Replace this -->
            <shadedPattern>me.plugin.libs</shadedPattern>
          </relocation>
        </relocations>
      </configuration>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

2. Routes and how to access content

Routes are immutable objects used to address content - similar to URIs (Universe Resource Identifier). Please read more about them here.

3. Create your document:

Please note that this guide covers only the basics, there are a lot more variations of the method - learn more at the Javadoc or wiki.

YamlDocument config = YamlDocument.create(new File("config.yml"), getResource("config.yml"));

The file will automatically be managed by the library - no need to create it if it does not exist, nor copy the defaults. Everything's done automatically. Please note that if you chose to use Routes (objects), you will need to configure the document to use KeyFormat.OBJECT. You can do so via GeneralSettings, with the final .create() method looking like:

YamlDocument config = YamlDocument.create(new File("config.yml"), getResource("config.yml"), GeneralSettings.builder().setKeyFormat(KeyFormat.OBJECT).build(), LoaderSettings.DEFAULT, DumperSettings.DEFAULT, UpdaterSettings.DEFAULT);

4. Updater prerequisites:

A)

You might already be familiar with specifying version inside your document, most common is something like this:

config-version: 1

BoostedYAML defines such information as version ID. Pick a route at which the version ID of the document will be. You will never be able to change it and the defaults must have it specified and valid. Provide the route to UpdaterSettings like this:

UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build();

Do not forget to provide the built settings to the .create() method.

B)

The first version ID the document's going to have is 1, like shown below. The next release of the file will have ID of 2, then 3...:

config-version: 1   # 1st release
config-version: 2   # 2nd release
config-version: 3   # 3rd release
# etc.
C)

Parameters of the .create() might now look like this:

YamlDocument config = YamlDocument.create(new File("config.yml"), getResource("config.yml"), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build());

The custom LoaderSettings with enabled auto-update will ensure the document's automatically updated initially and each time it's reloaded.

That's it! No need to do some weird file version handling manually, let BoostedYAML do it for you. The updater also offers some nice features like ignored routes and relocations, which you can learn more about by clicking the links.

5. Use the document to it's fullest:

Reload/save anytime from/to the file:

config.reload();
config.save();

Obtain data using getX(String route), alternatively, use functional getters for functional method chaining:

Mode m = config.getStringOptional("mode").map(mode -> Mode.valueOf(mode.toUpperCase())).orElse(Mode.PERFORMANCE);

BoostedYAML also provides it's own serialization system and other cool options, about which you can read more at the wiki.

๐Ÿค– Support

You can read the detailed instructions at the wiki. If you need help with anything, feel free join the Discord server. Or, just to talk with us ๐Ÿ‘‹

boosted-yaml's People

Contributors

dejvokep avatar iatog avatar dependabot[bot] avatar

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.