Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
Jawnnypoo committed Jan 22, 2024
1 parent e9cef23 commit 2200ec8
Show file tree
Hide file tree
Showing 29 changed files with 111 additions and 109 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 10 additions & 13 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags:
- '*'
env:
RELEASE_SIGNING_ENABLED: true

jobs:
publish:
Expand All @@ -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 }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
44 changes: 21 additions & 23 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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()
}
}
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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" }
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 0 additions & 7 deletions sonatype.gradle

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/com/commit451/resourcespoet/Attr.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Attr {
var name: String
val formats = mutableListOf<Format>()

enum class Format constructor(private val attrName: String) {
enum class Format(private val attrName: String) {
BOOLEAN("boolean"),
FLOAT("float"),
COLOR("color"),
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/com/commit451/resourcespoet/Plural.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ package com.commit451.resourcespoet

/**
* Represents an Android Plural
* See <a https:></a>//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,
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/commit451/resourcespoet/ResourcesPoet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/commit451/resourcespoet/StyleItem.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.commit451.resourcespoet

/**
* An item within a style, like
* An item within a style, like:
*
* <item name="android:windowBackground">@android:color/black</item>
*/
Expand Down
6 changes: 3 additions & 3 deletions src/test/kotlin/com/commit451/resourcespoet/AddByTypeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ 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)
}

@Test
fun addIntegerType() {
val poet = ResourcesPoet.create()
.add(Type.INTEGER, "number", "0")
.add(Type.INTEGER, "number", "0")

TestUtil.assertEquals("integer.xml", poet)
}
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/kotlin/com/commit451/resourcespoet/AttrTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.commit451.resourcespoet

import org.junit.Test
import java.util.*

/**
* Tests the resources creation
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/commit451/resourcespoet/BoolTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/commit451/resourcespoet/ColorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/commit451/resourcespoet/CommentTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
32 changes: 16 additions & 16 deletions src/test/kotlin/com/commit451/resourcespoet/ConfigTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DimensionTest {
@Test
fun dimensionTest() {
val poet = ResourcesPoet.create()
.addDimension("margin", "2dp")
.addDimension("margin", "2dp")

TestUtil.assertEquals("dimension.xml", poet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit 2200ec8

Please sign in to comment.