diff --git a/.gitignore b/.gitignore index d6c778df6..9ea4f9ff5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ local.properties classes libs .kobalt/ -build/ +./build/ out .DS_Store diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt new file mode 100644 index 000000000..17954ed09 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt @@ -0,0 +1,17 @@ +package com.beust.kobalt.internal.build + +import java.io.File +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.attribute.BasicFileAttributes +/** + * Sometimes, build files are moved to temporary files, so we give them a specific name for clarity. + */ +class BuildFile(val path: Path, val name: String) { + public fun exists() : Boolean = Files.exists(path) + + public val lastModified : Long + get() = Files.readAttributes(path, BasicFileAttributes::class.java).lastModifiedTime().toMillis() + + public val directory : File get() = path.toFile().directory +} diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt new file mode 100644 index 000000000..4343ed3f4 --- /dev/null +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/VersionFile.kt @@ -0,0 +1,20 @@ +package com.beust.kobalt.internal.build + +import com.beust.kobalt.api.Kobalt +import com.beust.kobalt.misc.KFiles +import java.io.File + +class VersionFile { + companion object { + private val VERSION_FILE = "version.txt" + + fun generateVersionFile(directory: File) { + KFiles.saveFile(File(directory, VERSION_FILE), Kobalt.version) + } + + fun isSameVersionFile(directory: File) = + with(File(directory, VERSION_FILE)) { + ! exists() || (exists() && readText() == Kobalt.version) + } + } +} \ No newline at end of file