From 76e85eeb1f89971a65b6fce8616e4132b151011a Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 14 Nov 2015 17:47:37 -0800 Subject: [PATCH] Fix CheckVersion. --- .../kotlin/com/beust/kobalt/maven/MavenId.kt | 8 +++++-- .../com/beust/kobalt/misc/CheckVersions.kt | 24 +++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt b/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt index 35d05695..f550704f 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/MavenId.kt @@ -17,6 +17,10 @@ public class MavenId(val id: String) { var version: String? = null companion object { + fun isMavenId(id: String) = with(id.split(":")) { + size == 3 || size == 4 + } + fun create(groupId: String, artifactId: String, packaging: String?, version: String?) = MavenId(toId(groupId, artifactId, packaging, version)) @@ -27,10 +31,10 @@ public class MavenId(val id: String) { } init { - val c = id.split(":") - if (c.size != 3 && c.size != 4) { + if (! isMavenId(id)) { throw IllegalArgumentException("Illegal id: $id") } + val c = id.split(":") groupId = c[0] artifactId = c[1] if (! c[2].isEmpty()) { diff --git a/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index c8ed957a..afa5f79a 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -1,9 +1,9 @@ package com.beust.kobalt.misc -import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Project import com.beust.kobalt.maven.DepFactory import com.beust.kobalt.maven.MavenDependency +import com.beust.kobalt.maven.MavenId import javax.inject.Inject /** @@ -17,16 +17,16 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory, val newVersions = hashSetOf() projects.forEach { - val kobaltDependency = arrayListOf( - MavenDependency.create("com.beust:kobalt:" + Kobalt.version, executor)) - arrayListOf(kobaltDependency, it.compileDependencies, it.testDependencies).forEach { cd -> - cd.forEach { - val dep = depFactory.create(it.shortId, executor, false /* go remote */) - if (dep is MavenDependency && it is MavenDependency) { - if (dep.id != it.id - && Versions.toLongVersion(dep.version) - > Versions.toLongVersion(it.version)) { - newVersions.add(dep.id) + arrayListOf(it.compileDependencies, it.testDependencies).forEach { cds -> + cds.forEach { compileDependency -> + if (MavenId.isMavenId(compileDependency.id)) { + val dep = depFactory.create(compileDependency.shortId, executor, false /* go remote */) + if (dep is MavenDependency) { + val other = compileDependency as MavenDependency + if (dep.id != compileDependency.id + && Versions.toLongVersion(dep.version) > Versions.toLongVersion(other.version)) { + newVersions.add(dep.id) + } } } } @@ -35,7 +35,7 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory, if (newVersions.size > 0) { log(1, "New versions found:") - newVersions.forEach { log(1, " ${it}") } + newVersions.forEach { log(1, " $it") } } else { log(1, "All dependencies up to date") }