mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
Merge branch 'master' of github.com:cbeust/kobalt
This commit is contained in:
commit
49e69d0964
22 changed files with 445 additions and 168 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())
|
||||
}
|
||||
|
@ -106,6 +116,7 @@ fun buildFileClasspath(vararg deps: String) {
|
|||
}
|
||||
|
||||
fun newBuildFileClasspath(vararg deps: String) {
|
||||
//FIXME newBuildFileClasspath called twice
|
||||
deps.forEach { Kobalt.addBuildFileClasspath(it) }
|
||||
}
|
||||
|
||||
|
@ -115,7 +126,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)
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.beust.kobalt
|
|||
|
||||
class SystemProperties {
|
||||
companion object {
|
||||
val javaBase = System.getProperty("java.home") ?:
|
||||
(System.getenv("JAVA_HOME") ?: throw IllegalArgumentException("JAVA_HOME not defined"))
|
||||
val javaBase =
|
||||
System.getenv("JAVA_HOME")
|
||||
?: System.getProperty("java.home")
|
||||
?: throw IllegalArgumentException("JAVA_HOME not defined")
|
||||
val javaVersion = System.getProperty("java.version")
|
||||
val homeDir = System.getProperty("user.home")
|
||||
val tmpDir = System.getProperty("java.io.tmpdir")
|
||||
|
|
|
@ -12,4 +12,5 @@ data class CompilerActionInfo(val directory: String?,
|
|||
val outputDir: File,
|
||||
val compilerArgs: List<String>,
|
||||
val friendPaths: List<String>,
|
||||
val forceRecompile: Boolean)
|
||||
val forceRecompile: Boolean,
|
||||
val compilerSeparateProcess: Boolean = false)
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -131,6 +135,7 @@ class Kobalt {
|
|||
|
||||
fun cleanUp() {
|
||||
buildSourceDirs.clear()
|
||||
buildFileClasspath.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.*
|
|||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.google.common.annotations.VisibleForTesting
|
||||
import com.google.inject.Inject
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
@ -19,6 +20,9 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
|||
open var shortMessage: String? = null
|
||||
open var longMessage: String? = null
|
||||
|
||||
@Inject
|
||||
private lateinit var jvm: Jvm
|
||||
|
||||
abstract fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||
testConfig: TestConfig) : List<String>
|
||||
|
||||
|
@ -26,7 +30,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
|||
|
||||
open val extraClasspath: List<String> = emptyList()
|
||||
|
||||
open fun filterTestClasses(classes: List<String>) : List<String> = classes
|
||||
open fun filterTestClasses(project: Project, context: KobaltContext, classes: List<String>) : List<String> = classes
|
||||
|
||||
override fun run(project: Project, context: KobaltContext, configName: String,
|
||||
classpath: List<IClasspathDependency>) : TaskResult {
|
||||
|
@ -65,7 +69,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
|||
// }
|
||||
|
||||
context.logger.log(project.name, 2, "Found ${result.size} test classes")
|
||||
return filterTestClasses(result.map { it.second })
|
||||
return filterTestClasses(project, context, result.map { it.second })
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +120,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
|||
val args = args(project, context, classpath, testConfig)
|
||||
if (args.size > 0) {
|
||||
|
||||
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable
|
||||
val java = jvm.javaExecutable
|
||||
val jvmArgs = calculateAllJvmArgs(project, context, testConfig, classpath,
|
||||
Kobalt.INJECTOR.getInstance (PluginInfo::class.java))
|
||||
val allArgs = arrayListOf<String>().apply {
|
||||
|
|
|
@ -4,6 +4,10 @@ import com.beust.kobalt.TestConfig
|
|||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.google.inject.Inject
|
||||
import java.lang.reflect.Modifier
|
||||
import java.net.URLClassLoader
|
||||
|
||||
open class JUnitRunner() : GenericTestRunner() {
|
||||
|
||||
|
@ -14,5 +18,15 @@ open class JUnitRunner() : GenericTestRunner() {
|
|||
|
||||
override fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||
testConfig: TestConfig) = findTestClasses(project, context, testConfig)
|
||||
|
||||
@Inject
|
||||
lateinit var dependencyManager: DependencyManager
|
||||
|
||||
override fun filterTestClasses(project: Project, context: KobaltContext, classes: List<String>) : List<String> {
|
||||
val deps = dependencyManager.testDependencies(project, context)
|
||||
val cl = URLClassLoader(deps.map { it.jarFile.get().toURI().toURL() }.toTypedArray())
|
||||
return classes.filter { !Modifier.isAbstract(cl.loadClass(it).modifiers) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
|
||||
/**
|
||||
* KotlinTestRunner triggers if it finds a dependency on io.kotlintest but other than that, it just
|
||||
* uses the regular JUnitRunner.
|
||||
|
@ -12,6 +15,7 @@ class KotlinTestRunner : JUnitRunner() {
|
|||
* KotlinTestRunner runs tests in the init{} initializer, so ignore all the extra
|
||||
* classes generated by the Kotlin compiler.
|
||||
*/
|
||||
override fun filterTestClasses(classes: List<String>) = classes.filter { ! it.contains("$") }
|
||||
override fun filterTestClasses(projet: Project, context: KobaltContext, classes: List<String>)
|
||||
= classes.filter { !it.contains("$") }
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -79,10 +79,12 @@ open class NewRunCommand(val info: RunCommandInfo) {
|
|||
|
||||
// Run the command and collect the return code and streams
|
||||
val returnCode = process.waitFor(30, TimeUnit.SECONDS)
|
||||
val input = if (process.inputStream.available() > 0) fromStream(process.inputStream)
|
||||
else listOf()
|
||||
val error = if (process.errorStream.available() > 0) fromStream(process.errorStream)
|
||||
else listOf()
|
||||
val input =
|
||||
if (process.inputStream.available() > 0) fromStream(process.inputStream)
|
||||
else listOf()
|
||||
val error =
|
||||
if (process.errorStream.available() > 0) fromStream(process.errorStream)
|
||||
else listOf()
|
||||
|
||||
// Check to see if the command succeeded
|
||||
val isSuccess =
|
||||
|
@ -105,10 +107,10 @@ open class NewRunCommand(val info: RunCommandInfo) {
|
|||
open protected fun isSuccess(isSuccess: Boolean, input: List<String>, error: List<String>) : Boolean {
|
||||
var hasErrors = ! isSuccess
|
||||
if (info.useErrorStreamAsErrorIndicator && ! hasErrors) {
|
||||
hasErrors = hasErrors || error.size > 0
|
||||
hasErrors = hasErrors || error.isNotEmpty()
|
||||
}
|
||||
if (info.useInputStreamAsErrorIndicator && ! hasErrors) {
|
||||
hasErrors = hasErrors || input.size > 0
|
||||
hasErrors = hasErrors || input.isNotEmpty()
|
||||
}
|
||||
|
||||
return ! hasErrors
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue