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

Fix optional dependencies problem.

This commit is contained in:
Cedric Beust 2017-02-01 12:58:59 -08:00
parent 38bb53387e
commit ae450e4cbc
15 changed files with 323 additions and 127 deletions

View file

@ -46,7 +46,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
private val SCRIPT_JAR = "buildScript.jar"
fun compileBuildFiles(args: Args): FindProjectResult {
fun compileBuildFiles(args: Args, forceRecompile: Boolean = false): FindProjectResult {
//
// Create the KobaltContext
// Note: can't use apply{} here or each field will refer to itself instead of the constructor field
@ -66,7 +66,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
//
// Find all the projects in the build file, possibly compiling them
//
val projectResult = findProjects(context)
val projectResult = findProjects(context, forceRecompile)
return projectResult
}
@ -76,7 +76,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
class FindProjectResult(val context: KobaltContext, val projects: List<Project>, val pluginUrls: List<URL>,
val taskResult: TaskResult)
private fun findProjects(context: KobaltContext): FindProjectResult {
private fun findProjects(context: KobaltContext, forceRecompile: Boolean): FindProjectResult {
var errorTaskResult: TaskResult? = null
val projects = arrayListOf<Project>()
buildFiles.forEach { buildFile ->
@ -105,7 +105,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode)
val taskResult = maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path),
"Modified ${Constants.BUILD_FILE_NAME}", buildFile.realPath),
buildScriptJarFile, pluginUrls)
buildScriptJarFile, pluginUrls, forceRecompile)
if (taskResult.success) {
projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context))
} else {
@ -124,7 +124,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
}
private fun maybeCompileBuildFile(context: KobaltContext, buildFile: BuildFile, buildScriptJarFile: File,
pluginUrls: List<URL>) : TaskResult {
pluginUrls: List<URL>, forceRecompile: Boolean) : TaskResult {
kobaltLog(2, "Running build file ${buildFile.name} jar: $buildScriptJarFile")
// If the user specifed --profiles, always recompile the build file since we don't know if
@ -135,8 +135,8 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil
// compiled with.
val bs = BuildScriptJarFile(buildScriptJarFile)
val same = bs.sameProfiles(args.profiles)
if (same && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) {
kobaltLog(2, " Build file is up to date")
if (same && ! forceRecompile && buildScriptUtil.isUpToDate(buildFile, buildScriptJarFile)) {
kobaltLog(2, " Build file $buildScriptJarFile is up to date")
return TaskResult()
} else {
kobaltLog(2, " Need to recompile ${buildFile.name}")

View file

@ -13,6 +13,7 @@ import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.Topological
import com.beust.kobalt.misc.kobaltLog
import com.beust.kobalt.misc.warn
import com.beust.kobalt.plugin.KobaltPlugin
import com.google.inject.Inject
import java.io.File
@ -63,11 +64,15 @@ class BuildScriptUtil @Inject constructor(val plugins: Plugins, val files: KFile
val name = entry.name;
if (name.endsWith(".class")) {
val className = name.substring(0, name.length - 6).replace("/", ".")
val cl : Class<*>? = classLoader.loadClass(className)
if (cl != null) {
classes.add(cl)
} else {
throw KobaltException("Couldn't instantiate $className")
try {
val cl: Class<*>? = classLoader.loadClass(className)
if (cl != null) {
classes.add(cl)
} else {
throw KobaltException("Couldn't instantiate $className")
}
} catch(ex: ClassNotFoundException) {
warn("Couldn't find class $className")
}
}
entry = stream.nextJarEntry;

View file

@ -162,8 +162,8 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
//
// Compile the jar file
//
val kotlintDeps = dependencyManager.calculateDependencies(null, context)
val deps: List<String> = kotlintDeps.map { it.jarFile.get().absolutePath }
val kotlinDeps = dependencyManager.calculateDependencies(null, context)
val deps: List<String> = kotlinDeps.map { it.jarFile.get().absolutePath }
val outputJar = File(buildScriptJarFile.absolutePath)
val result = kotlinCompilePrivate {
classpath(files.kobaltJar)

View file

@ -112,7 +112,7 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
val allDependencies = project.compileDependencies + project.compileRuntimeDependencies
val allTheDependencies =
dependencyManager.calculateDependencies(project, context,
listOf(Scope.COMPILE, Scope.RUNTIME),
scopes = listOf(Scope.COMPILE, Scope.RUNTIME),
passedDependencies = allDependencies)
.map { it.jarFile.get().path }
allDeps.addAll(allTheDependencies)