diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a9a868..664724b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,27 +3,21 @@ name: Build on: [push, pull_request] jobs: - jvm: + build: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - java-version: - - 11 - steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 - name: Configure JDK - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'zulu' - java-version: ${{ matrix.java-version }} + java-version: '17' - name: Test run: ./gradlew build \ No newline at end of file diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b2b7a2f..872da39 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -4,6 +4,8 @@ on: push: tags: - '*' +env: + RELEASE_SIGNING_ENABLED: true jobs: publish: @@ -13,26 +15,21 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Install JDK 11 - uses: actions/setup-java@v1 + - name: Install JDK + uses: actions/setup-java@v4 with: - java-version: 11 + distribution: 'zulu' + java-version: 17 - name: Set version run: sed -i "s/VERSION_NAME=0.0.1/VERSION_NAME=$GITHUB_REF_NAME/" gradle.properties - - name: Upload release - run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-daemon --no-parallel + - name: Release to Maven Central + run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache env: ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} - ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} - - - name: Publish release - run: ./gradlew closeAndReleaseRepository --no-daemon --no-parallel - env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} \ No newline at end of file + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} \ No newline at end of file diff --git a/README.md b/README.md index b72af77..ebfb720 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ We do not allow configuration of more complicated resources like `drawable` and License -------- - Copyright 2022 Commit 451 + Copyright 2024 Commit 451 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/build.gradle.kts b/build.gradle.kts index b7e2bf3..0c887ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,32 +1,30 @@ -buildscript { - repositories { - mavenCentral() - gradlePluginPortal() - } - dependencies { - classpath("com.vanniktech:gradle-maven-publish-plugin:0.18.0") - } -} +import com.vanniktech.maven.publish.JavaLibrary +import com.vanniktech.maven.publish.JavadocJar +import com.vanniktech.maven.publish.SonatypeHost plugins { - kotlin("jvm") version "1.6.10" - id("com.github.ben-manes.versions") version "0.42.0" + alias(libs.plugins.org.jetbrains.kotlin) + alias(libs.plugins.com.vanniktech.publish) } -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } +kotlin { + jvmToolchain(17) } -apply(plugin = "com.vanniktech.maven.publish") -apply(from = "sonatype.gradle") - -repositories { - mavenCentral() +dependencies { + testImplementation(libs.junit) + testImplementation(libs.guava) } -dependencies { - testImplementation("junit:junit:4.13.2") - testImplementation("com.google.guava:guava:31.0.1-jre") +mavenPublishing { + configure( + JavaLibrary( + javadocJar = JavadocJar.Javadoc(), + sourcesJar = true, + ) + ) + publishToMavenCentral(SonatypeHost.S01) + if (System.getenv("RELEASE_SIGNING_ENABLED") == "true") { + signAllPublications() + } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..1c759f6 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,10 @@ +[versions] +org-jetbrains-kotlin = "1.9.20" + +[libraries] +junit = { group = "junit", name = "junit", version = "4.13.2" } +guava = { group = "com.google.guava", name = "guava", version = "32.0.0-jre" } + +[plugins] +org-jetbrains-kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "org-jetbrains-kotlin" } +com-vanniktech-publish = { id = "com.vanniktech.maven.publish", version = "0.27.0" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b1159fc..89aa556 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 27d304b..665cd1d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,16 @@ -rootProject.name = "resourcespoet" +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "resourcespoet" \ No newline at end of file diff --git a/sonatype.gradle b/sonatype.gradle deleted file mode 100644 index 4e873e3..0000000 --- a/sonatype.gradle +++ /dev/null @@ -1,7 +0,0 @@ -allprojects { - plugins.withId("com.vanniktech.maven.publish") { - mavenPublish { - sonatypeHost = "S01" - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/commit451/resourcespoet/Attr.kt b/src/main/kotlin/com/commit451/resourcespoet/Attr.kt index fd608f2..1486107 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/Attr.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/Attr.kt @@ -10,7 +10,7 @@ class Attr { var name: String val formats = mutableListOf() - enum class Format constructor(private val attrName: String) { + enum class Format(private val attrName: String) { BOOLEAN("boolean"), FLOAT("float"), COLOR("color"), diff --git a/src/main/kotlin/com/commit451/resourcespoet/Plural.kt b/src/main/kotlin/com/commit451/resourcespoet/Plural.kt index 2a01b9c..675d61d 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/Plural.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/Plural.kt @@ -4,15 +4,14 @@ package com.commit451.resourcespoet /** * Represents an Android Plural - * See //developer.android.com/guide/topics/resources/string-resource.html#Plurals">https://developer.android.com/guide/topics/resources/string-resource.html#Plurals - */ -data class Plural -/** - * Construct a new plural * @param quantity the quantity * @param value the value + * See [the Android docs](https://developer.android.com/guide/topics/resources/string-resource.html#Plurals) */ -(val quantity: Quantity, val value: String) { +data class Plural( + val quantity: Quantity, + val value: String, +) { enum class Quantity { zero, diff --git a/src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt b/src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt index 119adff..2615360 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt @@ -4,7 +4,6 @@ import org.w3c.dom.Document import org.w3c.dom.Element import org.xml.sax.SAXException import java.io.* -import java.util.* import javax.xml.parsers.DocumentBuilder import javax.xml.parsers.DocumentBuilderFactory import javax.xml.parsers.ParserConfigurationException @@ -25,7 +24,7 @@ class ResourcesPoet private constructor( companion object { - enum class ELEMENT constructor(val elementName: String) { + enum class ELEMENT(val elementName: String) { RESOURCES("resources"), FONT_FAMILIES("font-family") } diff --git a/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt b/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt index 6ee86ca..672daf8 100644 --- a/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt +++ b/src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt @@ -1,7 +1,7 @@ package com.commit451.resourcespoet /** - * An item within a style, like + * An item within a style, like: * * @android:color/black */ diff --git a/src/test/kotlin/com/commit451/resourcespoet/AddByTypeTest.kt b/src/test/kotlin/com/commit451/resourcespoet/AddByTypeTest.kt index 7f03844..08ceeae 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/AddByTypeTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/AddByTypeTest.kt @@ -11,7 +11,7 @@ class AddByTypeTest { @Test fun addStringType() { val poet = ResourcesPoet.create() - .add(Type.STRING, "app_name", "Test") + .add(Type.STRING, "app_name", "Test") TestUtil.assertEquals("string.xml", poet) } @@ -19,7 +19,7 @@ class AddByTypeTest { @Test fun addIntegerType() { val poet = ResourcesPoet.create() - .add(Type.INTEGER, "number", "0") + .add(Type.INTEGER, "number", "0") TestUtil.assertEquals("integer.xml", poet) } @@ -29,7 +29,7 @@ class AddByTypeTest { var exception: Exception? = null try { ResourcesPoet.create() - .add(Type.INTEGER_ARRAY, "fail", "fail") + .add(Type.INTEGER_ARRAY, "fail", "fail") } catch (e: Exception) { exception = e } diff --git a/src/test/kotlin/com/commit451/resourcespoet/AttrTest.kt b/src/test/kotlin/com/commit451/resourcespoet/AttrTest.kt index 89789f5..827d9ad 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/AttrTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/AttrTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -15,7 +14,7 @@ class AttrTest { formats.add(Attr.Format.REFERENCE) val attr = Attr("font", formats) val poet = ResourcesPoet.create() - .addAttr(attr) + .addAttr(attr) TestUtil.assertEquals("attr.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/BoolTest.kt b/src/test/kotlin/com/commit451/resourcespoet/BoolTest.kt index 094b8e7..6b3f95a 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/BoolTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/BoolTest.kt @@ -10,7 +10,7 @@ class BoolTest { @Test fun boolTest() { val poet = ResourcesPoet.create() - .addBool("is_cool", true) + .addBool("is_cool", true) TestUtil.assertEquals("bool.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/ColorTest.kt b/src/test/kotlin/com/commit451/resourcespoet/ColorTest.kt index ab9ea9b..2ba4574 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/ColorTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/ColorTest.kt @@ -10,7 +10,7 @@ class ColorTest { @Test fun colorTest() { val poet = ResourcesPoet.create() - .addColor("color_primary", "#FF0000") + .addColor("color_primary", "#FF0000") TestUtil.assertEquals("color.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/CommentTest.kt b/src/test/kotlin/com/commit451/resourcespoet/CommentTest.kt index 8756102..cbd0382 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/CommentTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/CommentTest.kt @@ -10,7 +10,7 @@ class CommentTest { @Test fun commentTest() { val poet = ResourcesPoet.create() - .addComment("This is a comment") + .addComment("This is a comment") TestUtil.assertEquals("comment.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/ConfigTest.kt b/src/test/kotlin/com/commit451/resourcespoet/ConfigTest.kt index b58a763..7b887f1 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/ConfigTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/ConfigTest.kt @@ -3,7 +3,6 @@ package com.commit451.resourcespoet import org.junit.Ignore import org.junit.Test import java.io.File -import java.util.* /** * Tests the resources creation @@ -30,29 +29,30 @@ class ConfigTest { typedArray.add("Two") val poet = ResourcesPoet.create() - .addBool("is_cool", true) - .addColor("color_primary", "#FF0000") - .addComment("This is a comment") - .addDimension("margin", "2dp") - .addDrawable("logo", "@drawable/logo") - .addId("some_id") - .addInteger("number", 0) - .addIntegerArray("numbers", numbers) - .addPlurals("songs", plurals) - .addString("app_name", "Test") - .addStringArray("stuff", strings) - .addStyle("AppTheme.Dark", "Base.AppTheme.Dark") - .addTypedArray("some_typed_array", typedArray) + .addBool("is_cool", true) + .addColor("color_primary", "#FF0000") + .addComment("This is a comment") + .addDimension("margin", "2dp") + .addDrawable("logo", "@drawable/logo") + .addId("some_id") + .addInteger("number", 0) + .addIntegerArray("numbers", numbers) + .addPlurals("songs", plurals) + .addString("app_name", "Test") + .addStringArray("stuff", strings) + .addStyle("AppTheme.Dark", "Base.AppTheme.Dark") + .addTypedArray("some_typed_array", typedArray) TestUtil.assertEquals("config.xml", poet) } - @Test @Ignore("broken due to indentations. Fix it!") + @Test + @Ignore("broken due to indentations. Fix it!") fun addToExistingFile() { val classLoader = javaClass.classLoader val file = File(classLoader.getResource("config.xml")!!.file) val poet = ResourcesPoet.create(file) - .addString("added", "this one was added") + .addString("added", "this one was added") TestUtil.assertEquals("config_with_extra_string.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/DimensionTest.kt b/src/test/kotlin/com/commit451/resourcespoet/DimensionTest.kt index 48c73e6..a91919e 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/DimensionTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/DimensionTest.kt @@ -10,7 +10,7 @@ class DimensionTest { @Test fun dimensionTest() { val poet = ResourcesPoet.create() - .addDimension("margin", "2dp") + .addDimension("margin", "2dp") TestUtil.assertEquals("dimension.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/DrawableTest.kt b/src/test/kotlin/com/commit451/resourcespoet/DrawableTest.kt index 76b2eff..32d9c82 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/DrawableTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/DrawableTest.kt @@ -10,7 +10,7 @@ class DrawableTest { @Test fun drawableTest() { val poet = ResourcesPoet.create() - .addDrawable("logo", "@drawable/logo") + .addDrawable("logo", "@drawable/logo") TestUtil.assertEquals("drawable.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/IdTest.kt b/src/test/kotlin/com/commit451/resourcespoet/IdTest.kt index e0d51e7..17f97fc 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/IdTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/IdTest.kt @@ -10,7 +10,7 @@ class IdTest { @Test fun idTest() { val poet = ResourcesPoet.create() - .addId("some_id") + .addId("some_id") TestUtil.assertEquals("id.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/IntegerArrayTest.kt b/src/test/kotlin/com/commit451/resourcespoet/IntegerArrayTest.kt index af28ec1..1902972 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/IntegerArrayTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/IntegerArrayTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -15,7 +14,7 @@ class IntegerArrayTest { numbers.add(2) val poet = ResourcesPoet.create() - .addIntegerArray("numbers", numbers) + .addIntegerArray("numbers", numbers) TestUtil.assertEquals("integer_array.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/IntegerTest.kt b/src/test/kotlin/com/commit451/resourcespoet/IntegerTest.kt index 0ff651d..5aa2efa 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/IntegerTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/IntegerTest.kt @@ -10,7 +10,7 @@ class IntegerTest { @Test fun integerTest() { val poet = ResourcesPoet.create() - .addInteger("number", 0) + .addInteger("number", 0) TestUtil.assertEquals("integer.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/PluralsTest.kt b/src/test/kotlin/com/commit451/resourcespoet/PluralsTest.kt index eecebbc..b15dd6f 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/PluralsTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/PluralsTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -15,7 +14,7 @@ class PluralsTest { plurals.add(Plural(Plural.Quantity.other, "%d songs")) val poet = ResourcesPoet.create() - .addPlurals("songs", plurals) + .addPlurals("songs", plurals) TestUtil.assertEquals("plurals.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/RemoveTest.kt b/src/test/kotlin/com/commit451/resourcespoet/RemoveTest.kt index 3e9752d..c0789fd 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/RemoveTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/RemoveTest.kt @@ -10,12 +10,13 @@ import java.io.File */ class RemoveTest { - @Test @Ignore("broken due to indentations. Fix it!") + @Test + @Ignore("broken due to indentations. Fix it!") fun removeTest() { val classLoader = javaClass.classLoader val file = File(classLoader.getResource("remove_before.xml")!!.file) val poet = ResourcesPoet.create(file) - .remove(Type.STRING, "red") + .remove(Type.STRING, "red") TestUtil.assertEquals("remove_after.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/StringArrayTest.kt b/src/test/kotlin/com/commit451/resourcespoet/StringArrayTest.kt index 90fc8f4..bf7dad0 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/StringArrayTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/StringArrayTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -15,7 +14,7 @@ class StringArrayTest { strings.add("Two") val poet = ResourcesPoet.create() - .addStringArray("stuff", strings) + .addStringArray("stuff", strings) TestUtil.assertEquals("string_array.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/StringTest.kt b/src/test/kotlin/com/commit451/resourcespoet/StringTest.kt index aa4eee1..e5d5328 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/StringTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/StringTest.kt @@ -10,7 +10,7 @@ class StringTest { @Test fun stringTest() { val poet = ResourcesPoet.create() - .addString("app_name", "Test") + .addString("app_name", "Test") TestUtil.assertEquals("string.xml", poet) } @@ -18,7 +18,7 @@ class StringTest { @Test fun stringTranslatableTest() { val poet = ResourcesPoet.create() - .addString("app_name", "Test", false) + .addString("app_name", "Test", false) TestUtil.assertEquals("string_translatable_false.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/StyleTest.kt b/src/test/kotlin/com/commit451/resourcespoet/StyleTest.kt index 429e45e..242a682 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/StyleTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/StyleTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -14,7 +13,7 @@ class StyleTest { styleItems.add(StyleItem("android:windowBackground", "@android:color/white")) styleItems.add(StyleItem("colorPrimaryDark", "@android:color/black")) val poet = ResourcesPoet.create() - .addStyle("AppTheme.Dark", "Base.AppTheme.Dark", styleItems) + .addStyle("AppTheme.Dark", "Base.AppTheme.Dark", styleItems) TestUtil.assertEquals("style.xml", poet) } diff --git a/src/test/kotlin/com/commit451/resourcespoet/TypedArrayTest.kt b/src/test/kotlin/com/commit451/resourcespoet/TypedArrayTest.kt index f5d02b6..d10c0b9 100644 --- a/src/test/kotlin/com/commit451/resourcespoet/TypedArrayTest.kt +++ b/src/test/kotlin/com/commit451/resourcespoet/TypedArrayTest.kt @@ -1,7 +1,6 @@ package com.commit451.resourcespoet import org.junit.Test -import java.util.* /** * Tests the resources creation @@ -15,7 +14,7 @@ class TypedArrayTest { strings.add("Two") val poet = ResourcesPoet.create() - .addTypedArray("some_typed_array", strings) + .addTypedArray("some_typed_array", strings) TestUtil.assertEquals("typed_array.xml", poet) }