mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Merge branch 'master' of https://github.com/cbeust/kobalt
This commit is contained in:
commit
6d46ba2d0e
13 changed files with 223 additions and 56 deletions
|
@ -74,8 +74,18 @@ data class ProxyConfig(val host: String = "", val port: Int = 0, val type: Strin
|
|||
fun toAetherProxy() = Proxy(type, host, port) // TODO make support for proxy auth
|
||||
}
|
||||
|
||||
data class HostConfig(var url: String = "", var name: String = url, var username: String? = null,
|
||||
var password: String? = null) {
|
||||
data class HostConfig(var url: String = "", var name: String = HostConfig.createRepoName(url),
|
||||
var username: String? = null, var password: String? = null) {
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* For repos specified in the build file (repos()) that don't have an associated unique name,
|
||||
* create such a name from the URL. This is a requirement from Maven Resolver, and failing to do
|
||||
* this leads to very weird resolution errors.
|
||||
*/
|
||||
private fun createRepoName(url: String) = url.replace("/", "_").replace("\\", "_").replace(":", "_")
|
||||
}
|
||||
|
||||
fun hasAuth() : Boolean {
|
||||
return (! username.isNullOrBlank()) && (! password.isNullOrBlank())
|
||||
}
|
||||
|
@ -115,7 +125,7 @@ fun authRepos(vararg repos : HostConfig) {
|
|||
}
|
||||
|
||||
@Directive
|
||||
fun authRepo(init: HostConfig.() -> Unit) = HostConfig().apply { init() }
|
||||
fun authRepo(init: HostConfig.() -> Unit) = HostConfig(name = "").apply { init() }
|
||||
|
||||
@Directive
|
||||
fun glob(g: String) : IFileSpec.GlobSpec = IFileSpec.GlobSpec(g)
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.beust.kobalt.HostConfig
|
|||
import com.beust.kobalt.Plugins
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||
import com.google.inject.Guice
|
||||
import com.google.inject.Injector
|
||||
import com.google.inject.Module
|
||||
|
@ -55,6 +56,9 @@ class Kobalt {
|
|||
// Repos from the build file
|
||||
result.addAll(reposFromBuildFiles)
|
||||
|
||||
result.forEach {
|
||||
KobaltMavenResolver.initAuthentication(it)
|
||||
}
|
||||
return result.toHashSet()
|
||||
}
|
||||
|
||||
|
|
|
@ -3,28 +3,33 @@ package com.beust.kobalt.archive
|
|||
import com.beust.kobalt.Glob
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.util.jar.Manifest
|
||||
import org.apache.commons.compress.archivers.zip.ZipFile as ApacheZipFile
|
||||
|
||||
/**
|
||||
* Abstraction of a zip/jar/war archive that automatically manages the addition of expanded jar files.
|
||||
* Uses ZipArchiveOutputStream for fast inclusion of expanded jar files.
|
||||
*/
|
||||
class MetaArchive(outputFile: File, val manifest: java.util.jar.Manifest?) : Closeable {
|
||||
class MetaArchive(outputFile: File, val manifest: Manifest?) : Closeable {
|
||||
private val zos = ZipArchiveOutputStream(outputFile).apply {
|
||||
encoding = "UTF-8"
|
||||
}
|
||||
|
||||
fun addFile(file: File, path: String) {
|
||||
fun addFile(f: File, entryFile: File, path: String?) {
|
||||
val file = f.normalize()
|
||||
FileInputStream(file).use { inputStream ->
|
||||
val entry = zos.createArchiveEntry(file, path)
|
||||
maybeAddEntry(entry) {
|
||||
addEntry(entry, inputStream)
|
||||
val actualPath = if (path != null) path + entryFile.path else entryFile.path
|
||||
ZipArchiveEntry(actualPath).let { entry ->
|
||||
maybeAddEntry(entry) {
|
||||
addEntry(entry, inputStream)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.HostConfig
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.maven.aether.KobaltMavenResolver
|
||||
import com.beust.kobalt.maven.dependency.FileDependency
|
||||
import com.beust.kobalt.misc.LocalProperties
|
||||
import java.io.*
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
|
@ -21,27 +20,7 @@ class Kurl(val hostInfo: HostConfig) {
|
|||
}
|
||||
|
||||
init {
|
||||
// See if the URL needs to be authenticated. Look in local.properties for keys
|
||||
// of the format authUrl.<host>.user=xxx and authUrl.<host>.password=xxx
|
||||
val properties = LocalProperties().localProperties
|
||||
val host = java.net.URL(hostInfo.url).host
|
||||
properties.entries.forEach {
|
||||
val key = it.key.toString()
|
||||
if (key == "$KEY.$host.$VALUE_USER") {
|
||||
hostInfo.username = properties.getProperty(key)
|
||||
} else if (key == "$KEY.$host.$VALUE_PASSWORD") {
|
||||
hostInfo.password = properties.getProperty(key)
|
||||
}
|
||||
}
|
||||
fun error(s1: String, s2: String) {
|
||||
throw KobaltException("Found \"$s1\" but not \"$s2\" in local.properties for $KEY.$host",
|
||||
docUrl = "http://beust.com/kobalt/documentation/index.html#maven-repos-authenticated")
|
||||
}
|
||||
if (! hostInfo.username.isNullOrBlank() && hostInfo.password.isNullOrBlank()) {
|
||||
error("username", "password")
|
||||
} else if(hostInfo.username.isNullOrBlank() && ! hostInfo.password.isNullOrBlank()) {
|
||||
error("password", "username")
|
||||
}
|
||||
KobaltMavenResolver.initAuthentication(hostInfo)
|
||||
}
|
||||
|
||||
override fun toString() = hostInfo.toString()
|
||||
|
|
|
@ -2,11 +2,14 @@ package com.beust.kobalt.maven.aether
|
|||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.HostConfig
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.internal.KobaltSettings
|
||||
import com.beust.kobalt.internal.getProxy
|
||||
import com.beust.kobalt.maven.Kurl
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.MavenId
|
||||
import com.beust.kobalt.misc.LocalProperties
|
||||
import com.google.common.eventbus.EventBus
|
||||
import com.google.inject.Inject
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
|
@ -21,6 +24,7 @@ import org.eclipse.aether.resolution.DependencyRequest
|
|||
import org.eclipse.aether.resolution.DependencyResult
|
||||
import org.eclipse.aether.resolution.VersionRangeRequest
|
||||
import org.eclipse.aether.resolution.VersionRangeResult
|
||||
import org.eclipse.aether.util.repository.AuthenticationBuilder
|
||||
import java.util.*
|
||||
|
||||
class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
||||
|
@ -32,6 +36,31 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
MavenId.toId(it.groupId, it.artifactId, it.extension, it.classifier, it.version)
|
||||
}
|
||||
fun isRangeVersion(id: String) = id.contains(",")
|
||||
|
||||
fun initAuthentication(hostInfo: HostConfig) {
|
||||
// See if the URL needs to be authenticated. Look in local.properties for keys
|
||||
// of the format authUrl.<host>.user=xxx and authUrl.<host>.password=xxx
|
||||
val properties = LocalProperties().localProperties
|
||||
val host = java.net.URL(hostInfo.url).host
|
||||
properties.entries.forEach {
|
||||
val key = it.key.toString()
|
||||
if (key == "${Kurl.KEY}.$host.${Kurl.VALUE_USER}") {
|
||||
hostInfo.username = properties.getProperty(key)
|
||||
} else if (key == "${Kurl.KEY}.$host.${Kurl.VALUE_PASSWORD}") {
|
||||
hostInfo.password = properties.getProperty(key)
|
||||
}
|
||||
}
|
||||
fun error(s1: String, s2: String) {
|
||||
throw KobaltException("Found \"$s1\" but not \"$s2\" in local.properties for ${Kurl.KEY}.$host",
|
||||
docUrl = "http://beust.com/kobalt/documentation/index.html#maven-repos-authenticated")
|
||||
}
|
||||
if (! hostInfo.username.isNullOrBlank() && hostInfo.password.isNullOrBlank()) {
|
||||
error("username", "password")
|
||||
} else if(hostInfo.username.isNullOrBlank() && ! hostInfo.password.isNullOrBlank()) {
|
||||
error("password", "username")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun resolveToArtifact(id: String, scope: Scope? = null,
|
||||
|
@ -110,8 +139,17 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings,
|
|||
private val system = Booter.newRepositorySystem()
|
||||
private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus)
|
||||
|
||||
private fun createRepo(hostConfig: HostConfig) =
|
||||
RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url).build()
|
||||
private fun createRepo(hostConfig: HostConfig) : RemoteRepository {
|
||||
val builder = RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url)
|
||||
if (hostConfig.hasAuth()) {
|
||||
val auth = AuthenticationBuilder()
|
||||
.addUsername(hostConfig.username)
|
||||
.addPassword(hostConfig.password)
|
||||
.build()
|
||||
builder.setAuthentication(auth)
|
||||
}
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
private val kobaltRepositories: List<RemoteRepository>
|
||||
get() = Kobalt.repos.map {
|
||||
|
|
|
@ -55,7 +55,10 @@ class JarUtils {
|
|||
kobaltLog(2, " Writing contents of jar file $foundFile")
|
||||
metaArchive.addArchive(foundFile)
|
||||
} else {
|
||||
metaArchive.addFile(File(directory, fromFile.path), foundFile.path)
|
||||
val fp = foundFile.path
|
||||
val toPath = File(file.to).normalize().path
|
||||
val finalPath = if (toPath.isEmpty()) null else (toPath + "/")
|
||||
metaArchive.addFile(File(directory, fromFile.path), foundFile, finalPath)
|
||||
}
|
||||
} catch(ex: Exception) {
|
||||
onError(ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue