1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

Better jar default naming.

This commit is contained in:
Cedric Beust 2016-06-14 23:43:20 -08:00
parent 960472be68
commit 182345d8e2
6 changed files with 16 additions and 15 deletions

View file

@ -21,6 +21,8 @@ class Archives {
private val DEFAULT_STREAM_FACTORY = { os : OutputStream -> ZipOutputStream(os) }
fun defaultArchiveName(project: Project) = project.name + "-" + project.version
fun generateArchive(project: Project,
context: KobaltContext,
archiveName: String?,

View file

@ -1,11 +1,14 @@
package com.beust.kobalt.archive
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
/**
* A jar is exactly like a zip with the addition of a manifest and an optional fatJar boolean.
*/
open class Jar(override var name: String? = null, var fatJar: Boolean = false) : Zip(name), AttributeHolder {
open class Jar(override val project: Project,
override var name : String = Archives.defaultArchiveName(project) + ".jar",
var fatJar: Boolean = false) : Zip(project, name), AttributeHolder {
@Directive
fun manifest(init: Manifest.(p: Manifest) -> Unit) : Manifest {
val m = Manifest(this)

View file

@ -1,8 +1,10 @@
package com.beust.kobalt.archive
import com.beust.kobalt.api.Project
import com.beust.kobalt.glob
class War(override var name: String? = null) : Jar(name), AttributeHolder {
class War(override val project: Project, override var name: String = Archives.defaultArchiveName(project) + ".war")
: Jar(project, name), AttributeHolder {
init {
include(from("src/main/webapp"),to(""), glob("**"))
include(from("kobaltBuild/classes"), to("WEB-INF/classes"), glob("**"))

View file

@ -2,12 +2,13 @@ package com.beust.kobalt.archive
import com.beust.kobalt.Glob
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.misc.From
import com.beust.kobalt.misc.IncludedFile
import com.beust.kobalt.misc.To
open class Zip(open var name: String? = null) {
open class Zip(open val project: Project, open var name: String = Archives.defaultArchiveName(project) + ".zip") {
val excludes = arrayListOf<Glob>()
@Directive

View file

@ -5,7 +5,6 @@ import com.beust.kobalt.api.*
import com.beust.kobalt.api.annotation.Directive
import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.archive.Jar
import com.beust.kobalt.internal.ActorUtils
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KFiles
@ -66,14 +65,8 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
}
private fun isFatJar(packages: List<PackageConfig>, jarName: String): Boolean {
packages.forEach { pc ->
(pc.jars as List<Jar>).forEach { jar ->
if ((jar.name == null || jar.name == jarName) && jar.fatJar) {
return true
}
}
}
return false
val foundJar = packages.flatMap { it.jars }.filter { jarName.endsWith(it.name) }
return foundJar.size == 1 && foundJar[0].fatJar
}
// IRunContributor

View file

@ -183,19 +183,19 @@ class PackageConfig(val project: Project) : AttributeHolder {
}
@Directive
fun jar(init: Jar.(p: Jar) -> Unit) = Jar().apply {
fun jar(init: Jar.(p: Jar) -> Unit) = Jar(project).apply {
init(this)
jars.add(this)
}
@Directive
fun zip(init: Zip.(p: Zip) -> Unit) = Zip().apply {
fun zip(init: Zip.(p: Zip) -> Unit) = Zip(project).apply {
init(this)
zips.add(this)
}
@Directive
fun war(init: War.(p: War) -> Unit) = War().apply {
fun war(init: War.(p: War) -> Unit) = War(project).apply {
init(this)
wars.add(this)
}