Browse Source

prepared configuration.json for publishing

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main
Stephan Richter 2 months ago
parent
commit
bb25d61480
  1. 4
      de.srsoftware.configuration.api/src/main/java/de/srsoftware/configuration/Locator.java
  2. 70
      de.srsoftware.configuration.json/build.gradle.kts
  3. 30
      de.srsoftware.configuration.json/src/main/java/de/srsoftware/configuration/JsonConfig.java

4
de.srsoftware.configuration.api/src/main/java/de/srsoftware/configuration/Locator.java

@ -8,8 +8,8 @@ import java.nio.file.Path; @@ -8,8 +8,8 @@ import java.nio.file.Path;
* Helper for getting a config file
*/
public class Locator {
private Locator(){}
private Locator() {
}
/**
* Get the proper configuration file for a given application name with the desired extension

70
de.srsoftware.configuration.json/build.gradle.kts

@ -3,4 +3,72 @@ description = "SRSoftware Configuration | JSON Configuration" @@ -3,4 +3,72 @@ description = "SRSoftware Configuration | JSON Configuration"
dependencies {
implementation(project(":de.srsoftware.configuration.api"))
implementation("org.json:json:latest.release")
}
}
plugins {
id("eu.kakde.gradle.sonatype-maven-central-publisher") version "1.0.6"
}
object Meta {
val COMPONENT_TYPE = "java" // "java" or "versionCatalog"
val GROUP = "de.srsoftware"
val ARTIFACT_ID = "configuration.json"
val VERSION = "1.0.0"
val PUBLISHING_TYPE = "AUTOMATIC" // USER_MANAGED or AUTOMATIC
val SHA_ALGORITHMS = listOf("SHA-256", "SHA-512") // sha256 and sha512 are supported but not mandatory. Only sha1 is mandatory but it is supported by default.
val DESC = "SRSoftware Configuration: Json-based Implementation"
val LICENSE = "MIT License"
val LICENSE_URL = "http://www.opensource.org/licenses/mit-license.php"
val GITHUB_REPO = "srsoftware-de/de.srsoftware.configuration"
val DEVELOPER_ID = "srichter"
val DEVELOPER_NAME = "Stephan Richter"
val DEVELOPER_ORGANIZATION = "SRSoftware"
val DEVELOPER_ORGANIZATION_URL = "https://srsoftware.de"
}
val sonatypeUsername: String? by project // this is defined in ~/.gradle/gradle.properties
val sonatypePassword: String? by project // this is defined in ~/.gradle/gradle.properties
sonatypeCentralPublishExtension {
// Set group ID, artifact ID, version, and other publication details
groupId.set(Meta.GROUP)
artifactId.set(Meta.ARTIFACT_ID)
version.set(Meta.VERSION)
componentType.set(Meta.COMPONENT_TYPE) // "java" or "versionCatalog"
publishingType.set(Meta.PUBLISHING_TYPE) // USER_MANAGED or AUTOMATIC
// Set username and password for Sonatype repository
username.set(sonatypeUsername)
password.set(sonatypePassword)
// Configure POM metadata
pom {
name.set(Meta.ARTIFACT_ID)
description.set(Meta.DESC)
url.set("https://github.com/${Meta.GITHUB_REPO}")
licenses {
license {
name.set(Meta.LICENSE)
url.set(Meta.LICENSE_URL)
}
}
developers {
developer {
id.set(Meta.DEVELOPER_ID)
name.set(Meta.DEVELOPER_NAME)
organization.set(Meta.DEVELOPER_ORGANIZATION)
organizationUrl.set(Meta.DEVELOPER_ORGANIZATION_URL)
}
}
scm {
url.set("https://github.com/${Meta.GITHUB_REPO}")
connection.set("scm:git:https://github.com/${Meta.GITHUB_REPO}")
developerConnection.set("scm:git:https://github.com/${Meta.GITHUB_REPO}")
}
issueManagement {
system.set("GitHub")
url.set("https://github.com/${Meta.GITHUB_REPO}/issues")
}
}
}

30
de.srsoftware.configuration.json/src/main/java/de/srsoftware/configuration/JsonConfig.java

@ -10,10 +10,19 @@ import java.util.*; @@ -10,10 +10,19 @@ import java.util.*;
import org.json.JSONObject;
/**
* A Configuration implementation, that stores its data in a json file.
* Altered json &lt;em&gt;is not automatically saved&gt;/em&lt; after editing!
*/
public class JsonConfig implements Configuration {
private final File file;
private final JSONObject json;
/**
* Create a new JsonConfig instance using the passed file for storage
* @param jsonConfigurationFile this file will be used to store json data
* @throws IOException if one of the file operations failed
*/
public JsonConfig(File jsonConfigurationFile) throws IOException {
file = jsonConfigurationFile;
if (file.isDirectory()) throw new IllegalArgumentException("%s is a directory, file expected".formatted(file));
@ -23,6 +32,11 @@ public class JsonConfig implements Configuration { @@ -23,6 +32,11 @@ public class JsonConfig implements Configuration {
json = new JSONObject(Files.readString(file.toPath()));
}
/**
* Create a new JsonConfig using the passed applicationName
* @param applicationName this determines the name of the file, to which data are stored
* @throws IOException if one of the file operations failed
*/
public JsonConfig(String applicationName) throws IOException {
this(Locator.locateConfig(applicationName, "json"));
}
@ -43,10 +57,18 @@ public class JsonConfig implements Configuration { @@ -43,10 +57,18 @@ public class JsonConfig implements Configuration {
if (json.get(key) instanceof JSONObject inner) drop(inner, path);
}
/**
* returns the file object of the json storage
* @return a File object
*/
public File file() {
return file;
}
/**
* creates a one-line representation of the json of this config
* @return the config as json string
*/
public String flat() {
return json.toString();
}
@ -95,6 +117,14 @@ public class JsonConfig implements Configuration { @@ -95,6 +117,14 @@ public class JsonConfig implements Configuration {
}
}
/**
* updates the storage file with the current json data
* @throws IOException if writing the file does so
*/
public void save() throws IOException {
Files.writeString(file.toPath(), json.toString(2));
}
@Override
@SuppressWarnings("unchecked")
public <C extends Configuration> C set(String key, Object value) throws IOException {

Loading…
Cancel
Save