1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-27 00:38:11 -07:00

Refactor CheckVersions to work on individual projects.

This commit is contained in:
Cedric Beust 2016-06-27 02:21:05 -08:00
parent 040bcd173b
commit edb119c6b1
2 changed files with 20 additions and 20 deletions

View file

@ -14,36 +14,36 @@ import javax.inject.Inject
public class CheckVersions @Inject constructor(val depManager: DependencyManager, public class CheckVersions @Inject constructor(val depManager: DependencyManager,
val executors : KobaltExecutors, val aether: Aether) { val executors : KobaltExecutors, val aether: Aether) {
fun run(projects: List<Project>) { fun run(projects: List<Project>) = projects.forEach { run(it) }
fun run(project: Project) {
val executor = executors.newExecutor("CheckVersions", 5) val executor = executors.newExecutor("CheckVersions", 5)
val newVersions = hashSetOf<String>() val newVersions = hashSetOf<String>()
projects.forEach { project -> listOf(project.compileDependencies, project.testDependencies).forEach { cds ->
listOf(project.compileDependencies, project.testDependencies).forEach { cds -> cds.forEach { dep ->
cds.forEach { dep -> if (MavenId.isMavenId(dep.id)) {
if (MavenId.isMavenId(dep.id)) { try {
try { val latestDep = depManager.create(dep.shortId, project.directory)
val latestDep = depManager.create(dep.shortId, project.directory) val artifact = (latestDep as AetherDependency).artifact
val artifact = (latestDep as AetherDependency).artifact val versions = aether.resolveVersion(artifact)
val versions = aether.resolveVersion(artifact) val highest = versions?.highestVersion?.toString()
val highest = versions?.highestVersion?.toString() if (highest != null && highest != dep.id
if (highest != null && highest != dep.id && Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) {
&& Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) { newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
}
} catch(e: KobaltException) {
log(1, " Cannot resolve ${dep.shortId}. ignoring")
} }
} catch(e: KobaltException) {
log(1, " Cannot resolve ${dep.shortId}. ignoring")
} }
} }
} }
} }
if (newVersions.size > 0) { if (newVersions.size > 0) {
log(1, "New versions found:") log(1, " New versions found:")
newVersions.forEach { log(1, " $it") } newVersions.forEach { log(1, " $it") }
} else { } else {
log(1, "All dependencies up to date") log(1, " All dependencies up to date")
} }
executor.shutdown() executor.shutdown()
} }

View file

@ -24,7 +24,7 @@ class KobaltPlugin @Inject constructor(val checkVersions: CheckVersions, val upd
@Task(name = "checkVersions", description = "Display all the outdated dependencies") @Task(name = "checkVersions", description = "Display all the outdated dependencies")
fun taskCheckVersions(project: Project) : TaskResult { fun taskCheckVersions(project: Project) : TaskResult {
checkVersions.run(context.allProjects) checkVersions.run(project)
return TaskResult() return TaskResult()
} }