diff --git a/.circleci/config.yml b/.circleci/config.yml
new file mode 100644
index 0000000..5697c0d
--- /dev/null
+++ b/.circleci/config.yml
@@ -0,0 +1,42 @@
+version: 2.1
+
+commands:
+ build_and_test:
+ parameters:
+ reports-dir:
+ type: string
+ default: "build/reports/test_results"
+ steps:
+ - checkout
+ - run:
+ name: Download dependencies
+ command: ./bld download
+ - run:
+ name: Compile source
+ command: ./bld compile
+ - run:
+ name: Run tests
+ command: ./bld jacoco -reports-dir=<< parameters.reports-dir >>
+ - store_test_results:
+ path: << parameters.reports-dir >>
+ - store_artifacts:
+ path: build/reports/jacoco/test/html
+
+jobs:
+ bld_jdk17:
+ docker:
+ - image: cimg/openjdk:17.0
+ steps:
+ - build_and_test
+
+ bld_jdk21:
+ docker:
+ - image: cimg/openjdk:21.0
+ steps:
+ - build_and_test
+
+workflows:
+ bld:
+ jobs:
+ - bld_jdk17
+ - bld_jdk21
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..1f808de
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,2 @@
+[*]
+insert_final_newline = true
diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml
new file mode 100644
index 0000000..64007ef
--- /dev/null
+++ b/.github/workflows/bld.yml
@@ -0,0 +1,76 @@
+name: bld-ci
+
+on: [push, pull_request, workflow_dispatch]
+
+jobs:
+ build-bld-project:
+ env:
+ COVERAGE_JDK: "17"
+
+ strategy:
+ matrix:
+ java-version: [17, 21, 24]
+ os: [ ubuntu-latest, windows-latest, macos-latest ]
+
+ runs-on: ${{ matrix.os }}
+
+ steps:
+ - name: Checkout source repository
+ uses: actions/checkout@v4
+ with:
+ fetch-depth: 0
+
+ - name: Set up JDK ${{ matrix.java-version }}
+ uses: actions/setup-java@v4
+ with:
+ distribution: "zulu"
+ java-version: ${{ matrix.java-version }}
+
+ - name: Download dependencies [bld example]
+ working-directory: examples/java/bld
+ run: ./bld download
+
+ - name: Compile and run [bld example]
+ working-directory: examples/java/bld
+ run: |
+ ./bld compile
+ ./bld run
+ ./bld run-example
+
+ - name: Run example [gradle java examples]
+ working-directory: examples/java/gradle
+ run: |
+ ./gradlew run
+ ./gradlew runExample
+
+ - name: Run example [gradle kotlin examples]
+ working-directory: examples/kotlin
+ run: |
+ ./gradlew run
+ ./gradlew runExample
+
+ - name: Download dependencies
+ run: ./bld download
+
+ - name: Compile source
+ run: ./bld compile
+
+ - name: Run tests
+ run: ./bld jacoco
+
+ - name: Remove pom.xml
+ if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
+ run: rm -rf pom.xml
+
+ - name: SonarCloud Scan
+ uses: sonarsource/sonarcloud-github-action@master
+ if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
+
+ - name: Upload coverage reports to Codecov
+ uses: codecov/codecov-action@v3
+ if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
+ env:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/.github_changelog_generator b/.github_changelog_generator
new file mode 100644
index 0000000..13dd68d
--- /dev/null
+++ b/.github_changelog_generator
@@ -0,0 +1 @@
+future-release=1.2.1
diff --git a/.gitignore b/.gitignore
index 355b112..dd3e0b4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,31 +1,58 @@
-**/.idea/dictionaries
-**/.idea/gradle.xml
-**/.idea/libraries
-**/.idea/tasks.xml
-**/.idea/workspace.xml
-*.sublime-*
-*.iws
-.classpath
-.DS_Store
.gradle
-.kobalt
-.nb-gradle
-.project
-.settings
-/bin
-/build
-/deploy
-/dist
-/gen
-/gradle.properties
-/lib/kotlin*
-/libs
-/local.properties
-/out
-/proguard-project.txt
-/project.properties
-/target
-/test-output
-ehthumbs.db
-kobaltBuild
-Thumbs.db
\ No newline at end of file
+.DS_Store
+build
+lib/bld/**
+!lib/bld/bld-wrapper.properties
+!lib/bld/bld-wrapper.jar
+lib/compile/
+lib/runtime/
+lib/standalone/
+lib/test/
+
+# IDEA ignores
+
+# User-specific
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# AWS User-specific
+.idea/**/aws.xml
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# SonarLint plugin
+.idea/sonarlint/
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+local.properties
+target
diff --git a/.idea/app.iml b/.idea/app.iml
new file mode 100644
index 0000000..6c0f6d7
--- /dev/null
+++ b/.idea/app.iml
@@ -0,0 +1,28 @@
+
+
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.
-import net.thauvin.erik.semver.Version;
-
-@Version(major = 1, minor = 0, patch = 0, preRelease = "beta")
-public class A {
-// ...
import net.thauvin.erik.semver.Version;
-
-@Version(properties = "version.properties")
-public class A {
-// ...
# version.properties
-version.major=1
-version.minor=0
-version.patch=0
-version.prerelease=beta
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 = "version.mustache")
-public class A {
-// ...
The default template implements the following static fields:
-Field | -Description | -Example | -
---|---|---|
PROJECT |
-The project name, if any. | -MyProject |
-
BUILDDATE |
-The build date. | -java.util.Date |
-
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 |
-
A very simple custom template might look something like:
-/* version.mustache */
-package {{packageName}}
-
-import java.util.Date;
-
-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 mustache variables automatically filled in by the processor are:
-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 using java.time
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. | -- |
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. |
-java |
-
In order to easily incorporate with existing projects, the property keys may be assigned custom values:
-@Version(
- properties = "example.properties",
- majorKey = "example.major",
- minorKey = "example.minor",
- patchKey = "example.patch",
- preReleaseKey = "example.prerelease",
- buildMetaKey = "example.buildmeta",
- projectKey = "example.project"
-)
-public class Example {
-// ...
# example.properties
-example.project=Example
-example.major=1
-example.minor=0
-example.patch=0
-# ...
To install and run from Maven, configure an artifact as follows:
-<dependency>
- <groupId>net.thauvin.erik</groupId>
- <artifactId>semver</artifactId>
- <version>1.0</version>
-</dependency>
To install and run from Gradle, add the following to the build.gradle
file:
dependencies {
- compileOnly 'net.thauvin.erik:semver:1.0'
-}
-The GeneratedVersion
class will be automatically created in the build/generated
directory upon compiling.
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.4"
-}
-Then add the following to the build.gradle
file:
dependencies {
- compileOnly 'net.thauvin.erik:semver:1.0'
-}
-
-annotationProcessor {
- library 'net.thauvin.erik:semver:1.0'
- processor 'net.thauvin.erik.semver.VersionProcessor'
- // sourcesDir 'src/generated/java'
-}
-
-compileJava {
- // 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.
-Please look at the build.gradle file in the example module directory for a sample.
-To install and run from Kobalt, add the following to the Build.kt
file:
dependencies {
- 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.
-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 (build.gradle) and Kobalt (Build.kt).
-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/README.md b/README.md index 553dec0..cada04f 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,62 @@ -# Semantic Version Annotation Processor +# Semantic Version Annotation Processor -[](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) +[](https://opensource.org/licenses/BSD-3-Clause) +[](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) +[](https://rife2.com/bld) +[](https://github.com/ethauvin/semver/releases/latest) +[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/semver/) +[](https://central.sonatype.com/artifact/net.thauvin.erik/semver) -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). +[](https://sonarcloud.io/dashboard?id=ethauvin_semver) +[](https://github.com/ethauvin/semver/actions/workflows/bld.yml) +[](https://ci.appveyor.com/project/ethauvin/semver) +[](https://circleci.com/gh/ethauvin/semver/tree/master) -This processor was inspired by Cédric Beust's [version-processor](https://github.com/cbeust/version-processor). +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](https://semver.org/) (major, minor, patch, etc.) that is read from a [Properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) 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) and works well in conjunction with the [__Semantic Version Plugin for Gradle__](https://github.com/ethauvin/semver-gradle). + +## Table of Contents + +- [Semantic Version Annotation Processor](#semantic-version-annotation-processor) + - [Table of Contents](#table-of-contents) + - [Examples](#examples) + - [Template](#template) + - [Default Template](#default-template) + - [Custom Template](#custom-template) + - [Elements \& Properties](#elements--properties) + - [Maven](#maven) + - [bld](#bld) + - [Gradle](#gradle) + - [Class Generation](#class-generation) + - [Class \& Source Generation](#class--source-generation) + - [Kotlin](#kotlin) + - [Kotlin \& Gradle](#kotlin--gradle) + - [Auto-Increment](#auto-increment) + - [Contributing](#contributing) ## Examples -* Using annotation elements: +- Using annotation elements: ```java import net.thauvin.erik.semver.Version; -@Version(major = 1, minor = 0, patch = 0, preRelease = "beta") +@Version(major = 2, minor = 1, patch = 1, preRelease = "beta") public class A { -// ... + // ... +} ``` -* Or using a [properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file: +- Or using a [properties](hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties) file: ```java import net.thauvin.erik.semver.Version; @Version(properties = "version.properties") public class A { -// ... + // ... +} ``` ```ini @@ -36,43 +67,40 @@ version.patch=0 version.prerelease=beta ``` -[View Example](https://github.com/ethauvin/semver/tree/master/example) +[View Examples](https://github.com/ethauvin/semver/tree/master/examples) ## 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. +Upon running the annotation processor, a source file [GeneratedVersion.java](https://github.com/ethauvin/semver/blob/master/examples/java/src/generated/java/com/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache [template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache). -To use your own template, simply create a `version.mustache` file. The processor will automatically look for it. +To use your own template, simply create a `version.mustache` file in the project's root directory. The processor will automatically look for it. To specify your own template name, use: ```java @Version(template = "version.mustache") public class A { -// ... + // ... +} ``` ### Default Template -The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static fields: +The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static variables: -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` +| 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.2.3-alpha+001` | +| `MAJOR` | The major version. | `1` | +| `MINOR` | The minor version. | `2` | +| `PATCH` | The patch version. | `3` | +| `PRERELEASE` | The pre-release version, if any. | `alpha` | +| `PRERELASE_PREFIX` | The pre-release prefix | `-` | +| `BUILDMETA` | The build metadata, if any. | `001` | +| `BUILDMETA_PREFIX` | The metadata prefix. | `+` | +| `SEPARATOR` | The version separator. | `.` | ### Custom Template @@ -80,153 +108,166 @@ A very simple custom template might look something like: ```java /* version.mustache */ -package {{packageName}} +package {{packageName}}; import java.util.Date; 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}}"; + public final static String VERSION = "{{semver}}"; } ``` + The mustache variables automatically filled in by the processor are: -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) +| 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` | +| `{{preReleasePrefix}}` | The pre-release prefix. | `String` | +| `{{buildMeta}}` | The build metadata version. | `String` | +| `{{buildMetaPrefix}}` | The metadata prefix. | `String` | +| `{{separator}}` | The version separator. | `String` | +| `{{semver}}` or `{{version}}` | The full semantic version. | `String` | ## 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. | -`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. | `java` +| 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. | | +| `preReleasePrefix` | `version.prerelease.prefix` | The pre-release prefix. | `-` | +| `buildMeta` | `version.buildmeta` | The build metadata version. | | +| `buildMetaPrefix` | `version.buildmeta.prefix` | The metadata prefix. | `+` | +| `separator` | `version.separator` | The version separator. | `.` | +| `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. | `java` | +| `keysPrefix` | | The prefix for all property keys. | `version.` | In order to easily incorporate with existing projects, the property keys may be assigned custom values: ```java @Version( properties = "example.properties", - majorKey = "example.major", - minorKey = "example.minor", - patchKey = "example.patch", - preReleaseKey = "example.prerelease", - buildMetaKey = "example.buildmeta", - projectKey = "example.project" + keysPrefix = "example.", + majorKey = "maj", + minorKey = "min", + patchKey = "build", + preReleaseKey = "rel", + buildMetaKey = "meta", + projectKey = "project" ) public class Example { -// ... + // ... +} ``` ```ini # example.properties example.project=Example -example.major=1 -example.minor=0 -example.patch=0 +example.maj=1 +example.min=0 +example.build=0 +example.rel=beta +example.meta= # ... ``` -## Usage with Maven, Grail, Kobalt and Kotlin -### Maven +> :warning: `keysPrefix` is a new element staring in `1.1.0` and may break older versions when using custom property keys.\ +> :zap: A quick fix is to include `keysPrefix=""` in the annotation to remove the default `version.` prefix. -To install and run from [Maven](http://maven.apache.org/), configure an artifact as follows: +## Maven + +To install and run from [Maven](https://maven.apache.org/), configure an artifact as follows: ```xmlGeneratedVersion
class containing the semantic
+version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
+
+@since 1.0
+
+
diff --git a/bin/main/semver-kt.mustache b/bin/main/semver-kt.mustache
new file mode 100644
index 0000000..0a58f86
--- /dev/null
+++ b/bin/main/semver-kt.mustache
@@ -0,0 +1,38 @@
+/*
+* This file is automatically generated.
+* Do not modify! -- ALL CHANGES WILL BE ERASED!
+*/
+
+package {{packageName}}
+
+import java.util.Date
+
+/**
+* Provides semantic version information.
+*
+* @author Semantic Version Annotation Processor
+*/
+object {{className}} {
+@JvmField
+val PROJECT = "{{project}}"
+@JvmField
+val BUILDDATE = Date({{epoch}}L)
+@JvmField
+val MAJOR = {{major}}
+@JvmField
+val MINOR = {{minor}}
+@JvmField
+val PATCH = {{patch}}
+@JvmField
+val PRERELEASE = "{{preRelease}}"
+@JvmField
+val PRERELEASE_PREFIX = "{{preReleasePrefix}}"
+@JvmField
+val BUILDMETA = "{{buildMeta}}"
+@JvmField
+val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}"
+@JvmField
+val SEPARATOR = "{{separator}}"
+@JvmField
+val VERSION = "{{version}}"
+}
diff --git a/bin/main/semver.mustache b/bin/main/semver.mustache
new file mode 100644
index 0000000..cd7c567
--- /dev/null
+++ b/bin/main/semver.mustache
@@ -0,0 +1,34 @@
+/*
+* This file is automatically generated.
+* Do not modify! -- ALL CHANGES WILL BE ERASED!
+*/
+
+package {{packageName}};
+
+import java.util.Date;
+
+/**
+* Provides semantic version information.
+*
+* @author Semantic Version Annotation Processor
+*/
+public final class {{className}} {
+public static final String PROJECT = "{{project}}";
+public static final Date BUILDDATE = new Date({{epoch}}L);
+public static final int MAJOR = {{major}};
+public static final int MINOR = {{minor}};
+public static final int PATCH = {{patch}};
+public static final String PRERELEASE = "{{preRelease}}";
+public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}";
+public static final String BUILDMETA = "{{buildMeta}}";
+public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}";
+public static final String SEPARATOR = "{{separator}}";
+public static final String VERSION = "{{version}}";
+
+/**
+* Disables the default constructor.
+*/
+private {{className}}() {
+throw new UnsupportedOperationException("Illegal constructor call.");
+}
+}
diff --git a/bin/test/net/thauvin/erik/semver/ConstantsTest.class b/bin/test/net/thauvin/erik/semver/ConstantsTest.class
new file mode 100644
index 0000000..934286a
Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/ConstantsTest.class differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class
new file mode 100644
index 0000000..d6401b4
Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class
new file mode 100644
index 0000000..af2b771
Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionTest.class b/bin/test/net/thauvin/erik/semver/VersionTest.class
new file mode 100644
index 0000000..0047ff2
Binary files /dev/null and b/bin/test/net/thauvin/erik/semver/VersionTest.class differ
diff --git a/bld b/bld
new file mode 100755
index 0000000..824b742
--- /dev/null
+++ b/bld
@@ -0,0 +1,2 @@
+#!/usr/bin/env sh
+java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build net.thauvin.erik.semver.SemverBuild "$@"
\ No newline at end of file
diff --git a/bld.bat b/bld.bat
new file mode 100644
index 0000000..ab43bcd
--- /dev/null
+++ b/bld.bat
@@ -0,0 +1,4 @@
+@echo off
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build net.thauvin.erik.semver.SemverBuild %*
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index 39dd5d0..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,217 +0,0 @@
-plugins {
- id "com.jfrog.bintray" version "1.7.3"
-}
-apply plugin: 'java'
-apply plugin: 'idea'
-apply plugin: 'maven'
-apply plugin: 'maven-publish'
-
-import org.apache.tools.ant.taskdefs.condition.Os
-
-defaultTasks 'deploy'
-
-def getVersion(isIncrement = false) {
- def propsFile = 'version.properties'
- def majorKey = 'version.major'
- def minorKey = 'version.minor'
- def patchKey = 'version.patch'
- def metaKey = 'version.buildmeta'
- def preKey = 'version.prerelease'
- if (isIncrement) {
- ant.propertyfile(file: propsFile) {
- entry(key: patchKey,
- type: 'int',
- default: '-1',
- operation: '+')
- }
- }
- def p = new Properties()
- file(propsFile).withInputStream { stream -> p.load(stream) }
- def metadata = p.getProperty(metaKey, '')
- def prerelease = p.getProperty(preKey, '')
- return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') +
- (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : ''))
-}
-
-version = getVersion()
-
-def deployDir = 'deploy'
-def isRelease = 'release' in gradle.startParameter.taskNames
-
-def mavenGroupId = 'net.thauvin.erik'
-def mavenName = 'SemVer'
-def mavenDescription = 'Semantic Version Annotation Processor'
-def mavenUrl = 'https://github.com/ethauvin/semver'
-def mavenLicense = 'The BSD 3-Clause License'
-def mavenLicenseUrl = 'http://opensource.org/licenses/BSD-3-Clause'
-def mavenScmCon = 'https://github.com/ethauvin/semver.git'
-def mavenScmDevCon = 'git@github.com:ethauvin/semver.git'
-
-def pkgLicenses = ['BSD 3-Clause']
-def pkgIssueTrackerUrl = mavenUrl + '/issues'
-def pkgLabels = ['java', 'annotation', 'processor', 'semantic', 'version']
-
-[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
-
-repositories {
- mavenLocal()
- jcenter()
-}
-
-dependencies {
- compile 'com.github.spullara.mustache.java:compiler:0.9.4'
- testCompile 'org.testng:testng:6.11'
-}
-
-bintray {
- user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
- key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY')
- publications = ['MyPublication']
- dryRun = true
- pkg {
- repo = 'maven'
- name = mavenName
- licenses = pkgLicenses
- desc = mavenDescription
- websiteUrl = mavenUrl
- issueTrackerUrl = pkgIssueTrackerUrl
- vcsUrl = mavenScmCon
- labels = pkgLabels
- publicDownloadNumbers = true
- version {
- name = project.version
- desc = 'Version ' + project.version
- vcsTag = project.version
- gpg {
- sign = true
- }
- }
- }
-}
-
-def pomConfig = {
- licenses {
- license {
- name mavenLicense
- url mavenLicenseUrl
- distribution 'repo'
- }
- }
- developers {
- developer {
- id 'ethauvin'
- name 'Erik C. Thauvin'
- email 'erik@thauvin.net'
- }
- }
- scm {
- connection 'scm:git:' + mavenScmCon
- developerConnection 'scm:git:' + mavenScmDevCon
- url mavenScmCon
- }
-}
-
-publishing {
- publications {
- MyPublication(MavenPublication) {
- from components.java
- artifact sourcesJar
- artifact javadocJar
- groupId mavenGroupId
- artifactId rootProject.name
- version project.version
-
- pom.withXml {
- def root = asNode()
- root.appendNode('name', mavenName)
- root.appendNode('description', mavenDescription)
- root.appendNode('url', mavenUrl)
- root.children().last() + pomConfig
- }
- }
- }
-}
-
-task javadocJar(type: Jar, dependsOn: javadoc) {
- group = 'Build'
- description = 'Builds an archive of the javadoc docs.'
- classifier = 'javadoc'
- from javadoc.destinationDir
-}
-
-task sourcesJar(type: Jar) {
- group = 'Build'
- description = 'Builds an archive of the source code.'
- classifier = 'sources'
- from sourceSets.main.allSource
-}
-
-artifacts {
- archives javadocJar
- archives sourcesJar
-}
-
-javadoc {
- title = mavenDescription + ' ' + version
- options.tags = ['created']
- options.author = true
- options.addStringOption('link', 'http://docs.oracle.com/javase/8/docs/api/')
- //options.addStringOption('sourcepath', project.hasProperty('jdkSrc') ? jdkSrc : "$System.env.JAVA_HOME/src.zip")
- if (JavaVersion.current().isJava8Compatible()) {
- options.addStringOption('Xdoclint:none', '-quiet')
- }
-}
-
-test {
- useTestNG()
-}
-
-compileJava {
- doFirst {
- project.version = getVersion(isRelease)
- }
-}
-
-clean {
- delete deployDir
-}
-
-task copyToDeploy(type: Copy) {
- from jar
- into deployDir
-}
-
-task deploy(dependsOn: ['build', 'copyToDeploy']) {
- description = 'Copies all needed files to the ${deployDir} directory.'
- group = 'Publishing'
- outputs.dir deployDir
- inputs.files copyToDeploy
- mustRunAfter clean
-}
-
-task wrapper(type: Wrapper) {
- gradleVersion = gradle.gradleVersion
-}
-
-task release(dependsOn: ['wrapper', 'clean', 'deploy']) {
- doLast {
- group = 'Publishing'
- description = 'Releases new version.'
- isRelease = true
- }
-}
-
-task pandoc(type: Exec) {
- group = 'Documentation'
- def pandoc_args = ['--from', 'markdown_github', '--to', 'html5', '-s', '-c', 'github-pandoc.css', '-o', 'README.html', 'README.md']
- if (Os.isFamily(Os.FAMILY_WINDOWS)) {
- commandLine(['cmd', '/c', 'pandoc'] + pandoc_args)
- } else {
- executable 'pandoc'
- args pandoc_args
- }
- standardOutput = new ByteArrayOutputStream()
- ext.output = {
- return standardOutput.toString()
- }
-}
\ No newline at end of file
diff --git a/clean.sh b/clean.sh
deleted file mode 100644
index 552252d..0000000
--- a/clean.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-
-DEBUG=false
-
-rm="rm -rf"
-
-if [ "$DEBUG" = true ]; then
- rm="echo rm -rf"
-fi
-
-buildkt="kobalt/src/Build.kt"
-
-name=$(cat $buildkt | grep -m 1 "name = " | cut -d"\"" -f 2)
-group=$(cat $buildkt | grep -m 1 "group = " | cut -d"\"" -f 2)
-
-if [ -z "$1" ]; then
- version=$(cat $buildkt | grep -m 1 "version = " | cut -d"\"" -f 2)
-else
- version="$1"
-fi
-
-maven="/k/maven/repository/${group//.//}/${name}/${version}"
-kobalt="$HOME/.kobalt/cache/${group//.//}/${name}/${version}"
-localRepo="$HOME/.kobalt/localMavenRepo/${group//.//}/${name}/${version}"
-
-read -p "Delete version ${version}? " -n 1 -r
-echo
-if [[ $REPLY =~ ^[Yy]$ ]]; then
- for dir in "$kobalt" "$maven" "$localRepo"; do
- if [ -d "$dir" ]; then
- echo -e "Deleting : \e[32;1m$dir\e[0m"
- $rm "$dir"
- else
- echo -e "Not Found: \e[31;1m$dir\e[0m"
- fi
- done
-fi
\ No newline at end of file
diff --git a/config/pmd.xml b/config/pmd.xml
new file mode 100644
index 0000000..2641880
--- /dev/null
+++ b/config/pmd.xml
@@ -0,0 +1,109 @@
+
+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 +and works well in conjunction with the Semantic +Version Plugin for Gradle.
+import net.thauvin.erik.semver.Version;
+
+@Version(major = 2, minor = 1, patch = 1, preRelease = "beta")
+public class A {
+// ...
+ }
import net.thauvin.erik.semver.Version;
+
+@Version(properties = "version.properties")
+public class A {
+// ...
+ }
# version.properties
+version.major=1
+version.minor=0
+version.patch=0
+version.prerelease=beta
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 in the project's root directory. The
+processor will automatically look for it.
To specify your own template name, use:
+@Version(template = "version.mustache")
+public class A {
+// ...
+ }
The default +template implements the following static variables:
+Field | +Description | +Example | +
---|---|---|
PROJECT |
+The project name, if any. | +MyProject |
+
BUILDDATE |
+The build date. | +java.util.Date |
+
VERSION |
+The full version string. | +1.2.3-alpha+001 |
+
MAJOR |
+The major version. | +1 |
+
MINOR |
+The minor version. | +2 |
+
PATCH |
+The patch version. | +3 |
+
PRERELEASE |
+The pre-release version, if any. | +alpha |
+
PRERELASE_PREFIX |
+The pre-release prefix | +- |
+
BUILDMETA |
+The build metadata, if any. | +001 |
+
BUILDMETA_PREFIX |
+The metadata prefix. | ++ |
+
SEPARATOR |
+The version separator. | +. |
+
A very simple custom template might look something like:
+/* version.mustache */
+package {{packageName}};
+
+import java.util.Date;
+
+public final class {{className}} {
+public final static String PROJECT = "{{project}}";
+ public final static Date DATE = new Date({{epoch}}L);
+ public final static String VERSION = "{{semver}}";
+ }
The mustache variables automatically filled in by the processor +are:
+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 |
+
{{preReleasePrefix}} |
+The pre-release prefix. | +String |
+
{{buildMeta}} |
+The build metadata version. | +String |
+
{{buildMetaPrefix}} |
+The metadata prefix. | +String |
+
{{separator}} |
+The version separator. | +String |
+
{{semver}} or
+{{version}} |
+The full semantic version. | +String |
+
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. | ++ |
preReleasePrefix |
+version.prerelease.prefix |
+The pre-release prefix. | +- |
+
buildMeta |
+version.buildmeta |
+The build metadata version. | ++ |
buildMetaPrefix |
+version.buildmeta.prefix |
+The metadata prefix. | ++ |
+
separator |
+version.separator |
+The version separator. | +. |
+
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. |
+java |
+
keysPrefix |
++ | The prefix for all property keys. | +version. |
+
In order to easily incorporate with existing projects, the property +keys may be assigned custom values:
+@Version(
+= "example.properties",
+ properties = "example.",
+ keysPrefix = "maj",
+ majorKey = "min",
+ minorKey = "build",
+ patchKey = "rel",
+ preReleaseKey = "meta",
+ buildMetaKey = "project"
+ projectKey )
+public class Example {
+// ...
+ }
# example.properties
+example.project=Example
+example.maj=1
+example.min=0
+example.build=0
+example.rel=beta
+example.meta=
+# ...
++⚠️ +
+keysPrefix
is a new element staring in1.1.0
+and may break older versions when using custom property keys.
+⚡ A quick fix is to include +keysPrefix=""
in the annotation to remove the default +version.
prefix.
To install and run from Maven, configure an artifact as +follows:
+dependency>
+ <groupId>net.thauvin.erik</groupId>
+ <artifactId>semver</artifactId>
+ <version>1.2.1</version>
+ <dependency> </
Please look at pom.xml +in the examples/java +directory for a sample:
+mvn verify
To install and run from bld, just +add the dependency to your build file:
+public class ExampleBuild extends Project {
+public ExampleBuild() {
+ // ...
+ scope(compile)
+ .include(dependency("net.thauvin.erik", "semver", version(1, 2, 1)));
+ }
+ }
Please look at ExampleBuild
+in the examples/java/bld
+directory for a sample. It also shows how to incorporate the generated
+code into the source tree
, more information is also
+available here.
bld also has a Generated +Version extension which provides similar functionalities.
+To install and run from Gradle, add +the following to build.gradle:
+{
+ repositories mavenCentral()
+ }
+
+{
+ dependencies 'net.thauvin.erik:semver:1.2.1'
+ annotationProcessor 'net.thauvin.erik:semver:1.2.1'
+ compileOnly }
+
+.withType(JavaCompile).configureEach {
+ tasks.compilerArgs += [ "-Asemver.project.dir=$projectDir" ]
+ options}
The directory containing the configuration files
+(version.properties
, version.mustache
) must be
+specified using the semver.project.dir
processor
+argument.
The GeneratedVersion.java
+class will be automatically created in the build/generated
+directory upon compiling.
Please look at build.gradle +in the examples/java/gradle +directory for a sample.
+In order to also incorporate the generated source code into the
+source tree
, add the following to build.gradle:
.withType(JavaCompile).configureEach {
+ tasks.generatedSourceOutputDirectory.set(file("${projectDir}/src/generated/java"))
+ options}
The GeneratedVersion.java
+file will now be located in src/generated
.
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 examples/kotlin +project for a build.gradle.kts +sample.
+To install and run from Gradle, add +the following to build.gradle.kts:
+var semverProcessor = "net.thauvin.erik:semver:1.2.1"
+
+{
+ dependencies (semverProcessor)
+ kapt(semverProcessor)
+ compileOnly}
+
+{
+ kapt {
+ arguments ("semver.project.dir", projectDir)
+ arg}
+ }
The directory containing the configuration files
+(version.properties
, version.mustache
) must be
+specified using the semver.project.dir
processor
+argument.
Incrementing the version is best left to your favorite build system. +For a solution using Gradle, please have a look at the Semver Version +Plugin for Gradle.
+There are also full examples +in both Java +and Kotlin +showing how to use both the plugin and annotation processor +concurrently.
+If you want to contribute to this project, all you have to do is +clone the GitHub repository:
+git clone git@github.com:ethauvin/semver.git
+Then use bld to build:
+cd semver
+./bld compile
+The project has an IntelliJ +IDEA project structure. You can just open it after all the +dependencies were downloaded and peruse the code.
+ + diff --git a/github-pandoc.css b/docs/github-pandoc.css similarity index 100% rename from github-pandoc.css rename to docs/github-pandoc.css diff --git a/example/.gitignore b/example/.gitignore deleted file mode 100644 index 51e51c5..0000000 --- a/example/.gitignore +++ /dev/null @@ -1,28 +0,0 @@ -**/.idea/dictionaries -**/.idea/gradle.xml -**/.idea/libraries -**/.idea/tasks.xml -**/.idea/workspace.xml -*.iws -.DS_Store -.classpath -.gradle -.kobalt -.nb-gradle -.project -.settings -/bin -/build -/deploy -/dist -/gen -/gradle.properties -/libs -/local.properties -/out -/proguard-project.txt -/project.properties -/test-output -Thumbs.db -ehthumbs.db -kobaltBuild \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle deleted file mode 100644 index 92eabb2..0000000 --- a/example/build.gradle +++ /dev/null @@ -1,95 +0,0 @@ -plugins { - id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.4" -} -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'application' - -defaultTasks 'run' - -def isRelease = 'release' in gradle.startParameter.taskNames -def deployDir = 'deploy' -def processorJar = 'net.thauvin.erik:semver:1.0.0' - -// Get version from properties file. Increment patch if specified. -def getVersion(isIncrement = false) { - def propsFile = 'version.properties' - def majorKey = 'version.major' - def minorKey = 'version.minor' - def patchKey = 'version.patch' - def metaKey = 'version.buildmeta' - def preKey = 'version.prerelease' - if (isIncrement) { - ant.propertyfile(file: propsFile) { - entry(key: patchKey, - type: 'int', - default: '-1', - operation: '+') - } - } - def p = new Properties() - file(propsFile).withInputStream { stream -> p.load(stream) } - def metadata = p.getProperty(metaKey, '') - def prerelease = p.getProperty(preKey, '') - return (p.getProperty(majorKey, '1') + '.' + p.getProperty(minorKey, '0') + '.' + p.getProperty(patchKey, '0') + - (prerelease.length() > 0 ? '-' + prerelease : '') + (metadata.length() > 0 ? '+' + metadata : '')) -} - -version = getVersion() - -mainClassName = 'net.thauvin.erik.semver.example.Example' -[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' - -repositories { - mavenLocal() - mavenCentral() -} - -dependencies { - compileOnly processorJar -} - -annotationProcessor { - // Update version, increment on release. - project.version = getVersion(isRelease) - library processorJar - processor 'net.thauvin.erik.semver.VersionProcessor' - // sourcesDir 'src/generated/java' -} - -compileJava { - options.compilerArgs << '-proc:none' -} - -jar { - manifest.attributes('Main-Class': mainClassName) -} - -clean { - delete deployDir -} - -task copyToDeploy(type: Copy) { - from jar - into deployDir -} - -task deploy(dependsOn: ['build', 'copyToDeploy']) { - description = 'Copies all needed files to the ${deployDir} directory.' - group = 'Publishing' - outputs.dir deployDir - inputs.files copyToDeploy - mustRunAfter clean -} - -task release(dependsOn: ['wrapper', 'clean', 'deploy']) { - doLast { - group = 'Publishing' - description = 'Releases new version.' - isRelease = true - } -} - -task wrapper(type: Wrapper) { - gradleVersion = gradle.gradleVersion -} diff --git a/example/gradle/wrapper/gradle-wrapper.jar b/example/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 3baa851..0000000 Binary files a/example/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/example/gradlew b/example/gradlew deleted file mode 100644 index 27309d9..0000000 --- a/example/gradlew +++ /dev/null @@ -1,164 +0,0 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/example/gradlew.bat b/example/gradlew.bat deleted file mode 100644 index 832fdb6..0000000 --- a/example/gradlew.bat +++ /dev/null @@ -1,90 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt deleted file mode 100644 index 46eeb64..0000000 --- a/example/kobalt/src/Build.kt +++ /dev/null @@ -1,70 +0,0 @@ -import com.beust.kobalt.* -import com.beust.kobalt.plugin.application.* -import com.beust.kobalt.plugin.apt.* -import com.beust.kobalt.plugin.publish.* -import com.beust.kobalt.plugin.packaging.* -import java.io.FileInputStream -import java.util.* - -// .kobaltw run - -val bs = buildScript { - repos(localMaven()) -} - -fun StringBuilder.prepend(s: String): StringBuilder { - if (this.isNotEmpty()) { - this.insert(0, s) - } - return this -} - -val example = project { - - name = "example" - - fun versionFor(): String { - val propsFile = "version.properties" - val majorKey = "version.major" - val minorKey = "version.minor" - val patchKey = "version.patch" - val metaKey = "version.buildmeta" - val preKey = "version.prerelease" - - val p = Properties().apply { FileInputStream(propsFile).use { fis -> load(fis) } } - - return (p.getProperty(majorKey, "1") + "." + p.getProperty(minorKey, "0") + "." + p.getProperty(patchKey, "0") - + StringBuilder(p.getProperty(preKey, "")).prepend("-") - + StringBuilder(p.getProperty(metaKey, "")).prepend("+")) - } - - version = versionFor() - - val mainClassName = "net.thauvin.erik.semver.example.Example" - val processorJar = "net.thauvin.erik:semver:1.0.0" - - dependencies { - apt(processorJar) - compileOnly(processorJar) - } - - apt { - //outputDir = "../src/generated/java/" - } - - install { - target = "deploy" - } - - assemble { - jar { - manifest { - attributes("Main-Class", mainClassName) - } - } - } - - application { - mainClass = mainClassName - } -} \ No newline at end of file diff --git a/example/kobalt/wrapper/kobalt-wrapper.jar b/example/kobalt/wrapper/kobalt-wrapper.jar deleted file mode 100644 index 5390ba7..0000000 Binary files a/example/kobalt/wrapper/kobalt-wrapper.jar and /dev/null differ diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties deleted file mode 100644 index eb3786f..0000000 --- a/example/kobalt/wrapper/kobalt-wrapper.properties +++ /dev/null @@ -1 +0,0 @@ -kobalt.version=1.0.85 diff --git a/example/kobaltw b/example/kobaltw deleted file mode 100644 index c5186d5..0000000 --- a/example/kobaltw +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/example/kobaltw.bat b/example/kobaltw.bat deleted file mode 100644 index d578071..0000000 --- a/example/kobaltw.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo off -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* 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 a301be1..0000000 --- a/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java +++ /dev/null @@ -1,103 +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 { - public final static String PRERELEASE_PREFIX = "-"; - public final static String BUILDMETA_PREFIX = "+"; - - public final static String PROJECT = "Example"; - public final static Date BUILDDATE = new Date(1493952813608L); - public final static int MAJOR = 2; - public final static int MINOR = 17; - public final static int PATCH = 52; - public final static String PRERELEASE = "beta"; - public final static String BUILDMETA = "007"; - - /** - * 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
+ * To incorporate the generated source code into the source tree, add this directory as an additional source
+ * location in your IDE.
+ */
+ @Override
+ public void compile() throws Exception {
+ var generated = new File(buildDirectory(), "generated");
+ var ignore = generated.mkdir();
+ compileOperation().compileOptions().process(Processing.FULL).sourceOutput(generated);
+ super.compile();
+ }
+
+ @BuildCommand(value = "run-example", summary = "Runs the example")
+ public void runExample() throws Exception {
+ runOperation().fromProject(this).mainClass("com.example.Example").execute();
+ }
+}
diff --git a/examples/java/bld/src/main/java/com/example/App.java b/examples/java/bld/src/main/java/com/example/App.java
new file mode 100644
index 0000000..91134b7
--- /dev/null
+++ b/examples/java/bld/src/main/java/com/example/App.java
@@ -0,0 +1,31 @@
+package com.example;
+
+import net.thauvin.erik.semver.Version;
+
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+@Version(properties = "version.properties")
+public final class App {
+ /**
+ * Command line interface.
+ *
+ * @param args The command line parameters.
+ */
+ public static void main(final String... args) {
+ final var sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
+
+ System.out.println("-----------------------------------------------------");
+
+ System.out.println(" Version: " + GeneratedVersion.PROJECT + ' ' + GeneratedVersion.VERSION);
+
+ System.out.println(" Built on: " + sdf.format(GeneratedVersion.BUILDDATE));
+ System.out.println(" Major: " + GeneratedVersion.MAJOR);
+ System.out.println(" Minor: " + GeneratedVersion.MINOR);
+ System.out.println(" Patch: " + GeneratedVersion.PATCH);
+ System.out.println(" PreRelease: " + GeneratedVersion.PRERELEASE);
+ System.out.println(" BuildMetaData: " + GeneratedVersion.BUILDMETA);
+
+ System.out.println("-----------------------------------------------------");
+ }
+}
diff --git a/examples/java/bld/src/main/java/com/example/Example.java b/examples/java/bld/src/main/java/com/example/Example.java
new file mode 100644
index 0000000..1829d52
--- /dev/null
+++ b/examples/java/bld/src/main/java/com/example/Example.java
@@ -0,0 +1,21 @@
+package com.example;
+
+import net.thauvin.erik.semver.Version;
+
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+@Version(properties = "example.properties", template = "example.mustache", className = "ExampleVersion",
+ keysPrefix = "example.")
+public class Example {
+ public static void main(final String... args) {
+ final var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
+
+ System.out.println("-- From Example -------------------------------------");
+
+ System.out.println(" " + ExampleVersion.PROJECT + ' ' + ExampleVersion.VERSION
+ + " (" + sdf.format(ExampleVersion.BUILDDATE) + ')');
+
+ System.out.println("-----------------------------------------------------");
+ }
+}
diff --git a/examples/java/bld/src/test/java/com/example/ExampleTest.java b/examples/java/bld/src/test/java/com/example/ExampleTest.java
new file mode 100644
index 0000000..f0452f2
--- /dev/null
+++ b/examples/java/bld/src/test/java/com/example/ExampleTest.java
@@ -0,0 +1,18 @@
+package com.example;
+
+public class ExampleTest {
+ private static final String HELLO = "Hello!";
+
+ public static void main(String[] args) {
+ var hello = new ExampleTest().verifyHello();
+ if (HELLO.equals(hello)) {
+ System.out.println("Succeeded");
+ } else {
+ throw new AssertionError();
+ }
+ }
+
+ String verifyHello() {
+ return HELLO;
+ }
+}
diff --git a/examples/java/bld/version.properties b/examples/java/bld/version.properties
new file mode 100644
index 0000000..dc68bf3
--- /dev/null
+++ b/examples/java/bld/version.properties
@@ -0,0 +1,9 @@
+#Generated by the Semver Plugin for Gradle
+#Sat Apr 27 17:05:34 PDT 2019
+version.buildmeta=007
+version.major=11
+version.minor=11
+version.patch=20
+version.prerelease=beta
+version.project=Java App
+version.semver=11.11.20-beta+007
diff --git a/examples/java/gradle/.editorconfig b/examples/java/gradle/.editorconfig
new file mode 100644
index 0000000..1f808de
--- /dev/null
+++ b/examples/java/gradle/.editorconfig
@@ -0,0 +1,2 @@
+[*]
+insert_final_newline = true
diff --git a/examples/java/gradle/.gitattributes b/examples/java/gradle/.gitattributes
new file mode 100644
index 0000000..6ec2ae2
--- /dev/null
+++ b/examples/java/gradle/.gitattributes
@@ -0,0 +1,5 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto
+
+# batch files are specific to windows and always crlf
+*.bat eol=crlf
diff --git a/examples/java/gradle/.gitignore b/examples/java/gradle/.gitignore
new file mode 100644
index 0000000..a78c5c2
--- /dev/null
+++ b/examples/java/gradle/.gitignore
@@ -0,0 +1,82 @@
+!.vscode/extensions.json
+!.vscode/launch.json
+!.vscode/settings.json
+!.vscode/tasks.json
+!gradle-wrapper.jar
+.classpath
+.DS_Store
+.gradle
+.history
+.idea_modules/
+.idea/**/contentModel.xml
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/dataSources/
+.idea/**/dbnavigator.xml
+.idea/**/dictionaries
+.idea/**/dynamic.xml
+.idea/**/gradle.xml
+.idea/**/libraries
+.idea/**/mongoSettings.xml
+.idea/**/shelf
+.idea/**/sqlDataSources.xml
+.idea/**/tasks.xml
+.idea/**/uiDesigner.xml
+.idea/**/usage.statistics.xml
+.idea/**/workspace.xml
+.idea/caches/build_file_checksums.ser
+.idea/httpRequests
+.idea/replstate.xml
+.kobalt
+.mtj.tmp/
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+.nb-gradle
+.project
+.scannerwork
+.settings
+.vscode/*
+*.class
+*.code-workspace
+*.ctxt
+*.ear
+*.iws
+*.jar
+*.log
+*.nar
+*.rar
+*.sublime-*
+*.tar.gz
+*.war
+*.zip
+atlassian-ide-plugin.xml
+bin/
+build/
+cmake-build-*/
+com_crashlytics_export_strings.xml
+crashlytics-build.properties
+crashlytics.properties
+dependency-reduced-pom.xml
+deploy/
+dist/
+ehthumbs.db
+fabric.properties
+gen/
+gradle.properties
+hs_err_pid*
+kobaltBuild
+kobaltw*-test
+lib/kotlin*
+libs/
+local.properties
+out/
+pom.xml.next
+pom.xml.releaseBackup
+pom.xml.tag
+pom.xml.versionsBackup
+proguard-project.txt
+project.properties
+release.properties
+target/
+test-output
+Thumbs.db
diff --git a/examples/java/gradle/.idea/.name b/examples/java/gradle/.idea/.name
new file mode 100644
index 0000000..2ba6afe
--- /dev/null
+++ b/examples/java/gradle/.idea/.name
@@ -0,0 +1 @@
+semver-examples-java-gradle
\ No newline at end of file
diff --git a/examples/java/gradle/.idea/compiler.xml b/examples/java/gradle/.idea/compiler.xml
new file mode 100644
index 0000000..a83902e
--- /dev/null
+++ b/examples/java/gradle/.idea/compiler.xml
@@ -0,0 +1,20 @@
+
+
- * Formatted as:
- *
- * For example:
+ *
+ * Formatted as:
+ * For example:
*
- * Formatted as:
- *
- * For example:
- *
- * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]
+ *
+ *
+ *
+ * [MAJOR][SEPARATOR][MINOR][SEPARATOR][PATCH][[PRERELEASE-PREFIX][PRERELEASE]][[BUILDMETA-PREFIX][BUILDMETA]]
+ *
+ *
*
1.0.0
1.0.0-beta
GeneratedVersion
class containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
+
+
+ GeneratedVersion
class containing the semantic
+version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
@since 1.0
-
-
+
+
diff --git a/src/main/resources/semver-kt.mustache b/src/main/resources/semver-kt.mustache
index febd83d..cf53df5 100644
--- a/src/main/resources/semver-kt.mustache
+++ b/src/main/resources/semver-kt.mustache
@@ -2,9 +2,10 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
+
package {{packageName}}
-import java.util.*
+import java.util.Date
/**
* Provides semantic version information.
@@ -12,47 +13,26 @@ import java.util.*
* @author Semantic Version Annotation Processor
*/
object {{className}} {
- @JvmField val PRERELEASE_PREFIX = "-"
- @JvmField val BUILDMEATA_PREFIX = "+"
-
- @JvmField val PROJECT = "{{project}}"
- @JvmField val BUILDDATE = Date({{epoch}}L)
- @JvmField val MAJOR = {{major}}
- @JvmField val MINOR = {{minor}}
- @JvmField val PATCH = {{patch}}
- @JvmField val PRERELEASE = "{{preRelease}}"
- @JvmField val BUILDMETA = "{{buildMeta}}"
-
- /**
- * The full version string formatted as [MAJOR].[MINOR].[PATCH]-[PRERELEASE]+[BUILDMETA]
- */
- @JvmField val VERSION = "$MAJOR.$MINOR.$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix()
-
- /**
- * 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 {
- PRERELEASE
- }
- }
-
- /**
- * 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 {
- BUILDMETA
- }
- }
-}
\ No newline at end of file
+ @JvmField
+ val PROJECT = "{{project}}"
+ @JvmField
+ val BUILDDATE = Date({{epoch}}L)
+ @JvmField
+ val MAJOR = {{major}}
+ @JvmField
+ val MINOR = {{minor}}
+ @JvmField
+ val PATCH = {{patch}}
+ @JvmField
+ val PRERELEASE = "{{preRelease}}"
+ @JvmField
+ val PRERELEASE_PREFIX = "{{preReleasePrefix}}"
+ @JvmField
+ val BUILDMETA = "{{buildMeta}}"
+ @JvmField
+ val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}"
+ @JvmField
+ val SEPARATOR = "{{separator}}"
+ @JvmField
+ val VERSION = "{{version}}"
+}
diff --git a/src/main/resources/semver.mustache b/src/main/resources/semver.mustache
index 88becf0..d9eb417 100644
--- a/src/main/resources/semver.mustache
+++ b/src/main/resources/semver.mustache
@@ -2,6 +2,7 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
+
package {{packageName}};
import java.util.Date;
@@ -12,91 +13,22 @@ import java.util.Date;
* @author Semantic Version Annotation Processor
*/
public final class {{className}} {
- public final static String PRERELEASE_PREFIX = "-";
- public final static String BUILDMETA_PREFIX = "+";
-
- public final static String PROJECT = "{{project}}";
- public final static Date BUILDDATE = 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 full version string.
- *
- *
- * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]
- *
- *
- */
- public final static String VERSION = Integer.toString(MAJOR) + '.'
- + Integer.toString(MINOR) + '.'
- + Integer.toString(PATCH)
- + preReleaseWithPrefix() + buildMetaWithPrefix();
+ public static final String PROJECT = "{{project}}";
+ public static final Date BUILDDATE = new Date({{epoch}}L);
+ public static final int MAJOR = {{major}};
+ public static final int MINOR = {{minor}};
+ public static final int PATCH = {{patch}};
+ public static final String PRERELEASE = "{{preRelease}}";
+ public static final String PRERELEASE_PREFIX = "{{preReleasePrefix}}";
+ public static final String BUILDMETA = "{{buildMeta}}";
+ public static final String BUILDMETA_PREFIX = "{{buildMetaPrefix}}";
+ public static final String SEPARATOR = "{{separator}}";
+ public static final String VERSION = "{{version}}";
/**
* Disables the default constructor.
- *
- * @throws UnsupportedOperationException If the constructor is called.
*/
- private {{className}}()
- throws UnsupportedOperationException {
+ private {{className}}() {
throw new UnsupportedOperationException("Illegal constructor call.");
}
-
- /**
- * Returns the build metadata with {@value #BUILDMETA_PREFIX} prefix.
- *
- * @return The build metadata, if any.
- */
- public static String buildMetaWithPrefix() {
- return buildMetaWithPrefix(BUILDMETA_PREFIX);
- }
-
- /**
- * Returns the build metadata.
- *
- * @param prefix Prefix to prepend.
- * @return The build metadata, if any.
- */
- public static String buildMetaWithPrefix(final String prefix) {
- if (BUILDMETA.length() > 0 && prefix.length() > 0) {
- return prefix + BUILDMETA;
- } else {
- return BUILDMETA;
- }
- }
-
- /**
- * Returns the pre-release version with {@value #PRERELEASE_PREFIX} prefix.
- *
- * @return The pre-release version, if any.
- */
- public static String preReleaseWithPrefix() {
- return preReleaseWithPrefix(PRERELEASE_PREFIX);
- }
-
- /**
- * Returns the pre-release version.
- *
- * @param prefix The prefix to prepend.
- * @return The pre-release version, if any.
- */
- public static String preReleaseWithPrefix(final String prefix) {
- if (PRERELEASE.length() > 0 && prefix.length() > 0) {
- return prefix + PRERELEASE;
- } else {
- return PRERELEASE;
- }
- }
-}
\ No newline at end of file
+}
diff --git a/example/src/main/java/net/thauvin/erik/semver/example/Example.java b/src/test/java/net/thauvin/erik/semver/ConstantsTest.java
similarity index 54%
rename from example/src/main/java/net/thauvin/erik/semver/example/Example.java
rename to src/test/java/net/thauvin/erik/semver/ConstantsTest.java
index d4e81a0..c82f718 100644
--- a/example/src/main/java/net/thauvin/erik/semver/example/Example.java
+++ b/src/test/java/net/thauvin/erik/semver/ConstantsTest.java
@@ -1,7 +1,7 @@
/*
- * Example.java
+ * ConstantsTest.java
*
- * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,35 +29,45 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-package net.thauvin.erik.semver.example;
-import net.thauvin.erik.semver.Version;
+package net.thauvin.erik.semver;
-import java.text.SimpleDateFormat;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * The 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
Example
class.
+ * The ConstantsTest
class.
*
- * @author Erik C. Thauvin
- * @created 2016-01-13
+ * @author Erik C. Thauvin
+ * @created 2019-04-14
* @since 1.0
*/
-@Version(properties = "version.properties")
-public class Example {
- public static void main(final String... args) {
- final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z");
-
- System.out.println("-----------------------------------------------------");
-
- System.out.println(" " + GeneratedVersion.PROJECT + ' ' + GeneratedVersion.VERSION);
-
- System.out.println(" Built on: " + sdf.format(GeneratedVersion.BUILDDATE));
- System.out.println(" Major: " + GeneratedVersion.MAJOR);
- System.out.println(" Minor: " + GeneratedVersion.MINOR);
- System.out.println(" Patch: " + GeneratedVersion.PATCH);
- System.out.println(" PreRelease: " + GeneratedVersion.PRERELEASE);
- System.out.println(" BuildMetaData: " + GeneratedVersion.BUILDMETA);
-
- System.out.println("-----------------------------------------------------");
+class ConstantsTest {
+ @Test
+ void testDefaults() {
+ assertEquals(1, Constants.DEFAULT_MAJOR, "major");
+ assertEquals(0, Constants.DEFAULT_MINOR, "minor");
+ assertEquals(0, Constants.DEFAULT_PATCH, "patch");
+ assertEquals("-", Constants.DEFAULT_PRERELEASE_PREFIX, "preRelease");
+ assertEquals("+", Constants.DEFAULT_BUILDMETA_PREFIX, "buildMeta");
+ assertEquals(".", Constants.DEFAULT_SEPARATOR, "separator");
}
-}
\ No newline at end of file
+
+ @Test
+ void testTemplates() {
+ final ListVersionInfoTest
class.
@@ -44,210 +46,150 @@ import java.util.Calendar;
* @created 2016-02-03
* @since 1.0
*/
-public class VersionInfoTest {
- private final Calendar now = Calendar.getInstance();
+class VersionInfoTest {
private VersionInfo versionInfo = new VersionInfo();
+ @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
- public void testGetVersion()
- throws Exception {
-
- Assert.assertEquals(versionInfo.getVersion(), "1.0.0", "getVersion(1.0.0)");
+ void testGetVersion() {
+ assertEquals("1.0.0", versionInfo.getVersion(), "getVersion(1.0.0)");
versionInfo.setMajor(3);
- Assert.assertEquals(versionInfo.getVersion(), "3.0.0", "getVersion(3.0.0)");
+ assertEquals("3.0.0", versionInfo.getVersion(), "getVersion(3.0.0)");
versionInfo.setMinor(2);
- Assert.assertEquals(versionInfo.getVersion(), "3.2.0", "getVersion(3.2.0)");
+ assertEquals("3.2.0", versionInfo.getVersion(), "getVersion(3.2.0)");
versionInfo.setPatch(1);
- Assert.assertEquals(versionInfo.getVersion(), "3.2.1", "getVersion(3.2.1)");
+ assertEquals("3.2.1", versionInfo.getVersion(), "getVersion(3.2.1)");
versionInfo.setPreRelease("beta");
- Assert.assertEquals(versionInfo.getVersion(), "3.2.1-beta", "getVersion(3.2.1-beta)");
+ assertEquals("3.2.1-beta", versionInfo.getVersion(), "getVersion(3.2.1-beta)");
versionInfo.setBuildMeta("001");
- Assert.assertEquals(versionInfo.getVersion(), "3.2.1-beta+001", "getVersion(3.2.1-beta+001)");
+ assertEquals("3.2.1-beta+001", versionInfo.getVersion(), "getVersion(3.2.1-beta+001)");
+
+ versionInfo.setPreReleasePrefix("+");
+
+ assertEquals("3.2.1+beta+001", versionInfo.getVersion(), "getVersion(3.2.1+beta+001)");
+
+ versionInfo.setPreReleasePrefix("-");
versionInfo.setPreRelease("");
- Assert.assertEquals(versionInfo.getVersion(), "3.2.1+001", "getVersion(3.2.1+001)");
+ assertEquals("3.2.1+001", versionInfo.getVersion(), "getVersion(3.2.1+001)");
+
+ versionInfo.setBuildMetaPrefix(".");
+
+ assertEquals("3.2.1.001", versionInfo.getVersion(), "getVersion(3.2.1.001)");
+
+ versionInfo.setBuildMetaPrefix("+");
+
+ versionInfo.setSeparator("-");
+
+ assertEquals("3-2-1+001", versionInfo.getVersion(), "getVersion(3-2-1+001)");
+
+ assertEquals(versionInfo.getSemver(), versionInfo.getVersion(),
+ "getVersion(3-2-1+001) = getSemver(3-2-1+001) ");
}
@Test
- public void testSetGet()
- throws Exception {
+ void testSetGet() {
+ versionInfo.setSeparator(".");
versionInfo.setMajor(1);
- Assert.assertEquals(versionInfo.getMajor(), 1, "getMajor(1)");
+ assertEquals(1, versionInfo.getMajor(), "getMajor(1)");
versionInfo.setMinor(2);
- Assert.assertEquals(versionInfo.getMinor(), 2, "getMinor(2)");
+ assertEquals(2, versionInfo.getMinor(), "getMinor(2)");
versionInfo.setPatch(3);
- Assert.assertEquals(versionInfo.getPatch(), 3, "getPatch(3)");
+ assertEquals(3, versionInfo.getPatch(), "getPatch(3)");
versionInfo.setPreRelease("alpha");
- Assert.assertEquals(versionInfo.getPreRelease(), "alpha", "getPreRelease(alpha)");
+ assertEquals("alpha", versionInfo.getPreRelease(), "getPreRelease(alpha)");
versionInfo.setBuildMeta("001");
- Assert.assertEquals(versionInfo.getBuildMeta(), "001", "getBuildMeta(001)");
+ assertEquals("001", versionInfo.getBuildMeta(), "getBuildMeta(001)");
versionInfo.setPackageName("com.example");
- Assert.assertEquals(versionInfo.getPackageName(), "com.example", "getPackageName(com.example)");
+ assertEquals("com.example", versionInfo.getPackageName(), "getPackageName(com.example)");
- Assert.assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)");
+ assertEquals("1.2.3-alpha+001", versionInfo.getVersion(), "getVersion(1.2.3-alpha+001)");
+
+ assertEquals(versionInfo.getSemver(), versionInfo.getVersion(), "getVersion() = getSemver()");
+
+ versionInfo.setBuildMetaPrefix("");
+
+ assertEquals("", versionInfo.getBuildMetaPrefix(), "getBuildMetaPrefix( )");
+
+ assertEquals("1.2.3-alpha001", versionInfo.getVersion(), "getVersion(1.2.3+alpha001)");
+
+ versionInfo.setPreReleasePrefix(".");
+
+ assertEquals(".", versionInfo.getPreReleasePrefix(), "getPreReleasePrefix(.)");
+
+ assertEquals("1.2.3.alpha001", versionInfo.getVersion(), "getVersion(1.2.3.alpha001");
+
+ versionInfo.setSeparator("-");
+
+ assertEquals("-", versionInfo.getSeparator(), "getSeparator(-)");
+
+ assertEquals("1-2-3.alpha001", versionInfo.getVersion(), "getVersion(1-2-3.alpha001)");
versionInfo.setProject("My Example");
- Assert.assertEquals(versionInfo.getProject(), "My Example", "getProject(My Example)");
+ assertEquals("My Example", versionInfo.getProject(), "getProject(My Example)");
versionInfo.setClassName("Example");
- Assert.assertEquals(versionInfo.getClassName(), "Example", "getClassName(Example");
+ assertEquals("Example", versionInfo.getClassName(), "getClassName(Example");
- Assert.assertTrue((versionInfo.getEpoch() - now.getTimeInMillis()) < 1000,
- "buildDate - now < 1s");
+ assertTrue((versionInfo.getEpoch() - new Date().getTime()) < 1000, "buildDate - now < 1s");
}
@Test
- public void testVersionInfo()
- throws Exception {
-
+ void testVersionInfo() {
final Version version = new VersionTest();
versionInfo = new VersionInfo(version);
- Assert.assertEquals(versionInfo.getMajor(), version.major(), "getMajor(major)");
+ assertEquals(version.major(), versionInfo.getMajor(), "getMajor(major)");
- Assert.assertEquals(versionInfo.getMinor(), version.minor(), "getMinor(minor)");
+ assertEquals(version.minor(), versionInfo.getMinor(), "getMinor(minor)");
- Assert.assertEquals(versionInfo.getPatch(), version.patch(), "getPatch(patch)");
+ assertEquals(version.patch(), versionInfo.getPatch(), "getPatch(patch)");
- Assert.assertEquals(versionInfo.getPreRelease(), version.preRelease(), "getPreRelease(preRelease)");
+ assertEquals(version.preRelease(), versionInfo.getPreRelease(), "getPreRelease(preRelease)");
- Assert.assertEquals(versionInfo.getBuildMeta(), version.buildMeta(), "getBuildMeta(buildMeta)");
+ assertEquals(version.preReleasePrefix(), versionInfo.getPreReleasePrefix(),
+ "getPreReleasePrefix(preReleasePrefix)");
- Assert.assertEquals(versionInfo.getPackageName(), version.packageName(),
- "getPackageName(packageName)");
+ assertEquals(version.buildMeta(), versionInfo.getBuildMeta(), "getBuildMeta(buildMeta)");
- Assert.assertEquals(versionInfo.getVersion(),
- version.major()
- + "."
- + version.minor()
- + '.'
- + version.patch()
- + '-'
- + version.preRelease()
- + '+'
- + version.buildMeta(),
- "getVersion(version)");
+ assertEquals(version.buildMetaPrefix(), versionInfo.getBuildMetaPrefix(),
+ "getBuildMetaPrefix(buildMetaPrefix)");
- Assert.assertEquals(versionInfo.getProject(), version.project(), "getProject(project)");
+ assertEquals(version.packageName(), versionInfo.getPackageName(), "getPackageName(packageName)");
- Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)");
+ assertEquals(versionInfo.getVersion(),
+ version.major() + "." + version.minor() + '.' + version.patch() + '-' + version.preRelease() + '+'
+ + version.buildMeta(), "getVersion(version)");
+
+ assertEquals(versionInfo.getSemver(), versionInfo.getVersion(), "getVersion(version) = getSemver(version)");
+
+ assertEquals(version.project(), versionInfo.getProject(), "getProject(project)");
+
+ assertEquals(version.className(), versionInfo.getClassName(), "getClassName(className)");
}
}
-
-@SuppressWarnings("ClassExplicitlyAnnotation")
-class VersionTest implements Version {
- @Override
- public Class extends Annotation> annotationType() {
- return null;
- }
-
- @Override
- public String buildMeta() {
- return "007";
- }
-
- @Override
- public String buildMetaKey() {
- return "product.build.meta";
- }
-
- @Override
- public String className() {
- return "MyTest";
- }
-
- @Override
- public int major() {
- return 2;
- }
-
- @Override
- public String majorKey() {
- return "product.build.major";
- }
-
- @Override
- public int minor() {
- return 17;
- }
-
- @Override
- public String minorKey() {
- return "product.build.minor";
- }
-
- @Override
- public String packageName() {
- return "com.foo.example";
- }
-
- @Override
- public int patch() {
- return 52;
- }
-
- @Override
- public String patchKey() {
- return "product.build.patch";
- }
-
- @Override
- public String preRelease() {
- return "beta";
- }
-
- @Override
- public String preReleaseKey() {
- return "product.build.prerelease";
- }
-
- @Override
- public String project() {
- return "My Test Project";
- }
-
- @Override
- public String projectKey() {
- return "product.build.project";
- }
-
- @Override
- public String properties() {
- return "test.properties";
- }
-
- @Override
- public String template() {
- return "myversion.mustache";
- }
-
- @Override
- public String type() {
- return "kt";
- }
-}
\ No newline at end of file
diff --git a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java
new file mode 100644
index 0000000..c49af74
--- /dev/null
+++ b/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java
@@ -0,0 +1,186 @@
+/*
+ * VersionProcessorTest.java
+ *
+ * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.semver;
+
+import com.github.mustachejava.Mustache;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The VersionProcessorTest
class.
+ *
+ * @author Erik C. Thauvin
+ * @created 2019-04-02
+ * @since 1.2.0
+ */
+class VersionProcessorTest {
+ private final VersionProcessor processor = new VersionProcessor();
+ private final VersionTest version = new VersionTest();
+
+ /**
+ * Compares two strings by removing all line separators and whitespace.
+ *
+ * @param text1 The first text to compare
+ * @param text2 The second text to compare
+ * @return true if the texts are equivalent when line separators are ignored, false otherwise
+ */
+ static boolean compareTextIgnoringLineSeparators(String text1, String text2) {
+ // Handle null cases
+ if (text1 == null && text2 == null) {
+ return true;
+ }
+ if (text1 == null || text2 == null) {
+ return false;
+ }
+
+ // Remove all line separators and whitespace
+ var cleanedText1 = text1.replaceAll("\\r?\\n|\\r|\\s", "");
+ var cleanedText2 = text2.replaceAll("\\r?\\n|\\r|\\s", "");
+
+ // Compare the cleaned strings
+ return cleanedText1.equals(cleanedText2);
+ }
+
+ @SuppressWarnings("PMD.AvoidAccessibilityAlteration")
+ @Test
+ void testCompileTemplate()
+ throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException {
+ final var method = processor.getClass().getDeclaredMethod("compileTemplate", File.class, String.class);
+ method.setAccessible(true);
+
+ final var mustache = (Mustache) method.invoke(processor, new File("src/main/resources"),
+ Constants.DEFAULT_JAVA_TEMPLATE);
+
+ assertEquals(Constants.DEFAULT_JAVA_TEMPLATE, mustache.getName(), Constants.DEFAULT_JAVA_TEMPLATE);
+
+ try (var writer = new StringWriter()) {
+ mustache.execute(writer, version).flush();
+ assertTrue(compareTextIgnoringLineSeparators(
+ String.format("/*" +
+ " * This file is automatically generated." +
+ " * Do not modify! -- ALL CHANGES WILL BE ERASED!" +
+ " */" +
+ "package %s;" +
+ "import java.util.Date;" +
+ "/**" +
+ " * Provides semantic version information." +
+ " *" +
+ " * @author Semantic Version Annotation Processor" +
+ " */" +
+ "public final class %s {" +
+ " public static final String PROJECT = \"%s\";" +
+ " public static final Date BUILDDATE = new Date(L);" +
+ " public static final int MAJOR = %d;" +
+ " public static final int MINOR = %d;" +
+ " public static final int PATCH = %d;" +
+ " public static final String PRERELEASE = \"%s\";" +
+ " public static final String PRERELEASE_PREFIX = \"%s\";" +
+ " public static final String BUILDMETA = \"%s\";" +
+ " public static final String BUILDMETA_PREFIX = \"%s\";" +
+ " public static final String SEPARATOR = \"%s\";" +
+ " public static final String VERSION = \"\";" +
+ " /**" +
+ " * Disables the default constructor." +
+ " */" +
+ " private %s() {" +
+ " throw new UnsupportedOperationException(\"Illegal constructor call.\");" +
+ " }" +
+ "}", version.packageName(), version.className(), version.project(), version.major(),
+ version.minor(), version.patch(), version.preRelease(), version.preReleasePrefix(),
+ version.buildMeta(), version.buildMetaPrefix(), version.separator(), version.className()),
+ writer.toString()));
+ }
+ }
+
+ @SuppressWarnings("PMD.AvoidAccessibilityAlteration")
+ @Test
+ void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ final var method = processor.getClass().getDeclaredMethod("findValues", Version.class);
+ method.setAccessible(true);
+ final var versionInfo = (VersionInfo) method.invoke(processor, version);
+
+ assertEquals("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)");
+ assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
+ }
+
+ @Test
+ void testGetSupportedAnnotationTypes() {
+ assertTrue(processor.getSupportedAnnotationTypes().contains("net.thauvin.erik.semver.Version"));
+ }
+
+ @Test
+ void testGetSupportedSourceVersion() {
+ assertTrue(processor.getSupportedSourceVersion().ordinal() >= 17);
+ }
+
+ @SuppressWarnings("PMD.AvoidAccessibilityAlteration")
+ @Test
+ void testGetTemplate() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ final var method = processor.getClass().getDeclaredMethod("getTemplate", boolean.class, Version.class);
+ method.setAccessible(true);
+
+ assertEquals(version.template(), method.invoke(processor, true, version), version.template);
+ version.setTemplate(Constants.DEFAULT_JAVA_TEMPLATE);
+ assertEquals(Constants.DEFAULT_TEMPLATE_NAME, method.invoke(processor, true, version),
+ "default");
+ assertEquals(Constants.DEFAULT_KOTLIN_TEMPLATE, method.invoke(processor, false, version),
+ "kotlin");
+ }
+
+ @SuppressWarnings("PMD.AvoidAccessibilityAlteration")
+ @Test
+ void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ final var p = new Properties();
+ p.setProperty("1", "1");
+ p.setProperty("2", "2.1");
+ p.setProperty("3", "zero");
+ p.setProperty("4", " 4 ");
+
+ final var method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class,
+ int.class);
+ method.setAccessible(true);
+
+ assertEquals(1, method.invoke(processor, p, "1", -1), "parseIntProperty(1)");
+ assertEquals(-1, method.invoke(processor, p, "2", -1), "parseIntProperty(2.1)");
+ assertEquals(-1, method.invoke(processor, p, "3", -1), "parseIntProperty(zero)");
+ assertEquals(4, method.invoke(processor, p, "4", -1), "parseIntProperty( 4 )");
+ }
+}
diff --git a/src/test/java/net/thauvin/erik/semver/VersionTest.java b/src/test/java/net/thauvin/erik/semver/VersionTest.java
new file mode 100644
index 0000000..e27f316
--- /dev/null
+++ b/src/test/java/net/thauvin/erik/semver/VersionTest.java
@@ -0,0 +1,176 @@
+/*
+ * VersionTest.java
+ *
+ * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.semver;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * The VersionTest
class.
+ *
+ * @author Erik C. Thauvin
+ * @created 2019-04-02
+ * @since 1.2.0
+ */
+@SuppressWarnings({"ClassExplicitlyAnnotation", "PMD.TestClassWithoutTestCases"})
+class VersionTest implements Version {
+ String template = "myversion.mustache";
+
+ @Override
+ public Class extends Annotation> annotationType() {
+ return null;
+ }
+
+ @Override
+ public String buildMeta() {
+ return "007";
+ }
+
+ @Override
+ public String buildMetaKey() {
+ return "meta";
+ }
+
+ @Override
+ public String buildMetaPrefix() {
+ return "+";
+ }
+
+ @Override
+ public String buildMetaPrefixKey() {
+ return "meta.prefix";
+ }
+
+ @Override
+ public String className() {
+ return "MyTest";
+ }
+
+ @Override
+ public String keysPrefix() {
+ return "build.";
+ }
+
+ @Override
+ public int major() {
+ return 2;
+ }
+
+ @Override
+ public String majorKey() {
+ return "major";
+ }
+
+ @Override
+ public int minor() {
+ return 17;
+ }
+
+ @Override
+ public String minorKey() {
+ return "minor";
+ }
+
+ @Override
+ public String packageName() {
+ return "com.foo.example";
+ }
+
+ @Override
+ public int patch() {
+ return 52;
+ }
+
+ @Override
+ public String patchKey() {
+ return "patch";
+ }
+
+ @Override
+ public String preRelease() {
+ return "beta";
+ }
+
+ @Override
+ public String preReleaseKey() {
+ return "prerelease";
+ }
+
+ @Override
+ public String preReleasePrefix() {
+ return "-";
+ }
+
+ @Override
+ public String preReleasePrefixKey() {
+ return "prerelease.prefix";
+ }
+
+ @Override
+ public String project() {
+ return "My Test Project";
+ }
+
+ @Override
+ public String projectKey() {
+ return "project";
+ }
+
+ @Override
+ public String properties() {
+ return "test.properties";
+ }
+
+ @Override
+ public String separator() {
+ return ".";
+ }
+
+ @Override
+ public String separatorKey() {
+ return "separator";
+ }
+
+ @Override
+ public String template() {
+ return template;
+ }
+
+ @Override
+ public String type() {
+ return "kt";
+ }
+
+ public void setTemplate(final String template) {
+ this.template = template;
+ }
+}
diff --git a/test.properties b/test.properties
new file mode 100644
index 0000000..98cab4c
--- /dev/null
+++ b/test.properties
@@ -0,0 +1,9 @@
+build.major=0
+build.minor=0
+build.patch=7
+build.prerelease=vodka
+build.prerelease.prefix=:
+build.meta=martini
+build.meta.prefix=++
+build.separator=-
+build.project=James Bond
diff --git a/version.properties b/version.properties
deleted file mode 100644
index db3bacf..0000000
--- a/version.properties
+++ /dev/null
@@ -1,7 +0,0 @@
-#Thu, 06 Oct 2016 11:49:46 -0700
-version.project=semver
-version.major=1
-version.minor=0
-version.patch=0
-version.buildmeta=
-version.prerelease=