mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
* fix proxy resolution for artifact resolving: proxy resolution should not be dependant on KobaltContext
This commit is contained in:
parent
21e22161db
commit
9c112bd7a1
6 changed files with 40 additions and 37 deletions
|
@ -3,14 +3,11 @@ package com.beust.kobalt.api
|
|||
import com.beust.kobalt.Constants
|
||||
import com.beust.kobalt.HostConfig
|
||||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.ProxyConfig
|
||||
import com.google.inject.Injector
|
||||
import org.eclipse.aether.repository.Proxy
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.google.inject.Guice
|
||||
import com.google.inject.Injector
|
||||
import com.google.inject.Module
|
||||
import java.io.InputStream
|
||||
import java.net.InetSocketAddress
|
||||
import java.time.Duration
|
||||
import java.util.*
|
||||
|
||||
|
@ -32,18 +29,6 @@ class Kobalt {
|
|||
|
||||
var context: KobaltContext? = null
|
||||
|
||||
val proxyConfig = with(Kobalt.context?.settings?.proxy) {
|
||||
if (this != null) {
|
||||
ProxyConfig(host, port.toIntOr(0), type)
|
||||
} else null
|
||||
}
|
||||
|
||||
fun String.toIntOr(defaultValue: Int) = try { //TODO can be extracted to some global Utils
|
||||
toInt()
|
||||
} catch(e: NumberFormatException) {
|
||||
defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the repos calculated from the following places:
|
||||
* - Either repos specified in settings.xml or from Constants.DEFAULT_REPOS
|
||||
|
@ -129,10 +114,3 @@ class Kobalt {
|
|||
fun findPlugin(name: String) = Plugins.findPlugin(name)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun ProxyConfig?.toProxy() = if (this != null) {
|
||||
java.net.Proxy(java.net.Proxy.Type.HTTP, InetSocketAddress(host, port))
|
||||
} else null
|
||||
|
||||
fun ProxyConfig?.toAetherProxy() = if (this != null) Proxy(type, host, port) else null //TODO make support for proxy auth
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.ProxyConfig
|
||||
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 org.eclipse.aether.repository.Proxy
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.net.InetSocketAddress
|
||||
import javax.xml.bind.JAXBContext
|
||||
import javax.xml.bind.annotation.XmlElement
|
||||
import javax.xml.bind.annotation.XmlRootElement
|
||||
|
@ -62,6 +65,21 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
|
|||
|
||||
val proxy = xmlFile.proxy
|
||||
|
||||
|
||||
val proxyConfig = with(proxy) {
|
||||
if (this != null) {
|
||||
com.beust.kobalt.ProxyConfig(host, port.toIntOr(0), type)
|
||||
} else null
|
||||
}
|
||||
|
||||
fun String.toIntOr(defaultValue: Int) = try { //TODO can be extracted to some global Utils
|
||||
toInt()
|
||||
} catch(e: NumberFormatException) {
|
||||
defaultValue
|
||||
}
|
||||
|
||||
|
||||
|
||||
var kobaltCompilerVersion = xmlFile.kobaltCompilerVersion
|
||||
var kobaltCompilerRepo = xmlFile.kobaltCompilerRepo
|
||||
|
||||
|
@ -86,3 +104,9 @@ class KobaltSettings @Inject constructor(val xmlFile: KobaltSettingsXml) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
fun ProxyConfig?.toProxy() = if (this != null) {
|
||||
java.net.Proxy(java.net.Proxy.Type.HTTP, InetSocketAddress(host, port))
|
||||
} else null
|
||||
|
||||
fun ProxyConfig?.toAetherProxy() = if (this != null) Proxy(type, host, port) else null //TODO make support for proxy auth
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.toProxy
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.toProxy
|
||||
import com.beust.kobalt.misc.CountingFileRequestBody
|
||||
import com.beust.kobalt.misc.log
|
||||
import com.google.inject.Inject
|
||||
import okhttp3.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Http {
|
||||
class Http @Inject constructor(val settings:KobaltSettings) {
|
||||
companion object {
|
||||
// HTTP statuses
|
||||
val CREATED = 201
|
||||
|
@ -21,7 +22,7 @@ class Http {
|
|||
}
|
||||
|
||||
fun get(user: String?, password: String?, url: String) : Response {
|
||||
val client = OkHttpClient.Builder().proxy(Kobalt.proxyConfig.toProxy()).build()
|
||||
val client = OkHttpClient.Builder().proxy(settings.proxyConfig.toProxy()).build()
|
||||
val request = Request.Builder().url(url)
|
||||
if (user != null) {
|
||||
request.header("Authorization", Credentials.basic(user, password))
|
||||
|
@ -75,7 +76,7 @@ class Http {
|
|||
.build()
|
||||
|
||||
log(2, "Uploading $file to $url")
|
||||
val response = OkHttpClient.Builder().proxy(Kobalt.proxyConfig.toProxy()).build().newCall(request).execute()
|
||||
val response = OkHttpClient.Builder().proxy(settings.proxyConfig.toProxy()).build().newCall(request).execute()
|
||||
if (! response.isSuccessful) {
|
||||
error(response)
|
||||
} else {
|
||||
|
|
|
@ -3,10 +3,10 @@ package com.beust.kobalt.maven.aether
|
|||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.toAetherProxy
|
||||
import com.beust.kobalt.homeDir
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.KobaltSettingsXml
|
||||
import com.beust.kobalt.internal.toAetherProxy
|
||||
import com.beust.kobalt.maven.CompletedFuture
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
|
@ -72,7 +72,7 @@ class ExcludeOptionalDependencyFilter: DependencyFilter {
|
|||
}
|
||||
|
||||
@Singleton
|
||||
class Aether(val localRepo: File) {
|
||||
class Aether(val localRepo: File, val settings: KobaltSettings) {
|
||||
private val system = Booter.newRepositorySystem()
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo)
|
||||
private val classpathFilter = AndDependencyFilter(
|
||||
|
@ -81,7 +81,7 @@ class Aether(val localRepo: File) {
|
|||
private val kobaltRepositories : List<RemoteRepository>
|
||||
get() = Kobalt.repos.map {
|
||||
RemoteRepository.Builder("maven", "default", it.url)
|
||||
.setProxy(Kobalt.proxyConfig.toAetherProxy())
|
||||
.setProxy(settings.proxyConfig.toAetherProxy())
|
||||
// .setSnapshotPolicy(RepositoryPolicy(false, null, null))
|
||||
.build()
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ class AetherDependency(val artifact: Artifact): IClasspathDependency, Comparable
|
|||
fun main(argv: Array<String>) {
|
||||
KobaltLogger.LOG_LEVEL = 1
|
||||
val id = "org.testng:testng:6.9.11"
|
||||
val aether = KobaltAether(KobaltSettings(KobaltSettingsXml()), Aether(File(homeDir(".aether"))))
|
||||
val aether = KobaltAether(KobaltSettings(KobaltSettingsXml()), Aether(File(homeDir(".aether")),KobaltSettings(KobaltSettingsXml())))
|
||||
val r = aether.resolve(id)
|
||||
val r2 = aether.resolve(id)
|
||||
val d = org.eclipse.aether.artifact.DefaultArtifact("org.testng:testng:6.9")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.toProxy
|
||||
import com.beust.kobalt.internal.DocUrl
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.toProxy
|
||||
import com.beust.kobalt.maven.Http
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
@ -20,7 +20,7 @@ import java.util.concurrent.Callable
|
|||
import java.util.concurrent.Future
|
||||
|
||||
class GithubApi2 @Inject constructor(
|
||||
val executors: KobaltExecutors, val localProperties: LocalProperties, val http: Http) {
|
||||
val executors: KobaltExecutors, val localProperties: LocalProperties, val http: Http, val settings:KobaltSettings) {
|
||||
|
||||
companion object {
|
||||
const val PROPERTY_ACCESS_TOKEN = "github.accessToken"
|
||||
|
@ -60,7 +60,7 @@ class GithubApi2 @Inject constructor(
|
|||
// Read only Api
|
||||
//
|
||||
private val service = Retrofit.Builder()
|
||||
.client(OkHttpClient.Builder().proxy(Kobalt.proxyConfig.toProxy()).build())
|
||||
.client(OkHttpClient.Builder().proxy(settings.proxyConfig.toProxy()).build())
|
||||
.baseUrl("https://api.github.com")
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build()
|
||||
|
|
|
@ -53,7 +53,7 @@ public open class MainModule(val args: Args, val settings: KobaltSettings) : Abs
|
|||
bind(KobaltSettings::class.java).toProvider(Provider<KobaltSettings> {
|
||||
settings
|
||||
}).`in`(Singleton::class.java)
|
||||
bind(Aether::class.java).toInstance(Aether(settings.localRepo))
|
||||
bind(Aether::class.java).toInstance(Aether(settings.localRepo,settings))
|
||||
|
||||
// bindListener(Matchers.any(), object: TypeListener {
|
||||
// override fun <I> hear(typeLiteral: TypeLiteral<I>?, typeEncounter: TypeEncounter<I>?) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue