mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
If a dependent project fails, fail the ones that follow.
This commit is contained in:
parent
23032f52d7
commit
60036dcb43
13 changed files with 144 additions and 119 deletions
|
@ -12,14 +12,6 @@ abstract public class BasePlugin : IPlugin {
|
|||
this.context = context
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of projects depended upon (e.g. val p = javaProject(dependentProject)).
|
||||
*/
|
||||
protected val projects = arrayListOf<ProjectDescription>()
|
||||
|
||||
fun addProject(project: Project, dependsOn: Array<out Project>) =
|
||||
projects.add(ProjectDescription(project, dependsOn.toList()))
|
||||
|
||||
override lateinit var taskManager: TaskManager
|
||||
lateinit var plugins: Plugins
|
||||
}
|
||||
|
|
|
@ -75,8 +75,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
||||
context.pluginInfo.testRunnerContributors)
|
||||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
||||
return runContributor.run(project, context, dependencyManager.testDependencies(project, context,
|
||||
projects()))
|
||||
return runContributor.run(project, context, dependencyManager.testDependencies(project, context))
|
||||
} else {
|
||||
log(1, "Couldn't find a test runner for project ${project.name}, not running any tests")
|
||||
return TaskResult()
|
||||
|
@ -198,7 +197,18 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun projects() = projects
|
||||
val allProjects = arrayListOf<ProjectDescription>()
|
||||
|
||||
fun addDependentProjects(project: Project, dependents: List<Project>) {
|
||||
project.projectInfo.dependsOn.addAll(dependents)
|
||||
with(ProjectDescription(project, dependents)) {
|
||||
allProjects.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun projects() : List<ProjectDescription> {
|
||||
return allProjects
|
||||
}
|
||||
|
||||
@Task(name = "doc", description = "Generate the documentation for the project")
|
||||
fun taskJavadoc(project: Project): TaskResult {
|
||||
|
@ -229,9 +239,9 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||
|
||||
val fullClasspath = if (isTest)
|
||||
dependencyManager.testDependencies(project, context, projects)
|
||||
dependencyManager.testDependencies(project, context)
|
||||
else
|
||||
dependencyManager.dependencies(project, context, projects)
|
||||
dependencyManager.dependencies(project, context)
|
||||
|
||||
// Remove all the excluded dependencies from the classpath
|
||||
val classpath = fullClasspath.filter {
|
||||
|
|
|
@ -23,10 +23,16 @@ interface IProjectInfo {
|
|||
*/
|
||||
fun generateBuildConfig(project: Project, context: KobaltContext, packageName: String, variant: Variant,
|
||||
buildConfigs: List<BuildConfig>) : String
|
||||
|
||||
/**
|
||||
* The list of projects that this project depends on
|
||||
*/
|
||||
val dependsOn: ArrayList<Project>
|
||||
}
|
||||
|
||||
interface BaseProjectInfo : IProjectInfo {
|
||||
fun generate(field: BuildConfigField) : String
|
||||
abstract class BaseProjectInfo : IProjectInfo {
|
||||
abstract fun generate(field: BuildConfigField) : String
|
||||
|
||||
fun generate(type: String, name: String, value: Any) = generate(BuildConfigField(type, name, value))
|
||||
|
||||
fun generateFieldsFromContributors(project: Project, context: KobaltContext)
|
||||
|
@ -35,4 +41,6 @@ interface BaseProjectInfo : IProjectInfo {
|
|||
}.map {
|
||||
generate(it)
|
||||
}
|
||||
|
||||
override val dependsOn = arrayListOf<Project>()
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.beust.kobalt.api.Project
|
|||
import com.beust.kobalt.api.annotation.IncrementalTask
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.misc.benchmarkMillis
|
||||
import com.beust.kobalt.misc.kobaltError
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.common.collect.ArrayListMultimap
|
||||
import com.google.common.collect.Multimap
|
||||
|
@ -51,116 +52,129 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
|
|||
|
||||
public fun runTargets(taskNames: List<String>, projects: List<Project>) : RunTargetResult {
|
||||
var result = 0
|
||||
val failedProjects = hashSetOf<String>()
|
||||
val messages = Collections.synchronizedList(arrayListOf<String>())
|
||||
projects.forEach { project ->
|
||||
val projectName = project.name
|
||||
// There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both
|
||||
// define "install"), so use a multimap
|
||||
val tasksByNames = ArrayListMultimap.create<String, PluginTask>()
|
||||
annotationTasks.filter {
|
||||
it.project.name == project.name
|
||||
}.forEach {
|
||||
tasksByNames.put(it.name, it)
|
||||
}
|
||||
|
||||
AsciiArt.logBox("Building ${project.name}")
|
||||
|
||||
log(3, "Tasks:")
|
||||
tasksByNames.keys().forEach {
|
||||
log(3, " $it: " + tasksByNames.get(it))
|
||||
// Does the current project depend on any failed projects?
|
||||
val fp = project.projectInfo.dependsOn.filter {
|
||||
failedProjects.contains(it.name)
|
||||
}
|
||||
val graph = DynamicGraph<PluginTask>()
|
||||
taskNames.forEach { taskName ->
|
||||
val ti = TaskInfo(taskName)
|
||||
if (! tasksByNames.keys().contains(ti.taskName)) {
|
||||
throw KobaltException("Unknown task: $taskName")
|
||||
if (fp.size > 0) {
|
||||
failedProjects.add(project.name)
|
||||
kobaltError("Not building project ${project.name} since it depends on failed projects "
|
||||
+ fp.joinToString(","))
|
||||
} else {
|
||||
val projectName = project.name
|
||||
// There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both
|
||||
// define "install"), so use a multimap
|
||||
val tasksByNames = ArrayListMultimap.create<String, PluginTask>()
|
||||
annotationTasks.filter {
|
||||
it.project.name == project.name
|
||||
}.forEach {
|
||||
tasksByNames.put(it.name, it)
|
||||
}
|
||||
|
||||
if (ti.matches(projectName)) {
|
||||
tasksByNames[ti.taskName].forEach { task ->
|
||||
if (task != null && task.plugin.accept(project)) {
|
||||
val reverseAfter = hashMapOf<String, String>()
|
||||
alwaysRunAfter.keys().forEach { from ->
|
||||
val tasks = alwaysRunAfter.get(from)
|
||||
tasks.forEach {
|
||||
reverseAfter.put(it, from)
|
||||
}
|
||||
}
|
||||
log(3, "Tasks:")
|
||||
tasksByNames.keys().forEach {
|
||||
log(3, " $it: " + tasksByNames.get(it))
|
||||
}
|
||||
val graph = DynamicGraph<PluginTask>()
|
||||
taskNames.forEach { taskName ->
|
||||
val ti = TaskInfo(taskName)
|
||||
if (!tasksByNames.keys().contains(ti.taskName)) {
|
||||
throw KobaltException("Unknown task: $taskName")
|
||||
}
|
||||
|
||||
//
|
||||
// If the current target is free, add it as a single node to the graph
|
||||
//
|
||||
val allFreeTasks = calculateFreeTasks(tasksByNames, reverseAfter)
|
||||
val currentFreeTask = allFreeTasks.filter {
|
||||
TaskInfo(projectName, it.name).taskName == task.name
|
||||
}
|
||||
if (currentFreeTask.size == 1) {
|
||||
currentFreeTask[0].let {
|
||||
graph.addNode(it)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Add the transitive closure of the current task as edges to the graph
|
||||
//
|
||||
val transitiveClosure = calculateTransitiveClosure(project, tasksByNames, ti)
|
||||
transitiveClosure.forEach { pluginTask ->
|
||||
val rb = runBefore.get(pluginTask.name)
|
||||
rb.forEach {
|
||||
val tos = tasksByNames[it]
|
||||
if (tos != null && tos.size > 0) {
|
||||
tos.forEach { to ->
|
||||
graph.addEdge(pluginTask, to)
|
||||
}
|
||||
} else {
|
||||
log(1, "Couldn't find node $it: not applicable to project ${project.name}")
|
||||
if (ti.matches(projectName)) {
|
||||
tasksByNames[ti.taskName].forEach { task ->
|
||||
if (task != null && task.plugin.accept(project)) {
|
||||
val reverseAfter = hashMapOf<String, String>()
|
||||
alwaysRunAfter.keys().forEach { from ->
|
||||
val tasks = alwaysRunAfter.get(from)
|
||||
tasks.forEach {
|
||||
reverseAfter.put(it, from)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If any of the nodes in the graph has an "alwaysRunAfter", add that edge too
|
||||
//
|
||||
val allNodes = arrayListOf<PluginTask>()
|
||||
allNodes.addAll(graph.nodes)
|
||||
allNodes.forEach { node ->
|
||||
val other = alwaysRunAfter.get(node.name)
|
||||
other?.forEach { o ->
|
||||
tasksByNames[o]?.forEach {
|
||||
graph.addEdge(it, node)
|
||||
//
|
||||
// If the current target is free, add it as a single node to the graph
|
||||
//
|
||||
val allFreeTasks = calculateFreeTasks(tasksByNames, reverseAfter)
|
||||
val currentFreeTask = allFreeTasks.filter {
|
||||
TaskInfo(projectName, it.name).taskName == task.name
|
||||
}
|
||||
if (currentFreeTask.size == 1) {
|
||||
currentFreeTask[0].let {
|
||||
graph.addNode(it)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Add the transitive closure of the current task as edges to the graph
|
||||
//
|
||||
val transitiveClosure = calculateTransitiveClosure(project, tasksByNames, ti)
|
||||
transitiveClosure.forEach { pluginTask ->
|
||||
val rb = runBefore.get(pluginTask.name)
|
||||
rb.forEach {
|
||||
val tos = tasksByNames[it]
|
||||
if (tos != null && tos.size > 0) {
|
||||
tos.forEach { to ->
|
||||
graph.addEdge(pluginTask, to)
|
||||
}
|
||||
} else {
|
||||
log(1, "Couldn't find node $it: not applicable to project ${project.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// If any of the nodes in the graph has an "alwaysRunAfter", add that edge too
|
||||
//
|
||||
val allNodes = arrayListOf<PluginTask>()
|
||||
allNodes.addAll(graph.nodes)
|
||||
allNodes.forEach { node ->
|
||||
val other = alwaysRunAfter.get(node.name)
|
||||
other?.forEach { o ->
|
||||
tasksByNames[o]?.forEach {
|
||||
graph.addEdge(it, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Now that we have a full graph, run it
|
||||
//
|
||||
log(3, "About to run graph:\n ${graph.dump()} ")
|
||||
//
|
||||
// Now that we have a full graph, run it
|
||||
//
|
||||
log(3, "About to run graph:\n ${graph.dump()} ")
|
||||
|
||||
val factory = object : IThreadWorkerFactory<PluginTask> {
|
||||
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
||||
val factory = object : IThreadWorkerFactory<PluginTask> {
|
||||
override public fun createWorkers(nodes: List<PluginTask>): List<IWorker<PluginTask>> {
|
||||
// val tr = nodes.reduce { workers: List<TaskWorker>, node: PluginTask ->
|
||||
// val result: List<TaskWorker> = workers + TaskWorker(listOf(node), args.dryRun, messages)
|
||||
// result
|
||||
// }
|
||||
val thisResult = arrayListOf<IWorker<PluginTask>>()
|
||||
nodes.forEach {
|
||||
thisResult.add(TaskWorker(listOf(it), args.dryRun, messages))
|
||||
val thisResult = arrayListOf<IWorker<PluginTask>>()
|
||||
nodes.forEach {
|
||||
thisResult.add(TaskWorker(listOf(it), args.dryRun, messages))
|
||||
}
|
||||
return thisResult
|
||||
}
|
||||
return thisResult
|
||||
}
|
||||
|
||||
val executor = DynamicGraphExecutor(graph, factory)
|
||||
val thisResult = executor.run()
|
||||
if (result == 0) {
|
||||
result = thisResult
|
||||
}
|
||||
if (result != 0) {
|
||||
failedProjects.add(project.name)
|
||||
}
|
||||
}
|
||||
|
||||
val executor = DynamicGraphExecutor(graph, factory)
|
||||
val thisResult = executor.run()
|
||||
if (result == 0) {
|
||||
result = thisResult
|
||||
}
|
||||
|
||||
}
|
||||
return RunTargetResult(result, messages)
|
||||
}
|
||||
|
|
|
@ -114,9 +114,9 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
|
|||
/**
|
||||
* @return the compile dependencies for this project, including the contributors.
|
||||
*/
|
||||
fun dependencies(project: Project, context: KobaltContext,
|
||||
projects: List<ProjectDescription>) : List<IClasspathDependency> {
|
||||
fun dependencies(project: Project, context: KobaltContext) : List<IClasspathDependency> {
|
||||
val result = arrayListOf<IClasspathDependency>()
|
||||
val projects = listOf(ProjectDescription(project, project.projectInfo.dependsOn))
|
||||
result.add(FileDependency(KFiles.makeOutputDir(project).absolutePath))
|
||||
result.add(FileDependency(KFiles.makeOutputTestDir(project).absolutePath))
|
||||
with(project) {
|
||||
|
@ -131,9 +131,9 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
|
|||
/**
|
||||
* @return the test dependencies for this project, including the contributors.
|
||||
*/
|
||||
fun testDependencies(project: Project, context: KobaltContext,
|
||||
projects: List<ProjectDescription>) : List<IClasspathDependency> {
|
||||
fun testDependencies(project: Project, context: KobaltContext) : List<IClasspathDependency> {
|
||||
val result = arrayListOf<IClasspathDependency>()
|
||||
val projects = listOf(ProjectDescription(project, project.projectInfo.dependsOn))
|
||||
result.add(FileDependency(KFiles.makeOutputDir(project).absolutePath))
|
||||
result.add(FileDependency(KFiles.makeOutputTestDir(project).absolutePath))
|
||||
with(project) {
|
||||
|
|
|
@ -30,6 +30,8 @@ fun Any.warn(text: String) {
|
|||
KobaltLogger.logger.warn(javaClass.simpleName, text)
|
||||
}
|
||||
|
||||
fun Any.kobaltError(text: String, e: Throwable? = null) = error(text, e)
|
||||
|
||||
fun Any.error(text: String, e: Throwable? = null) {
|
||||
KobaltLogger.logger.error(javaClass.simpleName, text, e)
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
|
|||
val runContributor = ActorUtils.selectAffinityActor(project, context,
|
||||
context.pluginInfo.runnerContributors)
|
||||
if (runContributor != null && runContributor.affinity(project, context) > 0) {
|
||||
return runContributor.run(project, context, dependencyManager.dependencies(project, context, projects()))
|
||||
return runContributor.run(project, context, dependencyManager.dependencies(project, context))
|
||||
} else {
|
||||
warn("Couldn't find a runner for project ${project.name}")
|
||||
return TaskResult()
|
||||
|
|
|
@ -75,10 +75,10 @@ class JavaPlugin @Inject constructor(
|
|||
}
|
||||
|
||||
@Directive
|
||||
public fun javaProject(vararg project: Project, init: JavaProject.() -> Unit): JavaProject {
|
||||
public fun javaProject(vararg projects: Project, init: JavaProject.() -> Unit): JavaProject {
|
||||
return JavaProject().apply {
|
||||
init()
|
||||
(Kobalt.findPlugin(JavaPlugin.PLUGIN_NAME) as BasePlugin).addProject(this, project)
|
||||
(Kobalt.findPlugin(JavaPlugin.PLUGIN_NAME) as JvmCompilerPlugin).addDependentProjects(this, projects.toList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.beust.kobalt.internal.BaseProjectInfo
|
|||
import com.google.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class JavaProjectInfo : BaseProjectInfo {
|
||||
class JavaProjectInfo : BaseProjectInfo() {
|
||||
override val sourceDirectory = "java"
|
||||
override val defaultSourceDirectories = hashSetOf("src/main/java", "src/main/resources", "src/main/res")
|
||||
override val defaultTestDirectories = hashSetOf("src/test/java", "src/test/resources", "src/test/res")
|
||||
|
|
|
@ -82,7 +82,7 @@ class KotlinPlugin @Inject constructor(
|
|||
|
||||
val result =
|
||||
if (sourceFiles.size > 0) {
|
||||
compilePrivate(project, dependencyManager.testDependencies(project, context, projects()),
|
||||
compilePrivate(project, dependencyManager.testDependencies(project, context),
|
||||
sourceFiles,
|
||||
KFiles.makeOutputTestDir(project))
|
||||
} else {
|
||||
|
@ -153,10 +153,10 @@ class KotlinPlugin @Inject constructor(
|
|||
* @param project: the list of projects that need to be built before this one.
|
||||
*/
|
||||
@Directive
|
||||
fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
|
||||
fun kotlinProject(vararg projects: Project, init: KotlinProject.() -> Unit): KotlinProject {
|
||||
return KotlinProject().apply {
|
||||
init()
|
||||
(Kobalt.findPlugin(KotlinPlugin.PLUGIN_NAME) as BasePlugin).addProject(this, project)
|
||||
(Kobalt.findPlugin(KotlinPlugin.PLUGIN_NAME) as JvmCompilerPlugin).addDependentProjects(this, projects.toList())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import com.beust.kobalt.internal.BaseProjectInfo
|
|||
import com.google.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class KotlinProjectInfo : BaseProjectInfo {
|
||||
class KotlinProjectInfo : BaseProjectInfo() {
|
||||
override val sourceDirectory = "kotlin"
|
||||
override val defaultSourceDirectories = hashSetOf("src/main/kotlin", "src/main/resources", "src/main/res")
|
||||
override val defaultTestDirectories = hashSetOf("src/test/kotlin", "src/test/resources", "src/test/res")
|
||||
|
|
|
@ -142,7 +142,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val inf = arrayListOf<IncludedFile>()
|
||||
packages.filter { it.project.name == project.name }.forEach { pkg ->
|
||||
pkg.jars.forEach { inf.addAll(jarGenerator.findIncludedFiles(pkg.project, context, it)) }
|
||||
pkg.wars.forEach { inf.addAll(warGenerator.findIncludedFiles(pkg.project, context, it, projects)) }
|
||||
pkg.wars.forEach { inf.addAll(warGenerator.findIncludedFiles(pkg.project, context, it)) }
|
||||
pkg.zips.forEach { inf.addAll(zipGenerator.findIncludedFiles(pkg.project, context, it)) }
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
project.projectProperties.put(PACKAGES, packages)
|
||||
packages.filter { it.project.name == project.name }.forEach { pkg ->
|
||||
pkg.jars.forEach { jarGenerator.generateJar(pkg.project, context, it) }
|
||||
pkg.wars.forEach { warGenerator.generateWar(pkg.project, context, it, projects) }
|
||||
pkg.wars.forEach { warGenerator.generateWar(pkg.project, context, it) }
|
||||
pkg.zips.forEach { zipGenerator.generateZip(pkg.project, context, it) }
|
||||
if (pkg.generatePom) {
|
||||
pomFactory.create(project).generate()
|
||||
|
|
|
@ -18,8 +18,7 @@ import java.util.jar.JarOutputStream
|
|||
|
||||
class WarGenerator @Inject constructor(val dependencyManager: DependencyManager){
|
||||
|
||||
fun findIncludedFiles(project: Project, context: KobaltContext, war: War,
|
||||
projects: List<ProjectDescription>) : List<IncludedFile> {
|
||||
fun findIncludedFiles(project: Project, context: KobaltContext, war: War) : List<IncludedFile> {
|
||||
//
|
||||
// src/main/web app and classes
|
||||
//
|
||||
|
@ -32,7 +31,8 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
|||
// The transitive closure of libraries goes into WEB-INF/libs.
|
||||
// Copy them all in kobaltBuild/war/WEB-INF/libs and create one IncludedFile out of that directory
|
||||
//
|
||||
val allDependencies = dependencyManager.calculateDependencies(project, context, projects,
|
||||
val dependentProjects = listOf(ProjectDescription(project, project.projectInfo.dependsOn))
|
||||
val allDependencies = dependencyManager.calculateDependencies(project, context, dependentProjects,
|
||||
project.compileDependencies)
|
||||
|
||||
val WEB_INF = "WEB-INF/lib"
|
||||
|
@ -65,15 +65,14 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
|||
return result
|
||||
}
|
||||
|
||||
fun generateWar(project: Project, context: KobaltContext, war: War,
|
||||
projects: List<ProjectDescription>) : File {
|
||||
fun generateWar(project: Project, context: KobaltContext, war: War) : File {
|
||||
|
||||
val manifest = java.util.jar.Manifest()//FileInputStream(mf))
|
||||
war.attributes.forEach { attribute ->
|
||||
manifest.mainAttributes.putValue(attribute.first, attribute.second)
|
||||
}
|
||||
|
||||
val allFiles = findIncludedFiles(project, context, war, projects)
|
||||
val allFiles = findIncludedFiles(project, context, war)
|
||||
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
||||
return PackagingPlugin.generateArchive(project, context, war.name, ".war", allFiles,
|
||||
false /* don't expand jar files */, jarFactory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue