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

Fix #141: Make repos overridable.

This commit is contained in:
Cedric Beust 2016-03-04 16:43:06 -08:00
parent 009a097c1f
commit 15abe21565
2 changed files with 23 additions and 5 deletions

View file

@ -18,15 +18,22 @@ public class Kobalt {
var context: KobaltContext? = null var context: KobaltContext? = null
/** /**
* @return the repos from the build files and from the contributors. * @return the repos calculated from the following places:
* - Either repos specified in settings.xml or from Constants.DEFAULT_REPOS
* - Repos from the build file
*/ */
val repos : Set<HostConfig> val repos : Set<HostConfig>
get() { get() {
val result = HashSet(reposFromBuildFiles) val settingsRepos = Kobalt.context?.settings?.defaultRepos ?: emptyList()
val result = ArrayList(
(if (settingsRepos.isEmpty()) Constants.DEFAULT_REPOS
else settingsRepos)
.map { HostConfig(it) })
Kobalt.context?.pluginInfo?.repoContributors?.forEach { Kobalt.context?.pluginInfo?.repoContributors?.forEach {
result.addAll(it.reposFor(null)) result.addAll(it.reposFor(null))
} }
return result return result.toHashSet()
} }
val reposFromBuildFiles = HashSet<HostConfig>(Constants.DEFAULT_REPOS.map { HostConfig(it) }) val reposFromBuildFiles = HashSet<HostConfig>(Constants.DEFAULT_REPOS.map { HostConfig(it) })

View file

@ -18,6 +18,14 @@ import javax.xml.bind.annotation.XmlRootElement
class KobaltSettingsXml { class KobaltSettingsXml {
@XmlElement @JvmField @XmlElement @JvmField
var localRepo: String = homeDir(KFiles.KOBALT_DOT_DIR, "repository") var localRepo: String = homeDir(KFiles.KOBALT_DOT_DIR, "repository")
@XmlElement(name = "default-repos") @JvmField
var defaultRepos: DefaultReposXml? = null
}
class DefaultReposXml {
@XmlElement @JvmField
var repo: List<String> = arrayListOf()
} }
/** /**
@ -28,7 +36,9 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
/** /**
* Location of the local repo. * Location of the local repo.
*/ */
var localRepo = xmlFile.localRepo var localRepo = xmlFile.localRepo // var for testing
val defaultRepos = xmlFile.defaultRepos?.repo
companion object { companion object {
val SETTINGS_FILE_PATH = homeDir(KFiles.KOBALT_DIR, "settings.xml") val SETTINGS_FILE_PATH = homeDir(KFiles.KOBALT_DIR, "settings.xml")
@ -40,7 +50,8 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
val jaxbContext = JAXBContext.newInstance(KobaltSettingsXml::class.java) val jaxbContext = JAXBContext.newInstance(KobaltSettingsXml::class.java)
val xmlFile: KobaltSettingsXml = jaxbContext.createUnmarshaller().unmarshal(it) val xmlFile: KobaltSettingsXml = jaxbContext.createUnmarshaller().unmarshal(it)
as KobaltSettingsXml as KobaltSettingsXml
return KobaltSettings(xmlFile) val result = KobaltSettings(xmlFile)
return result
} }
} else { } else {
log(2, "Couldn't find ${KobaltSettings.SETTINGS_FILE_PATH}, using default settings") log(2, "Couldn't find ${KobaltSettings.SETTINGS_FILE_PATH}, using default settings")