mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Settings for Kobalt.
~/.kobalt/settings.xml.
This commit is contained in:
parent
24bd2c6299
commit
27d6332ea4
8 changed files with 81 additions and 13 deletions
|
@ -3,6 +3,7 @@ package com.beust.kobalt.api
|
|||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.Variant
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
|
@ -26,5 +27,6 @@ public class KobaltContext(val args: Args) {
|
|||
lateinit var pluginProperties: PluginProperties
|
||||
lateinit var dependencyManager: DependencyManager
|
||||
lateinit var executors: KobaltExecutors
|
||||
lateinit var settings: KobaltSettings
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.inject.Inject
|
||||
import com.google.inject.Singleton
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import javax.xml.bind.JAXBContext
|
||||
import javax.xml.bind.annotation.XmlElement
|
||||
import javax.xml.bind.annotation.XmlRootElement
|
||||
|
||||
/**
|
||||
* The root element of kobalt-settings.xml
|
||||
*/
|
||||
@XmlRootElement(name = "kobalt-settings")
|
||||
class KobaltSettingsXml {
|
||||
@XmlElement @JvmField
|
||||
var localRepo: String = homeDir(KFiles.KOBALT_DOT_DIR, "repository")
|
||||
}
|
||||
|
||||
/**
|
||||
* The object Kobalt refers to for settings.
|
||||
*/
|
||||
@Singleton
|
||||
class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
|
||||
/**
|
||||
* Location of the local repo.
|
||||
*/
|
||||
var localRepo = xmlFile.localRepo
|
||||
|
||||
companion object {
|
||||
val SETTINGS_FILE_PATH = homeDir(KFiles.KOBALT_DOT_DIR, "settings.xml")
|
||||
|
||||
fun readSettingsXml() : KobaltSettings {
|
||||
val file = File(KobaltSettings.SETTINGS_FILE_PATH)
|
||||
if (file.exists()) {
|
||||
FileInputStream(file).use {
|
||||
val jaxbContext = JAXBContext.newInstance(KobaltSettingsXml::class.java)
|
||||
val xmlFile: KobaltSettingsXml = jaxbContext.createUnmarshaller().unmarshal(it)
|
||||
as KobaltSettingsXml
|
||||
return KobaltSettings(xmlFile)
|
||||
}
|
||||
} else {
|
||||
log(2, "Couldn't find ${KobaltSettings.SETTINGS_FILE_PATH}, using default settings")
|
||||
return KobaltSettings(KobaltSettingsXml())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,15 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.Versions
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
open public class LocalRepo(open val localRepo: String = KFiles.localRepo) {
|
||||
open public class LocalRepo @Inject constructor(val kobaltSettings: KobaltSettings) {
|
||||
init {
|
||||
val l = File(localRepo)
|
||||
if (! l.exists()) {
|
||||
|
@ -15,6 +17,9 @@ open public class LocalRepo(open val localRepo: String = KFiles.localRepo) {
|
|||
}
|
||||
}
|
||||
|
||||
val localRepo: String
|
||||
get() = kobaltSettings.localRepo
|
||||
|
||||
fun existsPom(d: LocalDep, v: String) : Boolean {
|
||||
return File(d.toAbsolutePomFile(v)).exists()
|
||||
}
|
||||
|
|
|
@ -49,9 +49,6 @@ class KFiles {
|
|||
const val KOBALT_DIR : String = "kobalt"
|
||||
const val KOBALT_BUILD_DIR = "kobaltBuild"
|
||||
|
||||
// Directories under ~/.kobalt
|
||||
val localRepo = homeDir(KOBALT_DOT_DIR, "repository")
|
||||
|
||||
/** Where all the .zip files are extracted */
|
||||
val distributionsDir = homeDir(KOBALT_DOT_DIR, "wrapper", "dist")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue