mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
Run the correct jar name, even if its name was changed.
Fixes https://github.com/cbeust/kobalt/issues/355
This commit is contained in:
parent
904c405dd7
commit
f29c974c49
3 changed files with 23 additions and 5 deletions
|
@ -16,6 +16,8 @@ class Archives {
|
||||||
companion object {
|
companion object {
|
||||||
@ExportedProjectProperty(doc = "The name of the jar file", type = "String")
|
@ExportedProjectProperty(doc = "The name of the jar file", type = "String")
|
||||||
const val JAR_NAME = "jarName"
|
const val JAR_NAME = "jarName"
|
||||||
|
@ExportedProjectProperty(doc = "The name of the a jar file with a main() method", type = "String")
|
||||||
|
const val JAR_NAME_WITH_MAIN_CLASS = "jarNameWithMainClass"
|
||||||
|
|
||||||
private val DEFAULT_STREAM_FACTORY = { os : OutputStream -> ZipOutputStream(os) }
|
private val DEFAULT_STREAM_FACTORY = { os : OutputStream -> ZipOutputStream(os) }
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,10 @@ import com.beust.kobalt.archive.Archives
|
||||||
import com.beust.kobalt.internal.ActorUtils
|
import com.beust.kobalt.internal.ActorUtils
|
||||||
import com.beust.kobalt.maven.DependencyManager
|
import com.beust.kobalt.maven.DependencyManager
|
||||||
import com.beust.kobalt.maven.aether.Scope
|
import com.beust.kobalt.maven.aether.Scope
|
||||||
import com.beust.kobalt.misc.*
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.KobaltExecutors
|
||||||
|
import com.beust.kobalt.misc.RunCommand
|
||||||
|
import com.beust.kobalt.misc.kobaltLog
|
||||||
import com.beust.kobalt.plugin.packaging.PackageConfig
|
import com.beust.kobalt.plugin.packaging.PackageConfig
|
||||||
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
import com.beust.kobalt.plugin.packaging.PackagingPlugin
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
@ -97,7 +100,9 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runJarFile(project: Project, context: KobaltContext, config: ApplicationConfig) : TaskResult {
|
private fun runJarFile(project: Project, context: KobaltContext, config: ApplicationConfig) : TaskResult {
|
||||||
val fileName = project.projectProperties.get(Archives.JAR_NAME) as String
|
val fileName = project.projectProperties.get(Archives.JAR_NAME_WITH_MAIN_CLASS)?.toString()
|
||||||
|
?: throw KobaltException("Couldn't find any jar file with a main class in it")
|
||||||
|
|
||||||
val jarFileName = KFiles.joinDir(KFiles.libsDir(project), fileName)
|
val jarFileName = KFiles.joinDir(KFiles.libsDir(project), fileName)
|
||||||
val jarName = (jarFileName ?: KFiles.joinDir(KFiles.libsDir(project),
|
val jarName = (jarFileName ?: KFiles.joinDir(KFiles.libsDir(project),
|
||||||
context.variant.archiveName(project, null, ".jar")))
|
context.variant.archiveName(project, null, ".jar")))
|
||||||
|
|
|
@ -80,7 +80,15 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
//
|
//
|
||||||
val allIncludedFiles = arrayListOf<IncludedFile>()
|
val allIncludedFiles = arrayListOf<IncludedFile>()
|
||||||
val outputFiles = arrayListOf<File>()
|
val outputFiles = arrayListOf<File>()
|
||||||
|
val jarsWithMainClass = arrayListOf<String>()
|
||||||
|
|
||||||
allConfigs.forEach { packageConfig ->
|
allConfigs.forEach { packageConfig ->
|
||||||
|
packageConfig.jars.forEach {
|
||||||
|
if (it.attributes.any{ it.first == "Main-Class"}) {
|
||||||
|
jarsWithMainClass.add(it.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives ->
|
listOf(packageConfig.jars, packageConfig.wars, packageConfig.zips).forEach { archives ->
|
||||||
archives.forEach {
|
archives.forEach {
|
||||||
val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it)
|
val files = jarGenerator.findIncludedFiles(packageConfig.project, context, it)
|
||||||
|
@ -92,6 +100,12 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jarsWithMainClass.any()) {
|
||||||
|
project.projectProperties.put(Archives.JAR_NAME_WITH_MAIN_CLASS, jarsWithMainClass[0])
|
||||||
|
}
|
||||||
|
project.projectProperties.put(Archives.JAR_NAME,
|
||||||
|
context.variant.archiveName(project, null, ".jar"))
|
||||||
|
|
||||||
// Turn the IncludedFiles into actual Files
|
// Turn the IncludedFiles into actual Files
|
||||||
val inputFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
val inputFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
||||||
val foundFiles = includedFile.allFromFiles(project.directory)
|
val foundFiles = includedFile.allFromFiles(project.directory)
|
||||||
|
@ -119,9 +133,6 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
{ -> outMd5 },
|
{ -> outMd5 },
|
||||||
{ project ->
|
{ project ->
|
||||||
try {
|
try {
|
||||||
project.projectProperties.put(Archives.JAR_NAME,
|
|
||||||
context.variant.archiveName(project, null, ".jar"))
|
|
||||||
|
|
||||||
fun findFiles(ff: ArchiveGenerator, zip: Zip) : List<IncludedFile> {
|
fun findFiles(ff: ArchiveGenerator, zip: Zip) : List<IncludedFile> {
|
||||||
val archiveName = ff.fullArchiveName(project, context, zip.name).name
|
val archiveName = ff.fullArchiveName(project, context, zip.name).name
|
||||||
return zipToFiles[archiveName]!!
|
return zipToFiles[archiveName]!!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue