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

New build syntax.

This commit is contained in:
Cedric Beust 2015-10-29 03:31:30 -07:00
parent 70c4a3960f
commit fded2800b6
6 changed files with 62 additions and 57 deletions

View file

@ -1,4 +1,6 @@
import com.beust.kobalt.* import com.beust.kobalt.*
import com.beust.kobalt.api.License
import com.beust.kobalt.api.Scm
import com.beust.kobalt.internal.test import com.beust.kobalt.internal.test
import com.beust.kobalt.plugin.java.javaProject import com.beust.kobalt.plugin.java.javaProject
import com.beust.kobalt.plugin.kotlin.kotlinProject import com.beust.kobalt.plugin.kotlin.kotlinProject
@ -25,16 +27,17 @@ val wrapper = javaProject {
name = "kobalt-wrapper" name = "kobalt-wrapper"
version = readVersion() version = readVersion()
directory = homeDir("kotlin/kobalt/modules/wrapper") directory = homeDir("kotlin/kobalt/modules/wrapper")
}
val assembleWrapper = assemble(wrapper) { assemble {
jar { jar {
name = wrapper.name + ".jar" name = projectName + ".jar"
manifest { manifest {
attributes("Main-Class", "com.beust.kobalt.wrapper.Main") attributes("Main-Class", "com.beust.kobalt.wrapper.Main")
}
} }
} }
} }
val kobalt = kotlinProject(wrapper) { val kobalt = kotlinProject(wrapper) {
name = "kobalt" name = "kobalt"
group = "com.beust" group = "com.beust"
@ -42,9 +45,8 @@ val kobalt = kotlinProject(wrapper) {
version = readVersion() version = readVersion()
description = "A build system in Kotlin" description = "A build system in Kotlin"
url = "http://beust.com/kobalt" url = "http://beust.com/kobalt"
licenses = listOf(com.beust.kobalt.api.License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0")) licenses = listOf(License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
scm = com.beust.kobalt.api.Scm( scm = Scm(url = "http://github.com/cbeust/kobalt",
url = "http://github.com/cbeust/kobalt",
connection = "https://github.com/cbeust/kobalt.git", connection = "https://github.com/cbeust/kobalt.git",
developerConnection = "git@github.com:cbeust/kobalt.git") developerConnection = "git@github.com:cbeust/kobalt.git")
@ -70,34 +72,35 @@ val kobalt = kotlinProject(wrapper) {
"com.google.code.gson:gson:2.4" "com.google.code.gson:gson:2.4"
) )
} }
}
val testKobalt = test(kobalt) { assemble {
args("-log", "2", "src/test/resources/testng.xml") mavenJars {
} fatJar = true
manifest {
val assembleKobalt = assemble(kobalt) { attributes("Main-Class", "com.beust.kobalt.MainKt")
mavenJars { }
fatJar = true }
manifest { zip {
attributes("Main-Class", "com.beust.kobalt.MainKt") include("kobaltw")
include(from("$buildDirectory/libs"), to("kobalt/wrapper"),
"$projectName-$version.jar")
include(from("modules/wrapper/$buildDirectory/libs"), to("kobalt/wrapper"),
"$projectName-wrapper.jar")
} }
} }
zip {
include("kobaltw") test {
include(from("${kobalt.buildDirectory}/libs"), to("kobalt/wrapper"), args("-log", "2", "src/test/resources/testng.xml")
"${kobalt.name}-${kobalt.version}.jar") }
include(from("modules/wrapper/${kobalt.buildDirectory}/libs"), to("kobalt/wrapper"),
"${kobalt.name}-wrapper.jar") kotlinCompiler {
args("-nowarn")
}
jcenter {
publish = true
file("$buildDirectory/libs/$name-$version.zip", "$name/$version/$name-$version.zip")
} }
} }
val cs = kotlinCompiler {
args("-nowarn")
}
val jc = jcenter(kobalt) {
publish = true
file("${kobalt.buildDirectory}/libs/${kobalt.name}-${kobalt.version}.zip",
"${kobalt.name}/${kobalt.version}/${kobalt.name}-${kobalt.version}.zip")
}

View file

