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

GH-409: Run —update or —server even if the build file is incorrect.

Fixes https://github.com/cbeust/kobalt/issues/409
This commit is contained in:
Cedric Beust 2017-04-17 09:27:17 -07:00
parent e11bdfa2b9
commit afacd86267

View file

@ -3,6 +3,7 @@ package com.beust.kobalt
import com.beust.jcommander.JCommander import com.beust.jcommander.JCommander
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.PluginTask import com.beust.kobalt.api.PluginTask
import com.beust.kobalt.api.Project
import com.beust.kobalt.app.ProjectFinder import com.beust.kobalt.app.ProjectFinder
import com.beust.kobalt.app.ProjectGenerator import com.beust.kobalt.app.ProjectGenerator
import com.beust.kobalt.app.Templates import com.beust.kobalt.app.Templates
@ -44,10 +45,26 @@ class Options @Inject constructor(
val p = if (args.buildFile != null) File(args.buildFile) else File(".") val p = if (args.buildFile != null) File(args.buildFile) else File(".")
// val buildFile = BuildFile(Paths.get(p.absolutePath), p.name) // val buildFile = BuildFile(Paths.get(p.absolutePath), p.name)
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 val pluginClassLoader = javaClass.classLoader
val allProjectResult = projectFinder.initForBuildFile(buildSources, args) //
val allProjects = allProjectResult.projects // Attempt to parse the build file in order to correctly set up repos, plug-ins, etc...
// If the build file can't be parsed, don't give up just yet since some options don't need
// a correct build file to work.
//
var buildError: Throwable? = null
val allProjects =
try {
projectFinder.initForBuildFile(buildSources, args).projects
} catch(ex: Exception) {
buildError = ex
listOf<Project>()
}
fun runIfSuccessfulBuild(buildError: Throwable?, action: () -> Unit) {
buildError?.let { throw it }
action()
}
// 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)
@ -77,9 +94,11 @@ class Options @Inject constructor(
}), }),
Option( { -> args.projectInfo }, { Option( { -> args.projectInfo }, {
// --projectInfo // --projectInfo
allProjects.forEach { runIfSuccessfulBuild(buildError) {
it.compileDependencies.filter { it.isMaven }.forEach { allProjects.forEach {
resolveDependency.run(it.id) it.compileDependencies.filter { it.isMaven }.forEach {
resolveDependency.run(it.id)
}
} }
} }
}), }),
@ -93,7 +112,9 @@ class Options @Inject constructor(
}), }),
Option( { args.checkVersions }, { Option( { args.checkVersions }, {
// --checkVersions // --checkVersions
checkVersions.run(allProjects) runIfSuccessfulBuild(buildError) {
checkVersions.run(allProjects)
}
}), }),
Option( { args.download }, { Option( { args.download }, {
// --download // --download
@ -121,17 +142,19 @@ class Options @Inject constructor(
if (! buildSources.exists()) { if (! buildSources.exists()) {
throw KobaltException("Could not find build file: " + buildSources) throw KobaltException("Could not find build file: " + buildSources)
} }
val runTargetResult = taskManager.runTargets(args.targets, allProjects) runIfSuccessfulBuild(buildError) {
if (result == 0) { val runTargetResult = taskManager.runTargets(args.targets, allProjects)
result = if (runTargetResult.taskResult.success) 0 else 1 if (result == 0) {
} result = if (runTargetResult.taskResult.success) 0 else 1
}
// Shutdown all plug-ins // Shutdown all plug-ins
plugins.shutdownPlugins() plugins.shutdownPlugins()
// Run the build report contributors // Run the build report contributors
pluginInfo.buildReportContributors.forEach { pluginInfo.buildReportContributors.forEach {
it.generateReport(Kobalt.context!!) it.generateReport(Kobalt.context!!)
}
} }
} }
return result return result