diff --git a/build.gradle b/build.gradle index 2d92f804..4b59c084 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '0.14.449' + ext.kotlin_version = '1.0.0-beta-1038' repositories { mavenCentral() @@ -41,7 +41,6 @@ dependencies { // "org.jetbrains.kotlin:kotlin-compiler:${kotlin_version}", 'com.beust:jcommander:1.48', - 'com.beust:klaxon:0.16', 'com.squareup.okhttp:okhttp:2.4.0', 'org.jsoup:jsoup:1.8.2', 'com.google.inject:guice:4.0', diff --git a/kobalt.iml b/kobalt.iml index 6b210483..9a0ff1eb 100644 --- a/kobalt.iml +++ b/kobalt.iml @@ -16,18 +16,14 @@ - - - - @@ -42,5 +38,8 @@ + + + \ No newline at end of file diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index e9305bd7..418664cb 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -53,12 +53,11 @@ val kobalt = kotlinProject(wrapper) { } dependencies { - compile("org.jetbrains.kotlin:kotlin-stdlib:0.14.449", - "org.jetbrains.kotlin:kotlin-compiler-embeddable:0.14.449", + compile("org.jetbrains.kotlin:kotlin-stdlib:1.0.0-beta-1038", + "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.0.0-beta-1038", // file(homeDir("java/jcommander/target/jcommander-1.47.jar")), "com.beust:jcommander:1.48", - "com.beust:klaxon:0.16", "com.squareup.okhttp:okhttp:2.5.0", "org.jsoup:jsoup:1.8.3", "com.google.inject:guice:4.0", @@ -80,7 +79,7 @@ val assembleKobalt = assemble(kobalt) { mavenJars { fatJar = true manifest { - attributes("Main-Class", "com.beust.kobalt.KobaltPackage") + attributes("Main-Class", "com.beust.kobalt.MainKt") } } zip { @@ -92,9 +91,9 @@ val assembleKobalt = assemble(kobalt) { } } -val cs = kotlinCompiler { - args("-nowarn") -} +//val cs = kotlinCompiler { +// args("-nowarn") +//} val jc = jcenter(kobalt) { diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index f15363b9..d4668e74 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/kobalt/wrapper/kobalt-wrapper.properties @@ -1 +1 @@ -kobalt.version=0.195 \ No newline at end of file +kobalt.version=0.198 \ No newline at end of file diff --git a/src/main/kotlin/com/beust/kobalt/AsciiArt.kt b/src/main/kotlin/com/beust/kobalt/AsciiArt.kt index 7c6ac39c..0715235a 100644 --- a/src/main/kotlin/com/beust/kobalt/AsciiArt.kt +++ b/src/main/kotlin/com/beust/kobalt/AsciiArt.kt @@ -20,7 +20,7 @@ class AsciiArt { " |_|\\_\\ \\___/ |_.__/ \\__,_| |_| \\__| " ) - val banner : String get() = BANNERS.get(Random().nextInt(BANNERS.size())) + val banner : String get() = BANNERS.get(Random().nextInt(BANNERS.size)) fun box(s: String) : List { val ul = "\u2554" @@ -38,9 +38,9 @@ class AsciiArt { } return arrayListOf( - ul + r(s.length() + 2, h) + ur, + ul + r(s.length + 2, h) + ur, "$v $s $v", - bl + r(s.length() + 2, h) + br) + bl + r(s.length + 2, h) + br) } fun logBox(s: String) { diff --git a/src/main/kotlin/com/beust/kobalt/BuildScript.kt b/src/main/kotlin/com/beust/kobalt/BuildScript.kt index f8e7d1ff..95c14a02 100644 --- a/src/main/kotlin/com/beust/kobalt/BuildScript.kt +++ b/src/main/kotlin/com/beust/kobalt/BuildScript.kt @@ -11,7 +11,7 @@ import java.io.File @Directive fun homeDir(vararg dirs: String) : String = SystemProperties.homeDir + - File.separator + dirs.toArrayList().join(File.separator) + File.separator + dirs.toArrayList().joinToString(File.separator) @Directive fun file(file: String) : String = IClasspathDependency.PREFIX_FILE + file diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index d51e4ff4..47c92e24 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -139,7 +139,7 @@ private class Main @Inject constructor( // val sb = StringBuffer("List of tasks\n") Plugins.plugins.forEach { plugin -> - if (plugin.tasks.size() > 0) { + if (plugin.tasks.size > 0) { sb.append("\n ===== ${plugin.name} =====\n") plugin.tasks.forEach { task -> sb.append(" ${task.name}\t\t${task.doc}\n") diff --git a/src/main/kotlin/com/beust/kobalt/Plugins.kt b/src/main/kotlin/com/beust/kobalt/Plugins.kt index d452ed54..763975f4 100644 --- a/src/main/kotlin/com/beust/kobalt/Plugins.kt +++ b/src/main/kotlin/com/beust/kobalt/Plugins.kt @@ -73,7 +73,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider - get() = ArrayList(pluginMap.values()) + get() = ArrayList(pluginMap.values) /** * The list of plugins found in the build file. @@ -157,7 +157,7 @@ public class Plugins @Inject constructor (val taskManagerProvider : Provider commonVersion */ fun translate(key: String): String { - return key.split('.').mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }).join("") + return key.split('.').mapIndexed( { index, value -> if (index == 0) value else value.upperFirst() }) + .joinToString("") } } @@ -35,12 +36,12 @@ public class ProjectGenerator { } val compilerInfos = detect(File(".")) - if (compilerInfos.size() > 1) { + if (compilerInfos.size > 1) { log(1, "Multi language project detected, not supported yet") } val map = hashMapOf() map.put("directive", if (compilerInfos.isEmpty()) "project" else compilerInfos.get(0).directive) - if (compilerInfos.size() > 0) { + if (compilerInfos.size > 0) { compilerInfos.get(0).let { val currentDir = File(".").absoluteFile.parentFile with(map) { @@ -83,15 +84,13 @@ public class ProjectGenerator { put("artifactId", pom.artifactId ?: "com.example") put("version", pom.version ?: "0.1") put("name", pom.name ?: pom.artifactId) - put("repositories", pom.repositories.map({ "\"${it}\"" }).join(",")) + put("repositories", pom.repositories.map({ "\"${it}\"" }).joinToString(",")) } val properties = pom.properties - val mapped = properties.entrySet().toMap({it.key}, {translate(it.key)}) + val mapped = properties.entries.toMap({it.key}, {translate(it.key)}) - map.put("properties", properties - .entrySet() - .map({ Pair(mapped.get(it.key), it.value) })) + map.put("properties", properties.entries.map({ Pair(mapped.get(it.key), it.value) })) val partition = pom.dependencies.groupBy { it.scope } .flatMap { it.value } @@ -105,7 +104,7 @@ public class ProjectGenerator { private fun updateVersion(dep: Dependency, mapped: Map) = if ( dep.version.startsWith("\${")) { - val property = dep.version.substring(2, dep.version.length() - 1) + val property = dep.version.substring(2, dep.version.length - 1) Dependency(dep.groupId, dep.artifactId, "\${${mapped.get(property)}}", dep.optional, dep.scope) } else { dep @@ -119,11 +118,11 @@ public class ProjectGenerator { val result = arrayListOf>>() Kobalt.compilers.forEach { val managedFiles = it.findManagedFiles(dir) - if (managedFiles.size() > 0) { + if (managedFiles.size > 0) { result.add(Pair(it, managedFiles)) } } - Collections.sort(result, { p1, p2 -> p1.second.size().compareTo(p2.second.size()) }) + Collections.sort(result, { p1, p2 -> p1.second.size.compareTo(p2.second.size) }) return result.map { it.first } } } diff --git a/src/main/kotlin/com/beust/kobalt/Template.kt b/src/main/kotlin/com/beust/kobalt/Template.kt index a62649fb..72954bb1 100644 --- a/src/main/kotlin/com/beust/kobalt/Template.kt +++ b/src/main/kotlin/com/beust/kobalt/Template.kt @@ -10,8 +10,8 @@ public class Template(val reader: Reader, val writer: PrintWriter, val map: Map< BufferedReader(reader).let { it.forEachLine { line -> var replacedLine = line - map.keySet().forEach { key -> - replacedLine = replacedLine.replace("{{${key}}}", map.get(key).toString(), false) + map.keys.forEach { key -> + replacedLine = replacedLine.replace("{{$key}}", map.get(key).toString(), false) } writer.append(replacedLine).append("\n") } diff --git a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt index 799bfa1e..21543539 100644 --- a/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt +++ b/src/main/kotlin/com/beust/kobalt/api/Kobalt.kt @@ -80,7 +80,7 @@ public class Kobalt { private fun readProperties(properties: Properties, ins: InputStream) { properties.load(ins) ins.close() - properties.forEach { es -> System.setProperty(es.getKey().toString(), es.getValue().toString()) } + properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) } } val version = properties.getProperty(PROPERTY_KOBALT_VERSION) diff --git a/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt index b89cc029..563a9ae0 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt @@ -45,7 +45,7 @@ public class DynamicGraphExecutor(val graph: DynamicGraph, */ public fun run() : Int { var lastResult = TaskResult() - while (graph.freeNodes.size() > 0) { + while (graph.freeNodes.size > 0) { log(3, "Current count: ${graph.nodeCount}") synchronized(graph) { val freeNodes = graph.freeNodes @@ -53,10 +53,10 @@ public class DynamicGraphExecutor(val graph: DynamicGraph, log(3, "submitting free nodes $freeNodes") val callables : List> = factory.createWorkers(freeNodes) callables.forEach { completion.submit(it) } - var n = callables.size() + var n = callables.size // When a callable ends, see if it freed a node. If not, keep looping - while (n > 0 && graph.freeNodes.size() == 0) { + while (n > 0 && graph.freeNodes.size == 0) { try { val future = completion.take() val taskResult = future.get(2, TimeUnit.SECONDS) @@ -137,7 +137,7 @@ public class DynamicGraph { // - no other nodes depend on it if (! dependedUpon.containsKey(m)) { result.add(m) - } else if (getUnfinishedNodes(du).size() == 0) { + } else if (getUnfinishedNodes(du).size == 0) { result.add(m) } } @@ -221,7 +221,7 @@ public class DynamicGraph { * @return the number of nodes in this graph. */ public val nodeCount: Int - get() = nodesReady.size() + nodesRunning.size() + nodesFinished.size() + get() = nodesReady.size + nodesRunning.size + nodesFinished.size override public fun toString() : String { val result = StringBuilder("[DynamicGraph ") diff --git a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index 6db8452e..07fc381c 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -28,14 +28,14 @@ abstract class GenericTestRunner(open val project: Project, open val classpath: val allArgs = arrayListOf() allArgs.add(java!!.absolutePath) allArgs.add("-classpath") - allArgs.add(classpath.map { it.jarFile.get().absolutePath }.join(File.pathSeparator)) + allArgs.add(classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator)) allArgs.add(mainClass) allArgs.addAll(args) val pb = ProcessBuilder(allArgs) pb.directory(File(project.directory)) pb.inheritIO() - log(1, "Running tests with classpath size ${classpath.size()}") + log(1, "Running tests with classpath size ${classpath.size}") val process = pb.start() val errorCode = process.waitFor() if (errorCode == 0) { diff --git a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index b5711f39..5eb4f201 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -99,7 +99,7 @@ abstract public class JvmCompilerPlugin @Inject constructor( throw IllegalArgumentException("Custom source sets not supported yet: ${sourceSet}") } - if (sourceDirs.size() > 0) { + if (sourceDirs.size > 0) { lp(project, "Copying ${sourceSet} resources") val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory!!, outputDir)) sourceDirs.map { File(it) }.filter { it.exists() } .forEach { diff --git a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt index c7d810f5..829845c6 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TaskManager.kt @@ -79,7 +79,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg val currentFreeTask = allFreeTasks.filter { TaskInfo(projectName, it.name).id == target } - if (currentFreeTask.size() == 1) { + if (currentFreeTask.size == 1) { currentFreeTask.get(0).let { val thisTaskInfo = TaskInfo(projectName, it.name) graph.addNode(it) @@ -150,13 +150,13 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg private fun calculateFreeTasks(tasksByNames: Map, reverseAfter: HashMap) : Collection { val freeTaskMap = hashMapOf() - tasksByNames.keySet().forEach { + tasksByNames.keys.forEach { if (! runBefore.containsKey(it) && ! reverseAfter.containsKey(it)) { freeTaskMap.put(it, tasksByNames.get(it)!!) } } - return freeTaskMap.values() + return freeTaskMap.values } /** @@ -172,7 +172,7 @@ public class TaskManager @Inject constructor(val plugins: Plugins, val args: Arg var done = false while (! done) { val newToProcess = hashSetOf() - log(3, "toProcess size: " + toProcess.size()) + log(3, "toProcess size: " + toProcess.size) toProcess.forEach { target -> val currentTask = TaskInfo(project.name!!, target.task) @@ -209,7 +209,7 @@ class TaskWorker(val tasks: List, val dryRun: Boolean) : IWorker { - if (tasks.size() > 0) { + if (tasks.size > 0) { tasks.get(0).let { log(1, "========== ${it.project.name}:${it.name}") } diff --git a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 9f60801d..00b6266d 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -12,12 +12,12 @@ public class TestNgRunner(override val project: Project, override val classpath: override val args: List get() { arrayListOf().let { - if (project.testArgs.size() > 0) { + if (project.testArgs.size > 0) { it.addAll(project.testArgs) } else { val testngXml = File(project.directory, KFiles.joinDir("src", "test", "resources", "testng.xml")) if (testngXml.exists()) { - it.add(testngXml.getAbsolutePath()) + it.add(testngXml.absolutePath) } else { it.add("-testclass") it.addAll(findTestClasses()) diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt index 3235f8a1..50261b2c 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt @@ -28,7 +28,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors, val buildFile = BuildFile(Paths.get(received.get("buildFile").asString), "GetDependenciesCommand") val scriptCompiler = buildFileCompilerFactory.create(listOf(buildFile)) scriptCompiler.observable.subscribe { - buildScriptInfo -> if (buildScriptInfo.projects.size() > 0) { + buildScriptInfo -> if (buildScriptInfo.projects.size > 0) { sender.sendData(toData(buildScriptInfo)) } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt index 9d1ce831..ed42c8c5 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltClient.kt @@ -48,7 +48,7 @@ public class KobaltClient @Inject constructor() : Runnable { } else { val data = jo.get("data").asString val dd = Gson().fromJson(data, GetDependenciesCommand.GetDependenciesData::class.java) - println("Read GetDependencyData, project count: ${dd.projects.size()}") + println("Read GetDependencyData, project count: ${dd.projects.size}") line = ins.readLine() } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt index 86d6082d..6cd8ed2b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/KobaltServer.kt @@ -72,7 +72,7 @@ public class KobaltServer @Inject constructor(val args: Args) : Runnable, IComma while (! quit) { val clientSocket = serverSocket.accept() outgoing = PrintWriter(clientSocket.outputStream, true) - if (pending.size() > 0) { + if (pending.size > 0) { log(1, "Emptying the queue, size $pending.size()") synchronized(pending) { pending.forEach { sendData(it) } diff --git a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt index 7b9ac9d0..f184884b 100644 --- a/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/kotlin/BuildFileCompiler.kt @@ -122,7 +122,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b // will add all the dynamic plugins found in this code to Plugins.dynamicPlugins // val pluginSourceFile = KFiles.createTempFile(".kt") - pluginSourceFile.writeText(pluginCode.join("\n"), Charset.defaultCharset()) + pluginSourceFile.writeText(pluginCode.joinToString("\n"), Charset.defaultCharset()) log(2, "Saved ${pluginSourceFile.absolutePath}") // @@ -180,7 +180,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b while (entry != null) { val name = entry.name; if (name.endsWith(".class")) { - val className = name.substring(0, name.length() - 6).replace("/", ".") + val className = name.substring(0, name.length - 6).replace("/", ".") var cl : Class<*>? = classLoader.loadClass(className) if (cl != null) { classes.add(cl) diff --git a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt b/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt index 6f20fbcf..f75c9afd 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/DepFactory.kt @@ -16,7 +16,7 @@ public class DepFactory @Inject constructor(val localRepo: LocalRepo, public fun create(id: String, executor: ExecutorService, localFirst : Boolean = true) : IClasspathDependency { if (id.startsWith(IClasspathDependency.PREFIX_FILE)) { - return FileDependency(id.substring(IClasspathDependency.PREFIX_FILE.length())) + return FileDependency(id.substring(IClasspathDependency.PREFIX_FILE.length)) } else { val c = id.split(":") var repoResult: RepoFinder.RepoResult? diff --git a/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt b/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt index df740334..5fb85508 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/Gpg.kt @@ -47,7 +47,7 @@ public class Gpg { val pb = ProcessBuilder(allArgs) pb.directory(directory) - log(2, "Signing file: " + allArgs.join(" ")) + log(2, "Signing file: " + allArgs.joinToString(" ")) val process = pb.start() val br = BufferedReader(InputStreamReader(process.errorStream)) diff --git a/src/main/kotlin/com/beust/kobalt/maven/Http.kt b/src/main/kotlin/com/beust/kobalt/maven/Http.kt index 9f1ea0bc..df9a80aa 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/Http.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/Http.kt @@ -29,7 +29,7 @@ public class Http { val response = client.newCall(request.build()).execute() return Body(response.body(), response.code()) } catch(ex: IOException) { - throw KobaltException("Could not load URL ${url}, error: " + ex.getMessage(), ex) + throw KobaltException("Could not load URL ${url}, error: " + ex.message, ex) } } diff --git a/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt b/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt index 210d88a0..7577af80 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/LocalRepo.kt @@ -34,7 +34,7 @@ open public class LocalRepo(open val localRepo: String = KFiles.localRepo) { if (files != null) { val directories = files.filter { it.isDirectory } - if (directories.size() > 0) { + if (directories.size > 0) { Collections.sort(directories, { f1, f2 -> val v1 = Versions.toLongVersion(f1.name) val v2 = Versions.toLongVersion(f2.name) diff --git a/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt b/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt index 344f9d59..7d33e990 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/MavenDependency.kt @@ -63,7 +63,7 @@ public class MavenDependency @Inject constructor(override @Assisted("groupId") v fun hasVersion(id: String) : Boolean { val c = id.split(":") - return c.size() == 3 && !Strings.isEmpty(c[2]) + return c.size == 3 && !Strings.isEmpty(c[2]) } fun toId(g: String, a: String, v: String) = "$g:$a:$v" diff --git a/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt b/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt index ad34557e..611d1211 100644 --- a/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt +++ b/src/main/kotlin/com/beust/kobalt/maven/RepoFinder.kt @@ -39,13 +39,13 @@ public class RepoFinder @Inject constructor(val http: Http, val executors: Kobal * Schedule an HTTP request to each repo in its own thread. */ private fun loadCorrectRepo(id: String): RepoResult { - val executor = executors.newExecutor("RepoFinder-${id}", Kobalt.repos.size()) + val executor = executors.newExecutor("RepoFinder-${id}", Kobalt.repos.size) val cs = ExecutorCompletionService(executor) try { log(2, "Looking for $id") Kobalt.repos.forEach { cs.submit(RepoFinderCallable(id, it)) } - for (i in 0..Kobalt.repos.size() - 1) { + for (i in 0..Kobalt.repos.size - 1) { try { val result = cs.take().get(2000, TimeUnit.MILLISECONDS) log(2, "Result for repo #${i}: ${result}") diff --git a/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt b/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt index d9be13d3..7056d707 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/CheckVersions.kt @@ -33,7 +33,7 @@ public class CheckVersions @Inject constructor(val depFactory : DepFactory, } } - if (newVersions.size() > 0) { + if (newVersions.size > 0) { log(1, "New versions found:") newVersions.forEach { log(1, " ${it}") } } else { diff --git a/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt b/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt index 71f9bafd..627bb7ab 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/GithubApi.kt @@ -1,11 +1,12 @@ package com.beust.kobalt.misc -import com.beust.klaxon.JsonArray -import com.beust.klaxon.JsonObject -import com.beust.klaxon.Parser -import com.beust.klaxon.string +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import com.google.gson.JsonParser import com.google.inject.Inject +import java.io.BufferedReader import java.io.IOException +import java.io.InputStreamReader import java.net.URL import java.util.concurrent.Callable import java.util.concurrent.Future @@ -26,11 +27,13 @@ public class GithubApi @Inject constructor(val executors: KobaltExecutors) { try { val ins = URL(url).openConnection().inputStream @Suppress("UNCHECKED_CAST") - val jo = Parser().parse(ins) as JsonArray + val reader = BufferedReader(InputStreamReader(ins)) + val jo = JsonParser().parse(reader) as JsonArray +// val jo = Parser().parse(ins) as JsonArray if (jo.size() > 0) { - var versionName = jo.get(0).string("name") + var versionName = (jo.get(0) as JsonObject).get("name").asString if (versionName == null) { - versionName = jo.get(0).string("tag_name") + versionName = (jo.get(0) as JsonObject).get("tag_name").asString } if (versionName != null) { result = versionName diff --git a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt index 417a9db3..c4f011b3 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KFiles.kt @@ -55,7 +55,7 @@ public class KFiles { public val TEST_CLASSES_DIR : String = "test-classes" - public fun joinDir(vararg ts: String): String = ts.toArrayList().join(File.separator) + public fun joinDir(vararg ts: String): String = ts.toArrayList().joinToString(File.separator) public fun makeDir(dir: String, s: String) : File { val result = File(dir, s) @@ -85,7 +85,7 @@ public class KFiles { } } // Return files relative to rootDir - val r = result.map { it.substring(rootDir.absolutePath.length() + 1)} + val r = result.map { it.substring(rootDir.absolutePath.length + 1)} return r } @@ -146,7 +146,7 @@ public class KFiles { Files.copy(from, to, option) } catch(ex: IOException) { // Windows is anal about this - log(1, "Couldn't copy $from to $to: ${ex.getMessage()}") + log(1, "Couldn't copy $from to $to: ${ex.message}") } } } diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt b/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt index 73180f14..1e2bc235 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KobaltExecutors.kt @@ -29,13 +29,13 @@ class KobaltExecutor(name: String, threadCount: Int) } catch (ce: CancellationException) { ex = ce; } catch (ee: ExecutionException) { - ex = ee.getCause(); + ex = ee.cause; } catch (ie: InterruptedException) { Thread.currentThread().interrupt(); // ignore/reset } } if (ex != null) { - error(if (ex.getMessage() != null) ex.getMessage()!! else ex.javaClass.toString()) + error(if (ex.message != null) ex.message!! else ex.javaClass.toString()) } } } @@ -61,7 +61,7 @@ public class KobaltExecutors { var remainingMs = maxMs var i = 0 - while (i < tasks.size() && remainingMs >= 0) { + while (i < tasks.size && remainingMs >= 0) { var start = System.currentTimeMillis() val r = cs.take().get(remainingMs, TimeUnit.MILLISECONDS) progress(r) @@ -72,7 +72,7 @@ public class KobaltExecutors { } if (remainingMs < 0) { - warn("Didn't receive all the results in time: $i / ${tasks.size()}") + warn("Didn't receive all the results in time: $i / ${tasks.size}") } else { log(2, "Received all results in ${maxMs - remainingMs} ms") } diff --git a/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt b/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt index 68cf4a77..0ddbdabd 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/KobaltLogger.kt @@ -51,7 +51,7 @@ class Logger(val dev: Boolean) { final fun error(tag: String, message: String, e: Throwable? = null) = println(getPattern("***** E", "***** ERROR ", tag, message) + - if (e != null) " Exception: " + e.getMessage() else "") + if (e != null) " Exception: " + e.message else "") final fun warn(tag: String, message: String, e: Throwable? = null) = println(getPattern("W", "***** WARNING ", tag, message)) diff --git a/src/main/kotlin/com/beust/kobalt/misc/Strings.kt b/src/main/kotlin/com/beust/kobalt/misc/Strings.kt index 10b36098..113488f1 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/Strings.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/Strings.kt @@ -26,6 +26,6 @@ public class Strings { /** * @Return the number of times the given character occurs in the string */ -public fun String.countChar(c: Char) : Int { +public infix fun String.countChar(c: Char) : Int { return CharMatcher.`is`(c).countIn(this) } diff --git a/src/main/kotlin/com/beust/kobalt/misc/ToString.kt b/src/main/kotlin/com/beust/kobalt/misc/ToString.kt index da032c53..f581922c 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/ToString.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/ToString.kt @@ -4,7 +4,7 @@ public class ToString(val name: String, vararg o: T) { val sb = StringBuffer() init { - for (i in 0..o.size() - 1 step 2) { + for (i in 0..o.size - 1 step 2) { if (i > 0) sb.append(", ") sb.append(o.get(i).toString() + ":" + o.get(i + 1)) } diff --git a/src/main/kotlin/com/beust/kobalt/misc/Topological.kt b/src/main/kotlin/com/beust/kobalt/misc/Topological.kt index 67b40b23..0b65dc75 100644 --- a/src/main/kotlin/com/beust/kobalt/misc/Topological.kt +++ b/src/main/kotlin/com/beust/kobalt/misc/Topological.kt @@ -25,7 +25,7 @@ class Topological { val result = arrayListOf() var dependMap = HashMultimap.create() dependingOn.keySet().forEach { dependMap.putAll(it, dependingOn.get(it))} - while (all.size() > 0) { + while (all.size > 0) { val freeNodes = all.filter { dependMap.get(it).isEmpty() } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt index 96967066..e30c40c9 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/java/JavaPlugin.kt @@ -50,11 +50,11 @@ public class JavaPlugin @Inject constructor( val args = arrayListOf( javac!!.absolutePath, "-d", outputDirectory.absolutePath) - if (cpList.size() > 0) { + if (cpList.size > 0) { val stringClasspath = cpList.map { it.jarFile.get().absolutePath } validateClasspath(stringClasspath) args.add("-classpath") - args.add(stringClasspath.join(File.pathSeparator)) + args.add(stringClasspath.joinToString(File.pathSeparator)) } args.addAll(sourceFiles) @@ -64,8 +64,8 @@ public class JavaPlugin @Inject constructor( // pb.redirectErrorStream(true) // pb.redirectError(File("/tmp/kobalt-err")) // pb.redirectOutput(File("/tmp/kobalt-out")) - val line = args.join(" ") - log(1, " Compiling ${sourceFiles.size()} files with classpath size ${cpList.size()}") + val line = args.joinToString(" ") + log(1, " Compiling ${sourceFiles.size} files with classpath size ${cpList.size}") log(2, " Compiling $project:\n$line") val process = pb.start() val errorCode = process.waitFor() @@ -89,7 +89,7 @@ public class JavaPlugin @Inject constructor( val classpath = calculateClasspath(project.compileDependencies) val args = arrayListOf( javadoc!!.absolutePath, - "-classpath", classpath.map { it.jarFile.get().absolutePath }.join(File.pathSeparator), + "-classpath", classpath.map { it.jarFile.get().absolutePath }.joinToString(File.pathSeparator), "-d", outputDir.absolutePath) args.addAll(sourceFiles) @@ -127,7 +127,7 @@ public class JavaPlugin @Inject constructor( .map { File(projectDir, it).absolutePath } val result = - if (absoluteSourceFiles.size() > 0) { + if (absoluteSourceFiles.size > 0) { compilePrivate(project, testDependencies(project), absoluteSourceFiles, diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 067adbfe..8aab82fa 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -24,7 +24,7 @@ class KotlinCompiler @Inject constructor(override val localRepo : LocalRepo, override val dependencyManager: DependencyManager, override val executors: KobaltExecutors) : JvmCompilerPlugin(localRepo, files, depFactory, dependencyManager, executors) { - private val KOTLIN_VERSION = "0.14.449" + private val KOTLIN_VERSION = "1.0.0-beta-1038" override val name = "kotlin" @@ -52,10 +52,10 @@ class KotlinCompiler @Inject constructor(override val localRepo : LocalRepo, validateClasspath(classpathList) - log(2, "Compiling ${source.size()} files with classpath:\n " + classpathList.join("\n ")) + log(2, "Compiling ${source.size} files with classpath:\n " + classpathList.joinToString("\n ")) CLICompiler.doMainNoExit(K2JVMCompiler(), arrayOf( "-d", output, - "-classpath", classpathList.join(File.pathSeparator), *source.toTypedArray(), + "-classpath", classpathList.joinToString(File.pathSeparator), *source.toTypedArray(), *args.toTypedArray())) executor.shutdown() return TaskResult() diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt index eb633546..7196e4b3 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinPlugin.kt @@ -53,7 +53,7 @@ public class KotlinPlugin @Inject constructor( File(projectDirectory, it).absolutePath } - compilePrivate(classpath, absoluteSourceFiles, buildDirectory.getAbsolutePath()) + compilePrivate(classpath, absoluteSourceFiles, buildDirectory.absolutePath) lp(project, "Compilation succeeded") return TaskResult() } @@ -83,7 +83,7 @@ public class KotlinPlugin @Inject constructor( outputDirectory: String): TaskResult { File(outputDirectory).mkdirs() - log(1, " Compiling ${sources.size()} files with classpath size ${cpList.size()}") + log(1, " Compiling ${sources.size} files with classpath size ${cpList.size}") return kotlinCompilePrivate { classpath(cpList.map { it.jarFile.get().absolutePath }) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt index f4eb227d..a3dac07e 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt @@ -57,7 +57,7 @@ public class JarUtils { val defaultHandler: (Exception) -> Unit = { ex: Exception -> // Ignore duplicate entry exceptions - if (! ex.getMessage()?.contains("duplicate")!!) { + if (! ex.message?.contains("duplicate")!!) { throw ex } } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index 335e27e4..ff71c127 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -66,7 +66,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}")) } ex.forEach { - if (it.matches(Paths.get(file.getName()))) { + if (it.matches(Paths.get(file.name))) { log(2, "Excluding ${file}") return true } @@ -129,7 +129,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende val filesNotExcluded : List = files.filter { ! isExcluded(it, jar.excludes) } val fileSpecs = arrayListOf() filesNotExcluded.forEach { - fileSpecs.add(FileSpec(it.path.toString().substring(prefixPath.toString().length() + 1))) + fileSpecs.add(FileSpec(it.path.toString().substring(prefixPath.toString().length + 1))) } allFiles.add(IncludedFile(From(prefixPath.toString() + "/"), To(""), fileSpecs)) } else { @@ -189,7 +189,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende warn("Directory ${fromPath} doesn't exist, not including it in the jar") } } - if (includedSpecs.size() > 0) { + if (includedSpecs.size > 0) { log(3, "Including specs ${includedSpecs}") result.add(IncludedFile(From(includedFile.from), To(includedFile.to), includedSpecs)) } @@ -210,12 +210,12 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File { val buildDir = KFiles.makeDir(project.directory, project.buildDirectory!!) val archiveDir = KFiles.makeDir(buildDir.path, "libs") - val fullArchiveName = archiveName ?: arrayListOf(project.name!!, project.version!!).join("-") + suffix + val fullArchiveName = archiveName ?: arrayListOf(project.name!!, project.version!!).joinToString("-") + suffix val result = File(archiveDir.path, fullArchiveName) val outStream = outputStreamFactory(FileOutputStream(result)) log(2, "Creating ${result}") JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles) - log(2, "Added ${includedFiles.size()} files to ${result}") + log(2, "Added ${includedFiles.size} files to ${result}") outStream.flush() outStream.close() log(1, " Created ${result}") @@ -360,7 +360,7 @@ class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List).get(0) +// @Suppress("UNCHECKED_CAST") +// val latestPublishedVersion = (jo.get("versions") as JsonArray).get(0) as JsonObject). } open public class UnauthenticatedJCenterApi @Inject constructor(open val http: Http){ @@ -28,11 +30,12 @@ open public class UnauthenticatedJCenterApi @Inject constructor(open val http: H } fun parseResponse(response: String) : JsonObject { - return Parser().parse(ByteArrayInputStream(response.toByteArray(Charset.defaultCharset()))) as JsonObject + return JsonParser().parse(response).asJsonObject +// return Parser().parse(ByteArrayInputStream(response.toByteArray(Charset.defaultCharset()))) as JsonObject } fun getPackage(name: String) : JCenterPackage { - val url = arrayListOf(BINTRAY_URL_API, "packages", "cbeust", "maven", "kobalt").join("/") + val url = arrayListOf(BINTRAY_URL_API, "packages", "cbeust", "maven", "kobalt").joinToString("/") val response = http.get(url).getAsString() val result = parseResponse(response) return JCenterPackage(result) @@ -53,21 +56,20 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val fun packageExists(packageName: String) : Boolean { val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", username!!, "maven", packageName) - .join("/") + .joinToString("/") val response = http.get(username, password, url).getAsString() val jo = parseResponse(response) - return jo.string("name") == packageName + return jo.get("name").asString == packageName } - fun createPackage(packageName: String) : String { - val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", username!!, "maven").join("/") - val jo = json { - obj("name" to packageName) - obj("license" to array("Apache 2.0")) - } - return http.post(username, password, url, jo.toJsonString()) - } +// class ForPost(val name: String, val license: Array) +// +// fun createPackage(packageName: String) : String { +// val url = arrayListOf(UnauthenticatedJCenterApi.BINTRAY_URL_API, "packages", username!!, "maven").join("/") +// val jsonString = Gson().toJson(ForPost(packageName, arrayOf("Apache 2.0"))) +// return http.post(username, password, url, jsonString) +// } fun uploadMaven(project: Project, files: List, configuration : JCenterConfiguration?) : TaskResult { if (! packageExists(project.name!!)) { @@ -86,7 +88,7 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val project.artifactId!!, project.version!!, f.name) - .join("/") + .joinToString("/") } return upload(files, configuration, fileToPath, generateMd5 = true, generateAsc = true) @@ -126,14 +128,14 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val if (configuration?.publish == true) options.add("publish=1") val optionPath = StringBuffer() - if (options.size() > 0) { - optionPath.append("?" + options.join("&")) + if (options.size > 0) { + optionPath.append("?" + options.joinToString("&")) } // // Uploads can'be done in parallel or JCenter rejects them // - val fileCount = filesToUpload.size() + val fileCount = filesToUpload.size if (fileCount > 0) { log(1, " Found $fileCount artifacts to upload: " + filesToUpload.get(0) + if (fileCount > 1) "..." else "") @@ -142,8 +144,8 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val fun dots(total: Int, list: List) : String { - val spaces : String = Array(total - list.size(), { " " }).join("") - return "|" + list.map { if (it) "." else "X" }.join("") + spaces + "|" + val spaces : String = Array(total - list.size, { " " }).joinToString("") + return "|" + list.map { if (it) "." else "X" }.joinToString("") + spaces + "|" } val results = arrayListOf() @@ -153,7 +155,7 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val { r: Response -> results.add(false) val jo = parseResponse(r.body().string()) - errorMessages.add(jo.string("message") ?: "No message found") + errorMessages.add(jo.get("message").asString ?: "No message found") }) val end = if (i >= fileCount) "\n" else "" log(1, " Uploading " + (i++) + " / $fileCount " + dots(fileCount, results) + end, false) @@ -161,8 +163,8 @@ public class JCenterApi @Inject constructor (@Nullable @Assisted("username") val if (errorMessages.isEmpty()) { return TaskResult() } else { - error("Errors while uploading:\n" + errorMessages.map { " $it" }.join("\n")) - return TaskResult(false, errorMessages.join("\n")) + error("Errors while uploading:\n" + errorMessages.map { " $it" }.joinToString("\n")) + return TaskResult(false, errorMessages.joinToString("\n")) } } else { warn("Found no artifacts to upload") diff --git a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt index 1c974fe3..a5808c4c 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/publish/PublishPlugin.kt @@ -67,7 +67,7 @@ public class PublishPlugin @Inject constructor(val http: Http, val files: com.be val jcenter = jcenterFactory.create(user, password) - val configuration = configurations.get(project.name) + val configuration = configurations.getRaw(project.name) // // Upload to Maven @@ -89,7 +89,7 @@ public class PublishPlugin @Inject constructor(val http: Http, val files: com.be } } } - return TaskResult(success, messages.join("\n ")) + return TaskResult(success, messages.joinToString("\n ")) } /** diff --git a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt b/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt index 9162acca..400789f7 100644 --- a/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt +++ b/src/main/kotlin/com/beust/kobalt/wrapper/Wrapper.kt @@ -44,7 +44,7 @@ public class Wrapper { private fun readProperties(properties: Properties, ins: InputStream) { properties.load(ins) ins.close() - properties.forEach { es -> System.setProperty(es.getKey().toString(), es.getValue().toString()) } + properties.forEach { es -> System.setProperty(es.key.toString(), es.value.toString()) } } private fun maybeCreateProperties() : Properties { @@ -169,7 +169,7 @@ public class Wrapper { args.addAll(argv) val pb = ProcessBuilder(args) pb.inheritIO() - log(2, "Launching\n ${args.join(" ")}") + log(2, "Launching\n ${args.joinToString(" ")}") val process = pb.start() process.waitFor() } diff --git a/src/main/resources/kobalt.properties b/src/main/resources/kobalt.properties index f15363b9..d4668e74 100644 --- a/src/main/resources/kobalt.properties +++ b/src/main/resources/kobalt.properties @@ -1 +1 @@ -kobalt.version=0.195 \ No newline at end of file +kobalt.version=0.198 \ No newline at end of file