mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-27 08:38:13 -07:00
Incremental packaging.
This commit is contained in:
parent
fa546e4510
commit
15b43c0127
12 changed files with 94 additions and 44 deletions
|
@ -22,7 +22,7 @@ import javax.tools.ToolProvider
|
|||
@Singleton
|
||||
class JavaCompiler @Inject constructor(val jvmCompiler: JvmCompiler) {
|
||||
fun compilerAction(executable: File) = object : ICompilerAction {
|
||||
override fun compile(info: CompilerActionInfo): TaskResult {
|
||||
override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult {
|
||||
if (info.sourceFiles.isEmpty()) {
|
||||
warn("No source files to compile")
|
||||
return TaskResult()
|
||||
|
|
|
@ -26,7 +26,7 @@ import kotlin.properties.Delegates
|
|||
* @since 08 03, 2015
|
||||
*/
|
||||
@Singleton
|
||||
class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
||||
class KotlinCompiler @Inject constructor(
|
||||
val files: KFiles,
|
||||
val dependencyManager: DependencyManager,
|
||||
val depFactory: DepFactory,
|
||||
|
@ -37,7 +37,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
|||
}
|
||||
|
||||
val compilerAction = object: ICompilerAction {
|
||||
override fun compile(info: CompilerActionInfo): TaskResult {
|
||||
override fun compile(projectName: String?, info: CompilerActionInfo): TaskResult {
|
||||
if (info.sourceFiles.size > 1) {
|
||||
log(1, " Compiling ${info.sourceFiles.size} files")
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
|||
*(info.compilerArgs.toTypedArray()),
|
||||
*(info.sourceFiles.toTypedArray())
|
||||
)
|
||||
val success = invokeCompiler(cp, allArgs)
|
||||
val success = invokeCompiler(projectName ?: "kobalt-" + Random().nextInt(), cp, allArgs)
|
||||
return TaskResult(success)
|
||||
}
|
||||
|
||||
|
@ -72,8 +72,8 @@ class KotlinCompiler @Inject constructor(val localRepo : LocalRepo,
|
|||
* There are plenty of ways in which this method can break but this will be immediately
|
||||
* apparent if it happens.
|
||||
*/
|
||||
private fun invokeCompiler(cp: List<File>, args: Array<String>): Boolean {
|
||||
val allArgs = listOf("-module-name", "module" + Random().nextInt()) + args
|
||||
private fun invokeCompiler(projectName: String, cp: List<File>, args: Array<String>): Boolean {
|
||||
val allArgs = listOf("-module-name", "project-" + projectName) + args
|
||||
log(2, "Calling kotlinc " + allArgs.joinToString(" "))
|
||||
val result : Boolean =
|
||||
if (true) {
|
||||
|
|
|
@ -14,7 +14,7 @@ import java.nio.file.Paths
|
|||
import java.util.jar.JarOutputStream
|
||||
|
||||
class JarGenerator @Inject constructor(val dependencyManager: DependencyManager){
|
||||
fun includedFilesForJarFile(project: Project, context: KobaltContext, jar: Jar) : List<IncludedFile> {
|
||||
fun findIncludedFiles(project: Project, context: KobaltContext, jar: Jar) : List<IncludedFile> {
|
||||
//
|
||||
// Add all the applicable files for the current project
|
||||
//
|
||||
|
@ -73,7 +73,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
|||
}
|
||||
|
||||
fun generateJar(project: Project, context: KobaltContext, jar: Jar) : File {
|
||||
val allFiles = includedFilesForJarFile(project, context, jar)
|
||||
val allFiles = findIncludedFiles(project, context, jar)
|
||||
|
||||
//
|
||||
// Generate the manifest
|
||||
|
|
|
@ -116,7 +116,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val file = File(KFiles.joinDir(directory, root.from, relFile.path))
|
||||
if (file.isFile) {
|
||||
if (file.lastModified() > lastModified) {
|
||||
log(2, " Outdated $file and $output "
|
||||
log(2, " TS - Outdated $file and $output "
|
||||
+ Date(file.lastModified()) + " " + Date(output.lastModified()))
|
||||
return true
|
||||
}
|
||||
|
@ -139,12 +139,43 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
super.apply(project, context)
|
||||
project.projectProperties.put(LIBS_DIR, libsDir(project))
|
||||
taskContributor.addVariantTasks(this, project, context, "assemble", runAfter = listOf("compile"),
|
||||
runTask = { taskAssemble(project) })
|
||||
runTask = { doTaskAssemble(project) })
|
||||
}
|
||||
|
||||
private fun findIncludedFiles(project: Project) : List<File> {
|
||||
val inf = arrayListOf<IncludedFile>()
|
||||
packages.filter { it.project.name == project.name }.forEach { pkg ->
|
||||
pkg.jars.forEach { inf.addAll(jarGenerator.findIncludedFiles(pkg.project, context, it)) }
|
||||
pkg.wars.forEach { inf.addAll(warGenerator.findIncludedFiles(pkg.project, context, it, projects)) }
|
||||
pkg.zips.forEach { inf.addAll(zipGenerator.findIncludedFiles(pkg.project, context, it)) }
|
||||
}
|
||||
|
||||
val result = arrayListOf<File>()
|
||||
inf.map { includedFile ->
|
||||
result.addAll(includedFile.allFromFiles().map {
|
||||
if (it.isAbsolute) it else File(KFiles.joinDir(project.directory, includedFile.from, it.path))
|
||||
})
|
||||
}
|
||||
result.forEach { if (! it.exists())
|
||||
throw RuntimeException("Should exist $it")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// @IncrementalTask(name = TASK_ASSEMBLE, description = "Package the artifacts",
|
||||
// runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE))
|
||||
// fun taskAssemble(project: Project) : IncrementalTaskInfo {
|
||||
// val i = findIncludedFiles(project)
|
||||
// val inputChecksum = Md5.toMd5Directories(i)
|
||||
// return IncrementalTaskInfo(
|
||||
// inputChecksum = inputChecksum,
|
||||
// outputChecksum = "1",
|
||||
// task = { project -> doTaskAssemble(project) })
|
||||
// }
|
||||
|
||||
@Task(name = TASK_ASSEMBLE, description = "Package the artifacts",
|
||||
runAfter = arrayOf(JvmCompilerPlugin.TASK_COMPILE))
|
||||
fun taskAssemble(project: Project) : TaskResult {
|
||||
fun doTaskAssemble(project: Project) : TaskResult {
|
||||
project.projectProperties.put(PACKAGES, packages)
|
||||
packages.filter { it.project.name == project.name }.forEach { pkg ->
|
||||
pkg.jars.forEach { jarGenerator.generateJar(pkg.project, context, it) }
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.jar.JarOutputStream
|
|||
|
||||
class WarGenerator @Inject constructor(val dependencyManager: DependencyManager){
|
||||
|
||||
fun includedFilesForJarFile(project: Project, context: KobaltContext, war: War,
|
||||
fun findIncludedFiles(project: Project, context: KobaltContext, war: War,
|
||||
projects: List<ProjectDescription>) : List<IncludedFile> {
|
||||
//
|
||||
// src/main/web app and classes
|
||||
|
@ -67,7 +67,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
|||
manifest.mainAttributes.putValue(attribute.first, attribute.second)
|
||||
}
|
||||
|
||||
val allFiles = includedFilesForJarFile(project, context, war, projects)
|
||||
val allFiles = findIncludedFiles(project, context, war, projects)
|
||||
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
||||
return PackagingPlugin.generateArchive(project, context, war.name, ".war", allFiles,
|
||||
false /* don't expand jar files */, jarFactory)
|
||||
|
|
17
src/test/kotlin/com/beust/kobalt/misc/IncludedFileTest.kt
Normal file
17
src/test/kotlin/com/beust/kobalt/misc/IncludedFileTest.kt
Normal file
|
@ -0,0 +1,17 @@
|
|||
package com.beust.kobalt.misc
|
||||
|
||||
import com.beust.kobalt.IFileSpec
|
||||
import org.testng.Assert
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
||||
@Test
|
||||
class IncludedFileTest {
|
||||
fun simple() {
|
||||
val from = "src/main/kotlin/"
|
||||
val inf = IncludedFile(From(from), To(""), listOf(IFileSpec.Glob("**.kt")))
|
||||
inf.allFromFiles().map { File(from, it.path) }.forEach {
|
||||
Assert.assertTrue(it.exists(), "Should exist: $it")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue