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")
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.beust.kobalt.app.ProjectGenerator
|
|||
import com.beust.kobalt.app.UpdateKobalt
|
||||
import com.beust.kobalt.app.remote.KobaltClient
|
||||
import com.beust.kobalt.app.remote.KobaltServer
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.TaskManager
|
||||
import com.beust.kobalt.internal.build.BuildFile
|
||||
|
@ -43,7 +44,7 @@ private fun parseArgs(argv: Array<String>): Main.RunInfo {
|
|||
|
||||
public fun mainNoExit(argv: Array<String>): Int {
|
||||
val (jc, args) = parseArgs(argv)
|
||||
Kobalt.INJECTOR = Guice.createInjector(MainModule(args))
|
||||
Kobalt.INJECTOR = Guice.createInjector(MainModule(args, KobaltSettings.readSettingsXml()))
|
||||
return Kobalt.INJECTOR.getInstance(Main::class.java).run(jc, args, argv)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.beust.kobalt.api.Kobalt
|
|||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.PluginProperties
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import com.beust.kobalt.internal.build.VersionFile
|
||||
|
@ -30,7 +31,7 @@ import javax.inject.Inject
|
|||
public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFiles: List<BuildFile>,
|
||||
@Assisted val pluginInfo: PluginInfo, val files: KFiles, val plugins: Plugins,
|
||||
val dependencyManager: DependencyManager, val pluginProperties: PluginProperties,
|
||||
val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil) {
|
||||
val executors: KobaltExecutors, val buildScriptUtil: BuildScriptUtil, val settings: KobaltSettings) {
|
||||
|
||||
interface IFactory {
|
||||
fun create(@Assisted("buildFiles") buildFiles: List<BuildFile>, pluginInfo: PluginInfo) : BuildFileCompiler
|
||||
|
@ -47,6 +48,7 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b
|
|||
context.pluginProperties = pluginProperties
|
||||
context.dependencyManager = dependencyManager
|
||||
context.executors = executors
|
||||
context.settings = settings
|
||||
Kobalt.context = context
|
||||
|
||||
//
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.beust.kobalt.app
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.maven.ArtifactFetcher
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
|
@ -16,7 +17,7 @@ import com.google.inject.TypeLiteral
|
|||
import com.google.inject.assistedinject.FactoryModuleBuilder
|
||||
import java.util.concurrent.ExecutorService
|
||||
|
||||
public open class MainModule(val args: Args) : AbstractModule() {
|
||||
public open class MainModule(val args: Args, val settings: KobaltSettings) : AbstractModule() {
|
||||
val executors = KobaltExecutors()
|
||||
|
||||
open fun configureTest() {
|
||||
|
@ -48,7 +49,9 @@ public open class MainModule(val args: Args) : AbstractModule() {
|
|||
bind(PluginInfo::class.java).toProvider(Provider<PluginInfo> {
|
||||
PluginInfo.readKobaltPluginXml()
|
||||
}).`in`(Singleton::class.java)
|
||||
|
||||
bind(KobaltSettings::class.java).toProvider(Provider<KobaltSettings> {
|
||||
settings
|
||||
}).`in`(Singleton::class.java)
|
||||
|
||||
// bindListener(Matchers.any(), object: TypeListener {
|
||||
// override fun <I> hear(typeLiteral: TypeLiteral<I>?, typeEncounter: TypeEncounter<I>?) {
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.app.MainModule
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.KobaltSettingsXml
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.google.inject.Scopes
|
||||
import java.io.File
|
||||
|
||||
class TestLocalRepo: LocalRepo(localRepo = SystemProperties.homeDir + File.separatorChar + ".kobalt-test")
|
||||
val TEST_KOBALT_SETTINGS = KobaltSettings(KobaltSettingsXml()).apply {
|
||||
localRepo = SystemProperties.homeDir + File.separatorChar + "" +
|
||||
".kobalt-test"
|
||||
}
|
||||
|
||||
public class TestModule : MainModule(Args()) {
|
||||
class TestLocalRepo: LocalRepo(TEST_KOBALT_SETTINGS)
|
||||
|
||||
public class TestModule : MainModule(Args(), TEST_KOBALT_SETTINGS) {
|
||||
override fun configureTest() {
|
||||
bind(LocalRepo::class.java).to(TestLocalRepo::class.java).`in`(Scopes.SINGLETON)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue