diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index a8b427f9..fe214622 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -76,7 +76,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS } class FindProjectResult(val context: KobaltContext, val projects: List, val pluginUrls: List, - val buildSourceDirectories: List, val taskResult: TaskResult) + val buildContentRoots: List, val taskResult: TaskResult) private fun findProjects(context: KobaltContext): FindProjectResult { val root = buildSources.root diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFiles.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFiles.kt index eb10fedd..98d8815a 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFiles.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFiles.kt @@ -40,7 +40,8 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory, class BuildFileWithBuildScript(val file: File, val buildScriptInfo: BuildScriptInfo) - class BuildFileParseResult(val buildKt: File, val buildSourceDirectories: List) + class BuildFileParseResult(val projectRoot: String, val buildKt: File, + val buildSourceDirectories: List) /** * @return the new Build.kt @@ -125,8 +126,9 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory, this } - val newDirs = listOf(projectDir) + newSourceDirs.flatMap{ it.dirs } - return BuildFileParseResult(newBuildFile, newDirs) + val newDirs = listOf(File(BuildFiles.buildContentRoot(projectDir)).relativeTo(File(projectDir)).path) + + newSourceDirs.flatMap{ it.dirs.map { BuildFiles.buildContentRoot(it)} } + return BuildFileParseResult(projectDir, newBuildFile, newDirs) } class SplitBuildFile(val imports: List, val code: List, val containsProfiles: Boolean) @@ -149,6 +151,10 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory, val BUILD_SCRIPT_REGEXP: Pattern = Pattern.compile("^val.*buildScript.*\\{") val BLOCK_EXTRACTOR = BlockExtractor(BUILD_SCRIPT_REGEXP, '{', '}') + /** + * The content root for a build file module. + */ + fun buildContentRoot(root: String) = root + File.separatorChar + "kobalt" } fun parseBuildScriptInfos(projectDir: String, context: KobaltContext, profiles: Profiles) @@ -219,7 +225,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory, return analyzedFiles } - private fun sourceDir(root: String) = File(KFiles.joinDir(root, "kobalt", "src")) + private fun sourceDir(root: String) = File(KFiles.joinDir(buildContentRoot(root), "src")) private fun findFiles(file: File, accept: (File) -> Boolean) : List { val result = arrayListOf() @@ -236,6 +242,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory, return result } + private fun findBuildSourceFiles(root: String) : List { val result = arrayListOf() diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt index f8a3b278..1a2ac3b7 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/GetDependencyGraphHandler.kt @@ -40,8 +40,9 @@ class GetDependencyGraphHandler : WebSocketListener { fun sendWebsocketCommand(endpoint: RemoteEndpoint, commandName: String, payload: T, errorMessage: String? = null) { - endpoint.sendString(Gson().toJson(WebSocketCommand(commandName, payload = Gson().toJson(payload), - errorMessage = errorMessage))) + val json = Gson().toJson(WebSocketCommand(commandName, payload = Gson().toJson(payload), + errorMessage = errorMessage)) + endpoint.sendString(json) } private fun findProfiles(map: Map>) = map[PARAMETER_PROFILES]?.getOrNull(0) @@ -91,9 +92,9 @@ class GetDependencyGraphHandler : WebSocketListener { args.buildFile = buildSources.root.absolutePath args.profiles = profiles - val allProjects = projectFinder.initForBuildFile(buildSources, args) + val projectResults = projectFinder.initForBuildFile(buildSources, args) - dependencyData.dependenciesDataFor(buildSources, args, object : IProgressListener { + dependencyData.dependenciesDataFor(buildSources, args, projectResults, object : IProgressListener { override fun onProgress(progress: Int?, message: String?) { sendWebsocketCommand(s.remote, ProgressCommand.NAME, ProgressCommand(progress, message)) } diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltHub.kt b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltHub.kt index 75982f7d..315f0217 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/KobaltHub.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/KobaltHub.kt @@ -1,14 +1,5 @@ package com.beust.kobalt.app.remote -import com.beust.kobalt.Args -import com.beust.kobalt.api.Kobalt -import com.beust.kobalt.app.MainModule -import com.beust.kobalt.homeDir -import com.beust.kobalt.internal.KobaltSettings -import com.beust.kobalt.internal.build.BuildSources -import com.google.gson.Gson -import java.io.File - //enum class Command(val n: Int, val command: ICommand) { // GET_DEPENDENCIES(1, Kobalt.INJECTOR.getInstance(GetDependenciesCommand::class.java)), // GET_DEPENDENCIES_GRAPH(2, Kobalt.INJECTOR.getInstance(GetDependenciesGraphCommand::class.java)); @@ -18,29 +9,29 @@ import java.io.File // } //} -class KobaltHub(val dependencyData: RemoteDependencyData) { - val args = Args() - - fun runCommand(n: Int) : String { - val buildSources = BuildSources(File(homeDir("kotlin/klaxon"))) - val data = - when(n) { - 1 -> Gson().toJson( - dependencyData.dependenciesDataFor(buildSources, args)) - 2 -> Gson().toJson( - dependencyData.dependenciesDataFor(buildSources, args, - useGraph = true)) - else -> throw RuntimeException("Unknown command") - } - println("Data: $data") - return data - } -} - -fun main(argv: Array) { - Kobalt.init(MainModule(Args(), KobaltSettings.readSettingsXml())) - val dependencyData = Kobalt.INJECTOR.getInstance(RemoteDependencyData::class.java) - val json = KobaltHub(dependencyData).runCommand(1) - val dd = Gson().fromJson(json, RemoteDependencyData.GetDependenciesData::class.java) - println("Data2: $dd") -} +//class KobaltHub(val dependencyData: RemoteDependencyData) { +// val args = Args() +// +// fun runCommand(n: Int) : String { +// val buildSources = BuildSources(File(homeDir("kotlin/klaxon"))) +// val data = +// when(n) { +// 1 -> Gson().toJson( +// dependencyData.dependenciesDataFor(buildSources, args)) +// 2 -> Gson().toJson( +// dependencyData.dependenciesDataFor(buildSources, args, +// useGraph = true)) +// else -> throw RuntimeException("Unknown command") +// } +// println("Data: $data") +// return data +// } +//} +// +//fun main(argv: Array) { +// Kobalt.init(MainModule(Args(), KobaltSettings.readSettingsXml())) +// val dependencyData = Kobalt.INJECTOR.getInstance(RemoteDependencyData::class.java) +// val json = KobaltHub(dependencyData).runCommand(1) +// val dd = Gson().fromJson(json, RemoteDependencyData.GetDependenciesData::class.java) +// println("Data2: $dd") +//} diff --git a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt index b03be293..bd1914ac 100644 --- a/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt +++ b/src/main/kotlin/com/beust/kobalt/app/remote/RemoteDependencyData.kt @@ -4,10 +4,16 @@ import com.beust.kobalt.Args import com.beust.kobalt.api.IClasspathDependency import com.beust.kobalt.api.Project import com.beust.kobalt.app.BuildFileCompiler -import com.beust.kobalt.internal.* +import com.beust.kobalt.internal.DynamicGraph +import com.beust.kobalt.internal.GraphUtil +import com.beust.kobalt.internal.PluginInfo +import com.beust.kobalt.internal.TaskManager import com.beust.kobalt.internal.build.BuildSources import com.beust.kobalt.maven.DependencyManager -import com.beust.kobalt.misc.* +import com.beust.kobalt.misc.KFiles +import com.beust.kobalt.misc.KobaltExecutors +import com.beust.kobalt.misc.StringVersion +import com.beust.kobalt.misc.log import com.google.inject.Inject import java.io.File @@ -22,7 +28,9 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v val buildFileCompilerFactory: BuildFileCompiler.IFactory, val pluginInfo: PluginInfo, val taskManager: TaskManager) { - fun dependenciesDataFor(buildSources: BuildSources, args: Args, progressListener: IProgressListener? = null, + fun dependenciesDataFor(buildSources: BuildSources, args: Args, + findProjectResult: BuildFileCompiler.FindProjectResult, + progressListener: IProgressListener? = null, useGraph : Boolean = false): GetDependenciesData { val projectDatas = arrayListOf() @@ -168,7 +176,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v }) } - return GetDependenciesData(projectDatas, allTasks, pluginDependencies, + return GetDependenciesData(projectDatas, allTasks, pluginDependencies, findProjectResult.buildContentRoots, projectResult.taskResult.errorMessage) } @@ -194,6 +202,7 @@ class RemoteDependencyData @Inject constructor(val executors: KobaltExecutors, v class GetDependenciesData(val projects: List = emptyList(), val allTasks: Collection = emptySet(), val pluginDependencies: List = emptyList(), + val buildContentRoots: List = emptyList(), val errorMessage: String?) { companion object { val NAME = "GetDependencies"