1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -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,
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 newVersions = hashSetOf<String>()
projects.forEach { project ->
listOf(project.compileDependencies, project.testDependencies).forEach { cds ->
cds.forEach { dep ->
if (MavenId.isMavenId(dep.id)) {
try {
val latestDep = depManager.create(dep.shortId, project.directory)
val artifact = (latestDep as AetherDependency).artifact
val versions = aether.resolveVersion(artifact)
val highest = versions?.highestVersion?.toString()
if (highest != null && highest != dep.id
&& Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) {
newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
}
} catch(e: KobaltException) {
log(1, " Cannot resolve ${dep.shortId}. ignoring")
listOf(project.compileDependencies, project.testDependencies).forEach { cds ->
cds.forEach { dep ->
if (MavenId.isMavenId(dep.id)) {
try {
val latestDep = depManager.create(dep.shortId, project.directory)
val artifact = (latestDep as AetherDependency).artifact
val versions = aether.resolveVersion(artifact)
val highest = versions?.highestVersion?.toString()
if (highest != null && highest != dep.id
&& Versions.toLongVersion(highest) > Versions.toLongVersion(dep.version)) {
newVersions.add(artifact.groupId + ":" + artifact.artifactId + ":" + highest)
}
} catch(e: KobaltException) {
log(1, " Cannot resolve ${dep.shortId}. ignoring")
}
}
}
}
if (newVersions.size > 0) {
log(1, "New versions found:")
newVersions.forEach { log(1, " $it") }
log(1, " New versions found:")
newVersions.forEach { log(1, " $it") }
} else {
log(1, "All dependencies up to date")
log(1, " All dependencies up to date")
}
executor.shutdown()
}