mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix suffixes.
This commit is contained in:
parent
8ccece97e0
commit
df5fcce61e
5 changed files with 30 additions and 17 deletions
|
@ -5,6 +5,7 @@ import com.beust.kobalt.internal.ActorUtils
|
||||||
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 java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture the product flavor and the build type of a build.
|
* Capture the product flavor and the build type of a build.
|
||||||
|
@ -41,11 +42,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
context.pluginInfo.compilerContributors)
|
context.pluginInfo.compilerContributors)
|
||||||
compilerContributors.forEach {
|
compilerContributors.forEach {
|
||||||
it.compilersFor(project, context).forEach { compiler ->
|
it.compilersFor(project, context).forEach { compiler ->
|
||||||
val sourceSuffixes = compiler.sourceSuffixes
|
result.addAll(sourceDirectories(project, compiler.sourceDirectory, variantFirst = true))
|
||||||
val suffixes = sourceSuffixes.flatMap { thisSuffix ->
|
|
||||||
sourceDirectories(project, thisSuffix)
|
|
||||||
}
|
|
||||||
result.addAll(suffixes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,23 +52,21 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
/**
|
/**
|
||||||
* Might be used by plug-ins.
|
* Might be used by plug-ins.
|
||||||
*/
|
*/
|
||||||
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources")
|
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources", variantFirst = false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suffix is either "java" (to find source files) or "resources" (to find resources)
|
* suffix is either "java" (to find source files) or "resources" (to find resources).
|
||||||
|
* The priority directory is always returned first. For example, if a "pro" product flavor
|
||||||
|
* is requested, "src/pro/kotlin" will appear in the result before "src/main/kotlin". Later,
|
||||||
|
* 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) : Set<File> {
|
private fun sourceDirectories(project: Project, suffix: String, variantFirst: Boolean) : List<File> {
|
||||||
val result = hashSetOf<File>()
|
val result = arrayListOf<File>()
|
||||||
val sourceDirectories = project.sourceDirectories.map { File(it) }
|
val sourceDirectories = project.sourceDirectories.map { File(it) }
|
||||||
if (isDefault) {
|
if (isDefault) {
|
||||||
result.addAll(sourceDirectories)
|
result.addAll(sourceDirectories)
|
||||||
} else {
|
} else {
|
||||||
result.addAll(allDirectories(project).map {
|
|
||||||
File(KFiles.joinDir("src", it, suffix))
|
|
||||||
}.filter {
|
|
||||||
it.exists()
|
|
||||||
})
|
|
||||||
|
|
||||||
// // The ordering of files is: 1) build type 2) product flavor 3) default
|
// // The ordering of files is: 1) build type 2) product flavor 3) default
|
||||||
buildType.let {
|
buildType.let {
|
||||||
val dir = File(KFiles.joinDir("src", it.name, suffix))
|
val dir = File(KFiles.joinDir("src", it.name, suffix))
|
||||||
|
@ -84,9 +79,14 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
result.add(dir)
|
result.add(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result.addAll(allDirectories(project).map {
|
||||||
|
File(KFiles.joinDir("src", it, suffix))
|
||||||
|
}.filter {
|
||||||
|
it.exists()
|
||||||
|
})
|
||||||
|
|
||||||
// Now that all the variant source directories have been added, add the project's default ones
|
// Now that all the variant source directories have been added, add the project's default ones
|
||||||
result.addAll(sourceDirectories)
|
result.addAll(sourceDirectories)
|
||||||
return result.filter { it.exists() }.toHashSet()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generated directory, if applicable
|
// Generated directory, if applicable
|
||||||
|
@ -94,7 +94,10 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
result.add(it)
|
result.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.filter { File(project.directory, it.path).exists() }.toHashSet()
|
val filteredResult = result.filter { File(project.directory, it.path).exists() }
|
||||||
|
val sortedResult = if (variantFirst) filteredResult
|
||||||
|
else filteredResult.reversed().toList()
|
||||||
|
return LinkedHashSet(sortedResult).toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
||||||
|
|
|
@ -8,6 +8,11 @@ interface ICompiler {
|
||||||
*/
|
*/
|
||||||
val sourceSuffixes: List<String>
|
val sourceSuffixes: List<String>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The trailing end of the source directory (e.g. "kotlin" in "src/main/kotlin")
|
||||||
|
*/
|
||||||
|
val sourceDirectory: String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the compilation based on the info.
|
* Run the compilation based on the info.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -46,6 +46,7 @@ class TaskContributor @Inject constructor(val incrementalManager: IncrementalMan
|
||||||
runTask: (Project) -> IncrementalTaskInfo) {
|
runTask: (Project) -> IncrementalTaskInfo) {
|
||||||
Variant.allVariants(project).forEach { variant ->
|
Variant.allVariants(project).forEach { variant ->
|
||||||
val variantTaskName = variant.toTask(taskName)
|
val variantTaskName = variant.toTask(taskName)
|
||||||
|
context.variant = variant
|
||||||
dynamicTasks.add(DynamicTask(plugin, variantTaskName, variantTaskName,
|
dynamicTasks.add(DynamicTask(plugin, variantTaskName, variantTaskName,
|
||||||
runBefore = runBefore.map { variant.toTask(it) },
|
runBefore = runBefore.map { variant.toTask(it) },
|
||||||
runAfter = runAfter.map { variant.toTask(it) },
|
runAfter = runAfter.map { variant.toTask(it) },
|
||||||
|
|
|
@ -56,6 +56,8 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
val compiler = object: ICompiler {
|
val compiler = object: ICompiler {
|
||||||
override val sourceSuffixes = listOf("java")
|
override val sourceSuffixes = listOf("java")
|
||||||
|
|
||||||
|
override val sourceDirectory = "java"
|
||||||
|
|
||||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (info.sourceFiles.size > 0) {
|
if (info.sourceFiles.size > 0) {
|
||||||
|
|
|
@ -115,6 +115,8 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
val compiler = object: ICompiler {
|
val compiler = object: ICompiler {
|
||||||
override val sourceSuffixes = listOf("kt")
|
override val sourceSuffixes = listOf("kt")
|
||||||
|
|
||||||
|
override val sourceDirectory = "kotlin"
|
||||||
|
|
||||||
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
override fun compile(project: Project, context: KobaltContext, info: CompilerActionInfo): TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (info.sourceFiles.size > 0) {
|
if (info.sourceFiles.size > 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue