Skip to content

Commit

Permalink
hocon: setup vendor project, remove config sorting on write and use o…
Browse files Browse the repository at this point in the history
…rder preserving collections (#446)

* hocon: setup vendor project

* hocon: don't sort configs by key

* hocon: make sort on write an option

* build: deduplicate logic between hocon and yaml loaders

* build: adjust shadow catalog entry and gitpatcher ver

* Revert "hocon: make sort on write an option"

This reverts commit 549655d.

* hocon: remove some unnecessary diff

* build: bump gitpatcher to 1.1.0

* build: don't shade scala files
  • Loading branch information
jpenilla authored Nov 9, 2023
1 parent b73e6e1 commit 53201ee
Show file tree
Hide file tree
Showing 17 changed files with 659 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ build-logic/*/bin/

# gitpatcher local data
/vendor/snakeyaml
/vendor/typesafe-config
/vendor/gradle.properties

# IntelliJ project data
.idea
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "vendor/snakeyaml-upstream"]
path = vendor/snakeyaml-upstream
url = https://bitbucket.org/snakeyaml/snakeyaml.git
[submodule "vendor/typesafe-config-upstream"]
path = vendor/typesafe-config-upstream
url = https://github.com/lightbend/config.git
1 change: 1 addition & 0 deletions build-logic/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
api libs.build.japicmp.plugin
api libs.build.forbiddenApis
api libs.build.goomph
api libs.build.shadow

codenarc libs.build.codenarc
codenarc libs.build.codenarcGroovy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
plugins {
id "org.spongepowered.configurate.build.component"
id "com.github.johnrengelman.shadow"
}

configurations {
shaded
compileClasspath { extendsFrom shaded }
runtimeClasspath { extendsFrom shaded }
testImplementation { extendsFrom shaded }
}

tasks {
shadowJar {
dependsOn ':core:jar' // why?
configurations = [project.configurations.shaded]
minimize()
}

assemble {
dependsOn shadowJar
}

pmdMain {
enabled = false
}
}

if (project.hasProperty("spongeKeyStore")) {
// Just update the input of the sign jar task
tasks.shadowJar {
dependsOn ':core:signJar' // why?
archiveClassifier = "unsigned-all"
}
tasks.jar {
archiveClassifier = "unsigned"
}

tasks.named("signJar", org.spongepowered.configurate.build.SignJarTask) {
dependsOn(tasks.shadowJar)

from(zipTree(tasks.shadowJar.outputs.files.singleFile))
}
} else {
// Replace the default artifact
// We have to replace the default artifact which is a bit ugly
// https://github.com/gradle/gradle/pull/13650 should make it easier
def forRelevantOutgoings = { action ->
action.resolveStrategy = Closure.DELEGATE_FIRST
action.delegate = configurations[JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME].outgoing
action()
action.delegate = configurations[JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME].outgoing
action()
}

forRelevantOutgoings {
artifact(tasks.shadowJar)
}

tasks.shadowJar {
archiveClassifier = ""
}
tasks.jar {
archiveClassifier = "thin"
}

afterEvaluate {
forRelevantOutgoings {
artifacts.removeIf { it.classifier.equals("thin") }
}
}
}
13 changes: 11 additions & 2 deletions format/hocon/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
plugins {
id "org.spongepowered.configurate.build.component"
id 'org.spongepowered.configurate.build.shadow-component'
}

description = "HOCON format loader for Configurate"

dependencies {
api projects.core
implementation libs.hocon
shaded("configurate.thirdparty:typesafe-config:version-from-submodule") {
// lib has no dependencies, but classpath is polluted by scala for tests...
transitive = false
}
testImplementation libs.guava
}

tasks {
shadowJar {
relocate("com.typesafe.config", "${project.group}.configurate.hocon.internal.typesafeconfig")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ void testBooleansNotShared(final @TempDir Path tempDir) throws IOException {
.path(saveTo).url(url).build();

final CommentedConfigurationNode node = loader.createNode(ConfigurationOptions.defaults());
node.node("test", "third").set(false).comment("really?");
node.node("test", "apple").comment("fruit").set(false);
node.node("test", "donut").set(true).comment("tasty");
node.node("test", "guacamole").set(true).comment("and chips?");
node.node("test", "third").set(false).comment("really?");

loader.save(node);
assertEquals(Resources.readLines(url, StandardCharsets.UTF_8), Files.readAllLines(saveTo, StandardCharsets.UTF_8));
Expand Down
8 changes: 4 additions & 4 deletions format/hocon/src/test/resources/roundtrip-test.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Gotta test an empty node
empty {}
other {
location="dog park"
op-level=dragon
}
# Test node
test {
op-level=unicorn
}
other {
op-level=dragon
location="dog park"
}
66 changes: 1 addition & 65 deletions format/yaml/build.gradle
Original file line number Diff line number Diff line change
@@ -1,80 +1,16 @@
plugins {
id 'org.spongepowered.configurate.build.component'
alias(libs.plugins.shadow)
id 'org.spongepowered.configurate.build.shadow-component'
}

description = "YAML format loader for Configurate"

configurations {
shaded
compileClasspath { extendsFrom shaded }
runtimeClasspath { extendsFrom shaded }
testImplementation { extendsFrom shaded }
}

dependencies {
api projects.core
shaded "configurate.thirdparty:snakeyaml:version-from-submodule"
}

tasks {
shadowJar {
dependsOn ':core:jar' // why?
configurations = [project.configurations.shaded]
minimize()
relocate("org.yaml.snakeyaml", "${project.group}.configurate.yaml.internal.snakeyaml")
}

assemble {
dependsOn shadowJar
}

pmdMain {
enabled = false
}
}

if (project.hasProperty("spongeKeyStore")) {
// Just update the input of the sign jar task
tasks.shadowJar {
dependsOn ':core:signJar' // why?
archiveClassifier = "unsigned-all"
}
tasks.jar {
archiveClassifier = "unsigned"
}

tasks.named("signJar", org.spongepowered.configurate.build.SignJarTask) {
dependsOn(tasks.shadowJar)

from(zipTree(tasks.shadowJar.outputs.files.singleFile))
}
} else {
// Replace the default artifact
// We have to replace the default artifact which is a bit ugly
// https://github.com/gradle/gradle/pull/13650 should make it easier
def forRelevantOutgoings = { action ->
action.resolveStrategy = Closure.DELEGATE_FIRST
action.delegate = configurations[JavaPlugin.API_ELEMENTS_CONFIGURATION_NAME].outgoing
action()
action.delegate = configurations[JavaPlugin.RUNTIME_ELEMENTS_CONFIGURATION_NAME].outgoing
action()
}

forRelevantOutgoings {
artifact(tasks.shadowJar)
}

tasks.shadowJar {
archiveClassifier = ""
}
tasks.jar {
archiveClassifier = "thin"
}

afterEvaluate {
forRelevantOutgoings {
artifacts.removeIf { it.classifier.equals("thin") }
}
}
}
5 changes: 2 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ guice-runtime = "com.google.inject:guice:5.0.1"

# Formats
gson = "com.google.code.gson:gson:2.8.0" # Fixed version, to avoid using API not present in older MC
hocon = "com.typesafe:config:1.4.3"
jackson = "com.fasterxml.jackson.core:jackson-core:2.15.3"

# Tool
Expand All @@ -66,6 +65,7 @@ build-japicmp-plugin = "me.champeau.gradle:japicmp-gradle-plugin:0.4.2"
build-japicmp = { module = "com.github.siom79.japicmp:japicmp", version.require = "0.15.+" }
build-nullaway = "net.ltgt.gradle:gradle-nullaway-plugin:1.6.0"
build-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
build-shadow = { module = "com.github.johnrengelman:shadow", version = "8.1.1" }

# For Renovate -- shouldn't need to use these directly
zPmd = { module = "net.sourceforge.pmd:pmd-java", version.ref = "pmd" }
Expand All @@ -77,10 +77,9 @@ aggregateJavadoc = "io.freefair.aggregate-javadoc-jar:8.4"
detekt = "io.gitlab.arturbosch.detekt:1.23.3"
dokka = "org.jetbrains.dokka:1.9.10"
gitPublish = "org.ajoberstar.git-publish:3.0.1"
gitpatcher = { id = "ca.stellardrift.gitpatcher", version = "1.0.0" }
gitpatcher = { id = "ca.stellardrift.gitpatcher", version = "1.1.0" }
indra-sonatype = { id = "net.kyori.indra.publishing.sonatype", version.ref = "indra" }
indra-git = { id = "net.kyori.indra.git", version.ref = "indra" }
kotlin = "org.jetbrains.kotlin.jvm:1.9.20"
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0-rc-1" }
shadow = "com.github.johnrengelman.shadow:8.1.1"
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
4 changes: 2 additions & 2 deletions vendor/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[*]
indent_size = 2
[snakeyaml/**]
indent_size = 2
7 changes: 7 additions & 0 deletions vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ snakeyaml

A fork of snakeyaml for fixes to comment handling that have not yet made it into
an upstream release.

typesafe-config
---------------

Modifications and enhancements to typesafe-config that are useful for
Configurate's use case, but that upstream does not want to adopt due to the
wider scope of their configuration loading API.
Loading

0 comments on commit 53201ee

Please sign in to comment.