Compare commits
5 commits
b18a9f641c
...
9ddf470e40
Author | SHA1 | Date | |
---|---|---|---|
9ddf470e40 | |||
65fb61daf4 | |||
5cf167e7bf | |||
a8d3d7a4ea | |||
878e1033f1 |
24 changed files with 292 additions and 152 deletions
1
.idea/inspectionProfiles/Project_Default.xml
generated
1
.idea/inspectionProfiles/Project_Default.xml
generated
|
@ -4,5 +4,6 @@
|
||||||
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
<option name="ADDITIONAL_TAGS" value="created,created.on" />
|
<option name="ADDITIONAL_TAGS" value="created,created.on" />
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="RedundantExplicitVariableType" enabled="true" level="INFORMATION" enabled_by_default="true" editorAttributes="INFORMATION_ATTRIBUTES" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
4
.idea/libraries/bld.xml
generated
4
.idea/libraries/bld.xml
generated
|
@ -2,11 +2,11 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.1.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.2.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.1-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.2-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -7,7 +7,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.bld/dist/bld-1.7.1.jar",
|
"${HOME}bld-1.7.2.jar",
|
||||||
"lib/compile/*.jar",
|
"lib/compile/*.jar",
|
||||||
"lib/runtime/*.jar",
|
"lib/runtime/*.jar",
|
||||||
"lib/test/*.jar"
|
"lib/test/*.jar"
|
||||||
|
|
118
README.md
118
README.md
|
@ -38,9 +38,10 @@ This processor was inspired by Cédric Beust's [version-processor](https://githu
|
||||||
```java
|
```java
|
||||||
import net.thauvin.erik.semver.Version;
|
import net.thauvin.erik.semver.Version;
|
||||||
|
|
||||||
@Version(major = 1, minor = 0, patch = 0, preRelease = "beta")
|
@Version(major = 2, minor = 1, patch = 1, preRelease = "beta")
|
||||||
public class A {
|
public class A {
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
* Or using a [properties](hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties) file:
|
* Or using a [properties](hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties) file:
|
||||||
|
@ -50,7 +51,8 @@ import net.thauvin.erik.semver.Version;
|
||||||
|
|
||||||
@Version(properties = "version.properties")
|
@Version(properties = "version.properties")
|
||||||
public class A {
|
public class A {
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
|
@ -74,26 +76,27 @@ To specify your own template name, use:
|
||||||
```java
|
```java
|
||||||
@Version(template = "version.mustache")
|
@Version(template = "version.mustache")
|
||||||
public class A {
|
public class A {
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Default Template
|
### Default Template
|
||||||
|
|
||||||
The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static variables:
|
The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache) implements the following static variables:
|
||||||
|
|
||||||
Field | Description | Example
|
| Field | Description | Example |
|
||||||
:------------------|:---------------------------------|:-----------------
|
|:-------------------|:---------------------------------|:----------------------------------------------------------------------------------|
|
||||||
`PROJECT` | The project name, if any. | `MyProject`
|
| `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)
|
| `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`
|
| `VERSION` | The full version string. | `1.2.3-alpha+001` |
|
||||||
`MAJOR` | The major version. | `1`
|
| `MAJOR` | The major version. | `1` |
|
||||||
`MINOR` | The minor version. | `2`
|
| `MINOR` | The minor version. | `2` |
|
||||||
`PATCH` | The patch version. | `3`
|
| `PATCH` | The patch version. | `3` |
|
||||||
`PRERELEASE` | The pre-release version, if any. | `alpha`
|
| `PRERELEASE` | The pre-release version, if any. | `alpha` |
|
||||||
`PRERELASE_PREFIX` | The pre-release prefix | `-`
|
| `PRERELASE_PREFIX` | The pre-release prefix | `-` |
|
||||||
`BUILDMETA` | The build metadata, if any. | `001`
|
| `BUILDMETA` | The build metadata, if any. | `001` |
|
||||||
`BUILDMETA_PREFIX` | The metadata prefix. | `+`
|
| `BUILDMETA_PREFIX` | The metadata prefix. | `+` |
|
||||||
`SEPARATOR` | The version separator. | `.`
|
| `SEPARATOR` | The version separator. | `.` |
|
||||||
|
|
||||||
### Custom Template
|
### Custom Template
|
||||||
|
|
||||||
|
@ -114,21 +117,21 @@ public final class {{className}} {
|
||||||
|
|
||||||
The mustache variables automatically filled in by the processor are:
|
The mustache variables automatically filled in by the processor are:
|
||||||
|
|
||||||
Variable | Description | Type
|
| Variable | Description | Type |
|
||||||
:-----------------------------|:----------------------------|:--------
|
|:------------------------------|:----------------------------|:---------|
|
||||||
`{{packageName}}` | The package name. | `String`
|
| `{{packageName}}` | The package name. | `String` |
|
||||||
`{{className}}` | The class name. | `String`
|
| `{{className}}` | The class name. | `String` |
|
||||||
`{{project}}` | The project name. | `String`
|
| `{{project}}` | The project name. | `String` |
|
||||||
`{{epoch}}` | The build epoch/unix time. | `long`
|
| `{{epoch}}` | The build epoch/unix time. | `long` |
|
||||||
`{{major}}` | The major version. | `int`
|
| `{{major}}` | The major version. | `int` |
|
||||||
`{{minor}}` | The minor version. | `int`
|
| `{{minor}}` | The minor version. | `int` |
|
||||||
`{{patch}}` | The patch version. | `int`
|
| `{{patch}}` | The patch version. | `int` |
|
||||||
`{{preRelease}}` | The pre-release version. | `String`
|
| `{{preRelease}}` | The pre-release version. | `String` |
|
||||||
`{{preReleasePrefix}}` | The pre-release prefix. | `String`
|
| `{{preReleasePrefix}}` | The pre-release prefix. | `String` |
|
||||||
`{{buildMeta}}` | The build metadata version. | `String`
|
| `{{buildMeta}}` | The build metadata version. | `String` |
|
||||||
`{{buildMetaPrefix}}` | The metadata prefix. | `String`
|
| `{{buildMetaPrefix}}` | The metadata prefix. | `String` |
|
||||||
`{{separator}}` | The version separator. | `String`
|
| `{{separator}}` | The version separator. | `String` |
|
||||||
`{{semver}}` or `{{version}}` | The full semantic version. | `String`
|
| `{{semver}}` or `{{version}}` | The full semantic version. | `String` |
|
||||||
|
|
||||||
Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)
|
Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)
|
||||||
|
|
||||||
|
@ -136,30 +139,30 @@ Please also look at this [example](https://github.com/ethauvin/mobibot/blob/mast
|
||||||
|
|
||||||
The following annotation elements and properties are available:
|
The following annotation elements and properties are available:
|
||||||
|
|
||||||
Element | Property | Description | Default
|
| Element | Property | Description | Default |
|
||||||
:------------------|:----------------------------|:----------------------------------|:-------------------------
|
|:-------------------|:----------------------------|:----------------------------------|:--------------------------|
|
||||||
`project` | `version.project` | The project name. |
|
| `project` | `version.project` | The project name. | |
|
||||||
`major` | `version.major` | The major version number. | `1`
|
| `major` | `version.major` | The major version number. | `1` |
|
||||||
`minor` | `version.major` | The minor version number. | `0`
|
| `minor` | `version.major` | The minor version number. | `0` |
|
||||||
`patch` | `version.patch` | The patch version number. | `0`
|
| `patch` | `version.patch` | The patch version number. | `0` |
|
||||||
`preRelease` | `version.prerelease` | The pre-release version. |
|
| `preRelease` | `version.prerelease` | The pre-release version. | |
|
||||||
`preReleasePrefix` | `version.prerelease.prefix` | The pre-release prefix. | `-`
|
| `preReleasePrefix` | `version.prerelease.prefix` | The pre-release prefix. | `-` |
|
||||||
`buildMeta` | `version.buildmeta` | The build metadata version. |
|
| `buildMeta` | `version.buildmeta` | The build metadata version. | |
|
||||||
`buildMetaPrefix` | `version.buildmeta.prefix` | The metadata prefix. | `+`
|
| `buildMetaPrefix` | `version.buildmeta.prefix` | The metadata prefix. | `+` |
|
||||||
`separator` | `version.separator` | The version separator. | `.`
|
| `separator` | `version.separator` | The version separator. | `.` |
|
||||||
`packageName` | | The package name. | _Same as annotated class_
|
| `packageName` | | The package name. | _Same as annotated class_ |
|
||||||
`className` | | The name of the generated class. | `GeneratedVersion`
|
| `className` | | The name of the generated class. | `GeneratedVersion` |
|
||||||
`properties` | | The properties file. |
|
| `properties` | | The properties file. | |
|
||||||
`template` | | The template file. | `version.mustache`
|
| `template` | | The template file. | `version.mustache` |
|
||||||
`type` | | Either `java` or `kt` for Kotlin. | `java`
|
| `type` | | Either `java` or `kt` for Kotlin. | `java` |
|
||||||
`keysPrefix` | | The prefix for all property keys. | `version.`
|
| `keysPrefix` | | The prefix for all property keys. | `version.` |
|
||||||
|
|
||||||
In order to easily incorporate with existing projects, the property keys may be assigned custom values:
|
In order to easily incorporate with existing projects, the property keys may be assigned custom values:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
@Version(
|
@Version(
|
||||||
properties = "example.properties",
|
properties = "example.properties",
|
||||||
keysPrefix = "example."
|
keysPrefix = "example.",
|
||||||
majorKey = "maj",
|
majorKey = "maj",
|
||||||
minorKey = "min",
|
minorKey = "min",
|
||||||
patchKey = "build",
|
patchKey = "build",
|
||||||
|
@ -168,7 +171,8 @@ In order to easily incorporate with existing projects, the property keys may be
|
||||||
projectKey = "project"
|
projectKey = "project"
|
||||||
)
|
)
|
||||||
public class Example {
|
public class Example {
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
|
@ -208,8 +212,13 @@ mvn verify
|
||||||
To install and run from [bld](https://rife2.com/bld), just add the dependency to your build file:
|
To install and run from [bld](https://rife2.com/bld), just add the dependency to your build file:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
scope(compile)
|
public class ExampleBuild extends Project {
|
||||||
.include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT")));
|
public ExampleBuild() {
|
||||||
|
// ...
|
||||||
|
scope(compile)
|
||||||
|
.include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT")));
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
Please look at [ExamapleBuild](https://github.com/ethauvin/semver/blob/master/examples/java/bld/src/bld/java/com/example/ExampleBuild.java) in the [examples/java/bld](https://github.com/ethauvin/semver/tree/master/examples/java/bld) directory for a sample.
|
Please look at [ExamapleBuild](https://github.com/ethauvin/semver/blob/master/examples/java/bld/src/bld/java/com/example/ExampleBuild.java) in the [examples/java/bld](https://github.com/ethauvin/semver/tree/master/examples/java/bld) directory for a sample.
|
||||||
|
|
||||||
|
@ -264,7 +273,8 @@ import net.thauvin.erik.semver.Version
|
||||||
|
|
||||||
@Version(properties = "version.properties", type="kt")
|
@Version(properties = "version.properties", type="kt")
|
||||||
open class Main {
|
open class Main {
|
||||||
// ...
|
// ...
|
||||||
|
}
|
||||||
```
|
```
|
||||||
The [Kotlin default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache) implements the same static fields and functions as the [Java template](#default-template).
|
The [Kotlin default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache) implements the same static fields and functions as the [Java template](#default-template).
|
||||||
|
|
||||||
|
|
114
docs/README.html
114
docs/README.html
|
@ -145,6 +145,7 @@ Version Plugin for Gradle</strong></a>.</p>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li><a href="#elements--properties">Elements & Properties</a></li>
|
<li><a href="#elements--properties">Elements & Properties</a></li>
|
||||||
<li><a href="#maven">Maven</a></li>
|
<li><a href="#maven">Maven</a></li>
|
||||||
|
<li><a href="#bld">bld</a></li>
|
||||||
<li><a href="#gradle">Gradle</a>
|
<li><a href="#gradle">Gradle</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#class-generation">Class Generation</a></li>
|
<li><a href="#class-generation">Class Generation</a></li>
|
||||||
|
@ -164,9 +165,10 @@ Generation</a></li>
|
||||||
<div class="sourceCode" id="cb1"><pre
|
<div class="sourceCode" id="cb1"><pre
|
||||||
class="sourceCode java"><code class="sourceCode java"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">net</span><span class="op">.</span><span class="im">thauvin</span><span class="op">.</span><span class="im">erik</span><span class="op">.</span><span class="im">semver</span><span class="op">.</span><span class="im">Version</span><span class="op">;</span></span>
|
class="sourceCode java"><code class="sourceCode java"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">net</span><span class="op">.</span><span class="im">thauvin</span><span class="op">.</span><span class="im">erik</span><span class="op">.</span><span class="im">semver</span><span class="op">.</span><span class="im">Version</span><span class="op">;</span></span>
|
||||||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>major <span class="op">=</span> <span class="dv">1</span><span class="op">,</span> minor <span class="op">=</span> <span class="dv">0</span><span class="op">,</span> patch <span class="op">=</span> <span class="dv">0</span><span class="op">,</span> preRelease <span class="op">=</span> <span class="st">"beta"</span><span class="op">)</span></span>
|
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>major <span class="op">=</span> <span class="dv">2</span><span class="op">,</span> minor <span class="op">=</span> <span class="dv">1</span><span class="op">,</span> patch <span class="op">=</span> <span class="dv">1</span><span class="op">,</span> preRelease <span class="op">=</span> <span class="st">"beta"</span><span class="op">)</span></span>
|
||||||
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
||||||
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span></code></pre></div>
|
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Or using a <a
|
<li>Or using a <a
|
||||||
href="hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties">properties</a>
|
href="hhttps://github.com/ethauvin/semver/blob/master/examples/java/version.properties">properties</a>
|
||||||
|
@ -177,7 +179,8 @@ class="sourceCode java"><code class="sourceCode java"><span id="cb2-1"><a href="
|
||||||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>properties <span class="op">=</span> <span class="st">"version.properties"</span><span class="op">)</span></span>
|
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>properties <span class="op">=</span> <span class="st">"version.properties"</span><span class="op">)</span></span>
|
||||||
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
||||||
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span></code></pre></div>
|
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<div class="sourceCode" id="cb3"><pre
|
<div class="sourceCode" id="cb3"><pre
|
||||||
class="sourceCode ini"><code class="sourceCode ini"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># version.properties</span></span>
|
class="sourceCode ini"><code class="sourceCode ini"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># version.properties</span></span>
|
||||||
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="dt">version.major</span><span class="ot">=</span><span class="dv">1</span></span>
|
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="dt">version.major</span><span class="ot">=</span><span class="dv">1</span></span>
|
||||||
|
@ -200,7 +203,8 @@ processor will automatically look for it.</p>
|
||||||
<div class="sourceCode" id="cb4"><pre
|
<div class="sourceCode" id="cb4"><pre
|
||||||
class="sourceCode java"><code class="sourceCode java"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>template <span class="op">=</span> <span class="st">"version.mustache"</span><span class="op">)</span></span>
|
class="sourceCode java"><code class="sourceCode java"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>template <span class="op">=</span> <span class="st">"version.mustache"</span><span class="op">)</span></span>
|
||||||
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> A <span class="op">{</span></span>
|
||||||
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span></code></pre></div>
|
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<h3 id="default-template">Default Template</h3>
|
<h3 id="default-template">Default Template</h3>
|
||||||
<p>The <a
|
<p>The <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache">default
|
href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache">default
|
||||||
|
@ -479,7 +483,7 @@ keys may be assigned custom values:</p>
|
||||||
<div class="sourceCode" id="cb6"><pre
|
<div class="sourceCode" id="cb6"><pre
|
||||||
class="sourceCode java"><code class="sourceCode java"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span></span>
|
class="sourceCode java"><code class="sourceCode java"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span></span>
|
||||||
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> properties <span class="op">=</span> <span class="st">"example.properties"</span><span class="op">,</span></span>
|
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> properties <span class="op">=</span> <span class="st">"example.properties"</span><span class="op">,</span></span>
|
||||||
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> keysPrefix <span class="op">=</span> <span class="st">"example."</span></span>
|
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> keysPrefix <span class="op">=</span> <span class="st">"example."</span><span class="op">,</span></span>
|
||||||
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> majorKey <span class="op">=</span> <span class="st">"maj"</span><span class="op">,</span></span>
|
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> majorKey <span class="op">=</span> <span class="st">"maj"</span><span class="op">,</span></span>
|
||||||
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> minorKey <span class="op">=</span> <span class="st">"min"</span><span class="op">,</span></span>
|
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> minorKey <span class="op">=</span> <span class="st">"min"</span><span class="op">,</span></span>
|
||||||
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> patchKey <span class="op">=</span> <span class="st">"build"</span><span class="op">,</span></span>
|
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> patchKey <span class="op">=</span> <span class="st">"build"</span><span class="op">,</span></span>
|
||||||
|
@ -488,7 +492,8 @@ class="sourceCode java"><code class="sourceCode java"><span id="cb6-1"><a href="
|
||||||
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> projectKey <span class="op">=</span> <span class="st">"project"</span></span>
|
<span id="cb6-9"><a href="#cb6-9" aria-hidden="true" tabindex="-1"></a> projectKey <span class="op">=</span> <span class="st">"project"</span></span>
|
||||||
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a><span class="op">)</span></span>
|
<span id="cb6-10"><a href="#cb6-10" aria-hidden="true" tabindex="-1"></a><span class="op">)</span></span>
|
||||||
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> Example <span class="op">{</span></span>
|
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> Example <span class="op">{</span></span>
|
||||||
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span></code></pre></div>
|
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb6-13"><a href="#cb6-13" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<div class="sourceCode" id="cb7"><pre
|
<div class="sourceCode" id="cb7"><pre
|
||||||
class="sourceCode ini"><code class="sourceCode ini"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># example.properties</span></span>
|
class="sourceCode ini"><code class="sourceCode ini"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># example.properties</span></span>
|
||||||
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="dt">example.project</span><span class="ot">=</span><span class="st">Example</span></span>
|
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a><span class="dt">example.project</span><span class="ot">=</span><span class="st">Example</span></span>
|
||||||
|
@ -514,7 +519,7 @@ follows:</p>
|
||||||
class="sourceCode xml"><code class="sourceCode xml"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">dependency</span>></span>
|
class="sourceCode xml"><code class="sourceCode xml"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><<span class="kw">dependency</span>></span>
|
||||||
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">groupId</span>>net.thauvin.erik</<span class="kw">groupId</span>></span>
|
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <<span class="kw">groupId</span>>net.thauvin.erik</<span class="kw">groupId</span>></span>
|
||||||
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">artifactId</span>>semver</<span class="kw">artifactId</span>></span>
|
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <<span class="kw">artifactId</span>>semver</<span class="kw">artifactId</span>></span>
|
||||||
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">version</span>>1.2.0</<span class="kw">version</span>></span>
|
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <<span class="kw">version</span>>1.2.1-SNAPSHOT</<span class="kw">version</span>></span>
|
||||||
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a></<span class="kw">dependency</span>></span></code></pre></div>
|
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a></<span class="kw">dependency</span>></span></code></pre></div>
|
||||||
<p>Please look at <a
|
<p>Please look at <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/java/pom.xml">pom.xml</a>
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/pom.xml">pom.xml</a>
|
||||||
|
@ -523,24 +528,40 @@ href="https://github.com/ethauvin/semver/tree/master/examples/java">examples/jav
|
||||||
directory for a sample:</p>
|
directory for a sample:</p>
|
||||||
<div class="sourceCode" id="cb9"><pre
|
<div class="sourceCode" id="cb9"><pre
|
||||||
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">mvn</span> verify</span></code></pre></div>
|
class="sourceCode bash"><code class="sourceCode bash"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="ex">mvn</span> verify</span></code></pre></div>
|
||||||
|
<h2 id="bld">bld</h2>
|
||||||
|
<p>To install and run from <a href="https://rife2.com/bld">bld</a>, just
|
||||||
|
add the dependency to your build file:</p>
|
||||||
|
<div class="sourceCode" id="cb10"><pre
|
||||||
|
class="sourceCode java"><code class="sourceCode java"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="kw">public</span> <span class="kw">class</span> ExampleBuild <span class="kw">extends</span> Project <span class="op">{</span></span>
|
||||||
|
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">public</span> <span class="fu">ExampleBuild</span><span class="op">()</span> <span class="op">{</span></span>
|
||||||
|
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">scope</span><span class="op">(</span>compile<span class="op">)</span></span>
|
||||||
|
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">include</span><span class="op">(</span><span class="fu">dependency</span><span class="op">(</span><span class="st">"net.thauvin.erik"</span><span class="op">,</span> <span class="st">"semver"</span><span class="op">,</span> <span class="fu">version</span><span class="op">(</span><span class="dv">1</span><span class="op">,</span> <span class="dv">2</span><span class="op">,</span> <span class="dv">1</span><span class="op">,</span> <span class="st">"SNAPSHOT"</span><span class="op">)));</span></span>
|
||||||
|
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||||
|
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
|
<p>Please look at <a
|
||||||
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/bld/src/bld/java/com/example/ExampleBuild.java">ExamapleBuild</a>
|
||||||
|
in the <a
|
||||||
|
href="https://github.com/ethauvin/semver/tree/master/examples/java/bld">examples/java/bld</a>
|
||||||
|
directory for a sample.</p>
|
||||||
<h2 id="gradle">Gradle</h2>
|
<h2 id="gradle">Gradle</h2>
|
||||||
<h3 id="class-generation">Class Generation</h3>
|
<h3 id="class-generation">Class Generation</h3>
|
||||||
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add
|
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add
|
||||||
the following to <a
|
the following to <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a>:</p>
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/gradle/build.gradle">build.gradle</a>:</p>
|
||||||
<div class="sourceCode" id="cb10"><pre
|
<div class="sourceCode" id="cb11"><pre
|
||||||
class="sourceCode gradle"><code class="sourceCode groovy"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>repositories <span class="op">{</span></span>
|
class="sourceCode gradle"><code class="sourceCode groovy"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>repositories <span class="op">{</span></span>
|
||||||
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mavenCentral</span><span class="op">()</span></span>
|
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">mavenCentral</span><span class="op">()</span></span>
|
||||||
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
||||||
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a>dependencies <span class="op">{</span></span>
|
<span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a>dependencies <span class="op">{</span></span>
|
||||||
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> annotationProcessor <span class="st">'net.thauvin.erik:semver:1.2.0'</span></span>
|
<span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> annotationProcessor <span class="st">'net.thauvin.erik:semver:1.2.1-SNAPSHOT'</span></span>
|
||||||
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> compileOnly <span class="st">'net.thauvin.erik:semver:1.2.0'</span></span>
|
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> compileOnly <span class="st">'net.thauvin.erik:semver:1.2.1-SNAPSHOT'</span></span>
|
||||||
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
||||||
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a>tasks<span class="op">.</span><span class="fu">withType</span><span class="op">(</span>JavaCompile<span class="op">)</span> <span class="op">{</span></span>
|
<span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a>tasks<span class="op">.</span><span class="fu">withType</span><span class="op">(</span>JavaCompile<span class="op">)</span> <span class="op">{</span></span>
|
||||||
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> options<span class="op">.</span>compilerArgs <span class="op">+=</span> <span class="op">[</span> <span class="st">"-Asemver.project.dir=</span><span class="ss">$projectDir</span><span class="st">"</span> <span class="op">]</span></span>
|
<span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> options<span class="op">.</span>compilerArgs <span class="op">+=</span> <span class="op">[</span> <span class="st">"-Asemver.project.dir=</span><span class="ss">$projectDir</span><span class="st">"</span> <span class="op">]</span></span>
|
||||||
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
<span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<p>The directory containing the configuration files
|
<p>The directory containing the configuration files
|
||||||
(<code>version.properties</code>, <code>version.mustache</code>) must be
|
(<code>version.properties</code>, <code>version.mustache</code>) must be
|
||||||
specified using the <code>semver.project.dir</code> processor
|
specified using the <code>semver.project.dir</code> processor
|
||||||
|
@ -550,18 +571,18 @@ href="https://github.com/ethauvin/semver/blob/master/examples/java/src/generated
|
||||||
class will be automatically created in the <code>build/generated</code>
|
class will be automatically created in the <code>build/generated</code>
|
||||||
directory upon compiling.</p>
|
directory upon compiling.</p>
|
||||||
<p>Please look at <a
|
<p>Please look at <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a>
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/gradle/build.gradle">build.gradle</a>
|
||||||
in the <a
|
in the <a
|
||||||
href="https://github.com/ethauvin/semver/tree/master/examples/java">examples/java</a>
|
href="https://github.com/ethauvin/semver/tree/master/examples/java/gradle">examples/java/gradle</a>
|
||||||
directory for a sample.</p>
|
directory for a sample.</p>
|
||||||
<h3 id="class--source-generation">Class & Source Generation</h3>
|
<h3 id="class--source-generation">Class & Source Generation</h3>
|
||||||
<p>In order to also incorporate the generated source code into the
|
<p>In order to also incorporate the generated source code into the
|
||||||
<code>source tree</code>, add the following to <a
|
<code>source tree</code>, add the following to <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a>:</p>
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/build.gradle">build.gradle</a>:</p>
|
||||||
<div class="sourceCode" id="cb11"><pre
|
<div class="sourceCode" id="cb12"><pre
|
||||||
class="sourceCode gradle"><code class="sourceCode groovy"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>tasks<span class="op">.</span><span class="fu">withType</span><span class="op">(</span>JavaCompile<span class="op">)</span> <span class="op">{</span></span>
|
class="sourceCode gradle"><code class="sourceCode groovy"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>tasks<span class="op">.</span><span class="fu">withType</span><span class="op">(</span>JavaCompile<span class="op">)</span> <span class="op">{</span></span>
|
||||||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> options<span class="op">.</span>generatedSourceOutputDirectory<span class="op">.</span><span class="fu">set</span><span class="op">(</span><span class="fu">file</span><span class="op">(</span><span class="st">"</span><span class="ss">${</span>projectDir<span class="ss">}</span><span class="st">/src/generated/java"</span><span class="op">))</span></span>
|
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> options<span class="op">.</span>generatedSourceOutputDirectory<span class="op">.</span><span class="fu">set</span><span class="op">(</span><span class="fu">file</span><span class="op">(</span><span class="st">"</span><span class="ss">${</span>projectDir<span class="ss">}</span><span class="st">/src/generated/java"</span><span class="op">))</span></span>
|
||||||
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<p>The <a
|
<p>The <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/java/src/generated/java/com/example/GeneratedVersion.java"><code>GeneratedVersion.java</code></a>
|
href="https://github.com/ethauvin/semver/blob/master/examples/java/src/generated/java/com/example/GeneratedVersion.java"><code>GeneratedVersion.java</code></a>
|
||||||
file will now be located in <code>src/generated</code>.</p>
|
file will now be located in <code>src/generated</code>.</p>
|
||||||
|
@ -570,12 +591,13 @@ file will now be located in <code>src/generated</code>.</p>
|
||||||
href="https://kotlinlang.org/">Kotlin</a>.</p>
|
href="https://kotlinlang.org/">Kotlin</a>.</p>
|
||||||
<p>To generate a Kotlin version file, simply specify the
|
<p>To generate a Kotlin version file, simply specify the
|
||||||
<code>type</code> as follows:</p>
|
<code>type</code> as follows:</p>
|
||||||
<div class="sourceCode" id="cb12"><pre
|
<div class="sourceCode" id="cb13"><pre
|
||||||
class="sourceCode kotlin"><code class="sourceCode kotlin"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">net</span><span class="op">.</span><span class="im">thauvin</span><span class="op">.</span><span class="im">erik</span><span class="op">.</span><span class="im">semver</span><span class="op">.</span><span class="im">Version</span></span>
|
class="sourceCode kotlin"><code class="sourceCode kotlin"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="kw">import</span> <span class="im">net</span><span class="op">.</span><span class="im">thauvin</span><span class="op">.</span><span class="im">erik</span><span class="op">.</span><span class="im">semver</span><span class="op">.</span><span class="im">Version</span></span>
|
||||||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>properties <span class="op">=</span> <span class="st">"version.properties"</span><span class="op">,</span> type<span class="op">=</span><span class="st">"kt"</span><span class="op">)</span></span>
|
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="at">@Version</span><span class="op">(</span>properties <span class="op">=</span> <span class="st">"version.properties"</span><span class="op">,</span> type<span class="op">=</span><span class="st">"kt"</span><span class="op">)</span></span>
|
||||||
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a><span class="kw">open</span> <span class="kw">class</span> Main <span class="op">{</span></span>
|
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="kw">open</span> <span class="kw">class</span> Main <span class="op">{</span></span>
|
||||||
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="co">// ...</span></span></code></pre></div>
|
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="co">// ...</span></span>
|
||||||
|
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<p>The <a
|
<p>The <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache">Kotlin
|
href="https://github.com/ethauvin/semver/blob/master/src/main/resources/semver-kt.mustache">Kotlin
|
||||||
default template</a> implements the same static fields and functions as
|
default template</a> implements the same static fields and functions as
|
||||||
|
@ -589,19 +611,19 @@ sample.</p>
|
||||||
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add
|
<p>To install and run from <a href="https://gradle.org/">Gradle</a>, add
|
||||||
the following to <a
|
the following to <a
|
||||||
href="https://github.com/ethauvin/semver/blob/master/examples/kotlin/build.gradle.kts">build.gradle.kts</a>:</p>
|
href="https://github.com/ethauvin/semver/blob/master/examples/kotlin/build.gradle.kts">build.gradle.kts</a>:</p>
|
||||||
<div class="sourceCode" id="cb13"><pre
|
<div class="sourceCode" id="cb14"><pre
|
||||||
class="sourceCode kotlin"><code class="sourceCode kotlin"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> <span class="va">semverProcessor</span> <span class="op">=</span> <span class="st">"net.thauvin.erik:semver:1.2.0"</span></span>
|
class="sourceCode kotlin"><code class="sourceCode kotlin"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> <span class="va">semverProcessor</span> <span class="op">=</span> <span class="st">"net.thauvin.erik:semver:1.2.1-SNAPSHOT"</span></span>
|
||||||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>dependencies <span class="op">{</span></span>
|
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a>dependencies <span class="op">{</span></span>
|
||||||
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> kapt<span class="op">(</span>semverProcessor<span class="op">)</span></span>
|
<span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a> kapt<span class="op">(</span>semverProcessor<span class="op">)</span></span>
|
||||||
<span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> compileOnly<span class="op">(</span>semverProcessor<span class="op">)</span></span>
|
<span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a> compileOnly<span class="op">(</span>semverProcessor<span class="op">)</span></span>
|
||||||
<span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
<span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span>
|
||||||
<span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a></span>
|
<span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a></span>
|
||||||
<span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a>kapt <span class="op">{</span></span>
|
<span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a>kapt <span class="op">{</span></span>
|
||||||
<span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a> arguments <span class="op">{</span></span>
|
<span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a> arguments <span class="op">{</span></span>
|
||||||
<span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a> arg<span class="op">(</span><span class="st">"semver.project.dir"</span><span class="op">,</span> projectDir<span class="op">)</span></span>
|
<span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a> arg<span class="op">(</span><span class="st">"semver.project.dir"</span><span class="op">,</span> projectDir<span class="op">)</span></span>
|
||||||
<span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
<span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span>
|
||||||
<span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
<span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div>
|
||||||
<p>The directory containing the configuration files
|
<p>The directory containing the configuration files
|
||||||
(<code>version.properties</code>, <code>version.mustache</code>) must be
|
(<code>version.properties</code>, <code>version.mustache</code>) must be
|
||||||
specified using the <code>semver.project.dir</code> processor
|
specified using the <code>semver.project.dir</code> processor
|
||||||
|
|
1
examples/java/bld/.idea/app.iml
generated
1
examples/java/bld/.idea/app.iml
generated
|
@ -9,6 +9,7 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/build/generated" isTestSource="false" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/src/main/resources/templates" />
|
<excludeFolder url="file://$MODULE_DIR$/src/main/resources/templates" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
|
4
examples/java/bld/.idea/libraries/bld.xml
generated
4
examples/java/bld/.idea/libraries/bld.xml
generated
|
@ -2,11 +2,11 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.1.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.2.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.1-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.2-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
4
examples/java/bld/.idea/misc.xml
generated
4
examples/java/bld/.idea/misc.xml
generated
|
@ -1,5 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<pattern value="com.example.ExampleBuild" method="runExample" />
|
||||||
|
</component>
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
</component>
|
</component>
|
||||||
|
|
2
examples/java/bld/.vscode/settings.json
vendored
2
examples/java/bld/.vscode/settings.json
vendored
|
@ -7,7 +7,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.bld/dist/bld-1.7.1.jar",
|
"${HOME}bld-1.7.2.jar",
|
||||||
"lib/compile/*.jar",
|
"lib/compile/*.jar",
|
||||||
"lib/runtime/*.jar",
|
"lib/runtime/*.jar",
|
||||||
"lib/test/*.jar"
|
"lib/test/*.jar"
|
||||||
|
|
Binary file not shown.
|
@ -4,4 +4,4 @@ bld.extensions=
|
||||||
bld.repositories=MAVEN_CENTRAL,RIFE2_RELEASES
|
bld.repositories=MAVEN_CENTRAL,RIFE2_RELEASES
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
bld.version=1.7.1
|
bld.version=1.7.2
|
||||||
|
|
|
@ -3,11 +3,20 @@ package com.example;
|
||||||
import rife.bld.BuildCommand;
|
import rife.bld.BuildCommand;
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static rife.bld.dependencies.Repository.*;
|
import static rife.bld.dependencies.Repository.*;
|
||||||
import static rife.bld.dependencies.Scope.compile;
|
import static rife.bld.dependencies.Scope.compile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example build.
|
||||||
|
*
|
||||||
|
* <ul style="list-style-type:none">
|
||||||
|
* <li>./bld run</li>
|
||||||
|
* <li>./bld runExample</li>
|
||||||
|
* </ul>
|
||||||
|
*/
|
||||||
public class ExampleBuild extends Project {
|
public class ExampleBuild extends Project {
|
||||||
public ExampleBuild() {
|
public ExampleBuild() {
|
||||||
pkg = "com.example";
|
pkg = "com.example";
|
||||||
|
@ -20,16 +29,29 @@ public class ExampleBuild extends Project {
|
||||||
|
|
||||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
||||||
|
|
||||||
scope(compile)
|
scope(compile).include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT")));
|
||||||
.include(dependency("net.thauvin.erik", "semver", version(1, 2, 1, "SNAPSHOT")));
|
|
||||||
}
|
|
||||||
|
|
||||||
@BuildCommand(summary = "Run the example")
|
|
||||||
public void runExample() throws Exception {
|
|
||||||
runOperation().executeOnce(() -> runOperation().fromProject(this).mainClass("com.example.Example"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new ExampleBuild().start(args);
|
new ExampleBuild().start(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves generated source files in the {@code build/generated} directory.
|
||||||
|
* <p>
|
||||||
|
* 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();
|
||||||
|
this.compileOperation().compileOptions().addAll(List.of("-s", generated.getAbsolutePath()));
|
||||||
|
super.compile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@BuildCommand(summary = "Run the example")
|
||||||
|
public void runExample() throws Exception {
|
||||||
|
runOperation().fromProject(this).mainClass("com.example.Example").execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public final class App {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
public static void main(final String... args) {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
|
final var sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
|
||||||
|
|
||||||
System.out.println("-----------------------------------------------------");
|
System.out.println("-----------------------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Locale;
|
||||||
keysPrefix = "example.")
|
keysPrefix = "example.")
|
||||||
public class Example {
|
public class Example {
|
||||||
public static void main(final String... args) {
|
public static void main(final String... args) {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
final var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
|
||||||
System.out.println("-- From Example -------------------------------------");
|
System.out.println("-- From Example -------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Date;
|
||||||
|
|
||||||
public final class ExampleVersion {
|
public final class ExampleVersion {
|
||||||
public static final String PROJECT = "Java Example";
|
public static final String PROJECT = "Java Example";
|
||||||
public static final Date BUILDDATE = new Date(1692423608415L);
|
public static final Date BUILDDATE = new Date(1692564205424L);
|
||||||
public static final String VERSION = "8.4.97-alpha+T800";
|
public static final String VERSION = "8.4.97-alpha+T800";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.util.Date;
|
||||||
*/
|
*/
|
||||||
public final class GeneratedVersion {
|
public final class GeneratedVersion {
|
||||||
public static final String PROJECT = "Java App";
|
public static final String PROJECT = "Java App";
|
||||||
public static final Date BUILDDATE = new Date(1692423608452L);
|
public static final Date BUILDDATE = new Date(1692564205452L);
|
||||||
public static final int MAJOR = 11;
|
public static final int MAJOR = 11;
|
||||||
public static final int MINOR = 11;
|
public static final int MINOR = 11;
|
||||||
public static final int PATCH = 20;
|
public static final int PATCH = 20;
|
||||||
|
|
|
@ -13,7 +13,7 @@ public final class App {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
public static void main(final String... args) {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
|
final var sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
|
||||||
|
|
||||||
System.out.println("-----------------------------------------------------");
|
System.out.println("-----------------------------------------------------");
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public final class Example {
|
||||||
* @param args The command line parameters.
|
* @param args The command line parameters.
|
||||||
*/
|
*/
|
||||||
public static void main(final String... args) {
|
public static void main(final String... args) {
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
final var sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||||
|
|
||||||
System.out.println("-- From Example -------------------------------------");
|
System.out.println("-- From Example -------------------------------------");
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -6,4 +6,4 @@ bld.extensions-testng=com.uwyn.rife2:bld-testng:0.9.1-SNAPSHOT
|
||||||
bld.repositories=MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
bld.repositories=MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
bld.version=1.7.1
|
bld.version=1.7.2
|
||||||
|
|
|
@ -34,7 +34,6 @@ package net.thauvin.erik.semver;
|
||||||
|
|
||||||
import com.github.mustachejava.DefaultMustacheFactory;
|
import com.github.mustachejava.DefaultMustacheFactory;
|
||||||
import com.github.mustachejava.Mustache;
|
import com.github.mustachejava.Mustache;
|
||||||
import com.github.mustachejava.MustacheFactory;
|
|
||||||
import com.github.mustachejava.MustacheNotFoundException;
|
import com.github.mustachejava.MustacheNotFoundException;
|
||||||
|
|
||||||
import javax.annotation.processing.*;
|
import javax.annotation.processing.*;
|
||||||
|
@ -79,6 +78,11 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Mustache compileTemplate(final File dir, final String template) {
|
||||||
|
final var mf = new DefaultMustacheFactory(dir);
|
||||||
|
return mf.compile(template);
|
||||||
|
}
|
||||||
|
|
||||||
private void error(final String s) {
|
private void error(final String s) {
|
||||||
log(Diagnostic.Kind.ERROR, s);
|
log(Diagnostic.Kind.ERROR, s);
|
||||||
}
|
}
|
||||||
|
@ -89,16 +93,16 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private VersionInfo findValues(final Version version) throws IOException {
|
private VersionInfo findValues(final Version version) throws IOException {
|
||||||
final VersionInfo versionInfo = new VersionInfo(version);
|
final var versionInfo = new VersionInfo(version);
|
||||||
|
|
||||||
if (!version.properties().isEmpty()) {
|
if (!version.properties().isEmpty()) {
|
||||||
final File propsFile = getLocalFile(version.properties());
|
final var propsFile = getLocalFile(version.properties());
|
||||||
if (propsFile.isFile() && propsFile.canRead()) {
|
if (propsFile.isFile() && propsFile.canRead()) {
|
||||||
note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
|
note("Found properties: " + propsFile.getName() + " (" + propsFile.getAbsoluteFile().getParent() + ')');
|
||||||
|
|
||||||
final Properties p = new Properties();
|
final var p = new Properties();
|
||||||
|
|
||||||
try (InputStreamReader reader = new InputStreamReader(
|
try (var reader = new InputStreamReader(
|
||||||
Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
|
Files.newInputStream(propsFile.toPath()), StandardCharsets.UTF_8)) {
|
||||||
p.load(reader);
|
p.load(reader);
|
||||||
|
|
||||||
|
@ -139,7 +143,7 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private File getLocalFile(final String fileName) {
|
private File getLocalFile(final String fileName) {
|
||||||
if (processingEnv != null) { // null when testing.
|
if (processingEnv != null) { // null when testing.
|
||||||
final String prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG);
|
final var prop = processingEnv.getOptions().get(Constants.SEMVER_PROJECT_DIR_ARG);
|
||||||
if (prop != null) {
|
if (prop != null) {
|
||||||
return new File(prop, fileName);
|
return new File(prop, fileName);
|
||||||
}
|
}
|
||||||
|
@ -181,20 +185,20 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
|
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
|
||||||
final boolean isLocalTemplate = getLocalFile(Constants.DEFAULT_TEMPLATE_NAME).exists();
|
final var isLocalTemplate = getLocalFile(Constants.DEFAULT_TEMPLATE_NAME).exists();
|
||||||
for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class)) {
|
for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class)) {
|
||||||
final Version version = element.getAnnotation(Version.class);
|
final var version = element.getAnnotation(Version.class);
|
||||||
if (element.getKind() == ElementKind.CLASS) {
|
if (element.getKind() == ElementKind.CLASS) {
|
||||||
final Element enclosingElement = element.getEnclosingElement();
|
final var enclosingElement = element.getEnclosingElement();
|
||||||
if (enclosingElement.getKind() == ElementKind.PACKAGE) {
|
if (enclosingElement.getKind() == ElementKind.PACKAGE) {
|
||||||
final PackageElement packageElement = (PackageElement) enclosingElement;
|
final var packageElement = (PackageElement) enclosingElement;
|
||||||
try {
|
try {
|
||||||
final VersionInfo versionInfo = findValues(version);
|
final var versionInfo = findValues(version);
|
||||||
if (Constants.EMPTY.equals(version.packageName())) {
|
if (Constants.EMPTY.equals(version.packageName())) {
|
||||||
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
|
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
|
||||||
}
|
}
|
||||||
note("Found version: " + versionInfo.getVersion());
|
note("Found version: " + versionInfo.getVersion());
|
||||||
final String template = getTemplate(isLocalTemplate, version);
|
final var template = getTemplate(isLocalTemplate, version);
|
||||||
|
|
||||||
writeTemplate(version.type(), versionInfo, template);
|
writeTemplate(version.type(), versionInfo, template);
|
||||||
} catch (IOException | MustacheNotFoundException e) {
|
} catch (IOException | MustacheNotFoundException e) {
|
||||||
|
@ -232,28 +236,27 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private void writeTemplate(final String type, final VersionInfo versionInfo, final String template)
|
private void writeTemplate(final String type, final VersionInfo versionInfo, final String template)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final File dir = getLocalFile("");
|
final var dir = getLocalFile("");
|
||||||
final MustacheFactory mf = new DefaultMustacheFactory(dir);
|
final var mustache = compileTemplate(dir, template);
|
||||||
final Mustache mustache = mf.compile(template);
|
|
||||||
|
|
||||||
final String templateName = switch (mustache.getName()) {
|
final var templateName = switch (mustache.getName()) {
|
||||||
case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)";
|
case Constants.DEFAULT_JAVA_TEMPLATE -> "default (Java)";
|
||||||
case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
|
case Constants.DEFAULT_KOTLIN_TEMPLATE -> "default (Kotlin)";
|
||||||
default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
|
default -> mustache.getName() + " (" + dir.getAbsolutePath() + ')';
|
||||||
};
|
};
|
||||||
note("Loaded template: " + templateName);
|
note("Loaded template: " + templateName);
|
||||||
|
|
||||||
final String fileName = versionInfo.getClassName() + '.' + type;
|
final var fileName = versionInfo.getClassName() + '.' + type;
|
||||||
if (Constants.KOTLIN_TYPE.equalsIgnoreCase(type)) {
|
if (Constants.KOTLIN_TYPE.equalsIgnoreCase(type)) {
|
||||||
final String kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
|
final var kaptGenDir = processingEnv.getOptions().get(Constants.KAPT_KOTLIN_GENERATED_OPTION_NAME);
|
||||||
if (kaptGenDir == null) {
|
if (kaptGenDir == null) {
|
||||||
throw new IOException("Could not find the target directory for generated Kotlin files.");
|
throw new IOException("Could not find the target directory for generated Kotlin files.");
|
||||||
}
|
}
|
||||||
final File ktFile = new File(kaptGenDir, fileName);
|
final var ktFile = new File(kaptGenDir, fileName);
|
||||||
if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) {
|
if (!ktFile.getParentFile().exists() && !ktFile.getParentFile().mkdirs()) {
|
||||||
note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath());
|
note("Could not create target directory: " + ktFile.getParentFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
try (OutputStreamWriter osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
|
try (var osw = new OutputStreamWriter(Files.newOutputStream(ktFile.toPath()),
|
||||||
StandardCharsets.UTF_8)) {
|
StandardCharsets.UTF_8)) {
|
||||||
mustache.execute(osw, versionInfo).flush();
|
mustache.execute(osw, versionInfo).flush();
|
||||||
}
|
}
|
||||||
|
@ -261,7 +264,7 @@ public class VersionProcessor extends AbstractProcessor {
|
||||||
} else {
|
} else {
|
||||||
final FileObject jfo = filer.createSourceFile(
|
final FileObject jfo = filer.createSourceFile(
|
||||||
versionInfo.getPackageName() + '.' + versionInfo.getClassName());
|
versionInfo.getPackageName() + '.' + versionInfo.getClassName());
|
||||||
try (Writer writer = jfo.openWriter()) {
|
try (var writer = jfo.openWriter()) {
|
||||||
mustache.execute(writer, versionInfo).flush();
|
mustache.execute(writer, versionInfo).flush();
|
||||||
}
|
}
|
||||||
note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');
|
note("Generated source: " + fileName + " (" + new File(jfo.getName()).getAbsoluteFile().getParent() + ')');
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ConstantsTest {
|
||||||
templates.add(Constants.DEFAULT_KOTLIN_TEMPLATE);
|
templates.add(Constants.DEFAULT_KOTLIN_TEMPLATE);
|
||||||
templates.add(Constants.DEFAULT_TEMPLATE_NAME);
|
templates.add(Constants.DEFAULT_TEMPLATE_NAME);
|
||||||
|
|
||||||
for (final String tp : templates) {
|
for (final var tp : templates) {
|
||||||
assertTrue(tp.endsWith(".mustache"), tp);
|
assertTrue(tp.endsWith(".mustache"), tp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,16 @@
|
||||||
|
|
||||||
package net.thauvin.erik.semver;
|
package net.thauvin.erik.semver;
|
||||||
|
|
||||||
|
import com.github.mustachejava.Mustache;
|
||||||
import org.junit.jupiter.api.Test;
|
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.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <code>VersionProcessorTest</code> class.
|
* The <code>VersionProcessorTest</code> class.
|
||||||
|
@ -49,29 +52,99 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
*/
|
*/
|
||||||
class VersionProcessorTest {
|
class VersionProcessorTest {
|
||||||
private final VersionProcessor processor = new VersionProcessor();
|
private final VersionProcessor processor = new VersionProcessor();
|
||||||
private final Version version = new VersionTest();
|
private final VersionTest version = new VersionTest();
|
||||||
|
|
||||||
|
@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();
|
||||||
|
assertEquals(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 <a href="https://github.com/ethauvin/semver">Semantic Version Annotation Processor</a>
|
||||||
|
*/
|
||||||
|
public final class MyTest {
|
||||||
|
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 MyTest() {
|
||||||
|
throw new UnsupportedOperationException("Illegal constructor call.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""", version.packageName(), version.project(), version.major(), version.minor(), version.patch(),
|
||||||
|
version.preRelease(), version.preReleasePrefix(), version.buildMeta(),
|
||||||
|
version.buildMetaPrefix(), version.separator()),
|
||||||
|
writer.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
||||||
@Test
|
@Test
|
||||||
void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
void testFindValues() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
final Method method = processor.getClass().getDeclaredMethod("findValues", Version.class);
|
final var method = processor.getClass().getDeclaredMethod("findValues", Version.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
final VersionInfo versionInfo = (VersionInfo) method.invoke(processor, version);
|
final var versionInfo = (VersionInfo) method.invoke(processor, version);
|
||||||
|
|
||||||
assertEquals("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)");
|
assertEquals("0-0-7:vodka++martini", versionInfo.getVersion(), "getVersion(0-0-7:vodka++martin)");
|
||||||
assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
|
assertEquals("James Bond", versionInfo.getProject(), "getProject(James Bond)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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")
|
@SuppressWarnings("PMD.AvoidAccessibilityAlteration")
|
||||||
@Test
|
@Test
|
||||||
void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
void testParseIntProperty() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
final Properties p = new Properties();
|
final var p = new Properties();
|
||||||
p.setProperty("1", "1");
|
p.setProperty("1", "1");
|
||||||
p.setProperty("2", "2.1");
|
p.setProperty("2", "2.1");
|
||||||
p.setProperty("3", "zero");
|
p.setProperty("3", "zero");
|
||||||
p.setProperty("4", " 4 ");
|
p.setProperty("4", " 4 ");
|
||||||
|
|
||||||
final Method method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class,
|
final var method = processor.getClass().getDeclaredMethod("parseIntProperty", Properties.class, String.class,
|
||||||
int.class);
|
int.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ import java.lang.annotation.Annotation;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"ClassExplicitlyAnnotation", "SameReturnValue", "java:S2187", "PMD.TestClassWithoutTestCases"})
|
@SuppressWarnings({"ClassExplicitlyAnnotation", "SameReturnValue", "java:S2187", "PMD.TestClassWithoutTestCases"})
|
||||||
class VersionTest implements Version {
|
class VersionTest implements Version {
|
||||||
|
String template = "myversion.mustache";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<? extends Annotation> annotationType() {
|
public Class<? extends Annotation> annotationType() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -160,11 +162,15 @@ class VersionTest implements Version {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String template() {
|
public String template() {
|
||||||
return "myversion.mustache";
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String type() {
|
||||||
return "kt";
|
return "kt";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTemplate(final String template) {
|
||||||
|
this.template = template;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue