diff --git a/.circleci/config.yml b/.circleci/config.yml
deleted file mode 100644
index 5697c0d..0000000
--- a/.circleci/config.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-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
deleted file mode 100644
index 1f808de..0000000
--- a/.editorconfig
+++ /dev/null
@@ -1,2 +0,0 @@
-[*]
-insert_final_newline = true
diff --git a/.github/workflows/bld.yml b/.github/workflows/bld.yml
deleted file mode 100644
index 64007ef..0000000
--- a/.github/workflows/bld.yml
+++ /dev/null
@@ -1,76 +0,0 @@
-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
deleted file mode 100644
index 13dd68d..0000000
--- a/.github_changelog_generator
+++ /dev/null
@@ -1 +0,0 @@
-future-release=1.2.1
diff --git a/.gitignore b/.gitignore
index dd3e0b4..355b112 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,58 +1,31 @@
-.gradle
+**/.idea/dictionaries
+**/.idea/gradle.xml
+**/.idea/libraries
+**/.idea/tasks.xml
+**/.idea/workspace.xml
+*.sublime-*
+*.iws
+.classpath
.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
+.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
diff --git a/.idea/app.iml b/.idea/app.iml
deleted file mode 100644
index 6c0f6d7..0000000
--- a/.idea/app.iml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
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 cada04f..553dec0 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,31 @@ -# Semantic Version Annotation Processor +# Semantic Version Annotation Processor -[](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) +[](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://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) +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). -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) +This processor was inspired by Cédric Beust's [version-processor](https://github.com/cbeust/version-processor). ## Examples -- Using annotation elements: +* Using annotation elements: ```java import net.thauvin.erik.semver.Version; -@Version(major = 2, minor = 1, patch = 1, preRelease = "beta") +@Version(major = 1, minor = 0, patch = 0, preRelease = "beta") public class A { - // ... -} +// ... ``` -- Or using a [properties](hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties) file: +* Or using a [properties](https://docs.oracle.com/javase/tutorial/essential/environment/properties.html) file: ```java import net.thauvin.erik.semver.Version; @Version(properties = "version.properties") public class A { - // ... -} +// ... ``` ```ini @@ -67,40 +36,43 @@ version.patch=0 version.prerelease=beta ``` -[View Examples](https://github.com/ethauvin/semver/tree/master/examples) +[View Example](https://github.com/ethauvin/semver/tree/master/example) ## 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). +Upon running the annotation processor, a source file [`GeneratedVersion.java`](https://github.com/ethauvin/semver/blob/master/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable [Mustache](https://mustache.github.io/) template. -To use your own template, simply create a `version.mustache` file in the project's root directory. The processor will automatically look for it. +To use your own template, simply create a `version.mustache` file. The processor will automatically look for it. To specify your own template name, use: ```java @Version(template = "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 variables: +The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static fields: -| 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. | `.` | +Field | Description | Example +:--------------|:---------------------------------|:----------------- +`PROJECT` | The project name, if any. | `MyProject` +`BUILDDATE` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html) +`VERSION` | The full version string. | `1.0.0-alpha+001` +`MAJOR` | The major version. | `1` +`MINOR` | The minor version. | `0` +`PATCH` | The patch version. | `0` +`PRERELEASE` | The pre-release version, if any. | `alpha` +`BUILDMETA` | The build metadata, if any. | `001` + +And the following methods/functions: + +Method | Description | Example +:------------------------|:----------------------------------------------------------|:-------- +`preReleaseWithPrefix()` | Returns the pre-release with a prefix, `-` by default. | `-alpha` +`buildMetaWithPrefix()` | Returns the build metadata with a prefix, `+` by default. | `+001` ### Custom Template @@ -108,166 +80,153 @@ 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 String VERSION = "{{semver}}"; + 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` | -| `{{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` | +Variable | Description | Type +:-----------------|:----------------------------|:-------- +`{{packageName}}` | The package name. | `String` +`{{className}}` | The class name. | `String` +`{{project}}` | The project name. | `String` +`{{epoch}}` | The build epoch/unix time. | `long` +`{{major}}` | The major version. | `int` +`{{minor}}` | The minor version. | `int` +`{{patch}}` | The patch version. | `int` +`{{preRelease}}` | The pre/release version. | `String` +`{{buildMeta}}` | The build metadata version. | `String` + +Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) ## Elements & Properties The following annotation elements and properties are available: -| Element | Property | Description | Default | -|:-------------------|:----------------------------|:----------------------------------|:--------------------------| -| `project` | `version.project` | The project name. | | -| `major` | `version.major` | The major version number. | `1` | -| `minor` | `version.major` | The minor version number. | `0` | -| `patch` | `version.patch` | The patch version number. | `0` | -| `preRelease` | `version.prerelease` | The pre-release version. | | -| `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.` | +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: ```java @Version( properties = "example.properties", - keysPrefix = "example.", - majorKey = "maj", - minorKey = "min", - patchKey = "build", - preReleaseKey = "rel", - buildMetaKey = "meta", - projectKey = "project" + majorKey = "example.major", + minorKey = "example.minor", + patchKey = "example.patch", + preReleaseKey = "example.prerelease", + buildMetaKey = "example.buildmeta", + projectKey = "example.project" ) public class Example { - // ... -} +// ... ``` ```ini # example.properties example.project=Example -example.maj=1 -example.min=0 -example.build=0 -example.rel=beta -example.meta= +example.major=1 +example.minor=0 +example.patch=0 # ... ``` +## Usage with Maven, Grail, Kobalt and Kotlin -> :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. +### Maven -## Maven - -To install and run from [Maven](https://maven.apache.org/), configure an artifact as follows: +To install and run from [Maven](http://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
deleted file mode 100644
index 0a58f86..0000000
--- a/bin/main/semver-kt.mustache
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
-* 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
deleted file mode 100644
index cd7c567..0000000
--- a/bin/main/semver.mustache
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
-* 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
deleted file mode 100644
index 934286a..0000000
Binary files a/bin/test/net/thauvin/erik/semver/ConstantsTest.class and /dev/null differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class b/bin/test/net/thauvin/erik/semver/VersionInfoTest.class
deleted file mode 100644
index d6401b4..0000000
Binary files a/bin/test/net/thauvin/erik/semver/VersionInfoTest.class and /dev/null differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class b/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class
deleted file mode 100644
index af2b771..0000000
Binary files a/bin/test/net/thauvin/erik/semver/VersionProcessorTest.class and /dev/null differ
diff --git a/bin/test/net/thauvin/erik/semver/VersionTest.class b/bin/test/net/thauvin/erik/semver/VersionTest.class
deleted file mode 100644
index 0047ff2..0000000
Binary files a/bin/test/net/thauvin/erik/semver/VersionTest.class and /dev/null differ
diff --git a/bld b/bld
deleted file mode 100755
index 824b742..0000000
--- a/bld
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/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
deleted file mode 100644
index ab43bcd..0000000
--- a/bld.bat
+++ /dev/null
@@ -1,4 +0,0 @@
-@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
new file mode 100644
index 0000000..39dd5d0
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,217 @@
+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
new file mode 100644
index 0000000..552252d
--- /dev/null
+++ b/clean.sh
@@ -0,0 +1,37 @@
+#!/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
deleted file mode 100644
index 2641880..0000000
--- a/config/pmd.xml
+++ /dev/null
@@ -1,109 +0,0 @@
-
-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/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..51e51c5 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,28 @@ +**/.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 new file mode 100644 index 0000000..92eabb2 --- /dev/null +++ b/example/build.gradle @@ -0,0 +1,95 @@ +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 new file mode 100644 index 0000000..3baa851 Binary files /dev/null and b/example/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/test/gradle/wrapper/gradle-wrapper.properties b/example/gradle/wrapper/gradle-wrapper.properties similarity index 74% rename from examples/test/gradle/wrapper/gradle-wrapper.properties rename to example/gradle/wrapper/gradle-wrapper.properties index b82aa23..7d773c3 100644 --- a/examples/test/gradle/wrapper/gradle-wrapper.properties +++ b/example/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ +#Mon Jul 18 17:32:58 PDT 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip -networkTimeout=10000 -validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip diff --git a/example/gradlew b/example/gradlew new file mode 100644 index 0000000..27309d9 --- /dev/null +++ b/example/gradlew @@ -0,0 +1,164 @@ +#!/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/examples/test/gradlew.bat b/example/gradlew.bat similarity index 52% rename from examples/test/gradlew.bat rename to example/gradlew.bat index 25da30d..832fdb6 100644 --- a/examples/test/gradlew.bat +++ b/example/gradlew.bat @@ -1,20 +1,4 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off +@if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,29 +9,25 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused +if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - @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="-Xmx64m" "-Xms64m" +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% equ 0 goto execute +if "%ERRORLEVEL%" == "0" goto init -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +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 @@ -55,36 +35,54 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto execute +if exist "%JAVA_EXE%" goto init -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +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 %* +"%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% equ 0 goto mainEnd +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! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/example/kobalt/src/Build.kt b/example/kobalt/src/Build.kt new file mode 100644 index 0000000..46eeb64 --- /dev/null +++ b/example/kobalt/src/Build.kt @@ -0,0 +1,70 @@ +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 new file mode 100644 index 0000000..5390ba7 Binary files /dev/null and b/example/kobalt/wrapper/kobalt-wrapper.jar differ diff --git a/example/kobalt/wrapper/kobalt-wrapper.properties b/example/kobalt/wrapper/kobalt-wrapper.properties new file mode 100644 index 0000000..eb3786f --- /dev/null +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=1.0.85 diff --git a/example/kobaltw b/example/kobaltw new file mode 100644 index 0000000..c5186d5 --- /dev/null +++ b/example/kobaltw @@ -0,0 +1,2 @@ +#!/usr/bin/env sh +java -jar "`dirname "$0"`/kobalt/wrapper/kobalt-wrapper.jar" $* diff --git a/example/kobaltw.bat b/example/kobaltw.bat new file mode 100644 index 0000000..d578071 --- /dev/null +++ b/example/kobaltw.bat @@ -0,0 +1,4 @@ +@echo off +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +java -jar "%DIRNAME%/kobalt/wrapper/kobalt-wrapper.jar" %* diff --git a/examples/java/gradle/settings.gradle b/example/settings.gradle similarity index 94% rename from examples/java/gradle/settings.gradle rename to example/settings.gradle index f170c1a..9c6dad5 100644 --- a/examples/java/gradle/settings.gradle +++ b/example/settings.gradle @@ -16,4 +16,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'examples-java' +rootProject.name = 'example' 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 new file mode 100644 index 0000000..a301be1 --- /dev/null +++ b/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java @@ -0,0 +1,103 @@ +/* + * 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
ConstantsTest
class.
+ * The Example
class.
*
- * @author Erik C. Thauvin
- * @created 2019-04-14
+ * @author Erik C. Thauvin
+ * @created 2016-01-13
* @since 1.0
*/
-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");
- }
+@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");
- @Test
- void testTemplates() {
- final List
- * 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
deleted file mode 100644
index 91134b7..0000000
--- a/examples/java/bld/src/main/java/com/example/App.java
+++ /dev/null
@@ -1,31 +0,0 @@
-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
deleted file mode 100644
index 1829d52..0000000
--- a/examples/java/bld/src/main/java/com/example/Example.java
+++ /dev/null
@@ -1,21 +0,0 @@
-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
deleted file mode 100644
index f0452f2..0000000
--- a/examples/java/bld/src/test/java/com/example/ExampleTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-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
deleted file mode 100644
index dc68bf3..0000000
--- a/examples/java/bld/version.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-#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
deleted file mode 100644
index 1f808de..0000000
--- a/examples/java/gradle/.editorconfig
+++ /dev/null
@@ -1,2 +0,0 @@
-[*]
-insert_final_newline = true
diff --git a/examples/java/gradle/.gitattributes b/examples/java/gradle/.gitattributes
deleted file mode 100644
index 6ec2ae2..0000000
--- a/examples/java/gradle/.gitattributes
+++ /dev/null
@@ -1,5 +0,0 @@
-# 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
deleted file mode 100644
index a78c5c2..0000000
--- a/examples/java/gradle/.gitignore
+++ /dev/null
@@ -1,82 +0,0 @@
-!.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
deleted file mode 100644
index 2ba6afe..0000000
--- a/examples/java/gradle/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-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
deleted file mode 100644
index a83902e..0000000
--- a/examples/java/gradle/.idea/compiler.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
- Formatted as:
- * For example:
- *
+ * Formatted as:
+ *
+ * For example:
+ *
+ * Formatted as:
+ *
+ * For example:
+ *
- *
- *
- *
- * [MAJOR][SEPARATOR][MINOR][SEPARATOR][PATCH][[PRERELEASE-PREFIX][PRERELEASE]][[BUILDMETA-PREFIX][BUILDMETA]]
- *
- *
- *
- *
- * @return The version string.
- */
- public String getVersion() {
- return major
- + separator
- + minor
- + separator
- + patch
- + (!preRelease.isEmpty() ? preReleasePrefix + preRelease : "")
- + (!buildMeta.isEmpty() ? buildMetaPrefix + buildMeta : "");
- }
-
- /**
- * Sets the build meta-data.
- *
- * @param buildMeta The new build meta-data.
- */
- public void setBuildMeta(final String buildMeta) {
- this.buildMeta = buildMeta;
- }
-
- /**
- * Sets the meta-data prefix.
- *
- * @param buildMetaPrefix The meta-data prefix.
- */
- public void setBuildMetaPrefix(final String buildMetaPrefix) {
- this.buildMetaPrefix = buildMetaPrefix;
- }
-
- /**
- * Sets the class name.
- *
- * @param className The new class name.
- */
- public void setClassName(final String className) {
- this.className = className;
- }
-
/**
* Sets the major version.
*
@@ -275,6 +144,15 @@ public class VersionInfo {
this.major = major;
}
+ /**
+ * Returns the major version.
+ *
+ * @return The major version.
+ */
+ public int getMinor() {
+ return minor;
+ }
+
/**
* Sets the minor version.
*
@@ -284,15 +162,33 @@ public class VersionInfo {
this.minor = minor;
}
+ /**
+ * Returns the package name.
+ *
+ * @return The package name.
+ */
+ public String getPackageName() {
+ return packageName;
+ }
+
/**
* Sets the package name.
*
* @param packageName The new package name.
*/
- public void setPackageName(final String packageName) {
+ public void setPackageName(String packageName) {
this.packageName = packageName;
}
+ /**
+ * Returns the patch version.
+ *
+ * @return The patch version.
+ */
+ public int getPatch() {
+ return patch;
+ }
+
/**
* Sets the patch version.
*
@@ -302,6 +198,15 @@ public class VersionInfo {
this.patch = patch;
}
+ /**
+ * Returns the pre-release version.
+ *
+ * @return The pre-release version.
+ */
+ public String getPreRelease() {
+ return preRelease;
+ }
+
/**
* Sets the pre-release version.
*
@@ -312,12 +217,12 @@ public class VersionInfo {
}
/**
- * Sets the pre-release prefix.
+ * Returns the project name.
*
- * @param preReleasePrefix The new pre-release prefix.
+ * @return The project name.
*/
- public void setPreReleasePrefix(final String preReleasePrefix) {
- this.preReleasePrefix = preReleasePrefix;
+ public String getProject() {
+ return project;
}
/**
@@ -330,11 +235,28 @@ public class VersionInfo {
}
/**
- * Sets the version separator.
+ * Returns the full version string.
+ * 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
+ * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]
+ *
*
- * @param separator The new version separator.
+ * @return The version string.
*/
- public void setSeparator(final String separator) {
- this.separator = separator;
+ public String getVersion() {
+ return Integer.toString(major)
+ + '.'
+ + Integer.toString(minor)
+ + '.'
+ + Integer.toString(patch)
+ + (preRelease.length() > 0 ? '-' + preRelease : "")
+ + (buildMeta.length() > 0 ? '+' + buildMeta : "");
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java
index 3ffd457..1e5381e 100644
--- a/src/main/java/net/thauvin/erik/semver/VersionProcessor.java
+++ b/src/main/java/net/thauvin/erik/semver/VersionProcessor.java
@@ -1,7 +1,7 @@
/*
* VersionProcessor.java
*
- * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,12 +29,11 @@
* 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.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
-import com.github.mustachejava.MustacheNotFoundException;
+import com.github.mustachejava.MustacheFactory;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
@@ -44,9 +43,8 @@ import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
+import javax.tools.StandardLocation;
import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@@ -58,110 +56,48 @@ import java.util.Set;
* @created 2016-01-13
* @since 1.0
*/
-@SuppressWarnings({"PMD.GuardLogStatement", "PMD.BeanMembersShouldSerialize"})
-@SupportedOptions({Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME, Constants.SEMVER_PROJECT_DIR_ARG})
public class VersionProcessor extends AbstractProcessor {
private Filer filer;
private Messager messager;
- private static String getTemplate(final boolean isLocalTemplate, final Version version) {
- final String template;
- if (isLocalTemplate && Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template())) {
- template = Constants.DEFAULT_TEMPLATE_NAME;
- } else if (Constants.DEFAULT_JAVA_TEMPLATE.equals(version.template()) && Constants.KOTLIN_TYPE
- .equals(version.type())) {
- template = Constants.DEFAULT_KOTLIN_TEMPLATE;
- } else {
- template = version.template();
- }
- return template;
- }
-
- private Mustache compileTemplate(final File dir, final String template) throws IOException {
- if (Constants.DEFAULT_JAVA_TEMPLATE.equals(template) || Constants.DEFAULT_KOTLIN_TEMPLATE.equals(template)) {
- try (var in = getClass().getResourceAsStream("/" + template)) {
- if (in != null) {
- try (var reader = new BufferedReader(new InputStreamReader(in))) {
- return new DefaultMustacheFactory().compile(reader, template);
- }
- } else {
- throw new IOException("Resource not found: " + template);
- }
- }
- } else {
- return new DefaultMustacheFactory(dir).compile(template);
- }
- }
-
private void error(final String s) {
log(Diagnostic.Kind.ERROR, s);
}
- @SuppressWarnings("PMD.UnusedPrivateMethod")
private void error(final String s, final Throwable t) {
- log(Diagnostic.Kind.ERROR, t != null ? t.toString() : s);
+ messager.printMessage(Diagnostic.Kind.ERROR, (t != null ? t.toString() : s));
}
- private VersionInfo findValues(final Version version) throws IOException {
- final var versionInfo = new VersionInfo(version);
+ private VersionInfo findValues(final Version version)
+ throws IOException {
+ final VersionInfo versionInfo = new VersionInfo(version);
- if (!version.properties().isEmpty()) {
- final var propsFile = getLocalFile(version.properties());
- if (propsFile.isFile() && propsFile.canRead()) {
- note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
+ if (version.properties().length() > 0) {
+ final File propsFile = new File(version.properties());
+ if (propsFile.exists()) {
+ note("Found properties: " + propsFile);
+ final Properties p = new Properties();
- final var p = new Properties();
-
- try (var reader = new InputStreamReader(
- Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
+ try (FileReader reader = new FileReader(propsFile)) {
p.load(reader);
- versionInfo.setProject(
- p.getProperty(version.keysPrefix() + version.projectKey(), version.project()));
- versionInfo.setMajor(
- parseIntProperty(p, version.keysPrefix() + version.majorKey(), version.major()));
- versionInfo.setMinor(
- parseIntProperty(p, version.keysPrefix() + version.minorKey(), version.minor()));
- versionInfo.setPatch(
- parseIntProperty(p, version.keysPrefix() + version.patchKey(), version.patch()));
- versionInfo.setBuildMeta(
- p.getProperty(version.keysPrefix() + version.buildMetaKey(), version.buildMeta()));
- versionInfo.setBuildMetaPrefix(
- p.getProperty(version.keysPrefix() + version.buildMetaPrefixKey(), version.buildMetaPrefix()));
- versionInfo.setPreRelease(
- p.getProperty(version.keysPrefix() + version.preReleaseKey(), version.preRelease()));
- versionInfo.setPreReleasePrefix(p.getProperty(version.keysPrefix() + version.preReleasePrefixKey(),
- version.preReleasePrefix()));
- versionInfo.setSeparator(
- p.getProperty(version.keysPrefix() + version.separatorKey(), version.separator()));
+ versionInfo.setProject(p.getProperty(version.projectKey(), version.project()));
+ versionInfo.setMajor(parseIntProperty(p, version.majorKey(), version.major()));
+ versionInfo.setMinor(parseIntProperty(p, version.minorKey(), version.minor()));
+ versionInfo.setPatch(parseIntProperty(p, version.patchKey(), version.patch()));
+ versionInfo.setBuildMeta(p.getProperty(version.buildMetaKey(), version.buildMeta()));
+ versionInfo.setPreRelease(p.getProperty(version.preReleaseKey(), version.preRelease()));
}
} else {
- final String findOrRead;
- if (propsFile.canRead()) {
- findOrRead = "find";
- } else {
- findOrRead = "read";
- }
- error("Could not " + findOrRead + ": " + propsFile);
- throw new FileNotFoundException(
- "Could not " + findOrRead + " the specified file: `" + propsFile.getAbsolutePath() + '`');
+ error("Could not find: " + propsFile);
+ throw new FileNotFoundException("The system cannot find the specified file: " + propsFile);
}
}
return versionInfo;
}
- private File getLocalFile(final String fileName) {
- if (processingEnv != null) { // null when testing.
- final var prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG);
- if (prop != null) {
- return new File(prop, fileName);
- }
- }
- return new File(new File("").getAbsolutePath(), fileName);
- }
-
/**
* {@inheritDoc}
*/
@@ -177,13 +113,12 @@ public class VersionProcessor extends AbstractProcessor {
*/
@Override
public SourceVersion getSupportedSourceVersion() {
- return SourceVersion.latestSupported();
+ return SourceVersion.RELEASE_8;
}
/**
* {@inheritDoc}
*/
- @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
@Override
public synchronized void init(final ProcessingEnvironment processingEnv) {
super.init(processingEnv);
@@ -191,94 +126,92 @@ public class VersionProcessor extends AbstractProcessor {
messager = processingEnv.getMessager();
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
- final var isLocalTemplate = getLocalFile(Constants.DEFAULT_TEMPLATE_NAME).exists();
- for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class)) {
- final var version = element.getAnnotation(Version.class);
- if (element.getKind() == ElementKind.CLASS) {
- final var enclosingElement = element.getEnclosingElement();
- if (enclosingElement.getKind() == ElementKind.PACKAGE) {
- final var packageElement = (PackageElement) enclosingElement;
- try {
- final var versionInfo = findValues(version);
- if (Constants.EMPTY.equals(version.packageName())) {
- versionInfo.setPackageName(packageElement.getQualifiedName().toString());
- }
- note("Found version: " + versionInfo.getVersion());
- final var template = getTemplate(isLocalTemplate, version);
-
- writeTemplate(version.type(), versionInfo, template);
- } catch (IOException | MustacheNotFoundException e) {
- error("An error occurred while running the annotation processor: " + e.getMessage(), e);
- }
- }
- }
- }
- return true;
- }
-
private void log(final Diagnostic.Kind kind, final String s) {
- if (messager != null) {
- messager.printMessage(kind,
- '[' + VersionProcessor.class.getSimpleName() + "] " + s + System.lineSeparator());
- }
+ messager.printMessage(kind, '[' + VersionProcessor.class.getSimpleName() + "] " + s);
}
private void note(final String s) {
log(Diagnostic.Kind.NOTE, s);
}
- private int parseIntProperty(final Properties p, final String key, final int defaultValue) {
+ private int parseIntProperty(final Properties p, final String property, final int defaultValue) {
try {
- return Math.abs(Integer.parseInt(p.getProperty(key, Integer.toString(defaultValue)).trim()));
+ return Integer.parseInt(p.getProperty(property, Integer.toString(defaultValue)));
} catch (NumberFormatException ignore) {
- warn("Invalid property value: " + key);
+ warn("Invalid property value: " + property);
return defaultValue;
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean process(final Set extends TypeElement> annotations, final RoundEnvironment roundEnv) {
+ for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class)) {
+ final Version version = element.getAnnotation(Version.class);
+ if (element.getKind() == ElementKind.CLASS) {
+ final Element enclosingElement = element.getEnclosingElement();
+ if (enclosingElement.getKind() == ElementKind.PACKAGE) {
+ final PackageElement packageElement = (PackageElement) enclosingElement;
+ try {
+ final VersionInfo versionInfo = findValues(version);
+ if (version.packageName().equals(Constants.EMPTY)) {
+ versionInfo.setPackageName(packageElement.getQualifiedName().toString());
+ }
+ note("Found version: " + versionInfo.getVersion());
+ final String template;
+ if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) &&
+ new File(Constants.DEFAULT_TEMPLATE_NAME).exists()) {
+ template = Constants.DEFAULT_TEMPLATE_NAME;
+ } else if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) &&
+ version.type().equals(Constants.KOTLIN_TYPE)) {
+ template = Constants.DEFAULT_KOTLIN_TEMPLATE;
+ } else {
+ template = version.template();
+ }
+ writeTemplate(version.type(), versionInfo, template);
+ } catch (IOException e) {
+ error("IOException occurred while running the annotation processor: " + e.getMessage(), e);
+ }
+ }
+ }
+ }
+ return true;
+ }
+
private void warn(final String s) {
log(Diagnostic.Kind.WARNING, s);
}
private void writeTemplate(final String type, final VersionInfo versionInfo, final String template)
throws IOException {
- final var dir = getLocalFile("");
- final Mustache mustache = compileTemplate(dir, template);
+ final MustacheFactory mf = new DefaultMustacheFactory();
+ final Mustache mustache = mf.compile(template);
- final var templateName = switch (mustache.getName()) {
- case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)";
- case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
- default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
- };
+ final String templateName;
+ if (mustache.getName().equals(Constants.DEFAULT_JAVA_TEMPLATE)) {
+ templateName = "default (Java)";
+ } else if (mustache.getName().equals(Constants.DEFAULT_KOTLIN_TEMPLATE)) {
+ templateName = "default (Kotlin)";
+ } else {
+ templateName = mustache.getName();
+ }
note("Loaded template: " + templateName);
- final var fileName = versionInfo.getClassName() + '.' + type;
- if (Constants.KOTLIN_TYPE.equalsIgnoreCase(type)) {
- final var kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
- if (kaptGenDir == null) {
- throw new IOException("Could not find the target directory for generated Kotlin files.");
- }
- final var ktFile = new File(kaptGenDir, fileName);
- if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) {
- note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath());
- }
- try (var osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
- StandardCharsets.UTF_8)) {
- mustache.execute(osw, versionInfo).flush();
- }
- note("Generated source: " + fileName + " (" + ktFile.getParentFile().getAbsolutePath() + ')');
+ final FileObject jfo;
+ if (type.equalsIgnoreCase(Constants.KOTLIN_TYPE)) {
+ jfo = filer.createResource(StandardLocation.SOURCE_OUTPUT, versionInfo.getPackageName(),
+ versionInfo.getClassName() + '.' + type);
} else {
- final FileObject jfo = filer.createSourceFile(
- versionInfo.getPackageName() + '.' + versionInfo.getClassName());
- try (var writer = jfo.openWriter()) {
- mustache.execute(writer, versionInfo).flush();
- }
- note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');
+ jfo = filer.createSourceFile(versionInfo.getPackageName() + '.' + versionInfo.getClassName());
}
+
+ try (final Writer writer = jfo.openWriter()) {
+ mustache.execute(writer, versionInfo).flush();
+ }
+
+ note("Generated source: " + jfo.getName());
}
-}
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/thauvin/erik/semver/package.html b/src/main/java/net/thauvin/erik/semver/package.html
index 1b1b126..c63dfc0 100644
--- a/src/main/java/net/thauvin/erik/semver/package.html
+++ b/src/main/java/net/thauvin/erik/semver/package.html
@@ -1,12 +1,11 @@
-
-
- 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
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 cf53df5..febd83d 100644
--- a/src/main/resources/semver-kt.mustache
+++ b/src/main/resources/semver-kt.mustache
@@ -2,10 +2,9 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
-
package {{packageName}}
-import java.util.Date
+import java.util.*
/**
* Provides semantic version information.
@@ -13,26 +12,47 @@ import java.util.Date
* @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}}"
-}
+ @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
diff --git a/src/main/resources/semver.mustache b/src/main/resources/semver.mustache
index d9eb417..88becf0 100644
--- a/src/main/resources/semver.mustache
+++ b/src/main/resources/semver.mustache
@@ -2,7 +2,6 @@
* This file is automatically generated.
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
-
package {{packageName}};
import java.util.Date;
@@ -13,22 +12,91 @@ import java.util.Date;
* @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}}";
+ 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();
/**
* Disables the default constructor.
+ *
+ * @throws UnsupportedOperationException If the constructor is called.
*/
- private {{className}}() {
+ private {{className}}()
+ throws UnsupportedOperationException {
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/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java
index 49d2e7c..057c4a6 100644
--- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java
+++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java
@@ -1,7 +1,7 @@
/*
* VersionInfoTest.java
*
- * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,13 @@
* 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 org.junit.jupiter.api.Test;
+import org.testng.Assert;
+import org.testng.annotations.Test;
-import java.util.Date;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.lang.annotation.Annotation;
+import java.util.Calendar;
/**
* The 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
VersionInfoTest
class.
@@ -46,150 +44,210 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @created 2016-02-03
* @since 1.0
*/
-class VersionInfoTest {
+public class VersionInfoTest {
+ private final Calendar now = Calendar.getInstance();
private VersionInfo versionInfo = new VersionInfo();
- @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
@Test
- void testGetVersion() {
- assertEquals("1.0.0", versionInfo.getVersion(), "getVersion(1.0.0)");
+ public void testGetVersion()
+ throws Exception {
+
+ Assert.assertEquals(versionInfo.getVersion(), "1.0.0", "getVersion(1.0.0)");
versionInfo.setMajor(3);
- assertEquals("3.0.0", versionInfo.getVersion(), "getVersion(3.0.0)");
+ Assert.assertEquals(versionInfo.getVersion(), "3.0.0", "getVersion(3.0.0)");
versionInfo.setMinor(2);
- assertEquals("3.2.0", versionInfo.getVersion(), "getVersion(3.2.0)");
+ Assert.assertEquals(versionInfo.getVersion(), "3.2.0", "getVersion(3.2.0)");
versionInfo.setPatch(1);
- assertEquals("3.2.1", versionInfo.getVersion(), "getVersion(3.2.1)");
+ Assert.assertEquals(versionInfo.getVersion(), "3.2.1", "getVersion(3.2.1)");
versionInfo.setPreRelease("beta");
- assertEquals("3.2.1-beta", versionInfo.getVersion(), "getVersion(3.2.1-beta)");
+ Assert.assertEquals(versionInfo.getVersion(), "3.2.1-beta", "getVersion(3.2.1-beta)");
versionInfo.setBuildMeta("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("-");
+ Assert.assertEquals(versionInfo.getVersion(), "3.2.1-beta+001", "getVersion(3.2.1-beta+001)");
versionInfo.setPreRelease("");
- 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) ");
+ Assert.assertEquals(versionInfo.getVersion(), "3.2.1+001", "getVersion(3.2.1+001)");
}
@Test
- void testSetGet() {
- versionInfo.setSeparator(".");
+ public void testSetGet()
+ throws Exception {
versionInfo.setMajor(1);
- assertEquals(1, versionInfo.getMajor(), "getMajor(1)");
+ Assert.assertEquals(versionInfo.getMajor(), 1, "getMajor(1)");
versionInfo.setMinor(2);
- assertEquals(2, versionInfo.getMinor(), "getMinor(2)");
+ Assert.assertEquals(versionInfo.getMinor(), 2, "getMinor(2)");
versionInfo.setPatch(3);
- assertEquals(3, versionInfo.getPatch(), "getPatch(3)");
+ Assert.assertEquals(versionInfo.getPatch(), 3, "getPatch(3)");
versionInfo.setPreRelease("alpha");
- assertEquals("alpha", versionInfo.getPreRelease(), "getPreRelease(alpha)");
+ Assert.assertEquals(versionInfo.getPreRelease(), "alpha", "getPreRelease(alpha)");
versionInfo.setBuildMeta("001");
- assertEquals("001", versionInfo.getBuildMeta(), "getBuildMeta(001)");
+ Assert.assertEquals(versionInfo.getBuildMeta(), "001", "getBuildMeta(001)");
versionInfo.setPackageName("com.example");
- assertEquals("com.example", versionInfo.getPackageName(), "getPackageName(com.example)");
+ Assert.assertEquals(versionInfo.getPackageName(), "com.example", "getPackageName(com.example)");
- 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)");
+ Assert.assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)");
versionInfo.setProject("My Example");
- assertEquals("My Example", versionInfo.getProject(), "getProject(My Example)");
+ Assert.assertEquals(versionInfo.getProject(), "My Example", "getProject(My Example)");
versionInfo.setClassName("Example");
- assertEquals("Example", versionInfo.getClassName(), "getClassName(Example");
+ Assert.assertEquals(versionInfo.getClassName(), "Example", "getClassName(Example");
- assertTrue((versionInfo.getEpoch() - new Date().getTime()) < 1000, "buildDate - now < 1s");
+ Assert.assertTrue((versionInfo.getEpoch() - now.getTimeInMillis()) < 1000,
+ "buildDate - now < 1s");
}
@Test
- void testVersionInfo() {
+ public void testVersionInfo()
+ throws Exception {
+
final Version version = new VersionTest();
versionInfo = new VersionInfo(version);
- assertEquals(version.major(), versionInfo.getMajor(), "getMajor(major)");
+ Assert.assertEquals(versionInfo.getMajor(), version.major(), "getMajor(major)");
- assertEquals(version.minor(), versionInfo.getMinor(), "getMinor(minor)");
+ Assert.assertEquals(versionInfo.getMinor(), version.minor(), "getMinor(minor)");
- assertEquals(version.patch(), versionInfo.getPatch(), "getPatch(patch)");
+ Assert.assertEquals(versionInfo.getPatch(), version.patch(), "getPatch(patch)");
- assertEquals(version.preRelease(), versionInfo.getPreRelease(), "getPreRelease(preRelease)");
+ Assert.assertEquals(versionInfo.getPreRelease(), version.preRelease(), "getPreRelease(preRelease)");
- assertEquals(version.preReleasePrefix(), versionInfo.getPreReleasePrefix(),
- "getPreReleasePrefix(preReleasePrefix)");
+ Assert.assertEquals(versionInfo.getBuildMeta(), version.buildMeta(), "getBuildMeta(buildMeta)");
- assertEquals(version.buildMeta(), versionInfo.getBuildMeta(), "getBuildMeta(buildMeta)");
+ Assert.assertEquals(versionInfo.getPackageName(), version.packageName(),
+ "getPackageName(packageName)");
- assertEquals(version.buildMetaPrefix(), versionInfo.getBuildMetaPrefix(),
- "getBuildMetaPrefix(buildMetaPrefix)");
+ Assert.assertEquals(versionInfo.getVersion(),
+ version.major()
+ + "."
+ + version.minor()
+ + '.'
+ + version.patch()
+ + '-'
+ + version.preRelease()
+ + '+'
+ + version.buildMeta(),
+ "getVersion(version)");
- assertEquals(version.packageName(), versionInfo.getPackageName(), "getPackageName(packageName)");
+ Assert.assertEquals(versionInfo.getProject(), version.project(), "getProject(project)");
- 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)");
+ Assert.assertEquals(versionInfo.getClassName(), version.className(), "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
deleted file mode 100644
index c49af74..0000000
--- a/src/test/java/net/thauvin/erik/semver/VersionProcessorTest.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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
deleted file mode 100644
index e27f316..0000000
--- a/src/test/java/net/thauvin/erik/semver/VersionTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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
deleted file mode 100644
index 98cab4c..0000000
--- a/test.properties
+++ /dev/null
@@ -1,9 +0,0 @@
-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
new file mode 100644
index 0000000..db3bacf
--- /dev/null
+++ b/version.properties
@@ -0,0 +1,7 @@
+#Thu, 06 Oct 2016 11:49:46 -0700
+version.project=semver
+version.major=1
+version.minor=0
+version.patch=0
+version.buildmeta=
+version.prerelease=