mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Tests can now run full builds.
This commit is contained in:
parent
24d902bfbf
commit
ba98592f49
6 changed files with 75 additions and 28 deletions
|
@ -28,7 +28,6 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
|
||||||
val depManager: DependencyManager,
|
val depManager: DependencyManager,
|
||||||
val settings: KobaltSettings,
|
val settings: KobaltSettings,
|
||||||
val executors: KobaltExecutors,
|
val executors: KobaltExecutors,
|
||||||
val pluginInfo: PluginInfo,
|
|
||||||
val incrementalManagerFactory: IncrementalManager.IFactory,
|
val incrementalManagerFactory: IncrementalManager.IFactory,
|
||||||
val taskManager: TaskManager) {
|
val taskManager: TaskManager) {
|
||||||
|
|
||||||
|
@ -171,6 +170,9 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
|
||||||
|
|
||||||
val dependencies = arrayListOf<IClasspathDependency>()
|
val dependencies = arrayListOf<IClasspathDependency>()
|
||||||
|
|
||||||
|
// @Inject
|
||||||
|
// lateinit var pluginInfo: PluginInfo
|
||||||
|
|
||||||
fun installPlugins(dependencies: List<IClasspathDependency>, scriptClassLoader: ClassLoader) {
|
fun installPlugins(dependencies: List<IClasspathDependency>, scriptClassLoader: ClassLoader) {
|
||||||
val executor = executors.newExecutor("Plugins", 5)
|
val executor = executors.newExecutor("Plugins", 5)
|
||||||
dependencies.forEach {
|
dependencies.forEach {
|
||||||
|
@ -191,6 +193,8 @@ class Plugins @Inject constructor (val taskManagerProvider : Provider<TaskManage
|
||||||
// The plug-in is pointing to a jar file, read kobalt-plugin.xml from it
|
// The plug-in is pointing to a jar file, read kobalt-plugin.xml from it
|
||||||
JarUtils.extractTextFile(JarFile(file), PluginInfo.PLUGIN_XML)
|
JarUtils.extractTextFile(JarFile(file), PluginInfo.PLUGIN_XML)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
|
||||||
if (pluginXml != null) {
|
if (pluginXml != null) {
|
||||||
val pluginClassLoader = URLClassLoader(arrayOf(file.toURI().toURL()))
|
val pluginClassLoader = URLClassLoader(arrayOf(file.toURI().toURL()))
|
||||||
val thisPluginInfo = PluginInfo.readPluginXml(pluginXml, pluginClassLoader, scriptClassLoader)
|
val thisPluginInfo = PluginInfo.readPluginXml(pluginXml, pluginClassLoader, scriptClassLoader)
|
||||||
|
|
|
@ -17,7 +17,7 @@ import javax.inject.Singleton
|
||||||
@Singleton
|
@Singleton
|
||||||
class TaskManager @Inject constructor(val args: Args,
|
class TaskManager @Inject constructor(val args: Args,
|
||||||
val incrementalManagerFactory: IncrementalManager.IFactory,
|
val incrementalManagerFactory: IncrementalManager.IFactory,
|
||||||
val pluginInfo: PluginInfo, val kobaltLog: ParallelLogger) {
|
val kobaltLog: ParallelLogger) {
|
||||||
private val dependsOn = TreeMultimap.create<String, String>()
|
private val dependsOn = TreeMultimap.create<String, String>()
|
||||||
private val reverseDependsOn = TreeMultimap.create<String, String>()
|
private val reverseDependsOn = TreeMultimap.create<String, String>()
|
||||||
private val runBefore = TreeMultimap.create<String, String>()
|
private val runBefore = TreeMultimap.create<String, String>()
|
||||||
|
@ -80,6 +80,9 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Inject
|
||||||
|
// lateinit var pluginInfo: PluginInfo
|
||||||
|
|
||||||
fun runTargets(passedTaskNames: List<String>, allProjects: List<Project>): RunTargetResult {
|
fun runTargets(passedTaskNames: List<String>, allProjects: List<Project>): RunTargetResult {
|
||||||
// Check whether tasks passed at command line exist
|
// Check whether tasks passed at command line exist
|
||||||
passedTaskNames.forEach {
|
passedTaskNames.forEach {
|
||||||
|
@ -87,6 +90,7 @@ class TaskManager @Inject constructor(val args: Args,
|
||||||
throw KobaltException("Unknown task: $it")
|
throw KobaltException("Unknown task: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val pluginInfo = Kobalt.INJECTOR.getInstance(PluginInfo::class.java)
|
||||||
var taskInfos = calculateDependentTaskNames(passedTaskNames, allProjects)
|
var taskInfos = calculateDependentTaskNames(passedTaskNames, allProjects)
|
||||||
|
|
||||||
// Remove non existing tasks (e.g. dynamic task defined for a single project)
|
// Remove non existing tasks (e.g. dynamic task defined for a single project)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
|
import com.beust.jcommander.JCommander
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.app.BuildFileCompiler
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
|
@ -10,11 +11,13 @@ import com.beust.kobalt.internal.build.SingleFileBuildSources
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import org.testng.annotations.BeforeClass
|
import org.testng.annotations.BeforeClass
|
||||||
|
import org.testng.annotations.Guice
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Guice(modules = arrayOf(TestModule::class))
|
||||||
open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
fun bc() {
|
fun bc() {
|
||||||
|
@ -90,8 +93,12 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
|
|
||||||
fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
|
fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
|
||||||
|
|
||||||
fun createProject(projectInfo: ProjectInfo) : File {
|
class ProjectDescription(val path: File, val name: String, val version: String)
|
||||||
|
|
||||||
|
fun createProject(projectInfo: ProjectInfo) : ProjectDescription {
|
||||||
val root = Files.createTempDirectory("kobalt-test").toFile()
|
val root = Files.createTempDirectory("kobalt-test").toFile()
|
||||||
|
val projectName = "p" + Math.abs(Random().nextInt())
|
||||||
|
val version = "1.0"
|
||||||
|
|
||||||
fun createFile(root: File, f: String, text: String) : File {
|
fun createFile(root: File, f: String, text: String) : File {
|
||||||
val file = File(root, f)
|
val file = File(root, f)
|
||||||
|
@ -100,21 +107,38 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
createFile(root, "kobalt/src/Build.kt", projectInfo.buildFile.text(root.absolutePath))
|
createFile(root, "kobalt/src/Build.kt",
|
||||||
|
projectInfo.buildFile.text(root.absolutePath, projectName, version))
|
||||||
|
|
||||||
projectInfo.files.forEach {
|
projectInfo.files.forEach {
|
||||||
createFile(root, it.path, it.content)
|
createFile(root, it.path, it.content)
|
||||||
}
|
}
|
||||||
return root
|
return ProjectDescription(root, projectName, version)
|
||||||
|
}
|
||||||
|
|
||||||
|
class LaunchProjectResult(val projectInfo: ProjectInfo, val projectDescription: ProjectDescription,
|
||||||
|
val result: Int)
|
||||||
|
|
||||||
|
fun launchProject(projectInfo: ProjectInfo, commandLine: Array<String>) : LaunchProjectResult {
|
||||||
|
val project = createProject(projectInfo)
|
||||||
|
println("Project: $project")
|
||||||
|
val main = Kobalt.INJECTOR.getInstance(Main::class.java)
|
||||||
|
val args = Args()
|
||||||
|
val jc = JCommander(args).apply { parse(*commandLine) }
|
||||||
|
args.buildFile = project.path.absolutePath + "/kobalt/src/Build.kt"
|
||||||
|
val result = Main.launchMain(main, jc, args, arrayOf("assemble"))
|
||||||
|
return LaunchProjectResult(projectInfo, project, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BuildFile(val imports: List<String>, val projectText: String) {
|
class BuildFile(val imports: List<String>, val projectText: String) {
|
||||||
fun text(projectDirectory: String) : String {
|
fun text(projectDirectory: String, projectName: String, version: String) : String {
|
||||||
val projectName = "p" + Math.abs(Random().nextInt())
|
|
||||||
val bottom = """
|
val bottom = """
|
||||||
|
|
||||||
val $projectName = project {
|
val $projectName = project {
|
||||||
name = "$projectName"
|
name = "$projectName"
|
||||||
|
version = "$version"
|
||||||
|
directory = "$projectDirectory"
|
||||||
$projectText
|
$projectText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
28
src/test/kotlin/com/beust/kobalt/internal/BuildFilesTest.kt
Normal file
28
src/test/kotlin/com/beust/kobalt/internal/BuildFilesTest.kt
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.BaseTest
|
||||||
|
import com.beust.kobalt.BuildFile
|
||||||
|
import com.beust.kobalt.ProjectFile
|
||||||
|
import com.beust.kobalt.ProjectInfo
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class BuildFilesTest : BaseTest() {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun shouldGenerateArtifact() {
|
||||||
|
val projectInfo = ProjectInfo(
|
||||||
|
BuildFile(listOf("com.beust.kobalt.plugin.packaging.*"), "assemble{jar{}}"),
|
||||||
|
listOf(ProjectFile("src/main/kotlin/A.kt", "val a = \"foo\"")))
|
||||||
|
|
||||||
|
val result = launchProject(projectInfo, arrayOf("assemble"))
|
||||||
|
|
||||||
|
val project = result.projectDescription
|
||||||
|
val jarFile = File(KFiles.joinDir(project.path.absolutePath, "kobaltBuild/libs", project.name + "-"
|
||||||
|
+ project.version + ".jar"))
|
||||||
|
|
||||||
|
assertThat(jarFile).exists()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,23 +1,15 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.TestModule
|
import com.beust.kobalt.BaseTest
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.project
|
import com.beust.kobalt.project
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.testng.annotations.BeforeClass
|
|
||||||
import org.testng.annotations.DataProvider
|
import org.testng.annotations.DataProvider
|
||||||
import org.testng.annotations.Guice
|
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
@Guice(modules = arrayOf(TestModule::class))
|
class BuildOrderTest : BaseTest() {
|
||||||
class BuildOrderTest {
|
|
||||||
val taskManager: TaskManager get() = Kobalt.INJECTOR.getInstance(TaskManager::class.java)
|
val taskManager: TaskManager get() = Kobalt.INJECTOR.getInstance(TaskManager::class.java)
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
fun beforeClass() {
|
|
||||||
Kobalt.init(TestModule())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun toExpectedList(vararg projectNames: Int) = projectNames.map { "p$it:assemble" }.toList()
|
private fun toExpectedList(vararg projectNames: Int) = projectNames.map { "p$it:assemble" }.toList()
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.BaseTest
|
||||||
import com.beust.kobalt.TestConfig
|
import com.beust.kobalt.TestConfig
|
||||||
import com.beust.kobalt.TestModule
|
import com.beust.kobalt.api.ITestJvmFlagContributor
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.ITestJvmFlagInterceptor
|
||||||
|
import com.beust.kobalt.api.KobaltContext
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.maven.dependency.FileDependency
|
import com.beust.kobalt.maven.dependency.FileDependency
|
||||||
import com.beust.kobalt.project
|
import com.beust.kobalt.project
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.testng.annotations.BeforeClass
|
|
||||||
import org.testng.annotations.Guice
|
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -15,8 +16,7 @@ import javax.inject.Inject
|
||||||
/**
|
/**
|
||||||
* Test ITestJvmFlagContributor and ITestJvmFlagInterceptor.
|
* Test ITestJvmFlagContributor and ITestJvmFlagInterceptor.
|
||||||
*/
|
*/
|
||||||
@Guice(modules = arrayOf(TestModule::class))
|
class DependencyTest @Inject constructor(val context: KobaltContext) : BaseTest() {
|
||||||
class DependencyTest @Inject constructor(val context: KobaltContext) {
|
|
||||||
private fun isWindows() = System.getProperty("os.name").toLowerCase().contains("ndows")
|
private fun isWindows() = System.getProperty("os.name").toLowerCase().contains("ndows")
|
||||||
private val A_JAR = if (isWindows()) "c:\\tmp\\a.jar" else "/tmp/a.jar"
|
private val A_JAR = if (isWindows()) "c:\\tmp\\a.jar" else "/tmp/a.jar"
|
||||||
private val B_JAR = if (isWindows()) "c:\\tmp\\b.jar" else "/tmp/b.jar"
|
private val B_JAR = if (isWindows()) "c:\\tmp\\b.jar" else "/tmp/b.jar"
|
||||||
|
@ -37,11 +37,6 @@ class DependencyTest @Inject constructor(val context: KobaltContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
fun beforeClass() {
|
|
||||||
Kobalt.init(TestModule())
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun runTest(pluginInfo: IPluginInfo, expected: List<String>) {
|
private fun runTest(pluginInfo: IPluginInfo, expected: List<String>) {
|
||||||
val result = TestNgRunner().calculateAllJvmArgs(project, context, TestConfig(project),
|
val result = TestNgRunner().calculateAllJvmArgs(project, context, TestConfig(project),
|
||||||
classpath, pluginInfo)
|
classpath, pluginInfo)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue