Skip to content

Commit

Permalink
Allow newer minor versions for openrewrite-remote
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 11, 2024
1 parent cf79a4e commit 0f8ded0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions rewrite-python/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ tasks.register("appendOpenRewriteRequirements") {
doLast {
val file = requirementsFile.get().asFile
file.appendText("cbor2\n")
file.appendText("openrewrite${generatePipVersionConstraint(project.version.toString())}\n")
file.appendText("openrewrite-remote${generatePipVersionConstraint(getDirectDependencyVersion("org.openrewrite:rewrite-remote-java"))}\n")
file.appendText("openrewrite${generatePipVersionConstraint(project.version.toString(), false)}\n")
file.appendText("openrewrite-remote${generatePipVersionConstraint(getDirectDependencyVersion("org.openrewrite:rewrite-remote-java"), true)}\n")
}
}

tasks.named("processResources") {
dependsOn("appendOpenRewriteRequirements")
}

fun generatePipVersionConstraint(version: String): String {
fun generatePipVersionConstraint(version: String, boundByMajorVersion: Boolean): String {
if (version.endsWith("-SNAPSHOT")) {
return "<${version.replace("-SNAPSHOT", "")}"
}
Expand All @@ -75,13 +75,17 @@ fun generatePipVersionConstraint(version: String): String {
throw IllegalArgumentException("Invalid version format: $version")
}

val major = versionParts[0]
val major = versionParts[0].toInt()
val minor = versionParts[1].toInt()
val patch = versionParts[2]

val nextMinor = minor + 1

return ">=${major}.${minor}.${patch},<${major}.${nextMinor}.0"
return if (boundByMajorVersion) {
val nextMajor = (major + 1).toString() + ".0.0"
">=${major}.${minor}.${patch},<${nextMajor}"
} else {
val nextMinor = major.toString() + "." + (minor + 1) + ".0"
">=${major}.${minor}.${patch},<${nextMinor}"
}
}

fun Task.getDirectDependencyVersion(dependencyName: String): String {
Expand All @@ -93,4 +97,4 @@ fun Task.getDirectDependencyVersion(dependencyName: String): String {
}
}
return version
}
}

0 comments on commit 0f8ded0

Please sign in to comment.