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

.kobalt find fixes.

This commit is contained in:
Cedric Beust 2016-04-23 05:15:49 -08:00
parent 4a43d17288
commit 8c13df5be1
2 changed files with 16 additions and 12 deletions

View file

@ -1,5 +1,6 @@
package com.beust.kobalt.internal.build package com.beust.kobalt.internal.build
import com.beust.kobalt.misc.KFiles
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
@ -9,10 +10,17 @@ import java.nio.file.attribute.BasicFileAttributes
* @param path is the path where that file was moved, @param realPath is where the actual file is. * @param path is the path where that file was moved, @param realPath is where the actual file is.
*/ */
class BuildFile(val path: Path, val name: String, val realPath: Path = path) { class BuildFile(val path: Path, val name: String, val realPath: Path = path) {
public fun exists() : Boolean = Files.exists(path) fun exists() : Boolean = Files.exists(path)
public val lastModified : Long val lastModified : Long
get() = Files.readAttributes(realPath, BasicFileAttributes::class.java).lastModifiedTime().toMillis() get() = Files.readAttributes(realPath, BasicFileAttributes::class.java).lastModifiedTime().toMillis()
public val directory : File get() = path.toFile().parentFile val directory : File get() = path.toFile().parentFile
/**
* @return the .kobalt directory where this build file will be compiled.
*/
val dotKobaltDir: File get() = File(directory.parentFile.parentFile, KFiles.KOBALT_DOT_DIR).apply {
mkdirs()
}
} }

View file

@ -222,22 +222,18 @@ class KFiles {
} }
} }
fun findDotDir(startDir: File) : File { private fun findDotDir(buildFile: BuildFile) : File {
var result = startDir val result = File(buildFile.directory.parentFile.parentFile, KOBALT_DOT_DIR).apply {
while (result != null && result.parentFile != null && ! File(result, KOBALT_DOT_DIR).exists()) { mkdirs()
result = result.parentFile
} }
if (result == null) { return result
throw IllegalArgumentException("Couldn't locate $KOBALT_DOT_DIR in $startDir")
}
return File(result, KOBALT_DOT_DIR)
} }
/** /**
* The build location for build scripts is .kobalt/build * The build location for build scripts is .kobalt/build
*/ */
fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String { fun findBuildScriptLocation(buildFile: BuildFile, jarFile: String) : String {
val result = joinDir(findDotDir(buildFile.directory).absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile) val result = joinDir(buildFile.dotKobaltDir.absolutePath, KFiles.SCRIPT_BUILD_DIR, jarFile)
log(2, "Script jar file: $result") log(2, "Script jar file: $result")
return result return result
} }