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

Return buildContentRoots to the plug-in.

This commit is contained in:
Cedric Beust 2017-03-31 11:12:41 -07:00
parent a6836fbd79
commit 4ea4f0a58c
5 changed files with 56 additions and 48 deletions

View file

@ -76,7 +76,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
}
class FindProjectResult(val context: KobaltContext, val projects: List<Project>, val pluginUrls: List<URL>,
val buildSourceDirectories: List<String>, val taskResult: TaskResult)
val buildContentRoots: List<String>, val taskResult: TaskResult)
private fun findProjects(context: KobaltContext): FindProjectResult {
val root = buildSources.root

View file

@ -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<String>)
class BuildFileParseResult(val projectRoot: String, val buildKt: File,
val buildSourceDirectories: List<String>)
/**
* @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<String>, val code: List<String>, 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<File> {
val result = arrayListOf<File>()
@ -236,6 +242,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
return result
}
private fun findBuildSourceFiles(root: String) : List<File> {
val result = arrayListOf<File>()

View file

@ -40,8 +40,9 @@ class GetDependencyGraphHandler : WebSocketListener {
fun <T> 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<String, List<String>>) = 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))
}

View file

@ -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<String>) {
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<String>) {
// 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")
//}

View file

@ -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<ProjectData>()
@ -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<ProjectData> = emptyList(),
val allTasks: Collection<TaskData> = emptySet(),
val pluginDependencies: List<DependencyData> = emptyList(),
val buildContentRoots: List<String> = emptyList(),
val errorMessage: String?) {
companion object {
val NAME = "GetDependencies"