mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -07:00
--gc.
This commit is contained in:
parent
2c0f930764
commit
d0977b17e7
4 changed files with 116 additions and 1 deletions
|
@ -9,6 +9,7 @@ import com.beust.kobalt.app.*
|
|||
import com.beust.kobalt.app.remote.DependencyData
|
||||
import com.beust.kobalt.app.remote.KobaltClient
|
||||
import com.beust.kobalt.app.remote.KobaltServer
|
||||
import com.beust.kobalt.internal.Gc
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.TaskManager
|
||||
|
@ -169,7 +170,9 @@ private class Main @Inject constructor(
|
|||
server.run()
|
||||
} else {
|
||||
// Options that don't need Build.kt to be parsed first
|
||||
if (args.update) {
|
||||
if (args.gc) {
|
||||
Gc().run()
|
||||
} else if (args.update) {
|
||||
// --update
|
||||
updateKobalt.updateKobalt()
|
||||
} else {
|
||||
|
|
41
src/main/kotlin/com/beust/kobalt/internal/Gc.kt
Normal file
41
src/main/kotlin/com/beust/kobalt/internal/Gc.kt
Normal file
|
@ -0,0 +1,41 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.misc.Io
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Clean up old Kobalt files.
|
||||
*/
|
||||
class Gc {
|
||||
fun run() {
|
||||
// Delete all the distributions except the current one
|
||||
val dist = KFiles.distributionsDir
|
||||
val version = Kobalt.version
|
||||
val tmpDir = Files.createTempDirectory("kobalt")
|
||||
|
||||
// Zipfile
|
||||
val io = Io(dryRun = true)
|
||||
val zipFileName = "kobalt-$version.zip"
|
||||
io.moveFile(File(KFiles.joinDir(dist, zipFileName)), tmpDir.toFile())
|
||||
|
||||
// Distribution directory
|
||||
val zipDirectoryName = "kobalt-$version"
|
||||
val zipDirectory = File(KFiles.joinDir(dist, zipDirectoryName))
|
||||
io.copyDirectory(zipDirectory, tmpDir.toFile())
|
||||
|
||||
// Delete the whole dist directory and recreate it
|
||||
File(dist).let { distFile ->
|
||||
io.rmDir(distFile)
|
||||
io.mkdir(distFile)
|
||||
|
||||
// Copy the files back
|
||||
tmpDir.toFile().absolutePath.let { fromPath ->
|
||||
io.moveFile(File(KFiles.joinDir(fromPath, zipFileName)), distFile)
|
||||
io.copyDirectory(File(KFiles.joinDir(fromPath, zipDirectoryName)), distFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue