Update static fields in templates to uppercase.

This commit is contained in:
Erik C. Thauvin 2017-04-23 19:49:45 -07:00
parent a5f4767fa5
commit 0b9e1ddce1
3 changed files with 55 additions and 47 deletions

View file

@ -56,14 +56,14 @@ The [default template](https://github.com/ethauvin/semver/blob/master/src/main/r
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.0.0-alpha+001` `VERSION` | The full version string. | `1.0.0-alpha+001`
`major` | The major version. | `1` `MAJOR` | The major version. | `1`
`minor` | The minor version. | `0` `MINOR` | The minor version. | `0`
`patch` | The patch version. | `0` `PATCH` | The patch version. | `0`
`preRelease` | The pre-release version, if any. | `alpha` `PRERELEASE` | The pre-release version, if any. | `alpha`
`buildMeta` | The build metadata, if any. | `001` `BUILDMETA` | The build metadata, if any. | `001`
And the following methods/functions: And the following methods/functions:
@ -248,4 +248,6 @@ For a solution using [Gradle](https://gradle.org/), please have a look at the [b
``` ```
gradle release run gradle release run
``` ```
For a solution using [Kobalt]([Kobalt](http://beust.com/kobalt/) look at my [Property File Editor](https://github.com/ethauvin/kobalt-property-file) plug-in.

View file

@ -14,44 +14,50 @@ import java.util.*
*/ */
object {{className}} { object {{className}} {
@JvmField @JvmField
val project = "{{project}}" val PRERELEASE_PREFIX = "-"
@JvmField @JvmField
val buildDate = Date({{epoch}}L) val BUILDMEATA_PREFIX = "+"
@JvmField @JvmField
val major = {{major}} val PROJECT = "{{project}}"
@JvmField @JvmField
val minor = {{minor}} val BUILDDATE = Date({{epoch}}L)
@JvmField @JvmField
val patch = {{patch}} val MAJOR = {{major}}
@JvmField @JvmField
val buildMeta = "{{buildMeta}}" val MINOR = {{minor}}
@JvmField @JvmField
val preRelease = "{{preRelease}}" val PATCH = {{patch}}
@JvmField @JvmField
val version = "$major.$minor.$patch" + preReleaseWithPrefix() + buildMetaWithPrefix() val BUILDMETA = "{{buildMeta}}"
@JvmField
val PRERELEASE = "{{preRelease}}"
@JvmField
val VERSION = "$MAJOR.$MINOR.$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix()
@JvmStatic @JvmStatic
fun preReleaseWithPrefix(prefix: String = "-"): String { fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String {
return if (preRelease.isNotEmpty() && prefix.isNotEmpty()) { return if (PRERELEASE.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$preRelease" "$prefix$PRERELEASE"
} else { } else {
preRelease PRERELEASE
} }
} }
@JvmStatic @JvmStatic
fun buildMetaWithPrefix(prefix: String = "+"): String { fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String {
return if (buildMeta.isNotEmpty() && prefix.isNotEmpty()) { return if (BUILDMETA.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$buildMeta" "$prefix$BUILDMETA"
} else { } else {
buildMeta BUILDMETA
} }
} }
} }

View file

@ -13,16 +13,16 @@ import java.util.Date;
* Annotation Processor</a> * Annotation Processor</a>
*/ */
public final class {{className}} { public final class {{className}} {
private final static String DEFAULT_PRERELEASE_PREFIX = "-"; public final static String PRERELEASE_PREFIX = "-";
private final static String DEFAULT_BUILDMETA_PREFIX = "+"; public final static String BUILDMETA_PREFIX = "+";
public final static String project = "{{project}}"; public final static String PROJECT = "{{project}}";
public final static Date buildDate = new Date({{epoch}}L); public final static Date BUILDDATE = new Date({{epoch}}L);
public final static int major = {{major}}; public final static int MAJOR = {{major}};
public final static int minor = {{minor}}; public final static int MINOR = {{minor}};
public final static int patch = {{patch}}; public final static int PATCH = {{patch}};
public final static String preRelease = "{{preRelease}}"; public final static String PRERELEASE = "{{preRelease}}";
public final static String buildMeta = "{{buildMeta}}"; public final static String BUILDMETA = "{{buildMeta}}";
/** /**
* The full version string. * The full version string.
@ -40,9 +40,9 @@ public final class {{className}} {
* <li><code>1.0.0-alpha+001</code></li> * <li><code>1.0.0-alpha+001</code></li>
* </ul> * </ul>
*/ */
public final static String version = Integer.toString(major) + '.' public final static String VERSION = Integer.toString(MAJOR) + '.'
+ Integer.toString(minor) + '.' + Integer.toString(MINOR) + '.'
+ Integer.toString(patch) + Integer.toString(PATCH)
+ preReleaseWithPrefix() + buildMetaWithPrefix(); + preReleaseWithPrefix() + buildMetaWithPrefix();
/** /**
@ -56,12 +56,12 @@ public final class {{className}} {
} }
/** /**
* Returns the build metadata with default prefix. * Returns the build metadata with {@value #BUILDMETA_PREFIX} prefix.
* *
* @return The build metadata, if any. * @return The build metadata, if any.
*/ */
public static String buildMetaWithPrefix() { public static String buildMetaWithPrefix() {
return buildMetaWithPrefix(DEFAULT_PRERELEASE_PREFIX); return buildMetaWithPrefix(BUILDMETA_PREFIX);
} }
/** /**
@ -71,20 +71,20 @@ public final class {{className}} {
* @return The build metadata, if any. * @return The build metadata, if any.
*/ */
public static String buildMetaWithPrefix(final String prefix) { public static String buildMetaWithPrefix(final String prefix) {
if (buildMeta.length() > 0 && prefix.length() > 0) { if (BUILDMETA.length() > 0 && prefix.length() > 0) {
return prefix + buildMeta; return prefix + BUILDMETA;
} else { } else {
return buildMeta; return BUILDMETA;
} }
} }
/** /**
* Returns the pre-release version with default prefix. * Returns the pre-release version with {@value #PRERELEASE_PREFIX} prefix.
* *
* @return The pre-release version, if any. * @return The pre-release version, if any.
*/ */
public static String preReleaseWithPrefix() { public static String preReleaseWithPrefix() {
return preReleaseWithPrefix(DEFAULT_PRERELEASE_PREFIX); return preReleaseWithPrefix(PRERELEASE_PREFIX);
} }
/** /**
@ -94,10 +94,10 @@ public final class {{className}} {
* @return The pre-release version, if any. * @return The pre-release version, if any.
*/ */
public static String preReleaseWithPrefix(final String prefix) { public static String preReleaseWithPrefix(final String prefix) {
if (preRelease.length() > 0 && prefix.length() > 0) { if (PRERELEASE.length() > 0 && prefix.length() > 0) {
return prefix + preRelease; return prefix + PRERELEASE;
} else { } else {
return preRelease; return PRERELEASE;
} }
} }
} }