diff --git a/README.html b/README.html index b8a9a4d..ba8dc5f 100644 --- a/README.html +++ b/README.html @@ -75,11 +75,12 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf version.minor=0 version.patch=0 version.prerelease=beta +

View Example

Template

Upon running the annotation processor, a source file GeneratedVersion.java is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache template.

To use your own template, simply create a version.mustache file. The processor will automatically look for it.

To specify your own template name, use:

-
@Version(template = "myversion.mustache")
+
@Version(template = "version.mustache")
 public class A {
 // ...

Default Template

@@ -94,42 +95,42 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf -project +PROJECT The project name, if any. MyProject -buildDate +BUILDDATE The build date. java.util.Date -version +VERSION The full version string. 1.0.0-alpha+001 -major +MAJOR The major version. 1 -minor +MINOR The minor version. 0 -patch +PATCH The patch version. 0 -preRelease +PRERELEASE The pre-release version, if any. alpha -buildMeta +BUILDMETA The build metadata, if any. 001 @@ -285,24 +286,30 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf +packageName + +The package name. +Same as annotated class + + className The name of the generated class. GeneratedVersion - + properties The properties file. - + template The template file. version.mustache - + type Either java or kt for Kotlin. @@ -346,7 +353,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf

Class & Source Generation

In order to also incorporate the generated source code into the source tree, use the EWERK Annotation Processor Plugin. Start by adding the following to the very top of the build.gradle file:

plugins {
-    id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.3"
+    id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.4"
 }

Then add the following to the build.gradle file:

dependencies {
@@ -381,10 +388,11 @@ compileJava {
 open class Main {
 // ...

The Kotlin default template implements the same static fields and functions as the Java template.

-

Please look at the Example for Kotlin project for samples on using Gradle and Kobalt.

+

Please look at the Example for Kotlin project for samples on using Gradle (build.gradle) and Kobalt (Build.kt).

Auto-Increment

Incrementing the version is best left to your favorite build system.

For a solution using Gradle, please have a look at the build.gradle file in the example module directory. To run the example with patch version auto-incrementing, issue the following command:

gradle release run
+

For a solution using Kobalt look at my Property File Editor plug-in.

diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 86733eb..b961a9f 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,5 +1,6 @@ import com.beust.kobalt.buildScript import com.beust.kobalt.file +import com.beust.kobalt.plugin.java.javadoc import com.beust.kobalt.plugin.packaging.assemble import com.beust.kobalt.plugin.packaging.install import com.beust.kobalt.plugin.publish.autoGitTag @@ -16,10 +17,10 @@ import java.io.FileInputStream import java.util.* val bs = buildScript { - //repos(file("K:/maven/repository")) + repos(file("K:/maven/repository")) plugins("net.thauvin.erik:kobalt-maven-local:", - "net.thauvin.erik:kobalt-exec:", - "net.thauvin.erik:kobalt-versioneye:") + "net.thauvin.erik:kobalt-exec:", + "net.thauvin.erik:kobalt-versioneye:") } fun StringBuilder.prepend(s: String): StringBuilder { @@ -47,12 +48,13 @@ fun versionFor(directory: String = "./"): String { val semver = project { name = "semver" + description = "Semantic Version Annotation Processor" group = "net.thauvin.erik" artifactId = name version = versionFor() pom = Model().apply { - description = "Semantic Version Annotation Processor" + description = project.description url = "https://github.com/ethauvin/semver" licenses = listOf(License().apply { name = "BSD 3-Clause" @@ -78,10 +80,6 @@ val semver = project { compile("org.testng:testng:6.11") } - install { - target = "deploy" - } - assemble { jar { //fatJar = true @@ -91,6 +89,10 @@ val semver = project { } } + install { + target = "deploy" + } + autoGitTag { enabled = true message = "Version $version" @@ -103,11 +105,25 @@ val semver = project { sign = true } + javadoc { + title = project.description + ' ' + project.version + tags("created") + author = true + //quiet = false + //verbose = true + links("http://docs.oracle.com/javase/8/docs/api/") + } exec { - val args = listOf("--from", "markdown_github", "--to", "html5", "-s", "-c", "github-pandoc.css", "-o", "README.html", "README.md") - commandLine(listOf("pandoc") + args, os = setOf(Os.LINUX)) - commandLine(listOf("cmd", "/c", "pandoc") + args, os = setOf(Os.WINDOWS)) + taskName = "pandoc" + commandLine("pandoc", + "--from", "markdown_github", + "--to", "html5", + "-s", + "-c", "github-pandoc.css", + "-o", "README.html", + "README.md", + os = setOf(Os.LINUX, Os.MINGW, Os.CYGWIN)) } versionEye { diff --git a/src/main/resources/semver-kt.mustache b/src/main/resources/semver-kt.mustache index f52fc25..ef2828c 100644 --- a/src/main/resources/semver-kt.mustache +++ b/src/main/resources/semver-kt.mustache @@ -13,38 +13,36 @@ import java.util.* * Annotation Processor */ object {{className}} { - @JvmField - val PRERELEASE_PREFIX = "-" + @JvmField val PRERELEASE_PREFIX = "-" - @JvmField - val BUILDMEATA_PREFIX = "+" + @JvmField val BUILDMEATA_PREFIX = "+" - @JvmField - val PROJECT = "{{project}}" + @JvmField val PROJECT = "{{project}}" - @JvmField - val BUILDDATE = Date({{epoch}}L) + @JvmField val BUILDDATE = Date({{epoch}}L) - @JvmField - val MAJOR = {{major}} + @JvmField val MAJOR = {{major}} - @JvmField - val MINOR = {{minor}} + @JvmField val MINOR = {{minor}} - @JvmField - val PATCH = {{patch}} + @JvmField val PATCH = {{patch}} - @JvmField - val BUILDMETA = "{{buildMeta}}" + @JvmField val BUILDMETA = "{{buildMeta}}" - @JvmField - val PRERELEASE = "{{preRelease}}" + @JvmField val PRERELEASE = "{{preRelease}}" - @JvmField - val VERSION = "$MAJOR.$MINOR.$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix() + /** + * The full version string formatted as [MAJOR].[MINOR].[PATCH]-[PRERELEASE]+[BUILDMETA] + */ + @JvmField val VERSION = "$MAJOR.$MINOR.$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix() - @JvmStatic - fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String { + /** + * Returns the pre-release version with prefix. + * + * @param prefix The prefix, defaults to [PRERELEASE_PREFIX]. + * @return The pre-release version, if any. + */ + @JvmStatic fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String { return if (PRERELEASE.isNotEmpty() && prefix.isNotEmpty()) { "$prefix$PRERELEASE" } else { @@ -52,8 +50,13 @@ object {{className}} { } } - @JvmStatic - fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String { + /** + * Returns the build metadata with prefix. + * + * @param prefix The prefix, defaults to [BUILDMEATA_PREFIX]. + * @return The build metadata, if any. + */ + @JvmStatic fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String { return if (BUILDMETA.isNotEmpty() && prefix.isNotEmpty()) { "$prefix$BUILDMETA" } else {