From 298703daf1a571f56a931c70c4302d828f33d0c7 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:55:28 +0700 Subject: [PATCH 01/10] Update Gradle 7.5.1 --- gradle/wrapper/gradle-wrapper.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a6ca58..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Tue Jun 06 14:02:38 ICT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip From 17acd6d6b94b69a0ac9b5b8741ef5d05b526e4fe Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:56:45 +0700 Subject: [PATCH 02/10] Update Kotlin 1.7.20, JUnit 4.13.2, Gson 2.10 --- build.gradle | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 70bf368..f204894 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id "org.jetbrains.kotlin.jvm" version '1.1.2-2' id "com.jfrog.bintray" version "1.7.3" + id "org.jetbrains.kotlin.jvm" version '1.7.20' id "maven-publish" } @@ -14,21 +14,22 @@ version = {-> return stdout.toString().trim() }.call() -sourceCompatibility = 1.7 -targetCompatibility = 1.7 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 repositories { + mavenCentral() jcenter() } dependencies { - def kotlinVersion = '1.1.2' + def kotlinVersion = '1.7.20' - compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - testCompile 'junit:junit:4.12' - testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" - testCompile "com.google.code.gson:gson:2.8.1" + testImplementation 'junit:junit:4.13.2' + testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" + testImplementation 'com.google.code.gson:gson:2.10' } apply from: 'bintray.gradle' From ff4e2a5ea34d30bd61c7ecafc1fa984286ecbb69 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:56:57 +0700 Subject: [PATCH 03/10] Migrate Java to Kotlin --- .../{AreaJavaTest.java => AreaJavaTest.kt} | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) rename src/test/kotlin/nectec/thai/unit/{AreaJavaTest.java => AreaJavaTest.kt} (73%) diff --git a/src/test/kotlin/nectec/thai/unit/AreaJavaTest.java b/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt similarity index 73% rename from src/test/kotlin/nectec/thai/unit/AreaJavaTest.java rename to src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt index 4f1478a..000f412 100644 --- a/src/test/kotlin/nectec/thai/unit/AreaJavaTest.java +++ b/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt @@ -14,17 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package nectec.thai.unit -package nectec.thai.unit; +import org.junit.Assert +import org.junit.Test -import org.junit.Assert; -import org.junit.Test; - -public class AreaJavaTest { - - @Test - public void name() throws Exception { - Area area = new Area(1600).copy(3200); - Assert.assertEquals(2, area.getRai()); - } +class AreaJavaTest { + @Test + fun name() { + val area = Area(1600).copy(3200.0) + Assert.assertEquals(2, area.rai.toLong()) + } } From aff6d099e5008acdc20357edb11fe3a00e0824b1 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:57:10 +0700 Subject: [PATCH 04/10] Fix unit test and remove lint warning --- src/test/kotlin/nectec/thai/unit/AreaTest.kt | 44 ++++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/test/kotlin/nectec/thai/unit/AreaTest.kt b/src/test/kotlin/nectec/thai/unit/AreaTest.kt index 755ecc1..1b54f39 100644 --- a/src/test/kotlin/nectec/thai/unit/AreaTest.kt +++ b/src/test/kotlin/nectec/thai/unit/AreaTest.kt @@ -24,33 +24,39 @@ import kotlin.test.assertTrue class AreaTest { - val area = Area(1600.0) + private val area = Area(1600.0) - @Test fun getRai() { + @Test + fun getRai() { assertEquals(1, area.rai) } - @Test fun getNgan() { + @Test + fun getNgan() { assertEquals(0, area.ngan) } - @Test fun getSquareWa() { + @Test + fun getSquareWa() { assertEquals(0.0, area.squareWa) } - @Test fun getSquareMetre() { + @Test + fun getSquareMetre() { assertEquals(1600.0, area.squareMetre) } - @Test fun formalPrint() { - assertEquals("1 ไร่", area.formalPrint()); - assertEquals("2 งาน", Area(0, 2, 0).formalPrint()); - assertEquals("1 ตารางวา", Area(0, 0, 1).formalPrint()); - assertEquals("1 ไร่ 99 ตารางวา", Area(0, 0, 499).formalPrint()); - assertEquals("2 ไร่ 3 งาน 99 ตารางวา", Area(0, 7, 499).formalPrint()); + @Test + fun formalPrint() { + assertEquals("1 ไร่", area.formalPrint()) + assertEquals("2 งาน", Area(0, 2, 0).formalPrint()) + assertEquals("1 ตารางวา", Area(0, 0, 1).formalPrint()) + assertEquals("1 ไร่ 99 ตารางวา", Area(0, 0, 499).formalPrint()) + assertEquals("2 ไร่ 3 งาน 99 ตารางวา", Area(0, 7, 499).formalPrint()) } - @Test fun prettyPrint() { + @Test + fun prettyPrint() { assertEquals("1-0-0 ไร่", area.prettyPrint()) assertEquals("0-2-0 ไร่", Area(0, 2, 0).prettyPrint()) assertEquals("0-0-1.9 ไร่", Area(0, 0, 1.9).prettyPrint()) @@ -58,7 +64,8 @@ class AreaTest { assertEquals("2-3-99.75 ไร่", Area(0, 7, 499.75).prettyPrint()) } - @Test fun rounding() { + @Test + fun rounding() { val ex1 = Area(2400.0) assertEquals(1, ex1.rai) assertEquals(2, ex1.ngan) @@ -80,13 +87,14 @@ class AreaTest { assertEquals(0.25, ex4.squareWa) } - @Test fun gsonToJson() { - assertEquals("{\"rai\":1,\"ngan\":0,\"squareWa\":0.0,\"squareMetre\":1600.0}", + @Test + fun gsonToJson() { + assertEquals("{\"squareMetre\":1600.0,\"rai\":1,\"ngan\":0,\"squareWa\":0.0}", Gson().toJson(Area(1600.0))) - } - @Test fun gsonFromJson() { + @Test + fun gsonFromJson() { val area = Gson().fromJson("{\"rai\":1,\"ngan\":0,\"squareWa\":0,\"squareMetre\":1600}", Area::class.java) assertEquals(1, area.rai) @@ -95,7 +103,7 @@ class AreaTest { @Test fun compare() { assertTrue(Area(1, 0, 0) > Area(0, 3, 99)) - assertTrue(Area(1, 0, 0) == Area(1600.0)) + assertEquals(Area(1, 0, 0), Area(1600.0)) assertTrue(Area(2, 0, 0) < Area(4, 0, 99)) } } From 072ca8d8b5ecf21eb04c7c2b3fbbf4c2a0ec533e Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:57:21 +0700 Subject: [PATCH 05/10] Fix lint warning --- src/main/kotlin/nectec/thai/unit/Area.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/nectec/thai/unit/Area.kt b/src/main/kotlin/nectec/thai/unit/Area.kt index c72c08c..8962e50 100644 --- a/src/main/kotlin/nectec/thai/unit/Area.kt +++ b/src/main/kotlin/nectec/thai/unit/Area.kt @@ -18,6 +18,7 @@ package nectec.thai.unit import java.lang.StringBuilder +import kotlin.math.floor data class Area(val squareMetre: Double) : Comparable { @@ -97,7 +98,7 @@ data class Area(val squareMetre: Double) : Comparable { } } - fun Double.round(): Any { - return if (this == Math.floor(this)) this.toInt() else this.toString() + private fun Double.round(): Any { + return if (this == floor(this)) this.toInt() else this.toString() } } From 825ffcfea3443bb75a6222ea797db5121c52fabb Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 02:59:06 +0700 Subject: [PATCH 06/10] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e0d53d8..7e762bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle .idea build +local.properties From efdc5243ffef4dc81dc45f6af21373f0ccb81f45 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 03:07:21 +0700 Subject: [PATCH 07/10] Use git version tag from 3rd party plugin --- build.gradle | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index f204894..ab142c0 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,12 @@ plugins { id "com.jfrog.bintray" version "1.7.3" id "org.jetbrains.kotlin.jvm" version '1.7.20' + id "com.palantir.git-version" version "0.15.0" id "maven-publish" } group 'th.or.nectec' -version = {-> - def stdout = new ByteArrayOutputStream() - exec { - commandLine 'git', 'describe', '--tags' - standardOutput = stdout - } - return stdout.toString().trim() -}.call() +version = versionDetails().lastTag sourceCompatibility = 1.8 targetCompatibility = 1.8 From eaa6e64be59df007d39498d5ea44990ac34a789f Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 03:14:48 +0700 Subject: [PATCH 08/10] Migrate kotlin test assertion to junit --- src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt | 12 ++++++------ src/test/kotlin/nectec/thai/unit/AreaTest.kt | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt b/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt index 000f412..7c8bd89 100644 --- a/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt +++ b/src/test/kotlin/nectec/thai/unit/AreaJavaTest.kt @@ -16,13 +16,13 @@ */ package nectec.thai.unit -import org.junit.Assert +import org.junit.Assert.assertEquals import org.junit.Test class AreaJavaTest { - @Test - fun name() { - val area = Area(1600).copy(3200.0) - Assert.assertEquals(2, area.rai.toLong()) - } + @Test + fun name() { + val area = Area(1600).copy(3200.0) + assertEquals(2, area.rai.toLong()) + } } diff --git a/src/test/kotlin/nectec/thai/unit/AreaTest.kt b/src/test/kotlin/nectec/thai/unit/AreaTest.kt index 1b54f39..11ac996 100644 --- a/src/test/kotlin/nectec/thai/unit/AreaTest.kt +++ b/src/test/kotlin/nectec/thai/unit/AreaTest.kt @@ -18,9 +18,9 @@ package nectec.thai.unit import com.google.gson.Gson +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Test -import kotlin.test.assertEquals -import kotlin.test.assertTrue class AreaTest { @@ -38,12 +38,12 @@ class AreaTest { @Test fun getSquareWa() { - assertEquals(0.0, area.squareWa) + assertEquals(0.0, area.squareWa, .0) } @Test fun getSquareMetre() { - assertEquals(1600.0, area.squareMetre) + assertEquals(1600.0, area.squareMetre, .0) } @Test @@ -69,22 +69,22 @@ class AreaTest { val ex1 = Area(2400.0) assertEquals(1, ex1.rai) assertEquals(2, ex1.ngan) - assertEquals(0.0, ex1.squareWa) + assertEquals(0.0, ex1.squareWa, .0) val ex2 = Area(1599.0) assertEquals(0, ex2.rai) assertEquals(3, ex2.ngan) - assertEquals(99.75, ex2.squareWa) + assertEquals(99.75, ex2.squareWa, .0) val ex3 = Area(1605.0) assertEquals(1, ex3.rai) assertEquals(0, ex3.ngan) - assertEquals(1.25, ex3.squareWa) + assertEquals(1.25, ex3.squareWa, .0) val ex4 = Area(1601.0) assertEquals(1, ex4.rai) assertEquals(0, ex4.ngan) - assertEquals(0.25, ex4.squareWa) + assertEquals(0.25, ex4.squareWa, .0) } @Test From 67ec9967db3e56b52bd92c0a81cf6fb0d9d64b9f Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 03:22:45 +0700 Subject: [PATCH 09/10] Migrate Bintray (JCenter) publishing to Sonartype (MavenCentral) --- build.gradle | 33 ++++++++++---- publish/mavencentral.gradle | 89 +++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 publish/mavencentral.gradle diff --git a/build.gradle b/build.gradle index ab142c0..2322d69 100644 --- a/build.gradle +++ b/build.gradle @@ -1,29 +1,44 @@ plugins { - id "com.jfrog.bintray" version "1.7.3" - id "org.jetbrains.kotlin.jvm" version '1.7.20' + id "org.jetbrains.kotlin.jvm" version "1.7.20" id "com.palantir.git-version" version "0.15.0" id "maven-publish" } -group 'th.or.nectec' +group "th.or.nectec" version = versionDetails().lastTag +ext { + libraryName = "Thai Units" + libraryDescription = "Kotlin library for handle Thai units of measurement" + + groupId = "com.github.nectec-opensource" + artifactId = "thai-unit" + + siteUrl = "https://github.com/${project.githubRepo}" + gitUrl = "https://github.com/${project.githubRepo}.git" + + developerId = 'piruin' + developName = 'Piruin Panichphol' + developerEmail = 'piruin.panichphol@nectec.or.th' + + licenseName = "The Apache License, Version 2.0" + licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0.txt" +} + sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() - jcenter() } dependencies { - def kotlinVersion = '1.7.20' + def kotlinVersion = "1.7.20" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" - testImplementation 'junit:junit:4.13.2' - testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" - testImplementation 'com.google.code.gson:gson:2.10' + testImplementation "junit:junit:4.13.2" + testImplementation "com.google.code.gson:gson:2.10" } -apply from: 'bintray.gradle' +apply from: './publish/mavencentral.gradle' diff --git a/publish/mavencentral.gradle b/publish/mavencentral.gradle new file mode 100644 index 0000000..86acd54 --- /dev/null +++ b/publish/mavencentral.gradle @@ -0,0 +1,89 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +group = project.groupId +version = project.version + +ext["signing.keyId"] = '' +ext["signing.password"] = '' +ext["signing.secretKeyRingFile"] = '' +ext["ossrhUsername"] = '' +ext["ossrhPassword"] = '' +ext["sonatypeStagingProfileId"] = '' + +File secretPropsFile = project.rootProject.file('local.properties') +if (secretPropsFile.exists()) { + Properties p = new Properties() + p.load(new FileInputStream(secretPropsFile)) + p.each { name, value -> + ext[name] = value + } +} else { + ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') + ext["signing.password"] = System.getenv('SIGNING_PASSWORD') + ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') + ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') + ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') + ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') +} + +publishing { + publications { + release(MavenPublication) { + groupId project.groupId + artifactId project.artifactId + version project.version + + artifact("$buildDir/libs/${project.getName()}-${version}.jar") + + pom { + name = project.libraryName + description = project.libraryDescription + url = project.siteUrl + licenses { + license { + name = project.licenseName + url = project.licenseUrl + } + } + developers { + developer { + id = project.developerId + name = project.developName + email = project.developerEmail + } + } + scm { + connection = project.gitUrl + developerConnection = project.gitUrl + url = project.siteUrl + } + withXml { + def dependenciesNode = asNode().appendNode('dependencies') + project.configurations.implementation.allDependencies.each { + if (it.name != 'unspecified') { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + } + } + } + } + } + } + repositories { + maven { + name = "sonatype" + url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + credentials { + username ossrhUsername + password ossrhPassword + } + } + } +} + +signing { + sign publishing.publications +} From 797464d941e7fc381e07fe4186a26c0cda4d6166 Mon Sep 17 00:00:00 2001 From: Akexorcist Date: Sun, 6 Nov 2022 03:40:02 +0700 Subject: [PATCH 10/10] Remove unused signing credentials --- publish/mavencentral.gradle | 8 -------- 1 file changed, 8 deletions(-) diff --git a/publish/mavencentral.gradle b/publish/mavencentral.gradle index 86acd54..1718a8c 100644 --- a/publish/mavencentral.gradle +++ b/publish/mavencentral.gradle @@ -4,12 +4,8 @@ apply plugin: 'signing' group = project.groupId version = project.version -ext["signing.keyId"] = '' -ext["signing.password"] = '' -ext["signing.secretKeyRingFile"] = '' ext["ossrhUsername"] = '' ext["ossrhPassword"] = '' -ext["sonatypeStagingProfileId"] = '' File secretPropsFile = project.rootProject.file('local.properties') if (secretPropsFile.exists()) { @@ -19,12 +15,8 @@ if (secretPropsFile.exists()) { ext[name] = value } } else { - ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') - ext["signing.password"] = System.getenv('SIGNING_PASSWORD') - ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') - ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') } publishing {