From e9e6fa0a19087a5eeb8a903e9e79d3faefcb64a3 Mon Sep 17 00:00:00 2001 From: Artem IG Date: Thu, 20 Oct 2022 22:15:15 +0300 Subject: [PATCH 1/2] !!release --- README.md | 8 +++---- build.gradle.kts | 2 +- src/main/kotlin/Build.kt | 2 +- src/main/kotlin/Main.kt | 17 +++++++++++---- src/main/kotlin/stages/build/Gradle.kt | 29 ++++++++++++++++++-------- src/test/kotlin/GradleTest.kt | 2 +- src/test/python/test_uber.py | 4 +++- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 13d819a..823f5c7 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ Set environment variables `MAVEN_GPG_KEY`, `MAVEN_GPG_PASSWORD` ``` cd /path/to/thelib -java -jar mavence.jar central my.domain:thelib +java -jar mavence.jar central ``` This single command will do all the necessary work: build, signing, staging @@ -308,7 +308,7 @@ test the package without sending it anywhere. ``` cd /path/to/thelib -java -jar mavence.jar local my.domain:thelib +java -jar mavence.jar local ``` ### Publish to Staging @@ -318,7 +318,7 @@ Set environment variables `MAVEN_GPG_KEY`, `MAVEN_GPG_PASSWORD` ``` cd /path/to/thelib -java -jar mavence.jar stage my.domain:thelib +java -jar mavence.jar stage ``` This will push the package to @@ -334,7 +334,7 @@ receives the result as JSON. Bash: ``` -JSON=$(java -jar mavence.jar local my.domain:thelib) +JSON=$(java -jar mavence.jar local) echo $JSON ``` diff --git a/build.gradle.kts b/build.gradle.kts index 35f0f78..5a1ec5f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "io.github.rtmigo" -version = "0.1.2" // -SNAPSHOT +version = "0.2.0" // -SNAPSHOT repositories { mavenCentral() diff --git a/src/main/kotlin/Build.kt b/src/main/kotlin/Build.kt index 9a88bdc..bd22eed 100644 --- a/src/main/kotlin/Build.kt +++ b/src/main/kotlin/Build.kt @@ -1,5 +1,5 @@ // DO NOT EDIT. Generated by Gradle task "generateBuildKt" object Build { - const val version = "0.1.2-SNAPSHOT" + const val version = "0.1.2" const val date = "2022-10-20" } \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 3773b85..6fa03a2 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -8,8 +8,10 @@ import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.options.* import kotlinx.coroutines.runBlocking import maven.* +import stages.build.* import stages.sign.* import stages.upload.* +import java.nio.file.* class Cli : NoOpCliktCommand( @@ -27,12 +29,19 @@ class Cli : NoOpCliktCommand( override fun run() = Unit } +private suspend fun gaa(): GroupArtifact { + val ad = ArtifactDir(Paths.get(".")) + return GroupArtifact(ad.group(), ad.artifact()) +} open class Local(help: String="Build, publish to $m2str") : CliktCommand(help = help) { - val groupAndArtifact by argument("") + //val groupAndArtifact by argument("") override fun run() = runBlocking { - cmdLocal(GroupArtifact.parse(groupAndArtifact), isFinal = true) + //val gw = Paths.get(".").toGradlew() + //gw. + //val ad = ArtifactDir(Paths.get(".")) + cmdLocal(gaa(), isFinal = true) Unit } } @@ -51,7 +60,7 @@ open class Stage(help: String = "Build, sign, publish to OSSRH Staging") : override fun run() = runBlocking { cmdSign( - cmdLocal(GroupArtifact.parse(this@Stage.groupAndArtifact)), + cmdLocal(gaa()), key = GpgPrivateKey(gpgKey), pass = GpgPassphrase(gpgPwd) ).use { @@ -67,7 +76,7 @@ open class Stage(help: String = "Build, sign, publish to OSSRH Staging") : class Central : Stage(help = "Build, sign, publish to OSSRH Staging, release to Central") { override fun run() = runBlocking { cmdSign( - cmdLocal(GroupArtifact.parse(groupAndArtifact)), + cmdLocal(gaa()), key = GpgPrivateKey(gpgKey), pass = GpgPassphrase(gpgPwd) ).use { signed -> diff --git a/src/main/kotlin/stages/build/Gradle.kt b/src/main/kotlin/stages/build/Gradle.kt index 907f700..78df5cd 100644 --- a/src/main/kotlin/stages/build/Gradle.kt +++ b/src/main/kotlin/stages/build/Gradle.kt @@ -11,12 +11,12 @@ import ExpectedException import GradlewFile - import ProjectRootDir import com.aballano.mnemonik.memoizeSuspend import com.github.pgreze.process.* import maven.* +import tools.rethrowingState import java.nio.file.* import kotlin.io.path.absolute import kotlin.io.path.exists @@ -57,7 +57,7 @@ suspend fun ArtifactDir.gradleClean() { check(result.resultCode == 0) } -suspend fun GradlewFile.getVersion(): String { +suspend fun GradlewFile.getGradleVersion(): String { val res = process( this.path.toString(), "--version", stdout = Redirect.CAPTURE @@ -71,8 +71,8 @@ suspend fun GradlewFile.getVersion(): String { } } -suspend fun GradlewFile.setVersion(newVersion: String) { - val oldVersion = this.getVersion() +suspend fun GradlewFile.setGradleVersion(newVersion: String) { + val oldVersion = this.getGradleVersion() if (oldVersion == newVersion) { println("Current version is $oldVersion. No need to change.") return @@ -85,7 +85,7 @@ suspend fun GradlewFile.setVersion(newVersion: String) { ) .also { check(it.resultCode == 0) } - check(this.getVersion() == newVersion) { "Failed to change version" } + check(this.getGradleVersion() == newVersion) { "Failed to change version" } } /// Returns all the keys that were added or removed, and also all the keys associated @@ -94,7 +94,10 @@ internal fun keysOfChanges(old: Map, new: Map): List = (old.keys + new.keys).filter { (old[it] ?: 0) != (new[it] ?: 0) } -suspend fun GradlewFile.publishAndDetect(ga: GroupArtifact, publicationName: String?): MetadataLocalXmlFile { +suspend fun GradlewFile.publishAndDetect( + ga: GroupArtifact, + publicationName: String? +): MetadataLocalXmlFile { //val old = readUpdateTimes() fun xml() = ga.expectedLocalXmlFile(ga) @@ -111,7 +114,8 @@ suspend fun GradlewFile.publishAndDetect(ga: GroupArtifact, publicationName: Str check(newXml.file.exists()) { "File '${newXml.file} not found'" } check(newXml.lastUpdated != oldLastUpdated) { - "'lastUpdated' value was not changed in ${newXml.file}"} + "'lastUpdated' value was not changed in ${newXml.file}" + } return newXml //val new = readUpdateTimes() @@ -193,8 +197,15 @@ private suspend fun gradleProperties(d: ArtifactDir): Map = private val cachedProperties = ::gradleProperties.memoizeSuspend() suspend fun ArtifactDir.gradleVersion() = cachedProperties(this)["version"]!! -suspend fun ArtifactDir.group() = Group(cachedProperties(this)["group"]!!) -suspend fun ArtifactDir.artifact() = Group(cachedProperties(this)["archivesBaseName"]!!) + +suspend fun ArtifactDir.group(): Group = rethrowingState( + { "Failed to detect the package Group in ${this.path}" }, + { Group(cachedProperties(this)["group"]!!) }) + +suspend fun ArtifactDir.artifact(): Artifact = rethrowingState( + { "Failed to detect the Artifact in ${this.path}" }, + { Artifact(cachedProperties(this)["archivesBaseName"]!!) }) + data class Dependency(val notation: Notation, val scope: String) diff --git a/src/test/kotlin/GradleTest.kt b/src/test/kotlin/GradleTest.kt index ba15e4b..8983202 100644 --- a/src/test/kotlin/GradleTest.kt +++ b/src/test/kotlin/GradleTest.kt @@ -8,7 +8,7 @@ import java.nio.file.* class GradleTest { @Test fun testVersion() = runBlocking { - Paths.get(".").toGradlew().getVersion()[0].isDigit().shouldBeTrue() + Paths.get(".").toGradlew().getGradleVersion()[0].isDigit().shouldBeTrue() } @Test diff --git a/src/test/python/test_uber.py b/src/test/python/test_uber.py index b3c7629..107962a 100644 --- a/src/test/python/test_uber.py +++ b/src/test/python/test_uber.py @@ -12,7 +12,9 @@ def test_build_local(self): # check that our program provides clean stdout with JSON only stdout = subprocess.check_output( ["java", "-jar", Path("build/libs/mavence.uber.jar").absolute(), - "local", "io.github.rtmigo:libr"], + "local", + #"io.github.rtmigo:libr" + ], cwd=deployable_project ) print("stdout:", stdout) From 8772915230d70195d345fcd5d131ee622c57c1a6 Mon Sep 17 00:00:00 2001 From: Artem IG Date: Thu, 20 Oct 2022 22:24:05 +0300 Subject: [PATCH 2/2] !!release --- src/main/kotlin/Build.kt | 2 +- src/main/kotlin/stages/build/Gradle.kt | 6 +++--- src/test/python/test_uber.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/Build.kt b/src/main/kotlin/Build.kt index bd22eed..0ca8505 100644 --- a/src/main/kotlin/Build.kt +++ b/src/main/kotlin/Build.kt @@ -1,5 +1,5 @@ // DO NOT EDIT. Generated by Gradle task "generateBuildKt" object Build { - const val version = "0.1.2" + const val version = "0.2.0" const val date = "2022-10-20" } \ No newline at end of file diff --git a/src/main/kotlin/stages/build/Gradle.kt b/src/main/kotlin/stages/build/Gradle.kt index 78df5cd..c8c2fc0 100644 --- a/src/main/kotlin/stages/build/Gradle.kt +++ b/src/main/kotlin/stages/build/Gradle.kt @@ -175,12 +175,12 @@ private suspend fun GradlewFile.tasks(): List = } -private suspend fun gradleProperties(d: ArtifactDir): Map = - d.path.toGradlew().let { +private suspend fun gradleProperties(artidir: ArtifactDir): Map = + artidir.path.toGradlew().let { process( it.path.toString(), "-q", "properties", - directory = it.path.parent.toFile(), + directory = artidir.path.toFile(), stdout = Redirect.CAPTURE ) }.let { diff --git a/src/test/python/test_uber.py b/src/test/python/test_uber.py index 107962a..422c7f1 100644 --- a/src/test/python/test_uber.py +++ b/src/test/python/test_uber.py @@ -3,7 +3,7 @@ import unittest from pathlib import Path -deployable_project = Path("src/test/sample/deployable") +deployable_project = Path("src/test/sample/deployable/libr") assert deployable_project.exists()