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

If a dependent project fails, fail the ones that follow.

This commit is contained in:
Cedric Beust 2016-01-15 01:51:59 +04:00
parent 23032f52d7
commit 60036dcb43
13 changed files with 144 additions and 119 deletions

View file

@ -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
}

View file

@ -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 {

View file

@ -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>()
}

View file

@ -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,8 +52,20 @@ 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 ->
AsciiArt.logBox("Building ${project.name}")
// Does the current project depend on any failed projects?
val fp = project.projectInfo.dependsOn.filter {
failedProjects.contains(it.name)
}
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
@ -63,8 +76,6 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
tasksByNames.put(it.name, it)
}
AsciiArt.logBox("Building ${project.name}")
log(3, "Tasks:")
tasksByNames.keys().forEach {
log(3, " $it: " + tasksByNames.get(it))
@ -160,7 +171,10 @@ public class TaskManager @Inject constructor(val args: Args, val incrementalMana
if (result == 0) {
result = thisResult
}
if (result != 0) {
failedProjects.add(project.name)
}
}
}
return RunTargetResult(result, messages)
}

View file

@ -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) {

View file

@ -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)
}

View file

@ -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()

View file

@ -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())
}
}

View file

@ -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")

View file

@ -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())
}
}

View file

@ -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")

View file

@ -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()

View file

@ -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)