diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..c83099e
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/copyright/Erik_s_Copyright_Notice.xml b/.idea/copyright/Erik_s_Copyright_Notice.xml
new file mode 100644
index 0000000..ef51a2d
--- /dev/null
+++ b/.idea/copyright/Erik_s_Copyright_Notice.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
new file mode 100644
index 0000000..249e2ff
--- /dev/null
+++ b/.idea/copyright/profiles_settings.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..8ff795e
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,53 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kobalt.xml b/.idea/kobalt.xml
new file mode 100644
index 0000000..426f587
--- /dev/null
+++ b/.idea/kobalt.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..1c24f9a
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..f738a13
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..f9b1200
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/example.iml b/.idea/modules/example.iml
deleted file mode 100644
index 5caf6e3..0000000
--- a/.idea/modules/example.iml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/semver.iml b/.idea/modules/semver.iml
deleted file mode 100644
index 24fcd77..0000000
--- a/.idea/modules/semver.iml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules/semver_main.iml b/.idea/modules/semver_main.iml
new file mode 100644
index 0000000..67c6803
--- /dev/null
+++ b/.idea/modules/semver_main.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules/semver_test.iml b/.idea/modules/semver_test.iml
new file mode 100644
index 0000000..4a98385
--- /dev/null
+++ b/.idea/modules/semver_test.iml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/scopes/Source.xml b/.idea/scopes/Source.xml
new file mode 100644
index 0000000..2f58665
--- /dev/null
+++ b/.idea/scopes/Source.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.html b/README.html
index 576afdd..b8a9a4d 100644
--- a/README.html
+++ b/README.html
@@ -51,19 +51,23 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
Semantic Version Annotation Processor
-
An annotation processor that automatically generates a GeneratedVersion class containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
+
An annotation processor that automatically generates a GeneratedVersion class based on a Mustache template and containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
Upon running the annotator 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 Velocity template.
-
@Version(template = "myversion.vm")
+
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")
publicclass A {
// ...
The GeneratedVersion class will be automatically created in the build directory upon compiling.
+
The GeneratedVersion class will be automatically created in the build/generated directory upon compiling.
Class & Source Generation
-
In order to also incorporate the generated source code into the source tree, use the EWERK Annotation Processor Plugin. Start by addding the following to the very top of the build.gradle file:
+
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"
}
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:
diff --git a/README.md b/README.md
index 4c12a3a..3b0f6b9 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[](http://opensource.org/licenses/BSD-3-Clause) [](https://www.versioneye.com/user/projects/56a680101b78fd00390001d2) [](https://travis-ci.org/ethauvin/semver) [](https://ci.appveyor.com/project/ethauvin/semver) [](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver) [  ](https://bintray.com/ethauvin/maven/SemVer/_latestVersion)
-An [annotation processor](https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html) that automatically generates a `GeneratedVersion` class containing the [semantic version](http://semver.org/) (major, minor, patch, etc.) that is read from a `Properties` file or defined in the [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html).
+An [annotation processor](https://docs.oracle.com/javase/8/docs/api/javax/annotation/processing/Processor.html) that automatically generates a `GeneratedVersion` class based on a [Mustache](https://mustache.github.io/) template and containing the [semantic version](http://semver.org/) (major, minor, patch, etc.) that is read from a `Properties` file or defined in the [annotation](https://docs.oracle.com/javase/tutorial/java/annotations/basics.html).
This processor was inspired by Cédric Beust's [version-processor](https://github.com/cbeust/version-processor).
@@ -11,7 +11,9 @@ This processor was inspired by Cédric Beust's [version-processor](https://githu
* Using annotation elements:
```java
-@Version(major = 1, minor = 0, patch = 0, prerelease = "beta")
+import net.thauvin.erik.semver.Version;
+
+@Version(major = 1, minor = 0, patch = 0, preRelease = "beta")
public class A {
// ...
```
@@ -19,6 +21,8 @@ public class A {
* Or using a [properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file:
```java
+import net.thauvin.erik.semver.Version;
+
@Version(properties = "version.properties")
public class A {
// ...
@@ -34,68 +38,92 @@ version.prerelease=beta
## Template
-Upon running the annotator processor, a source file [`GeneratedVersion.java`](https://github.com/ethauvin/semver/blob/master/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable [Velocity](http://velocity.apache.org/) template.
+Upon running the annotation processor, a source file [`GeneratedVersion.java`](https://github.com/ethauvin/semver/blob/master/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable [Mustache](https://mustache.github.io/) 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:
```java
-@Version(template = "myversion.vm")
+@Version(template = "myversion.mustache")
public class A {
// ...
```
### Default Template
-The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/version.vm) implements the following static methods:
+The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static fields:
-Method | Description | Example
-------------------|----------------------------------|------------------
-`getProject` | The project name, if any. | `MyProject`
-`getBuildDate` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
-`getVersion` | The full version string. | `1.0.0-alpha+001`
-`getMajor` | The major version. | `1`
-`getMinor` | The minor version. | `0`
-`getPatch` | The patch version. | `0`
-`getPreRelease` | The pre-release version, if any. | `alpha`
-`getBuildMetadata`| The build metadata, if any. | `001`
+Field | Description | Example
+:--------------|:---------------------------------|:-----------------
+`project` | The project name, if any. | `MyProject`
+`buildDate` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
+`version` | The full version string. | `1.0.0-alpha+001`
+`major` | The major version. | `1`
+`minor` | The minor version. | `0`
+`patch` | The patch version. | `0`
+`preRelease` | The pre-release version, if any. | `alpha`
+`buildMeta` | The build metadata, if any. | `001`
+
+And the following methods/functions:
+
+Method | Description | Example
+:------------------------|:----------------------------------------------------------|:--------
+`preReleaseWithPrefix()` | Returns the pre-release with a prefix, `-` by default. | `-alpha`
+`buildMetaWithPrefix()` | Returns the build metadata with a prefix, `+` by default. | `+001`
### Custom Template
A very simple custom template might look something like:
```java
-/* myversion.vm */
-package ${packageName}
+/* version.mustache */
+package {{packageName}}
import java.util.Date;
-public final class ${className} {
- public final static String BUILDMETA = "${buildmeta}";
- public final static Date DATE = new Date(${epoch}L);
- public final static int MAJOR = ${major};
- public final static int MINOR = ${minor};
- public final static int PATCH = ${patch};
- public final static String PRERELEASE = "${prerelease}";
- public final static String PROJECT = "${project}";
+public final class {{className}} {
+ public final static String PROJECT = "{{project}}";
+ public final static Date DATE = new Date({{epoch}}L);
+ public final static int MAJOR = {{major}};
+ public final static int MINOR = {{minor}};
+ public final static int PATCH = {{patch}};
+ public final static String PRERELEASE = "{{preRelease}}";
+ public final static String BUILDMETA = "{{buildMeta}}";
}
```
-The Velocity variables are automatically filled in by the processor.
+The mustache variables automatically filled in by the processor are:
-Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.vm) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)
+Variable | Description | Type
+:-----------------|:----------------------------|:--------
+`{{packageName}}` | The package name. | `String`
+`{{className}}` | The class name. | `String`
+`{{project}}` | The project name. | `String`
+`{{epoch}}` | The build epoch/unix time. | `long`
+`{{major}}` | The major version. | `int`
+`{{minor}}` | The minor version. | `int`
+`{{patch}}` | The patch version. | `int`
+`{{preRelease}}` | The pre/release version. | `String`
+`{{buildMeta}}` | The build metadata version. | `String`
+
+Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)
## Elements & Properties
The following annotation elements and properties are available:
-Element | Property | Description | Default
--------------|----------------------|----------------------------------|-------------
-`project` | `version.project` | The project name. |
-`major` | `version.major` | The major version number. | `1`
-`minor` | `version.major` | The minor version number. | `0`
-`patch` | `version.patch` | The patch version number. | `0`
-`prerelease` | `version.prerelease` | The pre-release version. |
-`buildmeta` | `version.buildmeta` | The build metadata version. |
-`className` | | The name of the generated class. | `GeneratedVersion`
-`properties` | | The properties file. |
-`template` | | The template file. | `version.vm`
+Element | Property | Description | Default
+:------------|:---------------------|:----------------------------------|:----------------
+`project` | `version.project` | The project name. |
+`major` | `version.major` | The major version number. | `1`
+`minor` | `version.major` | The minor version number. | `0`
+`patch` | `version.patch` | The patch version number. | `0`
+`preRelease` | `version.prerelease` | The pre-release version. |
+`buildMeta` | `version.buildmeta` | The build metadata version. |
+`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. | `java`
In order to easily incorporate with existing projects, the property keys may be assigned custom values:
@@ -105,8 +133,8 @@ In order to easily incorporate with existing projects, the property keys may be
majorKey = "example.major",
minorKey = "example.minor",
patchKey = "example.patch",
- prereleaseKey = "example.prerelease",
- buildmetaKey = "example.buildmeta",
+ preReleaseKey = "example.prerelease",
+ buildMetaKey = "example.buildmeta",
projectKey = "example.project"
)
public class Example {
@@ -121,7 +149,7 @@ example.minor=0
example.patch=0
# ...
```
-## Usage with Maven, Grail and Kobalt
+## Usage with Maven, Grail, Kobalt and Kotlin
### Maven
@@ -131,7 +159,7 @@ To install and run from [Maven](http://maven.apache.org/), configure an artifact
net.thauvin.eriksemver
- 0.9.6-beta
+ 1.0
```
@@ -143,15 +171,15 @@ To install and run from [Gradle](https://gradle.org/), add the following to the
```gradle
dependencies {
- compile 'net.thauvin.erik:semver:0.9.6-beta'
+ compileOnly 'net.thauvin.erik:semver:1.0'
}
```
-The `GeneratedVersion` class will be automatically created in the `build` directory upon compiling.
+The `GeneratedVersion` class will be automatically created in the `build/generated` directory upon compiling.
#### Class & Source Generation
-In order to also incorporate the generated source code into the `source tree`, use the [EWERK Annotation Processor Plugin](https://github.com/ewerk/gradle-plugins/tree/master/annotation-processor-plugin). Start by addding the following to the very top of the `build.gradle` file:
+In order to also incorporate the generated source code into the `source tree`, use the [EWERK Annotation Processor Plugin](https://github.com/ewerk/gradle-plugins/tree/master/annotation-processor-plugin). Start by adding the following to the very top of the `build.gradle` file:
```gradle
plugins {
@@ -163,17 +191,17 @@ Then add the following to the `build.gradle` file:
```gradle
dependencies {
- compileOnly 'net.thauvin.erik:semver:0.9.6-beta'
+ compileOnly 'net.thauvin.erik:semver:1.0'
}
annotationProcessor {
- library 'net.thauvin.erik:semver:0.9.6-beta'
+ library 'net.thauvin.erik:semver:1.0'
processor 'net.thauvin.erik.semver.VersionProcessor'
// sourcesDir 'src/generated/java'
}
compileJava {
- // Disable the classpath procesor
+ // Disable the classpath processor
options.compilerArgs << '-proc:none'
}
```
@@ -188,13 +216,30 @@ To install and run from [Kobalt](http://beust.com/kobalt/), add the following to
```gradle
dependencies {
- apt("net.thauvin.erik:semver:0.9.6-beta")
- compile("net.thauvin.erik:semver:0.9.6-beta")
+ apt("net.thauvin.erik:semver:1.0")
+ compileOnly("net.thauvin.erik:semver:1.0")
}
```
Please look at the [Build.kt](https://github.com/ethauvin/semver/blob/master/example/kobalt/src/Build.kt) file in the [example](https://github.com/ethauvin/semver/tree/master/example) module directory for a sample.
+### Kotlin
+
+The annotation processor also supports [Kotlin](https://kotlinlang.org/).
+
+To generate a Kotlin version file, simply specify the `type` as follows:
+
+```kotlin
+import net.thauvin.erik.semver.Version
+
+@Version(properties = "version.properties", type="kt")
+open class Main {
+// ...
+```
+The [Kotlin default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache) implements the same static fields and functions as the [Java template](#default-template).
+
+Please look at the [Example for Kotlin](https://github.com/ethauvin/semver-example-kotlin) project for samples on using [Gradle](https://gradle.org/) and [Kobalt](http://beust.com/kobalt/).
+
### Auto-Increment
Incrementing the version is best left to your favorite build system.
diff --git a/example/example.iml b/example/example.iml
new file mode 100644
index 0000000..581b531
--- /dev/null
+++ b/example/example.iml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt
index d123d2b..a94373e 100644
--- a/example/kobalt/src/Build.kt
+++ b/example/kobalt/src/Build.kt
@@ -1,14 +1,13 @@
import com.beust.kobalt.plugin.application.application
import com.beust.kobalt.plugin.apt.apt
-import com.beust.kobalt.plugin.packaging.assemble
-import com.beust.kobalt.plugin.packaging.install
+import com.beust.kobalt.plugin.packaging.*
import com.beust.kobalt.project
import java.io.FileInputStream
import java.util.*
fun StringBuilder.prepend(s: String): StringBuilder {
- if (this.length > 0) {
+ if (this.isNotEmpty()) {
this.insert(0, s)
}
return this
@@ -40,15 +39,15 @@ val example = project {
dependencies {
apt(processorJar)
- compile(processorJar)
+ compileOnly(processorJar)
}
apt {
- outputDir = "/src/generated/java/"
+ outputDir = "../src/generated/java/"
}
install {
- libDir = "deploy"
+ target = "deploy"
}
assemble {
diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties
index 0909c8d..9709019 100644
--- a/example/kobalt/wrapper/kobalt-wrapper.properties
+++ b/example/kobalt/wrapper/kobalt-wrapper.properties
@@ -1 +1 @@
-kobalt.version=1.0.26
\ No newline at end of file
+kobalt.version=1.0.71
\ No newline at end of file
diff --git a/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java b/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java
deleted file mode 100644
index bf0710c..0000000
--- a/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * This file is automatically generated.
- * Do not modify! -- ALL CHANGES WILL BE ERASED!
- */
-package net.thauvin.erik.semver.example;
-
-import java.util.Date;
-
-/**
- * Provides semantic version information.
- *
- * @author Semantic Version
- * Annotation Processor
- */
-public final class GeneratedVersion {
- private final static String buildmeta = "";
- private final static Date date = new Date(1490396459441L);
- private final static int major = 3;
- private final static int minor = 1;
- private final static int patch = 49;
- private final static String prerelease = "beta";
- private final static String project = "Example";
-
- /**
- * Disables the default constructor.
- *
- * @throws UnsupportedOperationException If the constructor is called.
- */
- private GeneratedVersion()
- throws UnsupportedOperationException {
- throw new UnsupportedOperationException("Illegal constructor call.");
- }
-
- /**
- * Returns the build date.
- *
- * @return The build date.
- */
- public static Date getBuildDate() {
- return date;
- }
-
- /**
- * Returns the project name.
- *
- * @return The project name, if any.
- */
- public static String getProject() {
- return project;
- }
-
- /**
- * Returns the full version string.
- *