@ -86,6 +86,10 @@ open public class Project(
val testDependencies : ArrayList<IClasspathDependency> = arrayListOf() val testDependencies : ArrayList<IClasspathDependency> = arrayListOf()
val testProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf() val testProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
/** Used to disambiguate various name properties */
@Directive
val projectName: String get() = name!!
} }
public class Sources(val project: Project, val sources: ArrayList<String>) { public class Sources(val project: Project, val sources: ArrayList<String>) {

View file

@ -14,7 +14,7 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
abstract public class JvmCompilerPlugin @Inject constructor( abstract class JvmCompilerPlugin @Inject constructor(
open val localRepo: LocalRepo, open val localRepo: LocalRepo,
open val files: KFiles, open val files: KFiles,
open val depFactory: DepFactory, open val depFactory: DepFactory,
@ -121,15 +121,15 @@ abstract public class JvmCompilerPlugin @Inject constructor(
} }
public class TestConfig(val project: Project) { class TestConfig(val project: Project) {
fun args(vararg arg: String) { fun args(vararg arg: String) {
project.testArgs.addAll(arg) project.testArgs.addAll(arg)
} }
} }
@Directive @Directive
public fun test(project: Project, init: TestConfig.() -> Unit) : TestConfig { fun Project.test(init: TestConfig.() -> Unit) : TestConfig {
val result = TestConfig(project) val result = TestConfig(this)
result.init() result.init()
return result return result
} }

View file

@ -15,7 +15,7 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
public class KotlinPlugin @Inject constructor( class KotlinPlugin @Inject constructor(
override val localRepo: LocalRepo, override val localRepo: LocalRepo,
override val files: KFiles, override val files: KFiles,
override val depFactory: DepFactory, override val depFactory: DepFactory,
@ -98,7 +98,7 @@ public class KotlinPlugin @Inject constructor(
* @param project: the list of projects that need to be built before this one. * @param project: the list of projects that need to be built before this one.
*/ */
@Directive @Directive
public fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject { fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
with(KotlinProject()) { with(KotlinProject()) {
init() init()
Kobalt.declareProjectDependencies(this, project) Kobalt.declareProjectDependencies(this, project)
@ -113,7 +113,7 @@ class KotlinCompilerConfig {
} }
@Directive @Directive
fun kotlinCompiler(init: KotlinCompilerConfig.() -> Unit) : KotlinCompilerConfig { fun Project.kotlinCompiler(init: KotlinCompilerConfig.() -> Unit) : KotlinCompilerConfig {
with (KotlinCompilerConfig()) { with (KotlinCompilerConfig()) {
init() init()
return this return this

View file

@ -1,9 +1,8 @@
package com.beust.kobalt.plugin.packaging package com.beust.kobalt.plugin.packaging
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.IFileSpec.FileSpec import com.beust.kobalt.IFileSpec.FileSpec
import com.beust.kobalt.IFileSpec.Glob import com.beust.kobalt.IFileSpec.Glob
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.Plugins
import com.beust.kobalt.api.BasePlugin import com.beust.kobalt.api.BasePlugin
import com.beust.kobalt.api.Kobalt import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project import com.beust.kobalt.api.Project
@ -29,14 +28,14 @@ import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Directive @Directive
public fun assemble(project: Project, init: Package.(p: Project) -> Unit): Package { fun Project.assemble(init: Package.(p: Project) -> Unit): Package {
val pd = Package(project) val pd = Package(this)
pd.init(project) pd.init(this)
return pd return pd
} }
@Singleton @Singleton
public class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager, class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() { val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
companion object { companion object {
@ -67,7 +66,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
} }
ex.forEach { ex.forEach {
if (it.matches(Paths.get(file.name))) { if (it.matches(Paths.get(file.name))) {
log(2, "Excluding ${file}") log(2, "Excluding $file")
return true return true
} }
} }
@ -175,7 +174,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
if (File(fromPath).exists()) { if (File(fromPath).exists()) {
spec.toFiles(fromPath).forEach { file -> spec.toFiles(fromPath).forEach { file ->
if (!File(fromPath, file.path).exists()) { if (!File(fromPath, file.path).exists()) {
throw AssertionError("File should exist: ${file}") throw AssertionError("File should exist: $file")
} }
if (!isExcluded(file, excludes)) { if (!isExcluded(file, excludes)) {
@ -186,11 +185,11 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
} }
} else { } else {
warn("Directory ${fromPath} doesn't exist, not including it in the jar") warn("Directory $fromPath doesn't exist, not including it in the jar")
} }
} }
if (includedSpecs.size > 0) { if (includedSpecs.size > 0) {
log(3, "Including specs ${includedSpecs}") log(3, "Including specs $includedSpecs")
result.add(IncludedFile(From(includedFile.from), To(includedFile.to), includedSpecs)) result.add(IncludedFile(From(includedFile.from), To(includedFile.to), includedSpecs))
} }
} }
@ -213,12 +212,12 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
val fullArchiveName = archiveName ?: arrayListOf(project.name!!, project.version!!).joinToString("-") + suffix val fullArchiveName = archiveName ?: arrayListOf(project.name!!, project.version!!).joinToString("-") + suffix
val result = File(archiveDir.path, fullArchiveName) val result = File(archiveDir.path, fullArchiveName)
val outStream = outputStreamFactory(FileOutputStream(result)) val outStream = outputStreamFactory(FileOutputStream(result))
log(2, "Creating ${result}") log(2, "Creating $result")
JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles) JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles)
log(2, "Added ${includedFiles.size} files to ${result}") log(2, text = "Added ${includedFiles.size} files to $result")
outStream.flush() outStream.flush()
outStream.close() outStream.close()
log(1, " Created ${result}") log(1, " Created $result")
return result return result
} }

View file

@ -114,10 +114,9 @@ data class JCenterConfiguration(val project: Project) {
} }
@Directive @Directive
public fun jcenter(project: Project, ini: JCenterConfiguration.() -> Unit) public fun Project.jcenter(ini: JCenterConfiguration.() -> Unit) : JCenterConfiguration {
: JCenterConfiguration { val pd = JCenterConfiguration(this)
val pd = JCenterConfiguration(project)
pd.ini() pd.ini()
(Kobalt.findPlugin("publish") as PublishPlugin).addConfiguration(project.name!!, pd) (Kobalt.findPlugin("publish") as PublishPlugin).addConfiguration(name!!, pd)
return pd return pd
} }