Skip to content

Latest commit

 

History

History
314 lines (266 loc) · 9.2 KB

README.md

File metadata and controls

314 lines (266 loc) · 9.2 KB

Settings

Java library to interpret multiple data formats as flexible configuration.

Settings library handle multiple data formats as configuration in a flexible way:

  • Node templates and transformation.
  • Node value substitution in non-compatible formats (like json and yaml).
  • Fallback format reader.
  • Iterable nodes.
  • Data update parameters.
  • Comparable paths to get nodes.
  • Multi-layer node values.

Currently supporting the formats:

Take in count this library is not focused as an object serializer, the main purpose is making flexible interactions with multiple data formats at the same time.

It also has simple methods to get nodes as multiple data types if you want to implement your own object serializer.

// Load settings from Map
Map<String, Object> map = new HashMap<>();
map.put("key", "value");
map.put("otherkey", 1234);

Settings settings = new Settings();
settings.merge(map);


// Settings from any file named "myfile", the format can be any supported format.
// If file doesn't exist, the optional file "myfile.json" inside .jar will be used.
SettingsData<Settings> data = SettingsData.of("myfile.*").or(DataType.INPUT_STREAM, "myfile.json");
// Load settings by providing a parent folder.
// Also, optional file will be saved inside the folder if original file doesn't exist
File folder = new File("folder");
Settings settings = data.load(folder, true);

Dependency

How to use Settings library in your project.

build.gradle
repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.saicone.settings:settings:VERSION'
    // Other modules
    implementation 'com.saicone.settings:settings-gson:VERSION'
    implementation 'com.saicone.settings:settings-hocon:VERSION'
    implementation 'com.saicone.settings:settings-toml:VERSION'
    implementation 'com.saicone.settings:settings-yaml:VERSION'
}
build.gradle.kts
repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.saicone.settings:settings:VERSION")
    // Other modules
    implementation("com.saicone.settings:settings-gson:VERSION")
    implementation("com.saicone.settings:settings-hocon:VERSION")
    implementation("com.saicone.settings:settings-toml:VERSION")
    implementation("com.saicone.settings:settings-yaml:VERSION")
}
pom.xml
<repositories>
    <repository>
        <id>Jitpack</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <!-- Other modules -->
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-gson</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-hocon</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-toml</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-yaml</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

Relocated Dependency

How to implement and relocate Settings library in your project.

build.gradle
plugins {
    id 'com.gradleup.shadow' version '8.3.5'
}

repositories {
    maven { url 'https://jitpack.io' }
}

dependencies {
    implementation 'com.saicone.settings:settings:VERSION'
    // Other modules
    implementation 'com.saicone.settings:settings-gson:VERSION'
    implementation 'com.saicone.settings:settings-hocon:VERSION'
    implementation 'com.saicone.settings:settings-toml:VERSION'
    implementation 'com.saicone.settings:settings-yaml:VERSION'
}

jar.dependsOn (shadowJar)

shadowJar {
    // Relocate packages (DO NOT IGNORE THIS)
    relocate 'com.saicone.types', project.group + '.libs.types'
    relocate 'com.saicone.settings', project.group + '.libs.settings'
    // Exclude unused classes (optional)
    minimize()
}
build.gradle.kts
plugins {
    id("com.gradleup.shadow") version "8.3.5"
}

repositories {
    maven("https://jitpack.io")
}

dependencies {
    implementation("com.saicone.settings:settings:VERSION")
    // Other modules
    implementation("com.saicone.settings:settings-gson:VERSION")
    implementation("com.saicone.settings:settings-hocon:VERSION")
    implementation("com.saicone.settings:settings-toml:VERSION")
    implementation("com.saicone.settings:settings-yaml:VERSION")
}

tasks {
    jar {
        dependsOn(tasks.shadowJar)
    }

    shadowJar {
        // Relocate packages (DO NOT IGNORE THIS)
        relocate("com.saicone.types", "${project.group}.libs.types")
        relocate("com.saicone.settings", "${project.group}.libs.settings")
        // Exclude unused classes (optional)
        minimize()
    }
}
pom.xml
<repositories>
    <repository>
        <id>Jitpack</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <!-- Other modules -->
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-gson</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-hocon</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-toml</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.saicone.settings</groupId>
        <artifactId>settings-yaml</artifactId>
        <version>VERSION</version>
        <scope>compile</scope>
    </dependency>
</dependencies>

<build>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.3.0</version>
        <configuration>
            <relocations>
                <!-- Relocate packages (DO NOT IGNORE THIS) -->
                <relocation>
                    <pattern>com.saicone.types</pattern>
                    <shadedPattern>${project.groupId}.libs.types</shadedPattern>
                </relocation>
                <relocation>
                    <pattern>com.saicone.settings</pattern>
                    <shadedPattern>${project.groupId}.libs.settings</shadedPattern>
                </relocation>
            </relocations>
            <!-- Exclude unused classes (optional) -->
            <minimizeJar>true</minimizeJar>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
</build>

Note

This project use Types library to convert data types, so it's required to relocate it's package along with settings package.