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.api.License
import com.beust.kobalt.api.Scm
import com.beust.kobalt.internal.test
import com.beust.kobalt.plugin.java.javaProject
import com.beust.kobalt.plugin.kotlin.kotlinProject
@ -25,16 +27,17 @@ val wrapper = javaProject {
name = "kobalt-wrapper"
version = readVersion()
directory = homeDir("kotlin/kobalt/modules/wrapper")
}
val assembleWrapper = assemble(wrapper) {
jar {
name = wrapper.name + ".jar"
manifest {
attributes("Main-Class", "com.beust.kobalt.wrapper.Main")
assemble {
jar {
name = projectName + ".jar"
manifest {
attributes("Main-Class", "com.beust.kobalt.wrapper.Main")
}
}
}
}
val kobalt = kotlinProject(wrapper) {
name = "kobalt"
group = "com.beust"
@ -42,9 +45,8 @@ val kobalt = kotlinProject(wrapper) {
version = readVersion()
description = "A build system in Kotlin"
url = "http://beust.com/kobalt"
licenses = listOf(com.beust.kobalt.api.License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
scm = com.beust.kobalt.api.Scm(
url = "http://github.com/cbeust/kobalt",
licenses = listOf(License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
scm = Scm(url = "http://github.com/cbeust/kobalt",
connection = "https://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"
)
}
}
val testKobalt = test(kobalt) {
args("-log", "2", "src/test/resources/testng.xml")
}
val assembleKobalt = assemble(kobalt) {
mavenJars {
fatJar = true
manifest {
attributes("Main-Class", "com.beust.kobalt.MainKt")
assemble {
mavenJars {
fatJar = true
manifest {
attributes("Main-Class", "com.beust.kobalt.MainKt")
}
}
zip {
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")
include(from("${kobalt.buildDirectory}/libs"), to("kobalt/wrapper"),
"${kobalt.name}-${kobalt.version}.jar")
include(from("modules/wrapper/${kobalt.buildDirectory}/libs"), to("kobalt/wrapper"),
"${kobalt.name}-wrapper.jar")
test {
args("-log", "2", "src/test/resources/testng.xml")
}
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 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>) {

View file

@ -14,7 +14,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
abstract public class JvmCompilerPlugin @Inject constructor(
abstract class JvmCompilerPlugin @Inject constructor(
open val localRepo: LocalRepo,
open val files: KFiles,
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) {
project.testArgs.addAll(arg)
}
}
@Directive
public fun test(project: Project, init: TestConfig.() -> Unit) : TestConfig {
val result = TestConfig(project)
fun Project.test(init: TestConfig.() -> Unit) : TestConfig {
val result = TestConfig(this)
result.init()
return result
}

View file

@ -15,7 +15,7 @@ import javax.inject.Inject
import javax.inject.Singleton
@Singleton
public class KotlinPlugin @Inject constructor(
class KotlinPlugin @Inject constructor(
override val localRepo: LocalRepo,
override val files: KFiles,
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.
*/
@Directive
public fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
fun kotlinProject(vararg project: Project, init: KotlinProject.() -> Unit): KotlinProject {
with(KotlinProject()) {
init()
Kobalt.declareProjectDependencies(this, project)
@ -113,7 +113,7 @@ class KotlinCompilerConfig {
}
@Directive
fun kotlinCompiler(init: KotlinCompilerConfig.() -> Unit) : KotlinCompilerConfig {
fun Project.kotlinCompiler(init: KotlinCompilerConfig.() -> Unit) : KotlinCompilerConfig {
with (KotlinCompilerConfig()) {
init()
return this

View file

@ -1,9 +1,8 @@
package com.beust.kobalt.plugin.packaging
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.IFileSpec.FileSpec
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.Kobalt
import com.beust.kobalt.api.Project
@ -29,14 +28,14 @@ import javax.inject.Inject
import javax.inject.Singleton
@Directive
public fun assemble(project: Project, init: Package.(p: Project) -> Unit): Package {
val pd = Package(project)
pd.init(project)
fun Project.assemble(init: Package.(p: Project) -> Unit): Package {
val pd = Package(this)
pd.init(this)
return pd
}
@Singleton
public class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
class PackagingPlugin @Inject constructor(val dependencyManager : DependencyManager,
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
companion object {
@ -67,7 +66,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
}
ex.forEach {
if (it.matches(Paths.get(file.name))) {
log(2, "Excluding ${file}")
log(2, "Excluding $file")
return true
}
}
@ -175,7 +174,7 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
if (File(fromPath).exists()) {
spec.toFiles(fromPath).forEach { file ->
if (!File(fromPath, file.path).exists()) {
throw AssertionError("File should exist: ${file}")
throw AssertionError("File should exist: $file")
}
if (!isExcluded(file, excludes)) {
@ -186,11 +185,11 @@ public class PackagingPlugin @Inject constructor(val dependencyManager : Depende
}
} 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) {
log(3, "Including specs ${includedSpecs}")
log(3, "Including specs $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 result = File(archiveDir.path, fullArchiveName)
val outStream = outputStreamFactory(FileOutputStream(result))
log(2, "Creating ${result}")
log(2, "Creating $result")
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.close()
log(1, " Created ${result}")
log(1, " Created $result")
return result
}

View file

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