Skip to content

Commit

Permalink
Merge d05bd7a into master
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 23, 2022
2 parents 4e7a1c1 + d05bd7a commit b0a6fce
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "io.github.rtmigo"
version = "0.5.1-SNAPSHOT" //
version = "0.6.0" //

repositories {
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/Build.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// DO NOT EDIT. Generated by Gradle task "generateBuildKt"
object Build {
const val version = "0.4.3"
const val date = "2022-10-23"
const val version = "0.6.0"
const val date = "2022-10-24"
}
18 changes: 11 additions & 7 deletions src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ class Cli : NoOpCliktCommand(
}
}

private suspend fun gaa(): GroupArtifact {
val ad = ArtifactDir(Paths.get(".").absolute())
return GroupArtifact(ad.group(), ad.artifact())
}
fun theArtifactDir() = ArtifactDir(Paths.get(".").absolute())

//private suspend fun gaa(): GroupArtifact {
// val ad = ArtifactDir(Paths.get(".").absolute())
// return GroupArtifact(ad.group(), ad.artifact())
//}

suspend fun ArtifactDir.toGroupArtifact() = GroupArtifact(this.group(), this.artifact())

data class CliConfig(val trace: Boolean)

Expand All @@ -58,7 +62,7 @@ open class CheckCentral : CliktCommand(

open class Local(help: String = "Build, publish to $m2str") : CliktCommand(help = help) {
override fun run() = catchingCommand(this) {
cmdLocal(gaa(), isFinal = true)
cmdLocal(theArtifactDir(), isFinal = true)
Unit
}
}
Expand Down Expand Up @@ -86,7 +90,7 @@ open class Stage(help: String = "Build, sign, publish to OSSRH Staging") :

override fun run() = catchingCommand(this) {
cmdSign(
cmdLocal(gaa()),
cmdLocal(theArtifactDir()),
key = GpgPrivateKey(gpgKey),
pass = GpgPassphrase(gpgPwd)
).use {
Expand All @@ -102,7 +106,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() = catchingCommand(this) {
cmdSign(
cmdLocal(gaa()),
cmdLocal(theArtifactDir()),
key = GpgPrivateKey(gpgKey),
pass = GpgPassphrase(gpgPwd)
).use { signed ->
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/maven/PomParsing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class PomXml(val xml: String) {
throw Exception("POM error: item '$selector'.", e)
}

fun validate() {
fun validate(targetCompatibility: Int) {
// Отсутствие некоторых элементов в схеме может привести к тому, что Sonatype Staging будет
// принимать файл, а потом зависать, так никогда и не делая репозиторий доступным. Это
// конечно большая загадка, в каких ЕЩЁ случаях он так сделает. Но тут можно хоть что-то
Expand All @@ -61,13 +61,13 @@ data class PomXml(val xml: String) {


val pomJavaVersion = this.javaVersion()
val runningJavaVersion = jriVersion()

if (pomJavaVersion<runningJavaVersion) {
// val runningJavaVersion = jriVersion()
//
if (pomJavaVersion<targetCompatibility) {
// TODO unit test
throw Exception("Currently running Java version is $runningJavaVersion, but " +
throw Exception("The targetCompatibility Java version is $targetCompatibility, but " +
"<java.version/> in POM is $pomJavaVersion. " +
"Either compile with older Java or change the " +
"Either target older Java or change the " +
"<java.version/> in POM.")
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/stages/build/Building.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import tools.*
import java.nio.file.Paths
import kotlin.io.path.*

suspend fun cmdLocal(ga: GroupArtifact, isFinal: Boolean = false): MavenArtifactDir {
suspend fun cmdLocal(ga: ArtifactDir, isFinal: Boolean = false): MavenArtifactDir {
eprintHeader("Publishing to $m2str")
val f = Paths.get(".").absolute()
.toGradlew().publishAndDetect(ga,null)
.toGradlew().publishAndDetect(ga.toGroupArtifact(),null)
eprint()

val mad = f.toMavenArtifactDir()
Expand All @@ -31,7 +31,9 @@ suspend fun cmdLocal(ga: GroupArtifact, isFinal: Boolean = false): MavenArtifact
srcFile.copyTo(dstFile, true)
}

PomXml(mad.asUnsignedFileset().pomFile.readText()).validate()
PomXml(mad.asUnsignedFileset().pomFile.readText()).validate(
targetCompatibility=ga.targetCompatibility()
)

eprint()
eprint(mad.asUnsignedFileset().pomFile.readText())
Expand Down
9 changes: 8 additions & 1 deletion src/main/kotlin/stages/build/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.aballano.mnemonik.memoizeSuspend
import com.github.pgreze.process.*

import maven.*
import tools.rethrowingState
import tools.*
import java.nio.file.*
import kotlin.io.path.absolute
import kotlin.io.path.exists
Expand Down Expand Up @@ -206,6 +206,13 @@ suspend fun ArtifactDir.artifact(): Artifact = rethrowingState(
{ "Failed to detect the Artifact in ${this.path}" },
{ Artifact(cachedProperties(this)["archivesBaseName"]!!) })

suspend fun ArtifactDir.targetCompatibility(): Int = rethrowingState(
{ "Failed get 'targetCompatibility' from ${this.path}" },
{ javaVersionToInt(cachedProperties(this)["targetCompatibility"]!!) })





data class Dependency(val notation: Notation, val scope: String)

Expand Down
16 changes: 15 additions & 1 deletion src/main/kotlin/tools/JriVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,18 @@ fun jriVersion(): Int {
}
}
return version.toInt()
}
}

fun javaVersionToInt(version: String): Int =
version.split('.').let {
if (it.size==1)
it.single().toInt()
else if (it.size>=2) {
if (it[0]=="1")
it[1].toInt()
else
it[0].toInt()
}
else
throw IllegalArgumentException(version)
}
25 changes: 25 additions & 0 deletions src/test/kotlin/JavaVersionTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import tools.javaVersionToInt

class JavaVersionTest {
@Test
fun test() {
javaVersionToInt("1.6").shouldBe(6)
javaVersionToInt("1.8").shouldBe(8)
javaVersionToInt("1.8.345").shouldBe(8)
javaVersionToInt("19").shouldBe(19)
javaVersionToInt("9.1").shouldBe(9)

shouldThrow<IllegalArgumentException> {
javaVersionToInt("")
}
shouldThrow<IllegalArgumentException> {
javaVersionToInt("labuda")
}
shouldThrow<IllegalArgumentException> {
javaVersionToInt("1.a.2")
}
}
}

0 comments on commit b0a6fce

Please sign in to comment.