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

Relative compile dependencies should be resolved correctly.

Related to https://github.com/cbeust/kobalt-intellij-plugin/issues/24
This commit is contained in:
Cedric Beust 2016-05-06 01:13:02 -08:00
parent f100f9bd62
commit 268b9a400f
4 changed files with 38 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.internal.KobaltSettings
import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KobaltExecutors
import java.io.File
class KobaltContext(val args: Args) {
var variant: Variant = Variant()
@ -47,4 +48,9 @@ class InternalContext {
* will be disabled.
*/
var buildFileOutOfDate: Boolean = false
/**
* The absolute directory of the current project.
*/
var absoluteDir: File? = null
}

View file

@ -23,4 +23,9 @@ class BuildFile(val path: Path, val name: String, val realPath: Path = path) {
val dotKobaltDir: File get() = File(directory.parentFile.parentFile, KFiles.KOBALT_DOT_DIR).apply {
mkdirs()
}
/**
* @return the absolute directory of this build file, assuming the build file is in $project/kobalt/src/Build.kt
*/
val absoluteDir = path.parent.parent.parent.toFile()
}

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.maven.dependency.FileDependency
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.log
import com.beust.kobalt.misc.warn
import com.google.common.collect.ArrayListMultimap
import java.io.File
import java.util.*
@ -30,7 +31,15 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
val path = if (project?.directory != null) {
val idPath = id.substring(FileDependency.PREFIX_FILE.length)
if (! File(idPath).isAbsolute) {
File(project!!.directory, idPath)
// If the project directory is relative, we might not be in the correct directory to locate
// that file, so we'll use the absolute directory deduced from the build file path. Pick
// the first one that produces an actual file
val result = listOf(File(project!!.directory), Kobalt.context?.internalContext?.absoluteDir).map {
File(it, idPath)
}.first {
it.exists()
}
result
} else {
File(idPath)
}
@ -119,7 +128,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
}
}
val result2 = reorderDependencies(result).filter {
val reordered = reorderDependencies(result)
val nonexistent = reordered.filter{ ! it.jarFile.get().exists() }
if (nonexistent.any()) {
warn("Nonexistent dependencies: $nonexistent")
}
val result2 = reordered.filter {
// Only keep existent files (nonexistent files are probably optional dependencies or parent poms
// that point to other poms but don't have a jar file themselves)
it.jarFile.get().exists()

View file

@ -73,6 +73,11 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
val pluginUrls = parsedBuildFile.pluginUrls
val buildScriptJarFile = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR))
//
// Save the current build script absolute directory
//
context.internalContext.absoluteDir = buildFile.absoluteDir
// If the script jar files were generated by a different version, wipe them in case the API
// changed in-between
buildScriptJarFile.parentFile.let { dir ->
@ -96,6 +101,10 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
errorTaskResult = taskResult
}
}
// Clear the absolute dir
context.internalContext.absoluteDir = null
}
val pluginUrls = parsedBuildFiles.flatMap { it.pluginUrls }
return FindProjectResult(projects, pluginUrls, if (errorTaskResult != null) errorTaskResult!! else TaskResult())