mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Extract checkLibVersions task to gradle plugin
This commit is contained in:
parent
c72aeed8bb
commit
4eaec83594
4 changed files with 57 additions and 33 deletions
|
@ -2,6 +2,7 @@ plugins {
|
||||||
java
|
java
|
||||||
application
|
application
|
||||||
eclipse
|
eclipse
|
||||||
|
`check-lib-versions`
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "0.7.4"
|
version = "0.7.4"
|
||||||
|
@ -57,39 +58,6 @@ tasks.withType<JavaExec> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find any 3rd party libraries which have released new versions
|
|
||||||
// to the central Maven repo since we last upgraded.
|
|
||||||
val checkLibVersions by tasks.registering {
|
|
||||||
doLast {
|
|
||||||
val checked = kotlin.collections.HashSet<Dependency>()
|
|
||||||
allprojects {
|
|
||||||
configurations.forEach { configuration ->
|
|
||||||
configuration.allDependencies.forEach { dependency ->
|
|
||||||
val version = dependency.version
|
|
||||||
if (!checked.contains(dependency)) {
|
|
||||||
val group = dependency.group
|
|
||||||
val path = group?.replace(".", "/") ?: ""
|
|
||||||
val name = dependency.name
|
|
||||||
val metaDataUrl = "https://repo1.maven.org/maven2/$path/$name/maven-metadata.xml"
|
|
||||||
try {
|
|
||||||
val url = org.codehaus.groovy.runtime.ResourceGroovyMethods.toURL(metaDataUrl)
|
|
||||||
val metaDataText = org.codehaus.groovy.runtime.ResourceGroovyMethods.getText(url)
|
|
||||||
val metadata = groovy.util.XmlSlurper().parseText(metaDataText)
|
|
||||||
val newest = (metadata.getProperty("versioning") as groovy.util.slurpersupport.GPathResult).getProperty("latest")
|
|
||||||
if (version != newest.toString()) {
|
|
||||||
println("UPGRADE {\"group\": \"$group\", \"name\": \"$name\", \"current\": \"$version\", \"latest\": \"$newest\"}")
|
|
||||||
}
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
logger.debug("Unable to download or parse $metaDataUrl: $e.message")
|
|
||||||
}
|
|
||||||
checked.add(dependency)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val assembleNativeImage by tasks.registering {
|
val assembleNativeImage by tasks.registering {
|
||||||
dependsOn("assemble")
|
dependsOn("assemble")
|
||||||
|
|
||||||
|
|
16
buildSrc/build.gradle.kts
Normal file
16
buildSrc/build.gradle.kts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
plugins {
|
||||||
|
`kotlin-dsl`
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
|
||||||
|
gradlePlugin {
|
||||||
|
plugins {
|
||||||
|
register("check-lib-versions") {
|
||||||
|
id = "check-lib-versions"
|
||||||
|
implementationClass = "CheckLibVersionsPlugin"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
buildSrc/src/main/kotlin/CheckLibVersionsPlugin.kt
Normal file
39
buildSrc/src/main/kotlin/CheckLibVersionsPlugin.kt
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import groovy.util.XmlSlurper
|
||||||
|
import groovy.util.slurpersupport.GPathResult
|
||||||
|
import org.codehaus.groovy.runtime.ResourceGroovyMethods
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.artifacts.Dependency
|
||||||
|
|
||||||
|
class CheckLibVersionsPlugin : Plugin<Project> {
|
||||||
|
override fun apply(project: Project) {
|
||||||
|
project.task("checkLibVersions") {
|
||||||
|
description = "Find any 3rd party libraries which have released new versions to the central Maven repo since we last upgraded."
|
||||||
|
doLast {
|
||||||
|
project.configurations.flatMap { it.allDependencies }
|
||||||
|
.toSet()
|
||||||
|
.forEach { checkDependency(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Task.checkDependency(dependency: Dependency) {
|
||||||
|
val version = dependency.version
|
||||||
|
val group = dependency.group
|
||||||
|
val path = group?.replace(".", "/") ?: ""
|
||||||
|
val name = dependency.name
|
||||||
|
val metaDataUrl = "https://repo1.maven.org/maven2/$path/$name/maven-metadata.xml"
|
||||||
|
try {
|
||||||
|
val url = ResourceGroovyMethods.toURL(metaDataUrl)
|
||||||
|
val metaDataText = ResourceGroovyMethods.getText(url)
|
||||||
|
val metadata = XmlSlurper().parseText(metaDataText)
|
||||||
|
val newest = (metadata.getProperty("versioning") as GPathResult).getProperty("latest")
|
||||||
|
if (version != newest.toString()) {
|
||||||
|
println("UPGRADE {\"group\": \"$group\", \"name\": \"$name\", \"current\": \"$version\", \"latest\": \"$newest\"}")
|
||||||
|
}
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
logger.debug("Unable to download or parse $metaDataUrl: $e.message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
|
`check-lib-versions`
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue