From 4fb726be91f5ea165bcc577a7e3d40d3a908cbfa Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sun, 13 Dec 2015 08:21:37 +0400 Subject: [PATCH] Deprecate Build.kt in the root dir. --- src/main/kotlin/com/beust/kobalt/Constants.kt | 6 ++++++ src/main/kotlin/com/beust/kobalt/Main.kt | 21 +++++++++---------- .../internal/build/BuildFileCompiler.kt | 4 +++- .../internal/remote/GetDependenciesCommand.kt | 4 +++- 4 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/main/kotlin/com/beust/kobalt/Constants.kt diff --git a/src/main/kotlin/com/beust/kobalt/Constants.kt b/src/main/kotlin/com/beust/kobalt/Constants.kt new file mode 100644 index 00000000..56fe4f09 --- /dev/null +++ b/src/main/kotlin/com/beust/kobalt/Constants.kt @@ -0,0 +1,6 @@ +package com.beust.kobalt + +object Constants { + val BUILD_FILE_NAME = "Build.kt" + val BUILD_FILE_DIRECTORY = "kobalt/src" +} diff --git a/src/main/kotlin/com/beust/kobalt/Main.kt b/src/main/kotlin/com/beust/kobalt/Main.kt index a1d8a0b4..a0367cd9 100644 --- a/src/main/kotlin/com/beust/kobalt/Main.kt +++ b/src/main/kotlin/com/beust/kobalt/Main.kt @@ -251,17 +251,16 @@ private class Main @Inject constructor( return result } - private fun findBuildFile(): File { - val files = arrayListOf("Build.kt", "build.kobalt", KFiles.src("build.kobalt"), - KFiles.src("Build.kt")) - try { - return files.map { - File(SystemProperties.currentDir, it) - }.first { - it.exists() + private fun findBuildFile() : File { + val deprecatedLocation = File(Constants.BUILD_FILE_NAME) + val result: File = + if (deprecatedLocation.exists()) { + warn(Constants.BUILD_FILE_NAME + " is in a deprecated location, please move it to " + + Constants.BUILD_FILE_DIRECTORY) + deprecatedLocation + } else { + File(KFiles.joinDir(Constants.BUILD_FILE_DIRECTORY, Constants.BUILD_FILE_NAME)) } - } catch(ex: NoSuchElementException) { - return File(KFiles.joinFileAndMakeDir("kobalt", "src", "Build.kt")) - } + return result } } diff --git a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt index 6e8b427d..09eaf904 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/build/BuildFileCompiler.kt @@ -1,6 +1,7 @@ package com.beust.kobalt.internal.build import com.beust.kobalt.Args +import com.beust.kobalt.Constants import com.beust.kobalt.KobaltException import com.beust.kobalt.Plugins import com.beust.kobalt.api.Kobalt @@ -78,7 +79,8 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b // compile it, jar it in buildScript.jar and run it val modifiedBuildFile = KFiles.createTempFile(".kt") KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode) - maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), "Modified Build.kt"), + maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), + "Modified ${Constants.BUILD_FILE_NAME}"), buildScriptJarFile, pluginUrls) val projects = buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context) result.addAll(projects) 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 f6bca211..4e5f7ae0 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/remote/GetDependenciesCommand.kt @@ -1,6 +1,7 @@ package com.beust.kobalt.internal.remote import com.beust.kobalt.Args +import com.beust.kobalt.Constants import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Project import com.beust.kobalt.internal.PluginInfo @@ -79,6 +80,7 @@ class GetDependenciesCommand @Inject constructor(val executors: KobaltExecutors, fun main(argv: Array) { val socket = Socket("localhost", 1234) (PrintWriter(socket.outputStream, true)).use { out -> - out.println("""{ "name" : "getDependencies", "buildFile": "/Users/beust/kotlin/kobalt/kobalt/src/Build.kt"}""") + out.println("""{ "name" : "getDependencies", "buildFile": + "/Users/beust/kotlin/kobalt/kobalt/src/${Constants.BUILD_FILE_NAME}"}""") } } \ No newline at end of file