mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Test resources were not copied properly.
This commit is contained in:
parent
b3890f822e
commit
f6690477de
4 changed files with 32 additions and 15 deletions
|
@ -2,6 +2,7 @@ package com.beust.kobalt
|
|||
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.internal.ActorUtils
|
||||
import com.beust.kobalt.internal.SourceSet
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.log
|
||||
import java.io.File
|
||||
|
@ -36,13 +37,14 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
return result
|
||||
}
|
||||
|
||||
fun sourceDirectories(project: Project, context: KobaltContext) : List<File> {
|
||||
fun sourceDirectories(project: Project, context: KobaltContext, sourceSet: SourceSet) : List<File> {
|
||||
val result = arrayListOf<File>()
|
||||
val compilerContributors = ActorUtils.selectAffinityActors(project, context,
|
||||
context.pluginInfo.compilerContributors)
|
||||
compilerContributors.forEach {
|
||||
it.compilersFor(project, context).forEach { compiler ->
|
||||
result.addAll(sourceDirectories(project, compiler.sourceDirectory, variantFirst = true))
|
||||
result.addAll(sourceDirectories(project, compiler.sourceDirectory, variantFirst = true,
|
||||
sourceSet = sourceSet))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,7 +54,8 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
/**
|
||||
* Might be used by plug-ins.
|
||||
*/
|
||||
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources", variantFirst = false)
|
||||
fun resourceDirectories(project: Project, sourceSet: SourceSet = SourceSet.MAIN)
|
||||
= sourceDirectories(project, "resources", variantFirst = false, sourceSet = sourceSet)
|
||||
.filter { it.path.contains("resources") || it.path.contains("res") }
|
||||
|
||||
/**
|
||||
|
@ -62,9 +65,17 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
* files that have already been seen get skipped, which is how compilation and resources
|
||||
* receive the correct priority in the final jar.
|
||||
*/
|
||||
private fun sourceDirectories(project: Project, suffix: String, variantFirst: Boolean) : List<File> {
|
||||
private fun sourceDirectories(project: Project, suffix: String, variantFirst: Boolean, sourceSet: SourceSet)
|
||||
: List<File> {
|
||||
val result = arrayListOf<File>()
|
||||
val sourceDirectories = project.sourceDirectories.map { File(it) }
|
||||
val sourceDirectories =
|
||||
if (sourceSet == SourceSet.MAIN) {
|
||||
project.sourceDirectories.map { File(it) }
|
||||
} else if (sourceSet == SourceSet.TEST){
|
||||
project.sourceDirectoriesTest.map { File(it) }
|
||||
} else {
|
||||
throw KobaltException("Unknown source set: $sourceSet))
|
||||
}
|
||||
if (isDefault) {
|
||||
result.addAll(sourceDirectories)
|
||||
} else {
|
||||
|
|
|
@ -56,7 +56,7 @@ open class Project(
|
|||
|
||||
companion object {
|
||||
val DEFAULT_SOURCE_DIRECTORIES = setOf("src/main/java", "src/main/kotlin", "src/main/resources")
|
||||
val DEFAULT_SOURCE_DIRECTORIES_TEST = setOf("src/test/java", "src/test/kotlin")
|
||||
val DEFAULT_SOURCE_DIRECTORIES_TEST = setOf("src/test/java", "src/test/kotlin", "src/test/resources")
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -49,8 +49,6 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
const val TASK_CLEAN = "clean"
|
||||
const val TASK_TEST = "test"
|
||||
|
||||
const val SOURCE_SET_MAIN = "main"
|
||||
const val SOURCE_SET_TEST = "test"
|
||||
const val DOCS_DIRECTORY = "docs/javadoc"
|
||||
}
|
||||
|
||||
|
@ -100,20 +98,20 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
/**
|
||||
* Copy the resources from a source directory to the build one
|
||||
*/
|
||||
protected fun copyResources(project: Project, sourceSet: String) {
|
||||
protected fun copyResources(project: Project, sourceSet: SourceSet) {
|
||||
val sourceDirs: ArrayList<String> = arrayListOf()
|
||||
var outputDir: String?
|
||||
if (sourceSet == JvmCompilerPlugin.SOURCE_SET_MAIN) {
|
||||
if (sourceSet == SourceSet.MAIN) {
|
||||
sourceDirs.addAll(project.sourceDirectories.filter { it.contains("resources") })
|
||||
outputDir = KFiles.CLASSES_DIR
|
||||
} else if (sourceSet == JvmCompilerPlugin.SOURCE_SET_TEST) {
|
||||
} else if (sourceSet == SourceSet.TEST) {
|
||||
sourceDirs.addAll(project.sourceDirectoriesTest.filter { it.contains("resources") })
|
||||
outputDir = KFiles.TEST_CLASSES_DIR
|
||||
} else {
|
||||
throw IllegalArgumentException("Custom source sets not supported yet: $sourceSet")
|
||||
throw IllegalArgumentException("Unknown source set: $sourceSet")
|
||||
}
|
||||
|
||||
val variantSourceDirs = context.variant.resourceDirectories(project)
|
||||
val variantSourceDirs = context.variant.resourceDirectories(project, sourceSet)
|
||||
if (variantSourceDirs.size > 0) {
|
||||
lp(project, "Copying $sourceSet resources")
|
||||
val absOutputDir = File(KFiles.joinDir(project.directory, project.buildDirectory, outputDir))
|
||||
|
@ -158,7 +156,8 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
|
||||
private fun doTaskCompile(project: Project, isTest: Boolean): TaskResult {
|
||||
// Set up the source files now that we have the variant
|
||||
sourceDirectories.addAll(context.variant.sourceDirectories(project, context))
|
||||
sourceDirectories.addAll(context.variant.sourceDirectories(project, context,
|
||||
if (isTest) SourceSet.TEST else SourceSet.MAIN))
|
||||
|
||||
val sourceDirectory = context.variant.maybeGenerateBuildConfig(project, context)
|
||||
if (sourceDirectory != null) {
|
||||
|
@ -243,7 +242,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
|||
*/
|
||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
||||
sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
||||
copyResources(project, JvmCompilerPlugin.SOURCE_SET_MAIN)
|
||||
copyResources(project, if (isTest) SourceSet.TEST else SourceSet.MAIN)
|
||||
|
||||
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
||||
else dependencyManager.dependencies(project, context)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
enum class SourceSet {
|
||||
MAIN,
|
||||
TEST
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue