mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Refactor source sets.
This commit is contained in:
parent
9bbb9fe09d
commit
53bf5cbd4b
4 changed files with 27 additions and 18 deletions
|
@ -68,9 +68,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
private fun sourceDirectories(project: Project, suffix: String, variantFirst: Boolean, sourceSet: SourceSet)
|
private fun sourceDirectories(project: Project, suffix: String, variantFirst: Boolean, sourceSet: SourceSet)
|
||||||
: List<File> {
|
: List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
val sourceDirectories = (if (sourceSet == SourceSet.MAIN) project.sourceDirectories
|
val sourceDirectories = sourceSet.correctSourceSet(project)
|
||||||
else if (sourceSet == SourceSet.TEST) project.sourceDirectoriesTest
|
|
||||||
else throw KobaltException("Unknown source set: $sourceSet"))
|
|
||||||
.filter { File(project.directory, it).exists() }
|
.filter { File(project.directory, it).exists() }
|
||||||
.map { File(it) }
|
.map { File(it) }
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.beust.kobalt.api
|
package com.beust.kobalt.api
|
||||||
|
|
||||||
|
import com.beust.kobalt.KobaltException
|
||||||
import com.beust.kobalt.TestConfig
|
import com.beust.kobalt.TestConfig
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
|
import com.beust.kobalt.internal.SourceSet
|
||||||
import com.beust.kobalt.maven.dependency.MavenDependency
|
import com.beust.kobalt.maven.dependency.MavenDependency
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.project
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
|
@ -115,17 +115,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
* Copy the resources from a source directory to the build one
|
* Copy the resources from a source directory to the build one
|
||||||
*/
|
*/
|
||||||
protected fun copyResources(project: Project, sourceSet: SourceSet) {
|
protected fun copyResources(project: Project, sourceSet: SourceSet) {
|
||||||
val sourceDirs: ArrayList<String> = arrayListOf()
|
var outputDir = sourceSet.correctOutputDir(project)
|
||||||
var outputDir: String?
|
|
||||||
if (sourceSet == SourceSet.MAIN) {
|
|
||||||
sourceDirs.addAll(project.sourceDirectories.filter { it.contains("resources") })
|
|
||||||
outputDir = KFiles.CLASSES_DIR
|
|
||||||
} else if (sourceSet == SourceSet.TEST) {
|
|
||||||
sourceDirs.addAll(project.sourceDirectoriesTest.filter { it.contains("resources") })
|
|
||||||
outputDir = KFiles.TEST_CLASSES_DIR
|
|
||||||
} else {
|
|
||||||
throw IllegalArgumentException("Unknown source set: $sourceSet")
|
|
||||||
}
|
|
||||||
|
|
||||||
val variantSourceDirs = context.variant.resourceDirectories(project, sourceSet)
|
val variantSourceDirs = context.variant.resourceDirectories(project, sourceSet)
|
||||||
if (variantSourceDirs.size > 0) {
|
if (variantSourceDirs.size > 0) {
|
||||||
|
@ -172,8 +162,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
|
|
||||||
private fun doTaskCompile(project: Project, isTest: Boolean): TaskResult {
|
private fun doTaskCompile(project: Project, isTest: Boolean): TaskResult {
|
||||||
// Set up the source files now that we have the variant
|
// 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, SourceSet.of(isTest)))
|
||||||
if (isTest) SourceSet.TEST else SourceSet.MAIN))
|
|
||||||
|
|
||||||
val sourceDirectory = context.variant.maybeGenerateBuildConfig(project, context)
|
val sourceDirectory = context.variant.maybeGenerateBuildConfig(project, context)
|
||||||
if (sourceDirectory != null) {
|
if (sourceDirectory != null) {
|
||||||
|
@ -264,7 +253,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
*/
|
*/
|
||||||
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
protected fun createCompilerActionInfo(project: Project, context: KobaltContext, isTest: Boolean,
|
||||||
sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
sourceDirectories: List<File>, sourceSuffixes: List<String>): CompilerActionInfo {
|
||||||
copyResources(project, if (isTest) SourceSet.TEST else SourceSet.MAIN)
|
copyResources(project, SourceSet.of(isTest))
|
||||||
|
|
||||||
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
val fullClasspath = if (isTest) dependencyManager.testDependencies(project, context)
|
||||||
else dependencyManager.dependencies(project, context)
|
else dependencyManager.dependencies(project, context)
|
||||||
|
|
|
@ -1,7 +1,26 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.KobaltException
|
||||||
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
|
||||||
enum class SourceSet {
|
enum class SourceSet {
|
||||||
MAIN,
|
MAIN,
|
||||||
TEST
|
TEST;
|
||||||
|
|
||||||
|
fun correctSourceSet(project: Project) =
|
||||||
|
if (this == SourceSet.MAIN) project.sourceDirectories
|
||||||
|
else if (this == SourceSet.TEST) project.sourceDirectoriesTest
|
||||||
|
else throw KobaltException("Unknown source set: $this")
|
||||||
|
|
||||||
|
fun correctOutputDir(project: Project) =
|
||||||
|
if (this == SourceSet.MAIN) KFiles.CLASSES_DIR
|
||||||
|
else if (this == SourceSet.TEST) KFiles.TEST_CLASSES_DIR
|
||||||
|
else throw IllegalArgumentException("Unknown source set: $this")
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun of(isTest: Boolean) = if (isTest) TEST else MAIN
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue