1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Clean up Strings.

This commit is contained in:
Cedric Beust 2016-01-15 02:12:19 +04:00
parent 7604cbf06b
commit 2b9533e011
4 changed files with 7 additions and 30 deletions

View file

@ -1,18 +1,9 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.maven.CompletedFuture
import com.beust.kobalt.misc.Strings
import java.io.File
import java.util.concurrent.Future
import kotlin.properties.Delegates
open public class LocalDep(override val mavenId: MavenId, open val localRepo: LocalRepo) open public class LocalDep(override val mavenId: MavenId, open val localRepo: LocalRepo)
: SimpleDep(mavenId) { : SimpleDep(mavenId) {
fun toAbsoluteJarFilePath(v: String) = localRepo.toFullPath(toJarFile(v)) fun toAbsoluteJarFilePath(v: String) = localRepo.toFullPath(toJarFile(v))
fun toAbsolutePomFile(v: String): String { fun toAbsolutePomFile(v: String) = localRepo.toFullPath(listOf(toPomFile(v)).joinToString("/"))
return localRepo.toFullPath(Strings.Companion.join("/", arrayListOf(toPomFile(v))))
}
} }

View file

@ -3,7 +3,10 @@ package com.beust.kobalt.maven
import com.beust.kobalt.HostConfig import com.beust.kobalt.HostConfig
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.* import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.Version
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import com.google.common.cache.CacheBuilder import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader import com.google.common.cache.CacheLoader
import com.google.common.cache.LoadingCache import com.google.common.cache.LoadingCache
@ -198,7 +201,7 @@ public class RepoFinder @Inject constructor(val executors: KobaltExecutors) {
val doc = parseXml(url) val doc = parseXml(url)
val ts = timestamp.evaluate(doc, XPathConstants.STRING) val ts = timestamp.evaluate(doc, XPathConstants.STRING)
val bn = buildNumber.evaluate(doc, XPathConstants.STRING) val bn = buildNumber.evaluate(doc, XPathConstants.STRING)
if (! Strings.isEmpty(ts.toString()) && ! Strings.isEmpty(bn.toString())) { if (! ts.toString().isEmpty() && ! bn.toString().isEmpty()) {
return Version(snapshotVersion, ts.toString() + "-" + bn.toString()) return Version(snapshotVersion, ts.toString() + "-" + bn.toString())
} else { } else {
val lastUpdated = XPATH.compile("/metadata/versioning/lastUpdated") val lastUpdated = XPATH.compile("/metadata/versioning/lastUpdated")

View file

@ -1,6 +1,5 @@
package com.beust.kobalt.maven package com.beust.kobalt.maven
import com.beust.kobalt.misc.Strings
import java.io.File import java.io.File
/** /**
@ -24,7 +23,7 @@ open class UnversionedDep(open val groupId: String, open val artifactId: String)
fun toDirectory(v: String, fileSystem: Boolean = true, trailingSlash: Boolean = true): String { fun toDirectory(v: String, fileSystem: Boolean = true, trailingSlash: Boolean = true): String {
val sep = if (fileSystem) File.separator else "/" val sep = if (fileSystem) File.separator else "/"
val l = listOf(groupId.replace(".", sep), artifactId, v) val l = listOf(groupId.replace(".", sep), artifactId, v)
val result = Strings.Companion.join(sep, l) val result = l.joinToString(sep)
return if (trailingSlash && ! result.endsWith(sep)) result + sep else result return if (trailingSlash && ! result.endsWith(sep)) result + sep else result
} }
} }

View file

@ -4,22 +4,6 @@ import com.google.common.base.CharMatcher
public class Strings { public class Strings {
companion object { companion object {
fun <T> join(separator: String, strings: List<T>) : String {
var result = StringBuffer()
var i = 0
strings.forEach {
if (i++ > 0) {
result.append(separator)
}
result.append(it)
}
return result.toString()
}
fun isEmpty(s: String?): Boolean {
return s == null || s.isEmpty()
}
fun pluralize(s: String, n: Int) = s + (if (n != 1) "s" else "") fun pluralize(s: String, n: Int) = s + (if (n != 1) "s" else "")
} }