mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27: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
|
@ -8,7 +8,10 @@ import com.beust.kobalt.archive.Archives
|
|||
import com.beust.kobalt.internal.ActorUtils
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
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.PackagingPlugin
|
||||
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 {
|
||||
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 jarName = (jarFileName ?: KFiles.joinDir(KFiles.libsDir(project),
|
||||
context.variant.archiveName(project, null, ".jar")))
|
||||
|
|
|
@ -80,7 +80,15 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
//
|
||||
val allIncludedFiles = arrayListOf<IncludedFile>()
|
||||
val outputFiles = arrayListOf<File>()
|
||||
val jarsWithMainClass = arrayListOf<String>()
|
||||
|
||||
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 ->
|
||||
archives.forEach {
|
||||
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
|
||||
val inputFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
||||
val foundFiles = includedFile.allFromFiles(project.directory)
|
||||
|
@ -119,9 +133,6 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
|||
{ -> outMd5 },
|
||||
{ project ->
|
||||
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]!!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue