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

Refactoring toward mixed mode.

This commit is contained in:
Cedric Beust 2016-02-02 21:30:29 +04:00
parent 15efe61a74
commit 93415868b0
6 changed files with 17 additions and 11 deletions

View file

@ -36,8 +36,9 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
fun resDirectories(project: Project) : List<File> = sourceDirectories(project, "res")
fun sourceDirectories(project: Project) : List<File> =
sourceDirectories(project, project.projectInfo.sourceDirectory)
fun sourceDirectories(project: Project) = project.projectInfo.sourceSuffixes.flatMap {
sourceDirectories(project, it)
}
/**
* suffix is either "java" (to find source files) or "res" (to find resources)

View file

@ -7,12 +7,15 @@ import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import java.util.*
class LanguageInfo(val name: String, val suffix : String = name)
/**
* Data that is useful for projects to have but should not be specified in the DSL.
*/
interface IProjectInfo {
/** Used to determine the last directory segment of the flavored sources, e.g. src/main/JAVA */
val sourceDirectory : String
val languageInfos: List<LanguageInfo>
val sourceSuffixes: List<String>
val defaultSourceDirectories: HashSet<String>
val defaultTestDirectories: HashSet<String>
@ -37,9 +40,11 @@ interface IProjectInfo {
fun dependsOnDirtyProjects(project: Project) = project.projectInfo.dependsOn.any { it.projectInfo.isDirty }
}
abstract class BaseProjectInfo : IProjectInfo {
abstract class BaseProjectInfo(override val languageInfos: List<LanguageInfo>) : IProjectInfo {
abstract fun generate(field: BuildConfigField) : String
override val sourceSuffixes = languageInfos.map { it.suffix }
fun generate(type: String, name: String, value: Any) = generate(BuildConfigField(type, name, value))
fun generateFieldsFromContributors(project: Project, context: KobaltContext)

View file

@ -37,7 +37,7 @@ class JavaPlugin @Inject constructor(
// IDocContributor
override fun affinity(project: Project, context: KobaltContext) =
if (project.sourceSuffix == ".java") 1 else 0
if (project.sourceDirectories.any { it.contains("java") }) 1 else 0
override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
val result =

View file

@ -6,11 +6,11 @@ import com.beust.kobalt.api.BuildConfigField
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.internal.BaseProjectInfo
import com.beust.kobalt.internal.LanguageInfo
import com.google.inject.Singleton
@Singleton
class JavaProjectInfo : BaseProjectInfo() {
override val sourceDirectory = "java"
class JavaProjectInfo : BaseProjectInfo(listOf(LanguageInfo("java", "java"))) {
override val defaultSourceDirectories = hashSetOf("src/main/java", "src/main/resources", "src/main/res")
override val defaultTestDirectories = hashSetOf("src/test/java", "src/test/resources", "src/test/res")

View file

@ -125,7 +125,7 @@ class KotlinPlugin @Inject constructor(
// ICompilerContributor
override fun affinity(project: Project, context: KobaltContext) =
if (project.sourceSuffix == ".kt") 1 else 0
if (project.sourceDirectories.any { it.contains("kotlin") }) 2 else 0
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
val result =

View file

@ -6,11 +6,11 @@ import com.beust.kobalt.api.BuildConfigField
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.internal.BaseProjectInfo
import com.beust.kobalt.internal.LanguageInfo
import com.google.inject.Singleton
@Singleton
class KotlinProjectInfo : BaseProjectInfo() {
override val sourceDirectory = "kotlin"
class KotlinProjectInfo : BaseProjectInfo(listOf(LanguageInfo("kotlin", "kt"))) {
override val defaultSourceDirectories = hashSetOf("src/main/kotlin", "src/main/resources", "src/main/res")
override val defaultTestDirectories = hashSetOf("src/test/kotlin", "src/test/resources", "src/test/res")