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/.gitattributes b/.gitattributes
deleted file mode 100644
index 6ec2ae2..0000000
--- a/.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/.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..24f188e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,58 +1,28 @@
-.gradle
+**/.idea/dictionaries
+**/.idea/gradle.xml
+**/.idea/libraries
+**/.idea/tasks.xml
+**/.idea/workspace.xml
+*.iws
.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
+.classpath
+.gradle
+.kobalt
+.nb-gradle
+.project
+.settings
+/bin
+/build
+/deploy
+/dist
+/gen
+/gradle.properties
+/local.properties
+/out
+/proguard-project.txt
+/project.properties
+/target
+/test-output
+Thumbs.db
+ehthumbs.db
+kobaltBuild
\ 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 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.
+@Version(major = 1, minor = 0, patch = 0, prerelease = "beta")
+public class A {
+// ...
@Version(properties = "version.properties")
+public class A {
+// ...
# version.properties
+version.major=1
+version.minor=0
+version.patch=0
+version.prerelease=beta
Upon running the annotator processor, a source file GeneratedVersion.java
is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Velocity template.
@Version(template = "myversion.vm")
+public class A {
+// ...
The default template implements the following static methods:
+Method | +Description | +Example | +
---|---|---|
getProject |
+The project name, if any. | +MyProject |
+
getBuildDate |
+The build date. | +java.util.Date |
+
getVersion |
+The full version string. | +1.0.0-alpha+001 |
+
getMajor |
+The major version. | +1 |
+
getMinor |
+The minor version. | +0 |
+
getPatch |
+The patch version. | +0 |
+
getPreRelease |
+The pre-release version, if any. | +alpha |
+
getBuildMetadata |
+The build metadata, if any. | +001 |
+
A very simple custom template might look something like:
+/* myversion.vm */
+package ${packageName}
+
+import java.util.Date;
+
+public final class ${className} {
+ public final static String BUILDMETA = "${buildmeta}";
+ public final static Date DATE = new Date(${epoch}L);
+ public final static int MAJOR = ${major};
+ public final static int MINOR = ${minor};
+ public final static int PATCH = ${patch};
+ public final static String PRERELEASE = "${prerelease}";
+ public final static String PROJECT = "${project}";
+}
The Velocity variables are automatically filled in by the processor.
+The following annotation elements and properties are available:
+Element | +Property | +Description | +Default | +
---|---|---|---|
project |
+version.project |
+The project name. | ++ |
major |
+version.major |
+The major version number. | +1 |
+
minor |
+version.major |
+The minor version number. | +0 |
+
patch |
+version.patch |
+The patch version number. | +0 |
+
prerelease |
+version.prerelease |
+The pre-release version. | ++ |
buildmeta |
+version.buildmeta |
+The build metadata version. | ++ |
className |
++ | The name of the generated class. | +GeneratedVersion |
+
properties |
++ | The properties file. | ++ |
template |
++ | The template file. | +version.vm |
+
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>0.9.6-beta</version>
+</dependency>
To install and run from Gradle, add the following to the build.gradle
file:
dependencies {
+ compile 'net.thauvin.erik:semver:0.9.6-beta'
+}
+The GeneratedVersion
class will be automatically created in the build
directory upon compiling.
In order to also incorporate the generated source code into the source tree
, use the EWERK Annotation Processor Plugin. Start by addding the following to the very top of the build.gradle
file:
plugins {
+ id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.2"
+}
+Then add the following to the build.gradle
file:
dependencies {
+ compileOnly 'net.thauvin.erik:semver:0.9.6-beta'
+}
+
+annotationProcessor {
+ library 'net.thauvin.erik:semver:0.9.6-beta'
+ processor 'net.thauvin.erik.semver.VersionProcessor'
+ // sourcesDir 'src/generated/java'
+}
+
+compileJava {
+ // Disable the classpath procesor
+ 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:0.9.6-beta")
+ compile("net.thauvin.erik:semver:0.9.6-beta")
+}
+Please look at the Build.kt file in the example module directory for a sample.
+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
+
+
diff --git a/README.md b/README.md
index cada04f..3c8d0ca 100644
--- a/README.md
+++ b/README.md
@@ -1,62 +1,27 @@
-# 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 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,267 +32,173 @@ version.patch=0
version.prerelease=beta
```
-[View Examples](https://github.com/ethauvin/semver/tree/master/examples)
-
## Template
-Upon running the annotation processor, a source file [GeneratedVersion.java](https://github.com/ethauvin/semver/blob/master/examples/java/src/generated/java/com/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable Mustache [template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache).
-
-To use your own template, simply create a `version.mustache` file in the project's root directory. The processor will automatically look for it.
-
-To specify your own template name, use:
+Upon running the annotator processor, a source file [`GeneratedVersion.java`](https://github.com/ethauvin/semver/blob/master/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java) is automatically generated with static methods to access the semantic version data. The source is based on a fully customizable [Velocity](http://velocity.apache.org/) template.
```java
-@Version(template = "version.mustache")
+@Version(template = "myversion.vm")
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/version.vm) implements the following static methods:
-| 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. | `.` |
+Method | Description | Example
+------------------|----------------------------------|------------------
+`getProject` | The project name, if any. | `MyProject`
+`getBuildDate` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
+`getVersion` | The full version string. | `1.0.0-alpha+001`
+`getMajor` | The major version. | `1`
+`getMinor` | The minor version. | `0`
+`getPatch` | The patch version. | `0`
+`getPreRelease` | The pre-release version, if any. | `alpha`
+`getBuildMetadata`| The build metadata, if any. | `001`
### Custom Template
A very simple custom template might look something like:
```java
-/* version.mustache */
-package {{packageName}};
+/* myversion.vm */
+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 class ${className} {
+ public final static String BUILDMETA = "${buildmeta}";
+ public final static Date DATE = new Date(${epoch}L);
+ public final static int MAJOR = ${major};
+ public final static int MINOR = ${minor};
+ public final static int PATCH = ${patch};
+ public final static String PRERELEASE = "${prerelease}";
+ public final static String PROJECT = "${project}";
}
```
-
-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 Velocity variables are automatically filled in by the processor.
+
## 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. |
+`className` | | The name of the generated class. | `GeneratedVersion`
+`properties` | | The properties file. |
+`template` | | The template file. | `version.vm`
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"
+ properties = "example.properties",
+ 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 and Kobalt
-> :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:
```xml
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/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..8192c45
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,222 @@
+plugins {
+ id "com.jfrog.bintray" version "1.5"
+}
+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 'org.apache.velocity:velocity:1.7'
+ testCompile 'org.testng:testng:6.9.12'
+}
+
+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']) << {
+ group = 'Publishing'
+ description = 'Releases new version.'
+ isRelease = true
+}
+
+task pandoc(type: Exec) {
+ group = 'Documentation'
+ def pandoc_args = []
+ 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()
+ }
+}
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..66b8272 --- /dev/null +++ b/example/build.gradle @@ -0,0 +1,96 @@ +plugins { + id "com.ewerk.gradle.plugins.annotation-processor" version "1.0.2" +} +apply plugin: 'java' +apply plugin: 'idea' +apply plugin: 'application' + +defaultTasks 'run' + +def isRelease = 'release' in gradle.startParameter.taskNames +def deployDir = 'deploy' + +// 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 'net.thauvin.erik:semver:0.9.6-beta' +} + +annotationProcessor { + // Update version, increment on release. + project.version = getVersion(isRelease) + library 'net.thauvin.erik:semver:0.9.6-beta' + 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']) << { + 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..13372ae 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..7968b98 100644 --- a/examples/test/gradle/wrapper/gradle-wrapper.properties +++ b/example/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ +#Sat Jan 23 18:16:10 PST 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.10-bin.zip diff --git a/example/gradlew b/example/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/example/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# 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 +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# 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 + +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" ] ; 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..8a0b282 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 @@ -24,30 +8,26 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal +@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= + 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" - @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 Windowz 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..bd87306 --- /dev/null +++ b/example/kobalt/src/Build.kt @@ -0,0 +1,80 @@ +import com.beust.kobalt.localMaven +import com.beust.kobalt.plugin.application.application +import com.beust.kobalt.plugin.apt.apt +import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.packaging.install +import com.beust.kobalt.project +import com.beust.kobalt.repos +import java.io.FileInputStream +import java.util.* + +val repos = repos(localMaven()) + +fun StringBuilder.prepend(s: String): StringBuilder { + if (this.length > 0) { + 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:0.9.6-beta" + + sourceDirectories { + path("src/main/java") + } + + sourceDirectoriesTest { + path("src/test/java") + } + + dependencies { + apt(processorJar) + compile(processorJar) + } + + dependenciesTest { + + } + + apt { + outputDir = "/src/generated/java/" + } + + install { + libDir = "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..c178849 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..40e4395 --- /dev/null +++ b/example/kobalt/wrapper/kobalt-wrapper.properties @@ -0,0 +1 @@ +kobalt.version=0.843 \ No newline at end of file diff --git a/example/kobaltw b/example/kobaltw new file mode 100644 index 0000000..b27b3d8 --- /dev/null +++ b/example/kobaltw @@ -0,0 +1 @@ +java -jar $(dirname $0)/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/src/test/java/net/thauvin/erik/semver/ConstantsTest.java b/example/src/main/java/net/thauvin/erik/semver/example/Example.java similarity index 54% rename from src/test/java/net/thauvin/erik/semver/ConstantsTest.java rename to example/src/main/java/net/thauvin/erik/semver/example/Example.java index c82f718..f854c44 100644 --- a/src/test/java/net/thauvin/erik/semver/ConstantsTest.java +++ b/example/src/main/java/net/thauvin/erik/semver/example/Example.java @@ -1,7 +1,7 @@ /* - * ConstantsTest.java + * Example.java * - * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net) + * Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,45 +29,37 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package net.thauvin.erik.semver.example; -package net.thauvin.erik.semver; +import net.thauvin.erik.semver.Version; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import java.text.SimpleDateFormat; /** - * TheConstantsTest
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:
+ *
+
+ Constants
class holds the constant variables used throughout this project.
*
- * @author Erik C. Thauvin
+ * @author Erik C. Thauvin
* @created 2016-01-13
* @since 1.0
*/
-@SuppressWarnings("PMD.DataClass")
-public final class Constants {
- /**
- * The default metadata prefix.
- */
- public static final String DEFAULT_BUILDMETA_PREFIX = "+";
- /**
- * The default class name.
- */
- public static final String DEFAULT_CLASS_NAME = "GeneratedVersion";
- /**
- * The default Java mustache template.
- */
- public static final String DEFAULT_JAVA_TEMPLATE = "semver.mustache";
- /**
- * The default java type.
- **/
- public static final String DEFAULT_JAVA_TYPE = "java";
- /**
- * The default keys prefix.
- */
- public static final String DEFAULT_KEYS_PREFIX = "version.";
- /**
- * The default Kotlin mustache template.
- */
- public static final String DEFAULT_KOTLIN_TEMPLATE = "semver-kt.mustache";
- /**
- * The default major version.
- */
- public static final int DEFAULT_MAJOR = 1;
- /**
- * The default minor version.
- */
- public static final int DEFAULT_MINOR = 0;
- /**
- * The default patch version.
- */
- public static final int DEFAULT_PATCH = 0;
- /**
- * The default prerelease prefix.
- */
- public static final String DEFAULT_PRERELEASE_PREFIX = "-";
- /**
- * The default version separator.
- */
- public static final String DEFAULT_SEPARATOR = ".";
- /**
- * The default mustache template.
- */
- public static final String DEFAULT_TEMPLATE_NAME = "version.mustache";
- /**
- * The empty string.
- */
- public static final String EMPTY = "";
- /**
- * The generated source files directory kotlin option.
- */
- public static final String KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated";
- /**
- * The build metadata property key.
- */
- public static final String KEY_VERSION_BUILDMETA = "buildmeta";
- /**
- * The build metadata prefix property key.
- */
- public static final String KEY_VERSION_BUILDMETA_PREFIX = "buildmeta.prefix";
- /**
- * The major version property key.
- */
- public static final String KEY_VERSION_MAJOR = "major";
- /**
- * The minor version property key.
- */
- public static final String KEY_VERSION_MINOR = "minor";
- /**
- * The patch version property key.
- */
- public static final String KEY_VERSION_PATCH = "patch";
- /**
- * The pre-release version property key.
- */
- public static final String KEY_VERSION_PRERELEASE = "prerelease";
- /**
- * The pre-release prefix property key.
- */
- public static final String KEY_VERSION_PRERELEASE_PREFIX = "prerelease.prefix";
- /**
- * The project property key.
- */
- public static final String KEY_VERSION_PROJECT = "project";
- /**
- * The version separator property key.
- */
- public static final String KEY_VERSION_SEPARATOR = "separator";
- /**
- * The kotlin type.
- */
- public static final String KOTLIN_TYPE = "kt";
- /**
- * The argument used to specify the project location.
- */
- public static final String SEMVER_PROJECT_DIR_ARG = "semver.project.dir";
+public final class Constants
+{
+ /**
+ * The default class name.
+ */
+ public static final String DEFAULT_CLASS_NAME = "GeneratedVersion";
- /**
- * Disables the default constructor.
- */
- private Constants() {
- throw new UnsupportedOperationException("Illegal constructor call.");
- }
-}
+ /**
+ * The default major version.
+ */
+ public static final int DEFAULT_MAJOR = 1;
+
+ /**
+ * The default minor version.
+ */
+ public static final int DEFAULT_MINOR = 0;
+
+ /**
+ * The default patch version.
+ */
+ public static final int DEFAULT_PATCH = 0;
+
+ /**
+ * The default Velocity template.
+ */
+ public static final String DEFAULT_TEMPLATE = "version.vm";
+
+ /**
+ * The empty string.
+ */
+ public static final String EMPTY = "";
+
+ /**
+ * The build metadata property key.
+ */
+ public static final String KEY_VERSION_BUILDMETA = "version.buildmeta";
+
+ /**
+ * The major version property key.
+ */
+ public static final String KEY_VERSION_MAJOR = "version.major";
+
+ /**
+ * The minor version property key.
+ */
+ public static final String KEY_VERSION_MINOR = "version.minor";
+
+ /**
+ * The patch version property key.
+ */
+ public static final String KEY_VERSION_PATCH = "version.patch";
+
+ /**
+ * The pre-release version property key.
+ */
+ public static final String KEY_VERSION_PRERELEASE = "version.prerelease";
+
+ /**
+ * The project property key.
+ */
+ public static final String KEY_VERSION_PROJECT = "version.project";
+
+ /**
+ * The velocity properties name.
+ */
+ public static final String VELOCITY_PROPERTIES = "velocity.properties";
+
+ /**
+ * Disables the default constructor.
+ *
+ * @throws UnsupportedOperationException if the constructor is called.
+ */
+ private Constants()
+ throws UnsupportedOperationException
+ {
+ throw new UnsupportedOperationException("Illegal constructor call.");
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/thauvin/erik/semver/Version.java b/src/main/java/net/thauvin/erik/semver/Version.java
index 821677f..fd1c986 100644
--- a/src/main/java/net/thauvin/erik/semver/Version.java
+++ b/src/main/java/net/thauvin/erik/semver/Version.java
@@ -1,7 +1,7 @@
/*
* Version.java
*
- * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,6 @@
* 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.ElementType;
@@ -40,179 +39,41 @@ import java.lang.annotation.Target;
/**
* The Version
class implements the annotation interface.
*
- * @author Erik C. Thauvin
+ * @author Erik C. Thauvin
* @created 2016-01-13
* @since 1.0
*/
-@SuppressWarnings("SameReturnValue")
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
-public @interface Version {
- /**
- * Returns the build metadata version.
- *
- * @return The build metadata version.
- */
- String buildMeta() default Constants.EMPTY;
+public @interface Version
+{
+ String buildmeta() default Constants.EMPTY;
- /**
- * Returns the build metadata key.
- *
- * @return The build metadata key.
- */
- String buildMetaKey() default Constants.KEY_VERSION_BUILDMETA;
+ String buildmetaKey() default Constants.KEY_VERSION_BUILDMETA;
- /**
- * Returns the build metadata prefix.
- *
- * @return The build metadata prefix.
- */
- String buildMetaPrefix() default Constants.DEFAULT_BUILDMETA_PREFIX;
+ String className() default Constants.DEFAULT_CLASS_NAME;
- /**
- * Returns the build metadata prefix key.
- *
- * @return The build metadata prefix key.
- */
- String buildMetaPrefixKey() default Constants.KEY_VERSION_BUILDMETA_PREFIX;
+ int major() default Constants.DEFAULT_MAJOR;
- /**
- * Returns the class name.
- *
- * @return The class name.
- */
- String className() default Constants.DEFAULT_CLASS_NAME;
+ String majorKey() default Constants.KEY_VERSION_MAJOR;
- /**
- * Returns the keys prefix.
- *
- * @return The keys prefix.
- */
- String keysPrefix() default Constants.DEFAULT_KEYS_PREFIX;
+ int minor() default Constants.DEFAULT_MINOR;
- /**
- * Returns the major version.
- *
- * @return The major version.
- */
- int major() default Constants.DEFAULT_MAJOR;
+ String minorKey() default Constants.KEY_VERSION_MINOR;
- /**
- * Returns the major key.
- *
- * @return The major key.
- */
- String majorKey() default Constants.KEY_VERSION_MAJOR;
+ int patch() default Constants.DEFAULT_PATCH;
- /**
- * Returns the minor version.
- *
- * @return The build minor version.
- */
- int minor() default Constants.DEFAULT_MINOR;
+ String patchKey() default Constants.KEY_VERSION_PATCH;
- /**
- * Returns the minor key.
- *
- * @return The minor key.
- */
- String minorKey() default Constants.KEY_VERSION_MINOR;
+ String prerelease() default Constants.EMPTY;
- /**
- * Returns the package name.
- *
- * @return The package name .
- */
- String packageName() default Constants.EMPTY;
+ String prereleaseKey() default Constants.KEY_VERSION_PRERELEASE;
- /**
- * Returns the patch version.
- *
- * @return The patch version.
- */
- int patch() default Constants.DEFAULT_PATCH;
+ String project() default Constants.EMPTY;
- /**
- * Returns the patch key.
- *
- * @return The patch key.
- */
- String patchKey() default Constants.KEY_VERSION_PATCH;
+ String projectKey() default Constants.KEY_VERSION_PROJECT;
- /**
- * Returns the pre-release version.
- *
- * @return The pre-release version.
- */
- String preRelease() default Constants.EMPTY;
+ String properties() default Constants.EMPTY;
- /**
- * Returns the pre-release key.
- *
- * @return The pre-release key.
- */
- String preReleaseKey() default Constants.KEY_VERSION_PRERELEASE;
-
- /**
- * Returns the pre-release prefix.
- *
- * @return The pre-release prefix.
- */
- String preReleasePrefix() default Constants.DEFAULT_PRERELEASE_PREFIX;
-
- /**
- * Returns the pre-release prefix key.
- *
- * @return The pre-release prefix key.
- */
- String preReleasePrefixKey() default Constants.KEY_VERSION_PRERELEASE_PREFIX;
-
- /**
- * Returns the project name.
- *
- * @return The project name.
- */
- String project() default Constants.EMPTY;
-
- /**
- * Returns the project key.
- *
- * @return The project.
- */
- String projectKey() default Constants.KEY_VERSION_PROJECT;
-
- /**
- * Returns the properties file name.
- *
- * @return The properties file name.
- */
- String properties() default Constants.EMPTY;
-
- /**
- * Returns the version separator.
- *
- * @return The separator.
- */
- String separator() default Constants.DEFAULT_SEPARATOR;
-
- /**
- * Returns the version separator key.
- *
- * @return The separator key.
- */
- String separatorKey() default Constants.KEY_VERSION_SEPARATOR;
-
- /**
- * Returns the template name.
- *
- * @return The template.
- */
- String template() default Constants.DEFAULT_JAVA_TEMPLATE;
-
- /**
- * Returns the template type.
- *
- * @return The type.
- */
- String type() default Constants.DEFAULT_JAVA_TYPE;
-}
+ String template() default Constants.DEFAULT_TEMPLATE;
+}
\ No newline at end of file
diff --git a/src/main/java/net/thauvin/erik/semver/VersionInfo.java b/src/main/java/net/thauvin/erik/semver/VersionInfo.java
index b2ea193..6da9672 100644
--- a/src/main/java/net/thauvin/erik/semver/VersionInfo.java
+++ b/src/main/java/net/thauvin/erik/semver/VersionInfo.java
@@ -1,7 +1,7 @@
/*
* VersionInfo.java
*
- * Copyright (c) 2016-2024, Erik C. Thauvin (erik@thauvin.net)
+ * Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,312 +29,208 @@
* 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;
/**
* The VersionInfo
class is used to hold and retrieve the semantic version values.
*
- * @author Erik C. Thauvin
+ * @author Erik C. Thauvin
* @created 2016-01-16
* @since 1.0
*/
-@SuppressWarnings("PMD.DataClass")
-public class VersionInfo {
- private final long epoch = System.currentTimeMillis();
+public class VersionInfo
+{
+ private final long epoch = System.currentTimeMillis();
- private String buildMeta;
- private String buildMetaPrefix;
- private String className;
- private int major;
- private int minor;
- private String packageName;
- private int patch;
- private String preRelease;
- private String preReleasePrefix;
- private String project;
- private String separator;
+ private String buildmeta;
+ private int major;
- /**
- * Creates a new object with default values.
- */
- public VersionInfo() {
- buildMeta = Constants.EMPTY;
- buildMetaPrefix = Constants.DEFAULT_BUILDMETA_PREFIX;
- className = Constants.DEFAULT_CLASS_NAME;
- minor = Constants.DEFAULT_MINOR;
- packageName = Constants.EMPTY;
- patch = Constants.DEFAULT_PATCH;
- preRelease = Constants.EMPTY;
- preReleasePrefix = Constants.DEFAULT_PRERELEASE_PREFIX;
- project = Constants.EMPTY;
- separator = Constants.DEFAULT_SEPARATOR;
- major = Constants.DEFAULT_MAJOR;
- }
+ private int minor;
- /**
- * Creates a new object with values from a {@link net.thauvin.erik.semver.VersionInfo VersionInfo} object.
- *
- * @param version The version object.
- */
- public VersionInfo(final Version version) {
- buildMeta = version.buildMeta();
- buildMetaPrefix = version.buildMetaPrefix();
- className = version.className();
- major = version.major();
- minor = version.minor();
- packageName = version.packageName();
- patch = version.patch();
- preRelease = version.preRelease();
- preReleasePrefix = version.preReleasePrefix();
- project = version.project();
- separator = version.separator();
- }
+ private int patch;
- /**
- * Returns the build meta-data.
- *
- * @return The build meta-data.
- */
- public String getBuildMeta() {
- return buildMeta;
- }
+ private String prerelease;
- /**
- * Returns the meta-data prefix.
- *
- * @return The meta-data prefix.
- */
- public String getBuildMetaPrefix() {
- return buildMetaPrefix;
- }
+ private String project;
- /**
- * Returns the class name.
- *
- * @return The class name.
- */
- public String getClassName() {
- return className;
- }
+ /**
+ * Creates a new object with default values
+ */
+ public VersionInfo()
+ {
+ major = Constants.DEFAULT_MAJOR;
+ minor = Constants.DEFAULT_MINOR;
+ patch = Constants.DEFAULT_PATCH;
+ buildmeta = Constants.EMPTY;
+ prerelease = Constants.EMPTY;
+ project = Constants.EMPTY;
+ }
- /**
- * Returns the build epoch/Unix timestamp.
- *
- * @return The build epoch.
- */
- public long getEpoch() {
- return epoch;
- }
+ /**
+ * Creates a new object with values from a {@link net.thauvin.erik.semver.Version Version} object.
+ *
+ * @param version The version object.
+ */
+ public VersionInfo(final Version version)
+ {
+ major = version.major();
+ minor = version.minor();
+ patch = version.patch();
+ buildmeta = version.buildmeta();
+ prerelease = version.prerelease();
+ project = version.project();
+ }
- /**
- * Returns the major version.
- *
- * @return The major version.
- */
- public int getMajor() {
- return major;
- }
+ /**
+ * Returns the build metadata.
+ *
+ * @return The build metadata.
+ */
+ public String getBuildMetadata()
+ {
+ return buildmeta;
+ }
- /**
- * Returns the major version.
- *
- * @return The major version.
- */
- public int getMinor() {
- return minor;
- }
+ /**
+ * Sets the build metadata.
+ *
+ * @param buildmeta The new build metadata.
+ */
+ public void setBuildMetadata(final String buildmeta)
+ {
+ this.buildmeta = buildmeta;
+ }
- /**
- * Returns the package name.
- *
- * @return The package name.
- */
- public String getPackageName() {
- return packageName;
- }
+ /**
+ * Returns the build epoch/Unix timestamp.
+ *
+ * @return The build epoch.
+ */
+ public long getEpoch()
+ {
+ return epoch;
+ }
- /**
- * Returns the patch version.
- *
- * @return The patch version.
- */
- public int getPatch() {
- return patch;
- }
+ /**
+ * Returns the major version.
+ *
+ * @return The major version.
+ */
+ public int getMajor()
+ {
+ return major;
+ }
- /**
- * Returns the pre-release version.
- *
- * @return The pre-release version.
- */
- public String getPreRelease() {
- return preRelease;
- }
+ /**
+ * Sets the major version.
+ *
+ * @param major The new major version.
+ */
+ public void setMajor(final int major)
+ {
+ this.major = major;
+ }
- /**
- * Returns the pre-release prefix.
- *
- * @return The pre-release prefix.
- */
- public String getPreReleasePrefix() {
- return preReleasePrefix;
- }
+ /**
+ * Returns the major version.
+ *
+ * @return The major version.
+ */
+ public int getMinor()
+ {
+ return minor;
+ }
- /**
- * Returns the project name.
- *
- * @return The project name.
- */
- public String getProject() {
- return project;
- }
+ /**
+ * Sets the minor version.
+ *
+ * @param minor The new minor version.
+ */
+ public void setMinor(final int minor)
+ {
+ this.minor = minor;
+ }
- /**
- * Sames as {@link #getVersion()}.
- *
- * @return The version string.
- */
- public String getSemver() {
- return getVersion();
- }
+ /**
+ * Returns the patch version.
+ *
+ * @return The patch version.
+ */
+ public int getPatch()
+ {
+ return patch;
+ }
- /**
- * Returns the version separator.
- *
- * @return The version separator.
- */
- public String getSeparator() {
- return separator;
- }
+ /**
+ * Sets the patch version.
+ *
+ * @param patch The new patch version.
+ */
+ public void setPatch(final int patch)
+ {
+ this.patch = patch;
+ }
- /**
- * Returns the full version string.
- *
- *
- *
- *
- *
- * [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 : "");
- }
+ /**
+ * Returns the pre-release version.
+ *
+ * @return The pre-release version.
+ */
+ public String getPreRelease()
+ {
+ return prerelease;
+ }
- /**
- * Sets the build meta-data.
- *
- * @param buildMeta The new build meta-data.
- */
- public void setBuildMeta(final String buildMeta) {
- this.buildMeta = buildMeta;
- }
+ /**
+ * Sets the pre-release version.
+ *
+ * @param prerelease The new pre-release version.
+ */
+ public void setPreRelease(final String prerelease)
+ {
+ this.prerelease = prerelease;
+ }
- /**
- * Sets the meta-data prefix.
- *
- * @param buildMetaPrefix The meta-data prefix.
- */
- public void setBuildMetaPrefix(final String buildMetaPrefix) {
- this.buildMetaPrefix = buildMetaPrefix;
- }
+ /**
+ * Returns the project name.
+ *
+ * @return The project name.
+ */
+ public String getProject()
+ {
+ return project;
+ }
- /**
- * Sets the class name.
- *
- * @param className The new class name.
- */
- public void setClassName(final String className) {
- this.className = className;
- }
+ /**
+ * Sets the project name.
+ *
+ * @param project The new project name.
+ */
+ public void setProject(final String project)
+ {
+ this.project = project;
+ }
- /**
- * Sets the major version.
- *
- * @param major The new major version.
- */
- public void setMajor(final int major) {
- this.major = major;
- }
-
- /**
- * Sets the minor version.
- *
- * @param minor The new minor version.
- */
- public void setMinor(final int minor) {
- this.minor = minor;
- }
-
- /**
- * Sets the package name.
- *
- * @param packageName The new package name.
- */
- public void setPackageName(final String packageName) {
- this.packageName = packageName;
- }
-
- /**
- * Sets the patch version.
- *
- * @param patch The new patch version.
- */
- public void setPatch(final int patch) {
- this.patch = patch;
- }
-
- /**
- * Sets the pre-release version.
- *
- * @param preRelease The new pre-release version.
- */
- public void setPreRelease(final String preRelease) {
- this.preRelease = preRelease;
- }
-
- /**
- * Sets the pre-release prefix.
- *
- * @param preReleasePrefix The new pre-release prefix.
- */
- public void setPreReleasePrefix(final String preReleasePrefix) {
- this.preReleasePrefix = preReleasePrefix;
- }
-
- /**
- * Sets the project name.
- *
- * @param project The new project name.
- */
- public void setProject(final String project) {
- this.project = project;
- }
-
- /**
- * Sets the version separator.
- *
- * @param separator The new version separator.
- */
- public void setSeparator(final String separator) {
- this.separator = 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]
+ *
+ *
+ * @return The version string.
+ */
+ 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..4a386f8 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, 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 org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
@@ -43,10 +42,9 @@ import javax.lang.model.element.ElementKind;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
-import javax.tools.FileObject;
+import javax.tools.JavaFileObject;
import java.io.*;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
+import java.net.URL;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
@@ -54,231 +52,200 @@ import java.util.Set;
/**
* The 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
VersionProcessor
class implements a semantic version annotation processor.
*
- * @author Erik C. Thauvin
+ * @author Erik C. Thauvin
* @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;
+public class VersionProcessor extends AbstractProcessor
+{
+ private Filer filer;
- private Messager messager;
+ 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 void error(final String s)
+ {
+ log(Diagnostic.Kind.ERROR, s);
+ }
- 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, final Throwable t)
+ {
+ messager.printMessage(Diagnostic.Kind.ERROR, (t != null ? t.toString() : s));
+ }
- private void error(final String s) {
- log(Diagnostic.Kind.ERROR, s);
- }
+ private VersionInfo findValues(final Version version)
+ throws IOException
+ {
+ final VersionInfo versionInfo;
- @SuppressWarnings("PMD.UnusedPrivateMethod")
- private void error(final String s, final Throwable t) {
- log(Diagnostic.Kind.ERROR, t != null ? t.toString() : s);
- }
+ if (version.properties().length() > 0)
+ {
+ versionInfo = new VersionInfo();
- private VersionInfo findValues(final Version version) throws IOException {
- final var versionInfo = new VersionInfo(version);
+ final File propsFile = new File(version.properties());
+ if (propsFile.exists())
+ {
+ note("Found properties: " + propsFile);
+ final Properties p = new Properties();
- if (!version.properties().isEmpty()) {
- final var propsFile = getLocalFile(version.properties());
- if (propsFile.isFile() && propsFile.canRead()) {
- note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
+ try (FileReader reader = new FileReader(propsFile))
+ {
+ p.load(reader);
- final var p = new Properties();
+ versionInfo.setProject(p.getProperty(version.projectKey(), Constants.EMPTY));
+ versionInfo.setMajor(parseIntProperty(p, version.majorKey(), Constants.DEFAULT_MAJOR));
+ versionInfo.setMinor(parseIntProperty(p, version.minorKey(), Constants.DEFAULT_MINOR));
+ versionInfo.setPatch(parseIntProperty(p, version.patchKey(), Constants.DEFAULT_PATCH));
+ versionInfo.setBuildMetadata(p.getProperty(version.buildmetaKey(), Constants.EMPTY));
+ versionInfo.setPreRelease(p.getProperty(version.prereleaseKey(), Constants.EMPTY));
+ }
+ }
+ else
+ {
+ error("Could not find: " + propsFile);
+ throw new FileNotFoundException(propsFile + " (The system cannot find the file specified)");
+ }
+ }
+ else
+ {
+ versionInfo = new VersionInfo(version);
+ }
- try (var reader = new InputStreamReader(
- Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
- p.load(reader);
+ return versionInfo;
+ }
- 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()));
- }
- } 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() + '`');
- }
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public SetGeneratedVersion
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
deleted file mode 100644
index cf53df5..0000000
--- a/src/main/resources/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/src/main/resources/semver.mustache b/src/main/resources/semver.mustache
deleted file mode 100644
index d9eb417..0000000
--- a/src/main/resources/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/src/main/resources/velocity.properties b/src/main/resources/velocity.properties
new file mode 100644
index 0000000..ba28119
--- /dev/null
+++ b/src/main/resources/velocity.properties
@@ -0,0 +1,4 @@
+runtime.log.logsystem.class = org.apache.velocity.runtime.log.SystemLogChute
+resource.loader = file, class
+file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
+class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
\ No newline at end of file
diff --git a/src/main/resources/version.vm b/src/main/resources/version.vm
new file mode 100644
index 0000000..7e0f798
--- /dev/null
+++ b/src/main/resources/version.vm
@@ -0,0 +1,172 @@
+##############################################################################
+##
+## Available variables:
+##
+## $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)
+##
+##############################################################################
+/*
+ * 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} {
+ private final static String buildmeta = "${buildmeta}";
+ private final static Date date = new Date(${epoch}L);
+ private final static int major = ${major};
+ private final static int minor = ${minor};
+ private final static int patch = ${patch};
+ private final static String prerelease = "${prerelease}";
+ private final static String project = "${project}";
+
+ /**
+ * Disables the default constructor.
+ *
+ * @throws UnsupportedOperationException If the constructor is called.
+ */
+ private ${className}()
+ throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Illegal constructor call.");
+ }
+
+ /**
+ * Returns the build date.
+ *
+ * @return The build date.
+ */
+ public static Date getBuildDate() {
+ return date;
+ }
+
+ /**
+ * Returns the project name.
+ *
+ * @return The project name, if any.
+ */
+ public static String getProject() {
+ return project;
+ }
+
+ /**
+ * Returns the full version string.
+ *
+ *
+ * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]
+ *
+ *
+ *
+ * @return The version string.
+ */
+ public static String getVersion() {
+ return Integer.toString(getMajor()) + '.'
+ + Integer.toString(getMinor()) + '.'
+ + Integer.toString(getPatch())
+ + getPreRelease(true) + getBuildMetadata(true);
+ }
+
+ /**
+ * Returns the major version.
+ *
+ * @return The major version.
+ */
+ public static int getMajor() {
+ return major;
+ }
+
+ /**
+ * Returns the minor version.
+ *
+ * @return The minor version.
+ */
+ public static int getMinor() {
+ return minor;
+ }
+
+ /**
+ * Returns the patch version.
+ *
+ * @return The patch version.
+ */
+ public static int getPatch() {
+ return patch;
+ }
+
+ /**
+ * Returns the pre-release version.
+ *
+ * @param isHyphen Prepend a hyphen, if 1.0.0
1.0.0-beta
1.0.0+20160124144700
1.0.0-alpha+001
true
.
+ * @return The pre-release version, if any.
+ */
+ public static String getPreRelease(final boolean isHyphen) {
+ if (prerelease.length() > 0) {
+ if (isHyphen) {
+ return '-' + prerelease;
+ } else {
+ return prerelease;
+ }
+ }
+
+ return "";
+ }
+
+ /**
+ * Returns the pre-release version.
+ *
+ * @return The pre-release version, if any.
+ */
+ public static String getPreRelease() {
+ return getPreRelease(false);
+ }
+
+ /**
+ * Returns the build metadata.
+ *
+ * @param isPlus Prepend a plus sign, if true
.
+ * @return The build metadata, if any.
+ */
+ public static String getBuildMetadata(final boolean isPlus) {
+ if (buildmeta.length() > 0) {
+ if (isPlus) {
+ return '+' + buildmeta;
+ } else {
+ return buildmeta;
+ }
+ }
+
+ return "";
+ }
+
+ /**
+ * Returns the build metadata.
+ *
+ * @return The build metadata, if any.
+ */
+ public static String getBuildMetadata() {
+ return getBuildMetadata(false);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java
index 49d2e7c..90639be 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, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,15 +29,10 @@
* 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 java.util.Date;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.testng.Assert;
+import org.testng.annotations.Test;
/**
* The VersionInfoTest
class.
@@ -46,150 +41,39 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
* @created 2016-02-03
* @since 1.0
*/
-class VersionInfoTest {
- private VersionInfo versionInfo = new VersionInfo();
+public class VersionInfoTest
+{
+ @Test
+ public void testGetVersion()
+ throws Exception
+ {
- @SuppressWarnings("PMD.AvoidUsingHardCodedIP")
- @Test
- void testGetVersion() {
- assertEquals("1.0.0", versionInfo.getVersion(), "getVersion(1.0.0)");
+ final VersionInfo version = new VersionInfo();
- versionInfo.setMajor(3);
+ Assert.assertEquals(version.getVersion(), "1.0.0");
- assertEquals("3.0.0", versionInfo.getVersion(), "getVersion(3.0.0)");
+ version.setMajor(3);
- versionInfo.setMinor(2);
+ Assert.assertEquals(version.getVersion(), "3.0.0");
- assertEquals("3.2.0", versionInfo.getVersion(), "getVersion(3.2.0)");
+ version.setMinor(2);
- versionInfo.setPatch(1);
+ Assert.assertEquals(version.getVersion(), "3.2.0");
- assertEquals("3.2.1", versionInfo.getVersion(), "getVersion(3.2.1)");
+ version.setPatch(1);
- versionInfo.setPreRelease("beta");
+ Assert.assertEquals(version.getVersion(), "3.2.1");
- assertEquals("3.2.1-beta", versionInfo.getVersion(), "getVersion(3.2.1-beta)");
+ version.setPreRelease("beta");
- versionInfo.setBuildMeta("001");
+ Assert.assertEquals(version.getVersion(), "3.2.1-beta");
- assertEquals("3.2.1-beta+001", versionInfo.getVersion(), "getVersion(3.2.1-beta+001)");
+ version.setBuildMetadata("001");
- versionInfo.setPreReleasePrefix("+");
+ Assert.assertEquals(version.getVersion(), "3.2.1-beta+001");
- assertEquals("3.2.1+beta+001", versionInfo.getVersion(), "getVersion(3.2.1+beta+001)");
+ version.setPreRelease("");
- versionInfo.setPreReleasePrefix("-");
-
- 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) ");
- }
-
- @Test
- void testSetGet() {
- versionInfo.setSeparator(".");
-
- versionInfo.setMajor(1);
-
- assertEquals(1, versionInfo.getMajor(), "getMajor(1)");
-
- versionInfo.setMinor(2);
-
- assertEquals(2, versionInfo.getMinor(), "getMinor(2)");
-
- versionInfo.setPatch(3);
-
- assertEquals(3, versionInfo.getPatch(), "getPatch(3)");
-
- versionInfo.setPreRelease("alpha");
-
- assertEquals("alpha", versionInfo.getPreRelease(), "getPreRelease(alpha)");
-
- versionInfo.setBuildMeta("001");
-
- assertEquals("001", versionInfo.getBuildMeta(), "getBuildMeta(001)");
-
- versionInfo.setPackageName("com.example");
-
- assertEquals("com.example", versionInfo.getPackageName(), "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)");
-
- versionInfo.setProject("My Example");
-
- assertEquals("My Example", versionInfo.getProject(), "getProject(My Example)");
-
- versionInfo.setClassName("Example");
-
- assertEquals("Example", versionInfo.getClassName(), "getClassName(Example");
-
- assertTrue((versionInfo.getEpoch() - new Date().getTime()) < 1000, "buildDate - now < 1s");
- }
-
- @Test
- void testVersionInfo() {
- final Version version = new VersionTest();
- versionInfo = new VersionInfo(version);
-
- assertEquals(version.major(), versionInfo.getMajor(), "getMajor(major)");
-
- assertEquals(version.minor(), versionInfo.getMinor(), "getMinor(minor)");
-
- assertEquals(version.patch(), versionInfo.getPatch(), "getPatch(patch)");
-
- assertEquals(version.preRelease(), versionInfo.getPreRelease(), "getPreRelease(preRelease)");
-
- assertEquals(version.preReleasePrefix(), versionInfo.getPreReleasePrefix(),
- "getPreReleasePrefix(preReleasePrefix)");
-
- assertEquals(version.buildMeta(), versionInfo.getBuildMeta(), "getBuildMeta(buildMeta)");
-
- assertEquals(version.buildMetaPrefix(), versionInfo.getBuildMetaPrefix(),
- "getBuildMetaPrefix(buildMetaPrefix)");
-
- assertEquals(version.packageName(), versionInfo.getPackageName(), "getPackageName(packageName)");
-
- 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(version.getVersion(), "3.2.1+001");
+ }
+}
\ 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..94e8df4
--- /dev/null
+++ b/version.properties
@@ -0,0 +1,6 @@
+#Thu, 28 Jan 2016 17:33:17 -0800
+version.major=0
+version.minor=9
+version.patch=6
+version.buildmeta=
+version.prerelease=beta