mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Merge branch 'master' of github.com:cbeust/kobalt
This commit is contained in:
commit
12c4a84160
10 changed files with 111 additions and 62 deletions
|
@ -1,6 +1,7 @@
|
||||||
# Kobalt
|
# Kobalt
|
||||||
|
|
||||||
<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:OpenSourceProjects_Kobalt_Build)/statusIcon" />
|
[<img src="https://teamcity.jetbrains.com/app/rest/builds/buildType:(id:OpenSourceProjects_Kobalt_Build)/statusIcon">](https://teamcity.jetbrains.com/project.html?projectId=OpenSourceProjects_Kobalt&tab=projectOverview)
|
||||||
|
|
||||||
|
|
||||||
Kobalt is a universal build system.
|
Kobalt is a universal build system.
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ object Versions {
|
||||||
val maven = "3.3.9"
|
val maven = "3.3.9"
|
||||||
val mavenResolver = "1.0.3"
|
val mavenResolver = "1.0.3"
|
||||||
val slf4j = "1.7.3"
|
val slf4j = "1.7.3"
|
||||||
val kotlin = "1.1.0"
|
val kotlin = "1.1.1"
|
||||||
val aether = "1.0.2.v20150114"
|
val aether = "1.0.2.v20150114"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.12
|
kobalt.version=1.0.13
|
|
@ -8,7 +8,7 @@ object Constants {
|
||||||
val BUILD_FILE_NAME = "Build.kt"
|
val BUILD_FILE_NAME = "Build.kt"
|
||||||
val BUILD_FILE_DIRECTORY = "kobalt/src"
|
val BUILD_FILE_DIRECTORY = "kobalt/src"
|
||||||
val BUILD_FILE_PATH = KFiles.joinDir(BUILD_FILE_DIRECTORY, BUILD_FILE_NAME)
|
val BUILD_FILE_PATH = KFiles.joinDir(BUILD_FILE_DIRECTORY, BUILD_FILE_NAME)
|
||||||
val KOTLIN_COMPILER_VERSION = "1.1.0"
|
val KOTLIN_COMPILER_VERSION = "1.1.1"
|
||||||
|
|
||||||
internal val DEFAULT_REPOS = listOf<String>(
|
internal val DEFAULT_REPOS = listOf<String>(
|
||||||
// "https://maven-central.storage.googleapis.com/",
|
// "https://maven-central.storage.googleapis.com/",
|
||||||
|
|
|
@ -58,10 +58,12 @@ class CompilerDescription(override val name: String, override val sourceDirecto
|
||||||
if (info.sourceFiles.isNotEmpty()) {
|
if (info.sourceFiles.isNotEmpty()) {
|
||||||
compiler.compile(project, context, info)
|
compiler.compile(project, context, info)
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any source files to compile")
|
warn("$name cdouldn't find any source files to compile")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun toString() = name + " compiler"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors,
|
||||||
* Should probably make exclusion more generic (full on string) or allow exclusion to be specified
|
* Should probably make exclusion more generic (full on string) or allow exclusion to be specified
|
||||||
* formally by groupId or artifactId.
|
* formally by groupId or artifactId.
|
||||||
*/
|
*/
|
||||||
fun isDependencyExcluded(dep: IClasspathDependency, excluded: List<IClasspathDependency>)
|
fun isDependencyExcluded(dep: IClasspathDependency, excluded: List<IClasspathDependency>): Boolean {
|
||||||
= excluded.any { excluded -> dep.id.startsWith(excluded.id) }
|
excluded.any { excluded -> dep.id.startsWith(excluded.id) }.let { result ->
|
||||||
|
if (result) {
|
||||||
|
context.logger.log(project?.name ?: "", 2, " Excluding dependency $dep")
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones,
|
// Dependencies get reordered by transitiveClosure() but since we just added a bunch of new ones,
|
||||||
// we need to reorder them again in case we're adding dependencies that are already present
|
// we need to reorder them again in case we're adding dependencies that are already present
|
||||||
|
|
|
@ -6,10 +6,10 @@ import com.google.inject.Inject
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class Git @Inject constructor() {
|
class Git @Inject constructor() {
|
||||||
fun maybeTagRelease(project: Project, uploadResult: TaskResult, autoGitTag: Boolean) : TaskResult {
|
fun maybeTagRelease(project: Project, uploadResult: TaskResult, auto: Boolean, tag: String, message: String) : TaskResult {
|
||||||
val result =
|
val result =
|
||||||
if (uploadResult.success && autoGitTag) {
|
if (uploadResult.success && auto) {
|
||||||
val tagSuccess = tagRelease(project)
|
val tagSuccess = tagRelease(project, auto, tag, message)
|
||||||
if (! tagSuccess) {
|
if (! tagSuccess) {
|
||||||
TaskResult(false, "Couldn't tag the project")
|
TaskResult(false, "Couldn't tag the project")
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,20 +21,21 @@ class Git @Inject constructor() {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tagRelease(project: Project) : Boolean {
|
private fun tagRelease(project: Project, auto: Boolean, tag: String, message: String) : Boolean {
|
||||||
|
val version = if (tag.isNullOrBlank()) project.version else tag
|
||||||
val success = try {
|
val success = try {
|
||||||
log(2, "Tagging this release as \"${project.version}\"")
|
log(2, "Tagging this release as \"$version\"")
|
||||||
val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder()
|
val repo = org.eclipse.jgit.storage.file.FileRepositoryBuilder()
|
||||||
.setGitDir(File(KFiles.joinDir(project.directory, ".git")))
|
.setGitDir(File(KFiles.joinDir(project.directory, ".git")))
|
||||||
.readEnvironment()
|
.readEnvironment()
|
||||||
.findGitDir()
|
.findGitDir()
|
||||||
.build()
|
.build()
|
||||||
val git = org.eclipse.jgit.api.Git(repo)
|
val git = org.eclipse.jgit.api.Git(repo)
|
||||||
val ref = git.tag().setName(project.version).call()
|
val ref = git.tag().setName(version).setMessage(message).call()
|
||||||
git.push().setPushTags().call()
|
git.push().setPushTags().call()
|
||||||
true
|
true
|
||||||
} catch(ex: Exception) {
|
} catch(ex: Exception) {
|
||||||
warn("Couldn't create tag ${project.version}: ${ex.message}", ex)
|
warn("Couldn't create tag ${version}: ${ex.message}", ex)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.beust.kobalt.plugin.packaging
|
package com.beust.kobalt.plugin.packaging
|
||||||
|
|
||||||
import aQute.bnd.osgi.Analyzer
|
|
||||||
import com.beust.kobalt.*
|
import com.beust.kobalt.*
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.*
|
||||||
import com.beust.kobalt.api.annotation.Directive
|
import com.beust.kobalt.api.annotation.Directive
|
||||||
|
@ -62,29 +61,39 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
runTask = { taskInstall(project) })
|
runTask = { taskInstall(project) })
|
||||||
}
|
}
|
||||||
|
|
||||||
val zipToFiles = hashMapOf<String, List<IncludedFile>>()
|
|
||||||
|
|
||||||
override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo {
|
override fun assemble(project: Project, context: KobaltContext) : IncrementalTaskInfo {
|
||||||
val allConfigs = packages.filter { it.project.name == project.name }
|
val allConfigs = packages.filter { it.project.name == project.name }
|
||||||
|
val zipToFiles = hashMapOf<String, List<IncludedFile>>()
|
||||||
|
|
||||||
val benchmark = benchmarkMillis {
|
val benchmark = benchmarkMillis {
|
||||||
if (true) {
|
if (true) {
|
||||||
|
//
|
||||||
|
// This loop prepares the data so we can calculate input and output checksums for the
|
||||||
|
// assemble task:
|
||||||
|
// - Input: Calculate the list of all the included files for every archive (jar/war/zip) and
|
||||||
|
// store them in the `zipToFiles` map.
|
||||||
|
// - Output: Calculate all the output archive files into `outputFiles`
|
||||||
|
//
|
||||||
|
// `zipToFiles` is used again after this loop so we can pass the list of included files we just
|
||||||
|
// calculated for all the archives in the actual execution of the task, so we don't have to
|
||||||
|
// look for them a second time.
|
||||||
|
//
|
||||||
val allIncludedFiles = arrayListOf<IncludedFile>()
|
val allIncludedFiles = arrayListOf<IncludedFile>()
|
||||||
val outputArchives = arrayListOf<File>()
|
val outputFiles = arrayListOf<File>()
|
||||||
allConfigs.forEach { packageConfig ->
|
allConfigs.forEach { packageConfig ->
|
||||||
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)
|
||||||
val suffixIndex = it.name.lastIndexOf(".")
|
|
||||||
val suffix = it.name.substring(suffixIndex)
|
|
||||||
val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
|
val outputFile = jarGenerator.fullArchiveName(project, context, it.name)
|
||||||
outputArchives.add(outputFile)
|
outputFiles.add(outputFile)
|
||||||
allIncludedFiles.addAll(files)
|
allIncludedFiles.addAll(files)
|
||||||
zipToFiles[it.name] = files
|
zipToFiles[it.name] = files
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val allFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
|
||||||
|
// Turn the IncludedFiles into actual Files
|
||||||
|
val inputFiles = allIncludedFiles.fold(arrayListOf<File>()) { files, includedFile: IncludedFile ->
|
||||||
val foundFiles = includedFile.allFromFiles(project.directory)
|
val foundFiles = includedFile.allFromFiles(project.directory)
|
||||||
val absFiles = foundFiles.map {
|
val absFiles = foundFiles.map {
|
||||||
File(KFiles.joinDir(project.directory, includedFile.from, it.path))
|
File(KFiles.joinDir(project.directory, includedFile.from, it.path))
|
||||||
|
@ -93,8 +102,8 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
files
|
files
|
||||||
}
|
}
|
||||||
|
|
||||||
val inMd5 = Md5.toMd5Directories(allFiles)
|
val inMd5 = Md5.toMd5Directories(inputFiles)
|
||||||
val outMd5 = Md5.toMd5Directories(outputArchives)
|
val outMd5 = Md5.toMd5Directories(outputFiles)
|
||||||
Pair(inMd5, outMd5)
|
Pair(inMd5, outMd5)
|
||||||
} else {
|
} else {
|
||||||
Pair(null, null)
|
Pair(null, null)
|
||||||
|
@ -150,7 +159,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
context.pluginInfo.incrementalAssemblyContributors.forEach {
|
context.pluginInfo.incrementalAssemblyContributors.forEach {
|
||||||
val taskInfo = it.assemble(project, context)
|
val taskInfo = it.assemble(project, context)
|
||||||
val closure = incrementalManagerFactory.create().toIncrementalTaskClosure(TASK_ASSEMBLE, {
|
val closure = incrementalManagerFactory.create().toIncrementalTaskClosure(TASK_ASSEMBLE, {
|
||||||
p: Project -> taskInfo }, context.variant)
|
_: Project -> taskInfo }, context.variant)
|
||||||
val thisResult = closure.invoke(project)
|
val thisResult = closure.invoke(project)
|
||||||
if (! thisResult.success) {
|
if (! thisResult.success) {
|
||||||
// Abort at the first failure
|
// Abort at the first failure
|
||||||
|
@ -174,24 +183,24 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE))
|
// @Task(name = "generateOsgiManifest", alwaysRunAfter = arrayOf(TASK_ASSEMBLE))
|
||||||
fun generateManifest(project: Project): TaskResult {
|
// fun generateManifest(project: Project): TaskResult {
|
||||||
val analyzer = Analyzer().apply {
|
// val analyzer = Analyzer().apply {
|
||||||
jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String)
|
// jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String)
|
||||||
val dependencies = project.compileDependencies + project.compileRuntimeDependencies
|
// val dependencies = project.compileDependencies + project.compileRuntimeDependencies
|
||||||
dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach {
|
// dependencyManager.calculateDependencies(project, context, passedDependencies = dependencies).forEach {
|
||||||
addClasspath(it.jarFile.get())
|
// addClasspath(it.jarFile.get())
|
||||||
}
|
// }
|
||||||
setProperty(Analyzer.BUNDLE_VERSION, project.version)
|
// setProperty(Analyzer.BUNDLE_VERSION, project.version)
|
||||||
setProperty(Analyzer.BUNDLE_NAME, project.group)
|
// setProperty(Analyzer.BUNDLE_NAME, project.group)
|
||||||
setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description)
|
// setProperty(Analyzer.BUNDLE_DESCRIPTION, project.description)
|
||||||
setProperty(Analyzer.IMPORT_PACKAGE, "*")
|
// setProperty(Analyzer.IMPORT_PACKAGE, "*")
|
||||||
setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version)
|
// setProperty(Analyzer.EXPORT_PACKAGE, "*;-noimport:=false;version=" + project.version)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
val manifest = analyzer.calcManifest()
|
// val manifest = analyzer.calcManifest()
|
||||||
manifest.write(System.out)
|
// manifest.write(System.out)
|
||||||
return TaskResult()
|
// return TaskResult()
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
@Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts",
|
@Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts",
|
||||||
|
|
|
@ -44,6 +44,16 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
return TaskResult()
|
return TaskResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun autoGitTag(project: Project, uploadResult: TaskResult, config: AutoGitTagConfig?) : TaskResult {
|
||||||
|
if (config != null) {
|
||||||
|
with(config) {
|
||||||
|
return git.maybeTagRelease(project, uploadResult, auto, tag, message)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return TaskResult()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun validateProject(project: Project) {
|
private fun validateProject(project: Project) {
|
||||||
requireNotNull(project.name, { "Project $project should have a name" })
|
requireNotNull(project.name, { "Project $project should have a name" })
|
||||||
requireNotNull(project.version, { "Project $project should have a version" })
|
requireNotNull(project.version, { "Project $project should have a version" })
|
||||||
|
@ -133,7 +143,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
messages.add(taskResult.errorMessage!!)
|
messages.add(taskResult.errorMessage!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
|
||||||
|
//
|
||||||
|
// Tag release, if applicable
|
||||||
|
//
|
||||||
|
autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name])
|
||||||
} else {
|
} else {
|
||||||
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
context.logger.log(project.name, 2, "Couldn't find any jcenter{} configuration, not uploading anything")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
@ -163,7 +177,11 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
logk(project.name, 2, "Uploading $it tag: ${project.version}")
|
||||||
github.uploadRelease(project.name, project.version!!, it)
|
github.uploadRelease(project.name, project.version!!, it)
|
||||||
}
|
}
|
||||||
git.maybeTagRelease(project, TaskResult(), configuration.autoGitTag)
|
|
||||||
|
//
|
||||||
|
// Tag release, if applicable
|
||||||
|
//
|
||||||
|
autoGitTag(project, TaskResult(), autoGitTagConfigurations[project.name])
|
||||||
} else {
|
} else {
|
||||||
warn("Couldn't find any github{} configuration, not uploading anything")
|
warn("Couldn't find any github{} configuration, not uploading anything")
|
||||||
TaskResult()
|
TaskResult()
|
||||||
|
@ -187,18 +205,30 @@ class PublishPlugin @Inject constructor(val files: KFiles, val factory: PomGener
|
||||||
fun addGithubConfiguration(projectName: String, config: GithubConfig) {
|
fun addGithubConfiguration(projectName: String, config: GithubConfig) {
|
||||||
githubConfigurations.put(projectName, config)
|
githubConfigurations.put(projectName, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map of project name -> AutoGitTagConfiguration
|
||||||
|
*/
|
||||||
|
private val autoGitTagConfigurations = hashMapOf<String, AutoGitTagConfig>()
|
||||||
|
fun addAutoGitTagConfiguration(projectName: String, config: AutoGitTagConfig) {
|
||||||
|
autoGitTagConfigurations.put(projectName, config)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class AutoGitTagConfig(val project: Project) {
|
||||||
|
@Directive
|
||||||
|
var auto: Boolean = true
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
var tag : String = project.version!!
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
var message : String = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
data class GithubConfig(val project: Project) {
|
data class GithubConfig(val project: Project) {
|
||||||
val files = arrayListOf<File>()
|
val files = arrayListOf<File>()
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, automatically tag this release with the current version number and push that tag to origin when
|
|
||||||
* the uploadGithub task is called.
|
|
||||||
*/
|
|
||||||
@Directive
|
|
||||||
var autoGitTag: Boolean = false
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun file(filePath: String, url: String) {
|
fun file(filePath: String, url: String) {
|
||||||
files.add(File(filePath))
|
files.add(File(filePath))
|
||||||
|
@ -213,6 +243,8 @@ fun Project.github(init: GithubConfig.() -> Unit): GithubConfig =
|
||||||
}
|
}
|
||||||
|
|
||||||
data class BintrayConfig(val project: Project) {
|
data class BintrayConfig(val project: Project) {
|
||||||
|
val files = arrayListOf<Pair<String, String>>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
* If true, the uploaded file will be published in your personal space (e.g. https://dl.bintray.com/cbeust/maven).
|
||||||
* Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to
|
* Once the file is uploaded there, it can be automatically synchronized to JCenter by linking your project to
|
||||||
|
@ -228,15 +260,6 @@ data class BintrayConfig(val project: Project) {
|
||||||
@Directive
|
@Directive
|
||||||
var sign: Boolean = false
|
var sign: Boolean = false
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, automatically tag this release with the current version number and push that tag to origin when
|
|
||||||
* the uploadBintray task is called.
|
|
||||||
*/
|
|
||||||
@Directive
|
|
||||||
var autoGitTag: Boolean = true
|
|
||||||
|
|
||||||
val files = arrayListOf<Pair<String, String>>()
|
|
||||||
|
|
||||||
@Directive
|
@Directive
|
||||||
fun file(filePath: String, url: String) {
|
fun file(filePath: String, url: String) {
|
||||||
files.add(Pair(filePath, url))
|
files.add(Pair(filePath, url))
|
||||||
|
@ -255,3 +278,10 @@ fun Project.bintray(init: BintrayConfig.() -> Unit) =
|
||||||
config.init()
|
config.init()
|
||||||
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config)
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addBintrayConfiguration(name, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Directive
|
||||||
|
fun Project.autoGitTag(init: AutoGitTagConfig.() -> Unit) =
|
||||||
|
AutoGitTagConfig(this).also { config ->
|
||||||
|
config.init()
|
||||||
|
(Kobalt.findPlugin(PublishPlugin.PLUGIN_NAME) as PublishPlugin).addAutoGitTagConfiguration(name, config)
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
kobalt.version=1.0.12
|
kobalt.version=1.0.13
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue