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

ApplicationPlugin wasn't respecting dependent projects.

This commit is contained in:
Cedric Beust 2015-11-19 00:11:46 -08:00
parent 70bff11edb
commit 302f1022e3
5 changed files with 33 additions and 18 deletions

View file

@ -25,7 +25,7 @@ class JvmCompiler @Inject constructor(val dependencyManager: DependencyManager)
// Dependencies // Dependencies
val allDependencies = (info.dependencies val allDependencies = (info.dependencies
+ dependencyManager.calculateDependencies(project, context!!, info.dependencies)) + dependencyManager.calculateDependencies(project, context!!, allDependencies = info.dependencies))
.distinct() .distinct()
// Plugins that add flags to the compiler // Plugins that add flags to the compiler

View file

@ -31,6 +31,9 @@ abstract class JvmCompilerPlugin @Inject constructor(
@ExportedProjectProperty(doc = "The location of the build directory", type = "String") @ExportedProjectProperty(doc = "The location of the build directory", type = "String")
const val BUILD_DIR = "buildDir" const val BUILD_DIR = "buildDir"
@ExportedProjectProperty(doc = "Projects this project depends on", type = "List<ProjectDescription>")
const val DEPENDENT_PROJECTS = "dependentProjects"
const val TASK_CLEAN = "clean" const val TASK_CLEAN = "clean"
const val TASK_TEST = "test" const val TASK_TEST = "test"
@ -49,6 +52,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
override fun apply(project: Project, context: KobaltContext) { override fun apply(project: Project, context: KobaltContext) {
super.apply(project, context) super.apply(project, context)
project.projectProperties.put(BUILD_DIR, project.buildDirectory + File.separator + "classes") project.projectProperties.put(BUILD_DIR, project.buildDirectory + File.separator + "classes")
project.projectProperties.put(DEPENDENT_PROJECTS, projects())
} }
/** /**
@ -61,7 +65,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
with(project) { with(project) {
arrayListOf(compileDependencies, compileProvidedDependencies, testDependencies, arrayListOf(compileDependencies, compileProvidedDependencies, testDependencies,
testProvidedDependencies).forEach { testProvidedDependencies).forEach {
result.addAll(dependencyManager.calculateDependencies(project, context, it)) result.addAll(dependencyManager.calculateDependencies(project, context, projects(), it))
} }
} }
val result2 = dependencyManager.reorderDependencies(result) val result2 = dependencyManager.reorderDependencies(result)
@ -152,10 +156,8 @@ abstract class JvmCompilerPlugin @Inject constructor(
private fun createCompilerActionInfo(project: Project) : CompilerActionInfo { private fun createCompilerActionInfo(project: Project) : CompilerActionInfo {
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN) copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
val projDeps = dependencyManager.dependentProjectDependencies(projects(), project, context) val classpath = dependencyManager.calculateDependencies(project, context, projects,
project.compileDependencies)
val classpath = dependencyManager.calculateDependencies(project, context, project.compileDependencies,
project.compileProvidedDependencies, projDeps)
val projectDirectory = File(project.directory) val projectDirectory = File(project.directory)
val buildDirectory = File(projectDirectory, project.buildDirectory + File.separator + "classes") val buildDirectory = File(projectDirectory, project.buildDirectory + File.separator + "classes")

View file

@ -7,7 +7,6 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.IClasspathDependency
import com.beust.kobalt.misc.* import com.beust.kobalt.misc.*
import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate import com.beust.kobalt.plugin.kotlin.kotlinCompilePrivate
import com.google.inject.assistedinject.Assisted import com.google.inject.assistedinject.Assisted
@ -194,7 +193,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
} }
private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File) { private fun generateJarFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File) {
val kotlintDeps = dependencyManager.calculateDependencies(null, context, listOf<IClasspathDependency>()) val kotlintDeps = dependencyManager.calculateDependencies(null, context)
val deps: List<String> = kotlintDeps.map { it.jarFile.get().absolutePath } val deps: List<String> = kotlintDeps.map { it.jarFile.get().absolutePath }
kotlinCompilePrivate { kotlinCompilePrivate {
classpath(files.kobaltJar) classpath(files.kobaltJar)

View file

@ -21,12 +21,14 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
* @return the classpath for this project, including the IClasspathContributors. * @return the classpath for this project, including the IClasspathContributors.
*/ */
fun calculateDependencies(project: Project?, context: KobaltContext, fun calculateDependencies(project: Project?, context: KobaltContext,
dependentProjects: List<ProjectDescription> = emptyList(),
vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency> { vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency> {
var result = arrayListOf<IClasspathDependency>() var result = arrayListOf<IClasspathDependency>()
allDependencies.forEach { dependencies -> allDependencies.forEach { dependencies ->
result.addAll(transitiveClosure(dependencies)) result.addAll(transitiveClosure(dependencies))
} }
result.addAll(runClasspathContributors(project, context)) result.addAll(runClasspathContributors(project, context))
result.addAll(dependentProjectDependencies(dependentProjects, project, context))
return result return result
} }
@ -90,12 +92,12 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
* If this project depends on other projects, we need to include their jar file and also * If this project depends on other projects, we need to include their jar file and also
* their own dependencies * their own dependencies
*/ */
fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>, private fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>,
project: Project, context: KobaltContext) : project: Project?, context: KobaltContext) :
List<IClasspathDependency> { List<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>() val result = arrayListOf<IClasspathDependency>()
projectDescriptions.filter { projectDescriptions.filter {
it.project.name == project.name it.project.name == project?.name
}.forEach { pd -> }.forEach { pd ->
pd.dependsOn.forEach { p -> pd.dependsOn.forEach { p ->
val classesDir = p.projectProperties.getString(JvmCompilerPlugin.BUILD_DIR) val classesDir = p.projectProperties.getString(JvmCompilerPlugin.BUILD_DIR)
@ -104,7 +106,7 @@ public class DependencyManager @Inject constructor(val executors: KobaltExecutor
} else { } else {
warn("Couldn't find any classes dir for project depended on ${p.name}") warn("Couldn't find any classes dir for project depended on ${p.name}")
} }
result.addAll(calculateDependencies(p, context)) result.addAll(calculateDependencies(p, context, projectDescriptions))
} }
} }

View file

@ -3,8 +3,10 @@ package com.beust.kobalt.plugin.application
import com.beust.kobalt.* import com.beust.kobalt.*
import com.beust.kobalt.api.ConfigPlugin import com.beust.kobalt.api.ConfigPlugin
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectDescription
import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.RunCommand import com.beust.kobalt.misc.RunCommand
@ -42,6 +44,7 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
@Task(name = "run", description = "Run the main class", runAfter = arrayOf("assemble")) @Task(name = "run", description = "Run the main class", runAfter = arrayOf("assemble"))
fun taskRun(project: Project): TaskResult { fun taskRun(project: Project): TaskResult {
var result = TaskResult()
configurationFor(project)?.let { config -> configurationFor(project)?.let { config ->
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!! val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
if (config.mainClass != null) { if (config.mainClass != null) {
@ -49,22 +52,31 @@ class ApplicationPlugin @Inject constructor(val executors: KobaltExecutors,
val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List<PackageConfig> val packages = project.projectProperties.get(PackagingPlugin.PACKAGES) as List<PackageConfig>
val allDeps = arrayListOf(jarName) val allDeps = arrayListOf(jarName)
if (! isFatJar(packages, jarName)) { if (! isFatJar(packages, jarName)) {
val projDeps = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS)
as List<ProjectDescription>
// If the jar file is not fat, we need to add the transitive closure of all dependencies // If the jar file is not fat, we need to add the transitive closure of all dependencies
// on the classpath // on the classpath
allDeps.addAll( allDeps.addAll(
dependencyManager.calculateDependencies(project, context, project.compileDependencies) dependencyManager.calculateDependencies(project, context, projDeps,
.map { it.jarFile.get().path }) allDependencies = project.compileDependencies).map { it.jarFile.get().path })
} }
val allDepsJoined = allDeps.joinToString(File.pathSeparator) val allDepsJoined = allDeps.joinToString(File.pathSeparator)
val args = listOf("-classpath", allDepsJoined) + config.jvmArgs + config.mainClass!! val args = listOf("-classpath", allDepsJoined) + config.jvmArgs + config.mainClass!!
RunCommand(java.absolutePath).run(args, successCallback = { output: List<String> -> val exitCode = RunCommand(java.absolutePath).run(args,
println(output.joinToString("\n")) successCallback = { output: List<String> ->
}) println(output.joinToString("\n"))
},
errorCallback = { output: List<String> ->
println("ERROR")
println(output.joinToString("\n"))
}
)
result = TaskResult(exitCode == 0)
} else { } else {
throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}") throw KobaltException("No \"mainClass\" specified in the application{} part of project ${project.name}")
} }
} }
return TaskResult() return result
} }
private fun isFatJar(packages: List<PackageConfig>, jarName: String): Boolean { private fun isFatJar(packages: List<PackageConfig>, jarName: String): Boolean {