1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-05-02 18:58:12 -07:00
kobalt/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/BuildScript.kt
Dmitry Zhuravlev e9416db9e7 * proxy handling improved for repositories defined in transitive dependencies.
proxy config now looks like:
<proxies>
       <proxy>
           <host>mycompany.com</host>
           <port>3128</port>
            <type>http</type>
            <nonProxyHosts>localhost</nonProxyHosts>
       </proxy>
       <proxy>
           <host>mycompany.com</host>
           <port>3128</port>
            <type>https</type>
           <nonProxyHosts>localhost</nonProxyHosts>
       </proxy>
   </proxies>
2016-06-14 15:56:32 +03:00

69 lines
2 KiB
Kotlin

package com.beust.kobalt
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.dependency.FileDependency
import org.eclipse.aether.repository.Proxy
import java.io.File
import java.net.InetSocketAddress
@Directive
fun homeDir(vararg dirs: String) : String = SystemProperties.homeDir +
File.separator + dirs.toMutableList().joinToString(File.separator)
@Directive
fun localMavenRepo() = homeDir(".m2" + File.separator + "repository/")
@Directive
fun file(file: String) : String = FileDependency.PREFIX_FILE + file
@Directive
fun plugins(vararg dependency : IClasspathDependency) {
dependency.forEach { Plugins.addDynamicPlugin(it) }
}
@Directive
fun plugins(vararg dependencies : String) {
val factory = Kobalt.INJECTOR.getInstance(DependencyManager::class.java)
dependencies.forEach {
Plugins.addDynamicPlugin(factory.create(it))
}
}
data class ProxyConfig(val host: String = "", val port: Int = 0, val type: String = "", val nonProxyHosts: String = "") {
fun toProxy() = java.net.Proxy(java.net.Proxy.Type.HTTP, InetSocketAddress(host, port))
fun toAetherProxy() = Proxy(type, host, port) // TODO make support for proxy auth
}
data class HostConfig(var url: String = "", var username: String? = null, var password: String? = null) {
fun hasAuth() : Boolean {
return (! username.isNullOrBlank()) && (! password.isNullOrBlank())
}
override fun toString() : String {
return url + if (username != null) {
"username: $username, password: ***"
} else {
""
}
}
}
@Directive
fun repos(vararg repos : String) {
repos.forEach { Kobalt.addRepo(HostConfig(it)) }
}
@Directive
fun authRepos(vararg repos : HostConfig) {
repos.forEach { Kobalt.addRepo(it) }
}
@Directive
fun authRepo(init: HostConfig.() -> Unit) = HostConfig().apply { init() }
@Directive
fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g)