mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
More refactoring.
This commit is contained in:
parent
bbadd4904d
commit
7b28290b8b
7 changed files with 67 additions and 36 deletions
|
@ -62,13 +62,14 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
runTask = { taskInstall(project) })
|
||||
}
|
||||
|
||||
val zipToFiles = hashMapOf<String, List<IncludedFile>>()
|
||||
|
||||
override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo {
|
||||
val allConfigs = packages.filter { it.project.name == project.name }
|
||||
|
||||
val benchmark = benchmarkMillis {
|
||||
if (true) {
|
||||
val allIncludedFiles = arrayListOf<IncludedFile>()
|
||||
val zipToFiles = hashMapOf<String, List<IncludedFile>>()
|
||||
val outputArchives = arrayListOf<File>()
|
||||
allConfigs.forEach { packageConfig ->
|
||||
listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives ->
|
||||
|
@ -76,7 +77,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it)
|
||||
val suffixIndex = it.name.lastIndexOf(".")
|
||||
val suffix = it.name.substring(suffixIndex)
|
||||
val outputFile = jarGenerator.fullArchiveName(project, context, it.name, suffix)
|
||||
val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
|
||||
outputArchives.add(outputFile)
|
||||
allIncludedFiles.addAll(files)
|
||||
zipToFiles[it.name] = files
|
||||
|
@ -111,10 +112,27 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
try {
|
||||
project.projectProperties.put(Archives.JAR_NAME,
|
||||
context.variant.archiveName(project, null, ".jar"))
|
||||
|
||||
fun findFiles(ff: ArchiveGenerator, zip: Zip) : List<IncludedFile> {
|
||||
val archiveName = ff.fullArchiveName(project, context, zip.name).name
|
||||
return zipToFiles[archiveName]!!
|
||||
}
|
||||
|
||||
allConfigs.forEach { packageConfig ->
|
||||
packageConfig.jars.forEach { jarGenerator.generateJar(packageConfig.project, context, it) }
|
||||
packageConfig.wars.forEach { warGenerator.generateWar(packageConfig.project, context, it) }
|
||||
packageConfig.zips.forEach { zipGenerator.generateZip(packageConfig.project, context, it) }
|
||||
val pairs = listOf(
|
||||
Pair(packageConfig.jars, jarGenerator),
|
||||
Pair(packageConfig.wars, warGenerator),
|
||||
Pair(packageConfig.zips, zipGenerator)
|
||||
)
|
||||
|
||||
pairs.forEach { pair ->
|
||||
val zips = pair.first
|
||||
val generator = pair.second
|
||||
zips.forEach {
|
||||
generator.generateArchive(packageConfig.project, context, it,
|
||||
findFiles(generator, it))
|
||||
}
|
||||
}
|
||||
if (packageConfig.generatePom) {
|
||||
pomFactory.create(project).generateAndSave()
|
||||
}
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package com.beust.kobalt.plugin.packaging
|
||||
|
||||
import com.beust.kobalt.ArchiveFileFinder
|
||||
import com.beust.kobalt.ArchiveGenerator
|
||||
import com.beust.kobalt.IFileSpec
|
||||
import com.beust.kobalt.JarGenerator
|
||||
import com.beust.kobalt.api.IClasspathDependency
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.archive.Archives
|
||||
import com.beust.kobalt.archive.War
|
||||
import com.beust.kobalt.archive.Zip
|
||||
import com.beust.kobalt.internal.ParallelLogger
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
|
@ -22,7 +21,7 @@ import java.nio.file.Paths
|
|||
import java.util.jar.JarOutputStream
|
||||
|
||||
class WarGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
|
||||
: ArchiveFileFinder {
|
||||
: ArchiveGenerator {
|
||||
|
||||
companion object {
|
||||
val WEB_INF = "WEB-INF"
|
||||
|
@ -30,6 +29,8 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager,
|
|||
val LIB = "$WEB_INF/lib"
|
||||
}
|
||||
|
||||
override val suffix = ".war"
|
||||
|
||||
override fun findIncludedFiles(project: Project, context: KobaltContext, war: Zip) : List<IncludedFile> {
|
||||
//
|
||||
// src/main/web app and classes
|
||||
|
@ -82,16 +83,16 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager,
|
|||
return result
|
||||
}
|
||||
|
||||
fun generateWar(project: Project, context: KobaltContext, war: War) : File {
|
||||
override fun generateArchive(project: Project, context: KobaltContext, war: Zip,
|
||||
files: List<IncludedFile>) : File {
|
||||
|
||||
val manifest = java.util.jar.Manifest()//FileInputStream(mf))
|
||||
war.attributes.forEach { attribute ->
|
||||
manifest.mainAttributes.putValue(attribute.first, attribute.second)
|
||||
}
|
||||
|
||||
val allFiles = findIncludedFiles(project, context, war)
|
||||
val jarFactory = { os: OutputStream -> JarOutputStream(os, manifest) }
|
||||
return Archives.generateArchive(project, context, war.name, ".war", allFiles,
|
||||
return Archives.generateArchive(project, context, war.name, ".war", files,
|
||||
false /* don't expand jar files */, jarFactory)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.beust.kobalt.plugin.packaging
|
||||
|
||||
import com.beust.kobalt.ArchiveFileFinder
|
||||
import com.beust.kobalt.ArchiveGenerator
|
||||
import com.beust.kobalt.JarGenerator
|
||||
import com.beust.kobalt.api.KobaltContext
|
||||
import com.beust.kobalt.api.Project
|
||||
|
@ -12,13 +12,14 @@ import com.beust.kobalt.misc.IncludedFile
|
|||
import com.google.inject.Inject
|
||||
|
||||
class ZipGenerator @Inject constructor(val dependencyManager: DependencyManager, val kobaltLog: ParallelLogger)
|
||||
: ArchiveFileFinder {
|
||||
: ArchiveGenerator {
|
||||
|
||||
override val suffix = ".zip"
|
||||
|
||||
override fun findIncludedFiles(project: Project, context: KobaltContext, zip: Zip): List<IncludedFile> {
|
||||
return JarGenerator.findIncludedFiles(project.directory, zip.includedFiles, zip.excludes)
|
||||
}
|
||||
|
||||
fun generateZip(project: Project, context: KobaltContext, zip: Zip) {
|
||||
val allFiles = findIncludedFiles(project, context, zip)
|
||||
Archives.generateArchive(project, context, zip.name, ".zip", allFiles)
|
||||
}
|
||||
override fun generateArchive(project: Project, context: KobaltContext, zip: Zip, files: List<IncludedFile>)
|
||||
= Archives.generateArchive(project, context, zip.name, ".zip", files)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue