Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVP https://github.com/ben-manes/gradle-versions-plugin/issues/325 #62

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ publishing {
}

repositories {
maven("/Users/jmfayard/try/gradle-versions-plugin/build/repository")
mavenCentral()
jcenter()
}
Expand All @@ -41,7 +42,7 @@ pluginBundle {
dependencies {
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.9")

implementation("com.github.ben-manes:gradle-versions-plugin:0.22.0")
implementation("com.github.ben-manes:gradle-versions-plugin:0.24.0")

implementation("com.squareup.okio:okio:2.1.0")
implementation( "com.squareup.moshi:moshi:1.7.0")
Expand Down
16 changes: 16 additions & 0 deletions plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package de.fayard

import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent
import org.gradle.api.Transformer

interface BuildSrcVersionsExtension {
var useFdqnFor: MutableList<String>

fun useFdqnFor(vararg dependencyName: String)

fun rejectVersionIf(filter: Transformer<Boolean, ComponentSelectionWithCurrent>)

var filter: Transformer<Boolean, ComponentSelectionWithCurrent>

//@Deprecated("use rejectVersionIf")
var rejectedVersionKeywords: MutableList<String>

//@Deprecated("use rejectVersionIf")
fun rejectedVersionKeywords(vararg keyword: String)

var renameLibs : String
Expand All @@ -19,6 +28,7 @@ interface BuildSrcVersionsExtension {

var versionsOnlyFile : String?


}

open class BuildSrcVersionsExtensionImpl(
Expand All @@ -31,6 +41,12 @@ open class BuildSrcVersionsExtensionImpl(
override var rejectedVersionKeywords: MutableList<String> = PluginConfig.DEFAULT_REJECTED_KEYWORDS
) : BuildSrcVersionsExtension {

@Transient
override var filter: Transformer<Boolean, ComponentSelectionWithCurrent> = PluginConfig.defaultFilter

override fun rejectVersionIf(filter: Transformer<Boolean, ComponentSelectionWithCurrent>) {
this.filter = filter
}

override fun rejectedVersionKeywords(vararg keyword: String) {
rejectedVersionKeywords = keyword.toMutableList()
Expand Down
32 changes: 7 additions & 25 deletions plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ open class BuildSrcVersionsPlugin : Plugin<Project> {

override fun apply(project: Project) = project.run {

configureBenManesVersions()

extensions.create(BuildSrcVersionsExtension::class, PluginConfig.EXTENSION_NAME, BuildSrcVersionsExtensionImpl::class)

configureBenManesVersions()

tasks.create("buildSrcVersions", BuildSrcVersionsTask::class) {
group = "Help"
description = "Update buildSrc/src/main/kotlin/{Versions.kt,Libs.kt}"
Expand All @@ -24,28 +24,10 @@ open class BuildSrcVersionsPlugin : Plugin<Project> {
Unit
}

fun Project.configureBenManesVersions(): DependencyUpdatesTask {
val rejectedKeywordsRegexps: List<Regex> by lazy {
project.extensions.getByType<BuildSrcVersionsExtension>().rejectedVersionKeywords
.map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-]*") }
}

val benManesVersions: DependencyUpdatesTask =
tasks.maybeCreate("dependencyUpdates", DependencyUpdatesTask::class.java)

benManesVersions.outputFormatter = "json"
benManesVersions.checkForGradleUpdate = true
benManesVersions.resolutionStrategy {

componentSelection {
all {
if (rejectedKeywordsRegexps.any { it.matches(candidate.version) }) {
reject("Release candidate")
}
}
}

fun Project.configureBenManesVersions(): DependencyUpdatesTask =
tasks.maybeCreate("dependencyUpdates", DependencyUpdatesTask::class.java).also { task: DependencyUpdatesTask ->
task.checkForGradleUpdate = true
task.outputFormatter = "json"
task.rejectVersionIf(project.extensions.getByType<BuildSrcVersionsExtension>().filter)
}
return benManesVersions
}
}
13 changes: 13 additions & 0 deletions plugin/src/main/kotlin/de/fayard/PluginConfig.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.fayard

import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import okio.buffer
import okio.source
import org.gradle.api.Transformer
import java.io.File

object PluginConfig {
Expand All @@ -15,6 +17,17 @@ object PluginConfig {
*/
const val EXTENSION_NAME = "buildSrcVersions"

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val regex = "^[0-9,.v-]+$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return isStable.not()
}

val defaultFilter = Transformer { current: ComponentSelectionWithCurrent ->
isNonStable(current.candidate.version)
}

const val DEFAULT_LIBS = "Libs"
const val DEFAULT_VERSIONS = "Versions"
const val DEFAULT_INDENT = " "
Expand Down
2 changes: 1 addition & 1 deletion sample-groovy/buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ object Versions {
*/
const val gradleLatestVersion: String = "5.6.2"

const val gradleCurrentVersion: String = "5.6.1"
const val gradleCurrentVersion: String = "5.6.2"
}
7 changes: 7 additions & 0 deletions sample-groovy/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
repositories {
def localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository"
if (new File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) }
gradlePluginPortal()
}
}
rootProject.name = 'sample-groovy'
includeBuild '../plugin'

7 changes: 6 additions & 1 deletion sample-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent
import de.fayard.PluginConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.11"
Expand Down Expand Up @@ -30,5 +32,8 @@ buildSrcVersions {
renameLibs = "Libs"
renameVersions = "Versions"
indent = " "
rejectedVersionKeywords("alpha", "beta", "rc", "cr", "m", "preview", "eap")

rejectVersionIf { current: ComponentSelectionWithCurrent ->
PluginConfig.isNonStable(current.candidate.version) || PluginConfig.isNonStable(current.currentVersion)
}
}
7 changes: 7 additions & 0 deletions sample-kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
repositories {
val localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository"
if (File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) }
gradlePluginPortal()
}
}
rootProject.name = "sample-kotlin"
includeBuild("../plugin")

7 changes: 7 additions & 0 deletions sample-versionsOnlyMode/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
pluginManagement {
repositories {
val localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository"
if (File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) }
gradlePluginPortal()
}
}
rootProject.name = "sample-versionsOnlyMode"
includeBuild("../plugin")