Skip to content

Commit

Permalink
adding a README adding properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Amesbury committed Aug 21, 2018
1 parent f171d28 commit fde8393
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mld-git-version
===============

A Gradle plugin that sets various properties available for use as the version based on the git repository.

[![Build Status](https://travis-ci.com/moonlitdoor/mld-git-version.svg?branch=master)](https://travis-ci.com/moonlitdoor/mld-git-version)
9 changes: 2 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import java.io.ByteArrayOutputStream
import java.io.OutputStream

allprojects {
group = "com.moonlitdoor.git-version"
version = getGitVersionName()

repositories {
jcenter()
}

}

fun getGitVersionName(): String {
val stdout = ByteArrayOutputStream()
val stdout: OutputStream = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "describe", "--tags")
standardOutput = stdout
Expand All @@ -25,7 +21,6 @@ fun getGitStatus(version: String): String {
commandLine = listOf("git", "status", "--porcelain")
standardOutput = stdout
}

return if (stdout.toString().trim().isNotEmpty()) {
if (version.contains("-g")) {
val withOutHash = version.subSequence(0, version.indexOf("-g"))
Expand Down
21 changes: 12 additions & 9 deletions git-version/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
`java-gradle-plugin`
`kotlin-dsl`
`maven-publish`
}

dependencies {

compileOnly(gradleKotlinDsl())

compile(kotlin("gradle-plugin"))
compile(kotlin("stdlib-jdk8"))

gradlePlugin {
(plugins) {
"git-version" {
id = "git-version"
implementationClass = "com.moonlitdoor.git.version.GitVersionPlugin"
}
}
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
publishing {
repositories {
// maven(url = "build/repository")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import java.util.concurrent.TimeUnit

@Suppress("Unused")
class GitVersionPlugin : Plugin<Project> {
override fun apply(target: Project?) {

override fun apply(target: Project?) {
target?.let {
val gitCommitCount = getGitCommitCount(it)
val gitTagCount = getGitTagCount(it)
it.extensions.add("gitCommitCount", gitCommitCount)
it.extensions.add("gitTagCount", gitTagCount)
it.extensions.add("gitCommitAndTagCount", gitCommitCount + gitTagCount)
it.extensions.add("gitVersion", getGitVersion(it))
it.extensions.add("gitBranchName", getGitBranchName(it))
}
}

private fun getGitVersion(project: Project): String {
Expand Down Expand Up @@ -72,4 +82,14 @@ class GitVersionPlugin : Plugin<Project> {
}
}

}
private fun getGitBranchName(project: Project): String {
val command = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
val process = ProcessBuilder(command)
.directory(project.projectDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
process.waitFor(60, TimeUnit.SECONDS)
return getGitStatus(project, process.inputStream.bufferedReader().readText().trim())
}
}

This file was deleted.

0 comments on commit fde8393

Please sign in to comment.