mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Surface the new build directories to expose them to the IDEA plug-in.
This commit is contained in:
parent
a2e197959d
commit
a6836fbd79
7 changed files with 32 additions and 18 deletions
|
@ -128,5 +128,9 @@ class Kobalt {
|
||||||
fun addBuildSourceDirs(dirs: Array<out String>) {
|
fun addBuildSourceDirs(dirs: Array<out String>) {
|
||||||
buildSourceDirs.addAll(dirs)
|
buildSourceDirs.addAll(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun cleanUp() {
|
||||||
|
buildSourceDirs.clear()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ class BuildScriptInfo(val file: File, val fullBuildFile: List<String>, val secti
|
||||||
|
|
||||||
val includedBuildSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
val includedBuildSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
||||||
|
|
||||||
|
fun addBuildSourceDir(dir: IncludedBuildSourceDir) = includedBuildSourceDirs.add(dir)
|
||||||
|
|
||||||
fun includedBuildSourceDirsForLine(line: Int): List<String> {
|
fun includedBuildSourceDirsForLine(line: Int): List<String> {
|
||||||
val result = includedBuildSourceDirs.find { it.line == line }?.dirs
|
val result = includedBuildSourceDirs.find { it.line == line }?.dirs
|
||||||
return result ?: emptyList()
|
return result ?: emptyList()
|
||||||
|
|
|
@ -46,7 +46,8 @@ class Options @Inject constructor(
|
||||||
val buildSources = if (p.isDirectory) BuildSources(p.absoluteFile) else SingleFileBuildSources(p)
|
val buildSources = if (p.isDirectory) BuildSources(p.absoluteFile) else SingleFileBuildSources(p)
|
||||||
var pluginClassLoader = javaClass.classLoader
|
var pluginClassLoader = javaClass.classLoader
|
||||||
|
|
||||||
val allProjects = projectFinder.initForBuildFile(buildSources, args)
|
val allProjectResult = projectFinder.initForBuildFile(buildSources, args)
|
||||||
|
val allProjects = allProjectResult.projects
|
||||||
|
|
||||||
// Modify `args` with options found in buildScript { kobaltOptions(...) }, if any
|
// Modify `args` with options found in buildScript { kobaltOptions(...) }, if any
|
||||||
addOptionsFromBuild(args, Kobalt.optionsFromBuild)
|
addOptionsFromBuild(args, Kobalt.optionsFromBuild)
|
||||||
|
@ -139,6 +140,7 @@ class Options @Inject constructor(
|
||||||
private fun cleanUp() {
|
private fun cleanUp() {
|
||||||
pluginInfo.cleanUp()
|
pluginInfo.cleanUp()
|
||||||
taskManager.cleanUp()
|
taskManager.cleanUp()
|
||||||
|
Kobalt.cleanUp()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addOptionsFromBuild(args: Args, optionsFromBuild: ArrayList<String>) {
|
private fun addOptionsFromBuild(args: Args, optionsFromBuild: ArrayList<String>) {
|
||||||
|
|
|
@ -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>,
|
class FindProjectResult(val context: KobaltContext, val projects: List<Project>, val pluginUrls: List<URL>,
|
||||||
val taskResult: TaskResult)
|
val buildSourceDirectories: List<String>, val taskResult: TaskResult)
|
||||||
|
|
||||||
private fun findProjects(context: KobaltContext): FindProjectResult {
|
private fun findProjects(context: KobaltContext): FindProjectResult {
|
||||||
val root = buildSources.root
|
val root = buildSources.root
|
||||||
|
@ -96,7 +96,8 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
// and possibly add new source build directories. The output of this process is a new Build.kt
|
// and possibly add new source build directories. The output of this process is a new Build.kt
|
||||||
// file that contains the aggregation of all the build files with the profiles applied and with
|
// file that contains the aggregation of all the build files with the profiles applied and with
|
||||||
// the included build files inserted at the correct line.
|
// the included build files inserted at the correct line.
|
||||||
val newBuildKt = buildFiles.parseBuildFiles(root.absolutePath, context)
|
val parseResult = buildFiles.parseBuildFiles(root.absolutePath, context)
|
||||||
|
val newBuildKt = parseResult.buildKt
|
||||||
|
|
||||||
//
|
//
|
||||||
// Save the current build script absolute directory
|
// Save the current build script absolute directory
|
||||||
|
@ -128,7 +129,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildSources") val buildS
|
||||||
// Clear the absolute dir
|
// Clear the absolute dir
|
||||||
context.internalContext.absoluteDir = null
|
context.internalContext.absoluteDir = null
|
||||||
|
|
||||||
return FindProjectResult(context, projects, pluginUrls,
|
return FindProjectResult(context, projects, pluginUrls, parseResult.buildSourceDirectories,
|
||||||
if (errorTaskResult != null) errorTaskResult else TaskResult())
|
if (errorTaskResult != null) errorTaskResult else TaskResult())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,13 +40,16 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
|
|
||||||
class BuildFileWithBuildScript(val file: File, val buildScriptInfo: BuildScriptInfo)
|
class BuildFileWithBuildScript(val file: File, val buildScriptInfo: BuildScriptInfo)
|
||||||
|
|
||||||
|
class BuildFileParseResult(val buildKt: File, val buildSourceDirectories: List<String>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the new Build.kt
|
* @return the new Build.kt
|
||||||
*/
|
*/
|
||||||
fun parseBuildFiles(projectDir: String, context: KobaltContext) : File {
|
fun parseBuildFiles(projectDir: String, context: KobaltContext) : BuildFileParseResult {
|
||||||
val profiles = Profiles(context)
|
val profiles = Profiles(context)
|
||||||
val bsiMap = hashMapOf<File, BuildFileWithBuildScript>()
|
val bsiMap = hashMapOf<File, BuildFileWithBuildScript>()
|
||||||
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
val newSourceDirs = arrayListOf<IncludedBuildSourceDir>()
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a map of File -> FileWithBuildScript
|
// Create a map of File -> FileWithBuildScript
|
||||||
//
|
//
|
||||||
|
@ -94,7 +97,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
// We're inside a buildScriptInfo section, see if it includes any buildSourceDirs
|
// We're inside a buildScriptInfo section, see if it includes any buildSourceDirs
|
||||||
// and if it does, include these build files here
|
// and if it does, include these build files here
|
||||||
//
|
//
|
||||||
val isd = bsi.includedBuildSourceDirsForLine(lineNumber)
|
val isd = bsi.includedBuildSourceDirsForLine(lineNumber)
|
||||||
log(2, " Skipping buildScript{} line $lineNumber from file $file")
|
log(2, " Skipping buildScript{} line $lineNumber from file $file")
|
||||||
if (isd.any()) {
|
if (isd.any()) {
|
||||||
// If we found any new buildSourceDirs, all all the files found in these directories
|
// If we found any new buildSourceDirs, all all the files found in these directories
|
||||||
|
@ -111,7 +114,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
//
|
//
|
||||||
// Create the big Build.kt out of the imports and code we've found so far
|
// Create the big Build.kt out of the imports and code we've found so far
|
||||||
//
|
//
|
||||||
with(File(KFiles.findBuildScriptDir(projectDir), "Build.kt")) {
|
val newBuildFile = with(File(KFiles.findBuildScriptDir(projectDir), "Build.kt")) {
|
||||||
parentFile.mkdirs()
|
parentFile.mkdirs()
|
||||||
val imp = arrayListOf<String>().apply {
|
val imp = arrayListOf<String>().apply {
|
||||||
addAll(imports)
|
addAll(imports)
|
||||||
|
@ -119,9 +122,11 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
Collections.sort(imp)
|
Collections.sort(imp)
|
||||||
writeText(imp.joinToString("\n"))
|
writeText(imp.joinToString("\n"))
|
||||||
appendText(code.joinToString("\n"))
|
appendText(code.joinToString("\n"))
|
||||||
|
this
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val newDirs = listOf(projectDir) + newSourceDirs.flatMap{ it.dirs }
|
||||||
|
return BuildFileParseResult(newBuildFile, newDirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
class SplitBuildFile(val imports: List<String>, val code: List<String>, val containsProfiles: Boolean)
|
class SplitBuildFile(val imports: List<String>, val code: List<String>, val containsProfiles: Boolean)
|
||||||
|
@ -205,7 +210,7 @@ class BuildFiles @Inject constructor(val factory: BuildFileCompiler.IFactory,
|
||||||
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
val newDirs = arrayListOf<String>().apply { addAll(Kobalt.buildSourceDirs) }
|
||||||
newDirs.removeAll(currentDirs)
|
newDirs.removeAll(currentDirs)
|
||||||
if (newDirs.any()) {
|
if (newDirs.any()) {
|
||||||
buildScriptInfo.includedBuildSourceDirs.add(IncludedBuildSourceDir(section.start, newDirs))
|
buildScriptInfo.addBuildSourceDir(IncludedBuildSourceDir(section.start, newDirs))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
|
||||||
import com.beust.kobalt.internal.build.IBuildSources
|
import com.beust.kobalt.internal.build.IBuildSources
|
||||||
import com.beust.kobalt.misc.kobaltLog
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
@ -16,7 +15,7 @@ import java.util.*
|
||||||
class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileCompiler.IFactory,
|
||||||
val pluginInfo: PluginInfo, val plugins: Plugins) {
|
val pluginInfo: PluginInfo, val plugins: Plugins) {
|
||||||
|
|
||||||
fun initForBuildFile(buildSources: IBuildSources, args: Args): List<Project> {
|
fun initForBuildFile(buildSources: IBuildSources, args: Args): BuildFileCompiler.FindProjectResult {
|
||||||
val findProjectResult = buildFileCompilerFactory.create(buildSources, pluginInfo)
|
val findProjectResult = buildFileCompilerFactory.create(buildSources, pluginInfo)
|
||||||
.compileBuildFiles(args)
|
.compileBuildFiles(args)
|
||||||
if (! findProjectResult.taskResult.success) {
|
if (! findProjectResult.taskResult.success) {
|
||||||
|
@ -49,7 +48,7 @@ class ProjectFinder @Inject constructor(val buildFileCompilerFactory: BuildFileC
|
||||||
//
|
//
|
||||||
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
plugins.applyPlugins(Kobalt.context!!, allProjects)
|
||||||
|
|
||||||
return allProjects
|
return findProjectResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
private fun runClasspathInterceptors(allProjects: List<Project>) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import com.beust.kobalt.app.ProjectFinder
|
||||||
import com.beust.kobalt.internal.build.BuildSources
|
import com.beust.kobalt.internal.build.BuildSources
|
||||||
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
import com.beust.kobalt.internal.eventbus.ArtifactDownloadedEvent
|
||||||
import com.beust.kobalt.maven.aether.Exceptions
|
import com.beust.kobalt.maven.aether.Exceptions
|
||||||
import com.beust.kobalt.misc.KFiles
|
|
||||||
import com.google.common.eventbus.EventBus
|
import com.google.common.eventbus.EventBus
|
||||||
import com.google.common.eventbus.Subscribe
|
import com.google.common.eventbus.Subscribe
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
@ -14,7 +13,6 @@ import org.eclipse.jetty.websocket.api.RemoteEndpoint
|
||||||
import org.eclipse.jetty.websocket.api.Session
|
import org.eclipse.jetty.websocket.api.Session
|
||||||
import org.eclipse.jetty.websocket.api.WebSocketListener
|
import org.eclipse.jetty.websocket.api.WebSocketListener
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Paths
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage the websocket endpoint "/v1/getDependencyGraph".
|
* Manage the websocket endpoint "/v1/getDependencyGraph".
|
||||||
|
@ -24,8 +22,9 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
// so I have to do dependency injections manually :-(
|
// so I have to do dependency injections manually :-(
|
||||||
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
|
val projectFinder = Kobalt.INJECTOR.getInstance(ProjectFinder::class.java)
|
||||||
|
|
||||||
|
// URL parameters sent by the client
|
||||||
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
val PARAMETER_PROJECT_ROOT = "projectRoot"
|
||||||
val PARAMETER_BUILD_FILE = "buildFile"
|
val PARAMETER_BUILD_FILE = "buildFile" // Deprecated
|
||||||
val PARAMETER_PROFILES = "profiles"
|
val PARAMETER_PROFILES = "profiles"
|
||||||
|
|
||||||
var session: Session? = null
|
var session: Session? = null
|
||||||
|
@ -63,8 +62,9 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
|
|
||||||
override fun onWebSocketConnect(s: Session) {
|
override fun onWebSocketConnect(s: Session) {
|
||||||
session = s
|
session = s
|
||||||
val buildSources = findBuildFile(s.upgradeRequest.parameterMap)
|
val parameterMap = s.upgradeRequest.parameterMap
|
||||||
val profiles = findProfiles(s.upgradeRequest.parameterMap)
|
val buildSources = findBuildFile(parameterMap)
|
||||||
|
val profiles = findProfiles(parameterMap)
|
||||||
|
|
||||||
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
fun <T> getInstance(cls: Class<T>) : T = Kobalt.INJECTOR.getInstance(cls)
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ class GetDependencyGraphHandler : WebSocketListener {
|
||||||
try {
|
try {
|
||||||
val dependencyData = getInstance(RemoteDependencyData::class.java)
|
val dependencyData = getInstance(RemoteDependencyData::class.java)
|
||||||
val args = getInstance(Args::class.java)
|
val args = getInstance(Args::class.java)
|
||||||
|
args.buildFile = buildSources.root.absolutePath
|
||||||
args.profiles = profiles
|
args.profiles = profiles
|
||||||
|
|
||||||
val allProjects = projectFinder.initForBuildFile(buildSources, args)
|
val allProjects = projectFinder.initForBuildFile(buildSources, args)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue