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

Revamp the scopes and scope filters.

This commit is contained in:
Cedric Beust 2016-07-26 02:24:35 -08:00
parent f9c7e488d5
commit d18c8009c8
12 changed files with 183 additions and 86 deletions

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.internal.ActorUtils
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.maven.aether.Scope
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
import com.beust.kobalt.misc.RunCommand
@ -105,7 +106,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
// on the classpath
val allDependencies = project.compileDependencies + project.compileRuntimeDependencies
val allTheDependencies =
dependencyManager.calculateDependencies(project, context, allDependencies = allDependencies)
dependencyManager.calculateDependencies(project, context,
listOf(Scope.COMPILE, Scope.RUNTIME),
passedDependencies = allDependencies)
.map { it.jarFile.get().path }
allDeps.addAll(allTheDependencies)
}

View file

@ -121,7 +121,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val analyzer = Analyzer().apply {
jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String)
val dependencies = project.compileDependencies + project.compileRuntimeDependencies
dependencyManager.calculateDependencies(project, context, allDependencies = dependencies).forEach {
dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach {
addClasspath(it.jarFile.get())
}
setProperty(Analyzer.BUNDLE_VERSION, project.version)

View file

@ -40,7 +40,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager)
// Copy them all in kobaltBuild/war/WEB-INF/libs and create one IncludedFile out of that directory
//
val allDependencies = dependencyManager.calculateDependencies(project, context,
allDependencies = project.compileDependencies)
passedDependencies = project.compileDependencies)
val outDir = project.buildDirectory + "/war"
val fullDir = outDir + "/" + LIB

View file

@ -1,14 +1,38 @@
package com.beust.kobalt
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.app.BuildFileCompiler
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.internal.KobaltPluginXml
import com.beust.kobalt.internal.PluginInfo
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.aether.KobaltAether
import org.testng.annotations.BeforeClass
import java.io.File
import java.nio.file.Paths
open class BaseTest(open val aether: KobaltAether) {
val context = KobaltContext(Args())
@BeforeClass
fun bc() {
Kobalt.init(TestModule())
context.aether = aether
}
fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory)
: BuildFileCompiler.FindProjectResult {
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {
deleteOnExit()
writeText(buildFileText)
}
val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt")
args.buildFile = tmpBuildFile.absolutePath
val jvmCompilerPlugin = Kobalt.findPlugin("JvmCompiler") as JvmCompilerPlugin
val pluginInfo = PluginInfo(KobaltPluginXml(), null, null).apply {
projectContributors.add(jvmCompilerPlugin)
}
return compilerFactory.create(listOf(thisBuildFile), pluginInfo).compileBuildFiles(args)
}
}

View file

@ -1,45 +1,30 @@
package com.beust.kobalt.internal
import com.beust.kobalt.Args
import com.beust.kobalt.BaseTest
import com.beust.kobalt.TestModule
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.app.BuildFileCompiler
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.aether.KobaltAether
import com.google.inject.Inject
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Guice
import org.testng.annotations.Test
import java.io.File
import java.nio.file.Paths
@Guice(modules = arrayOf(TestModule::class))
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory) {
private fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory)
: BuildFileCompiler.FindProjectResult {
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {
deleteOnExit()
writeText(buildFileText)
}
val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt")
args.buildFile = tmpBuildFile.absolutePath
val jvmCompilerPlugin = Kobalt.findPlugin("JvmCompiler") as JvmCompilerPlugin
val pluginInfo = PluginInfo(KobaltPluginXml(), null, null).apply {
projectContributors.add(jvmCompilerPlugin)
}
return compilerFactory.create(listOf(thisBuildFile), pluginInfo).compileBuildFiles(args)
}
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory,
override val aether: KobaltAether) : BaseTest(aether) {
private fun runTestWithProfile(enabled: Boolean) : Project {
val buildFileString = """
| import com.beust.kobalt.*
| import com.beust.kobalt.api.*
| val profile = false
| val p = project {
| name = if (profile) "profileOn" else "profileOff"
| }
""".trimMargin()
import com.beust.kobalt.*
import com.beust.kobalt.api.*
val profile = false
val p = project {
name = if (profile) "profileOn" else "profileOff"
}
"""
val args = Args()
if (enabled) args.profiles = "profile"

View file

@ -1,38 +1,73 @@
package com.beust.kobalt.maven
import com.beust.kobalt.Args
import com.beust.kobalt.BaseTest
import com.beust.kobalt.TestModule
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.app.BuildFileCompiler
import com.beust.kobalt.maven.aether.KobaltAether
import com.beust.kobalt.maven.aether.Scope
import com.google.inject.Inject
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Guice
import org.testng.annotations.Test
@Guice(modules = arrayOf(TestModule::class))
class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager) {
class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager,
val compilerFactory: BuildFileCompiler.IFactory, override val aether: KobaltAether) : BaseTest(aether) {
private fun assertContains(dependencies: List<IClasspathDependency>, vararg ids: String) {
ids.forEach { id ->
assertThat(dependencies.any { it.id.contains(id) }).isTrue()
}
}
@Test(description = "Make sure that COMPILE scope dependencies get resolved properly")
fun testScopeDependenciesShouldBeDownloaded() {
val testDeps = listOf(dependencyManager.create("org.testng:testng:6.9.11"))
fun assertContains(dependencies: List<IClasspathDependency>, vararg ids: String) {
ids.forEach { id ->
assertThat(dependencies.any { it.id.contains(id) }).isTrue()
}
}
// Should only resolve to TestNG
dependencyManager.transitiveClosure(testDeps, isTest = false).let { dependencies ->
dependencyManager.transitiveClosure(testDeps, listOf(Scope.COMPILE)).let { dependencies ->
assertThat(dependencies.any { it.id.contains(":jcommander:") }).isFalse()
assertContains(dependencies, ":testng:")
}
// Should resolve to TestNG and its dependencies
dependencyManager.transitiveClosure(testDeps, isTest = true).let { dependencies ->
dependencyManager.transitiveClosure(testDeps, listOf(Scope.TEST)).let { dependencies ->
assertContains(dependencies, ":jcommander:")
assertContains(dependencies, ":bsh:")
assertContains(dependencies, ":ant:")
assertContains(dependencies, ":ant-launcher:")
assertContains(dependencies, ":testng:")
}
}
@Test
fun honorRuntimeDependenciesBetweenProjects() {
val buildFileString = """
import com.beust.kobalt.*
val lib = project {
name = "lib"
dependencies {
compile("org.testng:testng:6.9.11")
runtime("com.beust:jcommander:1.48")
}
}
val p = project(lib) {
name = "transitive"
}
"""
val compileResult = compileBuildFile(buildFileString, Args(), compilerFactory)
val project2 = compileResult.projects[1]
val dependencies = dependencyManager.calculateDependencies(project2, Kobalt.context!!,
listOf(Scope.COMPILE, Scope.RUNTIME),
project2.compileDependencies + project2.compileRuntimeDependencies)
assertContains(dependencies, ":testng:")
assertContains(dependencies, ":jcommander:")
}
}

View file

@ -160,7 +160,7 @@ class DownloadTest @Inject constructor(
@Test
fun variablesShouldBeExpanded() {
val dep = dependencyManager.createMaven("org.mapdb:mapdb:3.0.0-M3")
val closure = dependencyManager.transitiveClosure(listOf(dep), false, "<testProject>")
val closure = dependencyManager.transitiveClosure(listOf(dep), requiredBy = "<testProject>")
val d = closure.filter { it.id.contains("eclipse-collections-api")}
Assert.assertEquals(d.size, 1)
}