mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
parent
981979d9ed
commit
e2b8d78cac
7 changed files with 37 additions and 37 deletions
|
@ -41,10 +41,11 @@ 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 = compilerContributors.flatMap { compiler.sourceSuffixes }
|
val sourceSuffixes = compiler.sourceSuffixes
|
||||||
result.addAll(sourceSuffixes.flatMap {
|
val suffixes = sourceSuffixes.flatMap { thisSuffix ->
|
||||||
sourceDirectories(project, it)
|
sourceDirectories(project, thisSuffix)
|
||||||
})
|
}
|
||||||
|
result.addAll(suffixes)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,13 +55,13 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
/**
|
/**
|
||||||
* Might be used by plug-ins.
|
* Might be used by plug-ins.
|
||||||
*/
|
*/
|
||||||
fun resDirectories(project: Project) : List<File> = sourceDirectories(project, "res")
|
fun resourceDirectories(project: Project) = sourceDirectories(project, "resources")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suffix is either "java" (to find source files) or "res" (to find resources)
|
* suffix is either "java" (to find source files) or "resources" (to find resources)
|
||||||
*/
|
*/
|
||||||
fun sourceDirectories(project: Project, suffix: String) : List<File> {
|
private fun sourceDirectories(project: Project, suffix: String) : Set<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = hashSetOf<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)
|
||||||
|
@ -85,7 +86,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
|
|
||||||
// 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
|
return result.filter { it.exists() }.toHashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generated directory, if applicable
|
// Generated directory, if applicable
|
||||||
|
@ -93,7 +94,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
result.add(it)
|
result.add(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result.filter { File(project.directory, it.path).exists() }.toHashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
fun archiveName(project: Project, archiveName: String?, suffix: String) : String {
|
||||||
|
@ -102,9 +103,10 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
||||||
archiveName ?: project.name + "-" + project.version + suffix
|
archiveName ?: project.name + "-" + project.version + suffix
|
||||||
} else {
|
} else {
|
||||||
val base = if (archiveName != null) archiveName.substring(0, archiveName.length - suffix.length)
|
val base = if (archiveName != null) archiveName.substring(0, archiveName.length - suffix.length)
|
||||||
else project.name + "-" + project.version
|
else project.name + "-" + project.version
|
||||||
val result: String =
|
val flavor = if (productFlavor.name.isEmpty()) "" else "-" + productFlavor.name
|
||||||
base + "-${productFlavor.name}" + "-${buildType.name}"
|
val type = if (buildType.name.isEmpty()) "" else "-" + buildType.name
|
||||||
|
val result: String = base + flavor + type + suffix
|
||||||
|
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,7 +174,7 @@ open class JvmCompilerPlugin @Inject constructor(
|
||||||
} else {
|
} else {
|
||||||
compilerContributors.forEach { contributor ->
|
compilerContributors.forEach { contributor ->
|
||||||
contributor.compilersFor(project, context).forEach { compiler ->
|
contributor.compilersFor(project, context).forEach { compiler ->
|
||||||
val sourceFiles = KFiles.findSourceFiles(project,
|
val sourceFiles = KFiles.findSourceFiles(project.directory,
|
||||||
context.sourceDirectories(project).map { it.path }, compiler.sourceSuffixes)
|
context.sourceDirectories(project).map { it.path }, compiler.sourceSuffixes)
|
||||||
if (sourceFiles.size > 0) {
|
if (sourceFiles.size > 0) {
|
||||||
// TODO: createCompilerActionInfo recalculates the source files, only compute them
|
// TODO: createCompilerActionInfo recalculates the source files, only compute them
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class JarUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun addFiles(directory: String, files: List<IncludedFile>, target: ZipOutputStream,
|
fun addFiles(directory: String, files: List<IncludedFile>, target: ZipOutputStream,
|
||||||
expandJarFiles: Boolean,
|
expandJarFiles: Boolean,
|
||||||
onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
||||||
files.forEach {
|
files.forEach {
|
||||||
|
@ -32,7 +32,7 @@ public class JarUtils {
|
||||||
private val DEFAULT_JAR_EXCLUDES =
|
private val DEFAULT_JAR_EXCLUDES =
|
||||||
Glob("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
|
Glob("META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA")
|
||||||
|
|
||||||
public fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
|
fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
|
||||||
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
||||||
val allFiles = file.allFromFiles(directory)
|
val allFiles = file.allFromFiles(directory)
|
||||||
allFiles.forEach { relSource ->
|
allFiles.forEach { relSource ->
|
||||||
|
|
|
@ -288,26 +288,24 @@ class KFiles {
|
||||||
/**
|
/**
|
||||||
* TODO: cache these per project so we don't do it more than once.
|
* TODO: cache these per project so we don't do it more than once.
|
||||||
*/
|
*/
|
||||||
fun findSourceFiles(project: Project, sourceDirectories: Collection<String>,
|
fun findSourceFiles(projectDirectory: String, sourceDirectories: Collection<String>,
|
||||||
suffixes: List<String>) : Set<String> {
|
suffixes: List<String>) : Set<String> {
|
||||||
val result = hashSetOf<String>()
|
val result = hashSetOf<String>()
|
||||||
Kobalt.context?.let {
|
sourceDirectories.forEach { source ->
|
||||||
sourceDirectories.forEach { source ->
|
val sourceDir = File(KFiles.joinDir(projectDirectory, source))
|
||||||
val sourceDir = File(KFiles.joinDir(project.directory, source))
|
if (sourceDir.exists()) {
|
||||||
if (sourceDir.exists()) {
|
KFiles.findRecursively(sourceDir, { file ->
|
||||||
KFiles.findRecursively(sourceDir, { file ->
|
val ind = file.lastIndexOf(".")
|
||||||
val ind = file.lastIndexOf(".")
|
if (ind >= 0) {
|
||||||
if (ind >= 0) {
|
val suffix = file.substring(ind + 1)
|
||||||
val suffix = file.substring(ind + 1)
|
if (suffixes.contains(suffix)) {
|
||||||
if (suffixes.contains(suffix)) {
|
result.add(file)
|
||||||
result.add(file)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
false
|
}
|
||||||
})
|
false
|
||||||
} else {
|
})
|
||||||
log(2, "Skipping nonexistent directory $sourceDir")
|
} else {
|
||||||
}
|
log(2, "Skipping nonexistent directory $sourceDir")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -27,7 +27,7 @@ class JavaPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
// IBuildConfigContributor
|
// IBuildConfigContributor
|
||||||
|
|
||||||
private fun hasSourceFiles(project: Project)
|
private fun hasSourceFiles(project: Project)
|
||||||
= KFiles.findSourceFiles(project, project.sourceDirectories, listOf("java")).size > 0
|
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, listOf("java")).size > 0
|
||||||
|
|
||||||
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors)
|
||||||
// IBuildConfigContributor
|
// IBuildConfigContributor
|
||||||
|
|
||||||
private fun hasSourceFiles(project: Project)
|
private fun hasSourceFiles(project: Project)
|
||||||
= KFiles.findSourceFiles(project, project.sourceDirectories, listOf("kt")).size > 0
|
= KFiles.findSourceFiles(project.directory, project.sourceDirectories, listOf("kt")).size > 0
|
||||||
|
|
||||||
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
override fun affinity(project: Project) = if (hasSourceFiles(project)) 1 else 0
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
result.add(IncludedFile(From(prefixPath.toString() + "/"), To(""), fileSpecs))
|
result.add(IncludedFile(From(prefixPath.toString() + "/"), To(""), fileSpecs))
|
||||||
|
|
||||||
// Resources, if applicable
|
// Resources, if applicable
|
||||||
project.sourceDirectories.filter { it.contains("resources") }.forEach {
|
context.variant.resourceDirectories(project).forEach {
|
||||||
result.add(IncludedFile(From(it), To(""), listOf(IFileSpec.GlobSpec("**"))))
|
result.add(IncludedFile(From(it.path), To(""), listOf(IFileSpec.GlobSpec("**"))))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue