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

License (3-Clause BSD) Dependency Status Build Status Build status Maven Central Download

-

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.

This processor was inspired by Cédric Beust's version-processor.

Examples

-
@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 {
 // ...
-
@Version(properties = "version.properties")
+
import net.thauvin.erik.semver.Version;
+
+@Version(properties = "version.properties")
 public class A {
 // ...
# version.properties
@@ -72,146 +76,237 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
 version.patch=0
 version.prerelease=beta

Template

-

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")
 public class A {
 // ...

Default Template

-

The default template implements the following static methods:

+

The default template implements the following static fields:

- - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + + + +
MethodDescriptionExampleFieldDescriptionExample
getProjectThe project name, if any.MyProjectprojectThe project name, if any.MyProject
getBuildDateThe build date.java.util.DatebuildDateThe build date.java.util.Date
getVersionThe full version string.1.0.0-alpha+001versionThe full version string.1.0.0-alpha+001
getMajorThe major version.1majorThe major version.1
getMinorThe minor version.0minorThe minor version.0
getPatchThe patch version.0patchThe patch version.0
getPreReleaseThe pre-release version, if any.alphapreReleaseThe pre-release version, if any.alpha
getBuildMetadataThe build metadata, if any.001buildMetaThe build metadata, if any.001
+

And the following methods/functions:

+ +++++ + + + + + + + + + + + + + + + + +
MethodDescriptionExample
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:

-
/* 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.

-

Please also look at this example using java.time

+

The mustache variables automatically filled in by the processor are:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableDescriptionType
{{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 using java.time

Elements & Properties

The following annotation elements and properties are available:

- - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + + + + + + +
ElementPropertyDescriptionDefaultElementPropertyDescriptionDefault
projectversion.projectThe project name.projectversion.projectThe project name.
majorversion.majorThe major version number.1majorversion.majorThe major version number.1
minorversion.majorThe minor version number.0minorversion.majorThe minor version number.0
patchversion.patchThe patch version number.0patchversion.patchThe patch version number.0
prereleaseversion.prereleaseThe pre-release version.preReleaseversion.prereleaseThe pre-release version.
buildmetaversion.buildmetaThe build metadata version.buildMetaversion.buildmetaThe build metadata version.
classNameThe name of the generated class.GeneratedVersionclassNameThe name of the generated class.GeneratedVersion
propertiesThe properties file.propertiesThe properties file.
templateThe template file.version.vmtemplateThe template file.version.mustache
typeEither java or kt for Kotlin.java
@@ -221,8 +316,8 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf 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 { @@ -233,39 +328,39 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf example.minor=0 example.patch=0 # ...
-

Usage with Maven, Grail and Kobalt

+

Usage with Maven, Grail, Kobalt and Kotlin

Maven

To install and run from Maven, configure an artifact as follows:

<dependency>
     <groupId>net.thauvin.erik</groupId>
     <artifactId>semver</artifactId>
-    <version>0.9.6-beta</version>
+    <version>1.0</version>
 </dependency>

Gradle

Class Generation

To install and run from Gradle, add the following to the build.gradle file:

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. 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"
 }

Then add the following to the build.gradle file:

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'
 }

The plugin implements a separate compile task that only runs the annotation processor and is executed during the build phase.

@@ -273,10 +368,20 @@ compileJava {

Kobalt

To install and run from Kobalt, add the following to the Build.kt file:

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 file in the example module directory for a sample.

+

Kotlin

+

The annotation processor also supports Kotlin.

+

To generate a Kotlin version file, simply specify the type as follows:

+
import net.thauvin.erik.semver.Version
+
+@Version(properties = "version.properties", type="kt")
+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.

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:

diff --git a/README.md b/README.md index 4c12a3a..3b0f6b9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![Dependency Status](https://www.versioneye.com/user/projects/56a680101b78fd00390001d2/badge.svg?style=flat)](https://www.versioneye.com/user/projects/56a680101b78fd00390001d2) [![Build Status](https://travis-ci.org/ethauvin/semver.svg?branch=master)](https://travis-ci.org/ethauvin/semver) [![Build status](https://ci.appveyor.com/api/projects/status/nbv4mxd1gpxtx69o?svg=true)](https://ci.appveyor.com/project/ethauvin/semver) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/semver) [ ![Download](https://api.bintray.com/packages/ethauvin/maven/SemVer/images/download.svg) ](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.erik semver - 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. - *

- * Formatted as: - *

- * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA] - *
- *

- * For example: - *

    - *
  • 1.0.0
  • - *
  • 1.0.0-beta
  • - *
  • 1.0.0+20160124144700
  • - *
  • 1.0.0-alpha+001
  • - *
- * - * @return The version string. - */ - public static String getVersion() { - return Integer.toString(getMajor()) + '.' - + Integer.toString(getMinor()) + '.' - + Integer.toString(getPatch()) - + getPreRelease(true) + getBuildMetadata(true); - } - - /** - * Returns the major version. - * - * @return The major version. - */ - public static int getMajor() { - return major; - } - - /** - * Returns the minor version. - * - * @return The minor version. - */ - public static int getMinor() { - return minor; - } - - /** - * Returns the patch version. - * - * @return The patch version. - */ - public static int getPatch() { - return patch; - } - - /** - * Returns the pre-release version. - * - * @param isHyphen Prepend a hyphen, if true. - * @return The pre-release version, if any. - */ - public static String getPreRelease(final boolean isHyphen) { - if (prerelease.length() > 0) { - if (isHyphen) { - return '-' + prerelease; - } else { - return prerelease; - } - } - - return ""; - } - - /** - * Returns the pre-release version. - * - * @return The pre-release version, if any. - */ - public static String getPreRelease() { - return getPreRelease(false); - } - - /** - * Returns the build metadata. - * - * @param isPlus Prepend a plus sign, if true. - * @return The build metadata, if any. - */ - public static String getBuildMetadata(final boolean isPlus) { - if (buildmeta.length() > 0) { - if (isPlus) { - return '+' + buildmeta; - } else { - return buildmeta; - } - } - - return ""; - } - - /** - * Returns the build metadata. - * - * @return The build metadata, if any. - */ - public static String getBuildMetadata() { - return getBuildMetadata(false); - } -} \ No newline at end of file diff --git a/example/version.properties b/example/version.properties index c99f89d..5588eff 100644 --- a/example/version.properties +++ b/example/version.properties @@ -1,7 +1,7 @@ #Mon, 18 Jul 2016 17:33:54 -0700 -version.prerelease=beta version.project=Example -version.minor=1 -version.buildmeta= -version.patch=49 -version.major=3 +version.major=2 +version.minor=17 +version.patch=52 +version.prerelease=beta +version.buildmeta=007 diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index 7eaa07a..2c8015f 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,23 +1,20 @@ -import com.beust.kobalt.file -import com.beust.kobalt.localMaven -import com.beust.kobalt.plugin.application.application -import com.beust.kobalt.plugin.apt.apt -import com.beust.kobalt.plugin.java.javaCompiler -import com.beust.kobalt.plugin.packaging.assemble -import com.beust.kobalt.plugin.packaging.install -import com.beust.kobalt.plugins -import com.beust.kobalt.project -import com.beust.kobalt.repos -import java.io.FileInputStream -import java.util.* +import com.beust.kobalt.* +import com.beust.kobalt.plugin.application.* +import com.beust.kobalt.plugin.packaging.* +import com.beust.kobalt.plugin.publish.* import net.thauvin.erik.kobalt.plugin.exec.* +import org.apache.maven.model.* +import java.io.* +import java.util.* val bs = buildScript { + plugins("net.thauvin.erik:kobalt-maven-local:") plugins("net.thauvin.erik:kobalt-exec:") + repos(localMaven()) } fun StringBuilder.prepend(s: String): StringBuilder { - if (this.length > 0) { + if (this.isNotEmpty()) { this.insert(0, s) } return this @@ -45,8 +42,27 @@ val semver = project { artifactId = name version = versionFor() + pom = Model().apply { + description = "Semantic Version Annotation Processor" + url = "https://github.com/ethauvin/semver" + licenses = listOf(License().apply { + name = "BSD 3-Clause" + url = "https://opensource.org/licenses/BSD-3-Clause" + }) + scm = Scm().apply { + url = "https://github.com/ethauvin/semver" + connection = "https://github.com/ethauvin/semver.git" + developerConnection = "git@github.com:ethauvin/semver.git" + } + developers = listOf(Developer().apply { + id = "ethauvin" + name = "Erik C. Thauvin" + email = "erik@thauvin.net" + }) + } + dependencies { - compile("org.apache.velocity:velocity:1.7") + compile("com.github.spullara.mustache.java:compiler:0.9.4") } dependenciesTest { @@ -54,17 +70,29 @@ val semver = project { } install { - libDir = "deploy" + target = "deploy" } assemble { - jar {} + jar { + fatJar = true + } + mavenJars {} } - application { - mainClass = "com.example.Main" + autoGitTag { + enabled = true + message = "Version $version" } + bintray { + publish = true + description = "Release version $version" + vcsTag = version + sign = true + } + + 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)) @@ -72,7 +100,7 @@ val semver = project { } } -val example = project(semver){ +val example = project(semver) { name = "example" directory = "example" @@ -80,26 +108,6 @@ val example = project(semver){ val mainClassName = "net.thauvin.erik.semver.example.Example" - sourceDirectories { - path("src/main/java") - } - - sourceDirectoriesTest { - path("src/test/java") - } - - dependencies { - compile("org.apache.velocity:velocity:1.7") - } - - dependenciesTest { - - } - - install { - libDir = "example/deploy" - } - assemble { jar { manifest { diff --git a/kobalt/wrapper/kobalt-wrapper.properties b/kobalt/wrapper/kobalt-wrapper.properties index 0909c8d..9709019 100644 --- a/kobalt/wrapper/kobalt-wrapper.properties +++ b/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/semver.iml b/semver.iml new file mode 100644 index 0000000..e624f82 --- /dev/null +++ b/semver.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/semver.ipr b/semver.ipr deleted file mode 100644 index 387f1ab..0000000 --- a/semver.ipr +++ /dev/null @@ -1,425 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Android Lint - - - Java - - - Portability issuesJava - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1.8.x - - - - - - - - \ No newline at end of file diff --git a/version.properties b/version.properties index 0011a7e..a836620 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,5 @@ #Thu, 06 Oct 2016 11:49:46 -0700 +version.project=semver version.major=0 version.minor=9 version.patch=7