mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Refactoring toward mixed mode.
This commit is contained in:
parent
15efe61a74
commit
93415868b0
6 changed files with 17 additions and 11 deletions
|
@ -36,8 +36,9 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
|
|
||||||
fun resDirectories(project: Project) : List<File> = sourceDirectories(project, "res")
|
fun resDirectories(project: Project) : List<File> = sourceDirectories(project, "res")
|
||||||
|
|
||||||
fun sourceDirectories(project: Project) : List<File> =
|
fun sourceDirectories(project: Project) = project.projectInfo.sourceSuffixes.flatMap {
|
||||||
sourceDirectories(project, project.projectInfo.sourceDirectory)
|
sourceDirectories(project, it)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suffix is either "java" (to find source files) or "res" (to find resources)
|
* suffix is either "java" (to find source files) or "res" (to find resources)
|
||||||
|
|
|
@ -7,12 +7,15 @@ import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import java.util.*
|
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.
|
* Data that is useful for projects to have but should not be specified in the DSL.
|
||||||
*/
|
*/
|
||||||
interface IProjectInfo {
|
interface IProjectInfo {
|
||||||
/** Used to determine the last directory segment of the flavored sources, e.g. src/main/JAVA */
|
val languageInfos: List<LanguageInfo>
|
||||||
val sourceDirectory : String
|
|
||||||
|
val sourceSuffixes: List<String>
|
||||||
|
|
||||||
val defaultSourceDirectories: HashSet<String>
|
val defaultSourceDirectories: HashSet<String>
|
||||||
val defaultTestDirectories: HashSet<String>
|
val defaultTestDirectories: HashSet<String>
|
||||||
|
@ -37,9 +40,11 @@ interface IProjectInfo {
|
||||||
fun dependsOnDirtyProjects(project: Project) = project.projectInfo.dependsOn.any { it.projectInfo.isDirty }
|
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
|
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 generate(type: String, name: String, value: Any) = generate(BuildConfigField(type, name, value))
|
||||||
|
|
||||||
fun generateFieldsFromContributors(project: Project, context: KobaltContext)
|
fun generateFieldsFromContributors(project: Project, context: KobaltContext)
|
||||||
|
|
|
@ -37,7 +37,7 @@ class JavaPlugin @Inject constructor(
|
||||||
|
|
||||||
// IDocContributor
|
// IDocContributor
|
||||||
override fun affinity(project: Project, context: KobaltContext) =
|
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 {
|
override fun generateDoc(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
|
|
|
@ -6,11 +6,11 @@ import com.beust.kobalt.api.BuildConfigField
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.BaseProjectInfo
|
import com.beust.kobalt.internal.BaseProjectInfo
|
||||||
|
import com.beust.kobalt.internal.LanguageInfo
|
||||||
import com.google.inject.Singleton
|
import com.google.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class JavaProjectInfo : BaseProjectInfo() {
|
class JavaProjectInfo : BaseProjectInfo(listOf(LanguageInfo("java", "java"))) {
|
||||||
override val sourceDirectory = "java"
|
|
||||||
override val defaultSourceDirectories = hashSetOf("src/main/java", "src/main/resources", "src/main/res")
|
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")
|
override val defaultTestDirectories = hashSetOf("src/test/java", "src/test/resources", "src/test/res")
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ class KotlinPlugin @Inject constructor(
|
||||||
// ICompilerContributor
|
// ICompilerContributor
|
||||||
|
|
||||||
override fun affinity(project: Project, context: KobaltContext) =
|
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 {
|
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
|
|
|
@ -6,11 +6,11 @@ import com.beust.kobalt.api.BuildConfigField
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.internal.BaseProjectInfo
|
import com.beust.kobalt.internal.BaseProjectInfo
|
||||||
|
import com.beust.kobalt.internal.LanguageInfo
|
||||||
import com.google.inject.Singleton
|
import com.google.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class KotlinProjectInfo : BaseProjectInfo() {
|
class KotlinProjectInfo : BaseProjectInfo(listOf(LanguageInfo("kotlin", "kt"))) {
|
||||||
override val sourceDirectory = "kotlin"
|
|
||||||
override val defaultSourceDirectories = hashSetOf("src/main/kotlin", "src/main/resources", "src/main/res")
|
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")
|
override val defaultTestDirectories = hashSetOf("src/test/kotlin", "src/test/resources", "src/test/res")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue