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
:--------------|:---------------------------------|:-----------------
`project` | The project name, if any. | `MyProject`
`buildDate` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
`version` | The full version string. | `1.0.0-alpha+001`
`major` | The major version. | `1`
`minor` | The minor version. | `0`
`patch` | The patch version. | `0`
`preRelease` | The pre-release version, if any. | `alpha`
`buildMeta` | The build metadata, if any. | `001`
`PROJECT` | The project name, if any. | `MyProject`
`BUILDDATE` | The build date. | [`java.util.Date`](https://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
`VERSION` | The full version string. | `1.0.0-alpha+001`
`MAJOR` | The major version. | `1`
`MINOR` | The minor version. | `0`
`PATCH` | The patch version. | `0`
`PRERELEASE` | The pre-release version, if any. | `alpha`
`BUILDMETA` | The build metadata, if any. | `001`
And the following methods/functions:
@ -248,4 +248,6 @@ For a solution using [Gradle](https://gradle.org/), please have a look at the [b
```
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}} {
@JvmField
val project = "{{project}}"
val PRERELEASE_PREFIX = "-"
@JvmField
val buildDate = Date({{epoch}}L)
val BUILDMEATA_PREFIX = "+"
@JvmField
val major = {{major}}
val PROJECT = "{{project}}"
@JvmField
val minor = {{minor}}
val BUILDDATE = Date({{epoch}}L)
@JvmField
val patch = {{patch}}
val MAJOR = {{major}}
@JvmField
val buildMeta = "{{buildMeta}}"
val MINOR = {{minor}}
@JvmField
val preRelease = "{{preRelease}}"
val PATCH = {{patch}}
@JvmField
val version = "$major.$minor.$patch" + preReleaseWithPrefix() + buildMetaWithPrefix()
val BUILDMETA = "{{buildMeta}}"
@JvmField
val PRERELEASE = "{{preRelease}}"
@JvmField
val VERSION = "$MAJOR.$MINOR.$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix()
@JvmStatic
fun preReleaseWithPrefix(prefix: String = "-"): String {
return if (preRelease.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$preRelease"
fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String {
return if (PRERELEASE.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$PRERELEASE"
} else {
preRelease
PRERELEASE
}
}
@JvmStatic
fun buildMetaWithPrefix(prefix: String = "+"): String {
return if (buildMeta.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$buildMeta"
fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String {
return if (BUILDMETA.isNotEmpty() && prefix.isNotEmpty()) {
"$prefix$BUILDMETA"
} else {
buildMeta
BUILDMETA
}
}
}

View file

@ -13,16 +13,16 @@ import java.util.Date;
* Annotation Processor</a>
*/
public final class {{className}} {
private final static String DEFAULT_PRERELEASE_PREFIX = "-";
private final static String DEFAULT_BUILDMETA_PREFIX = "+";
public final static String PRERELEASE_PREFIX = "-";
public final static String BUILDMETA_PREFIX = "+";
public final static String project = "{{project}}";
public final static Date buildDate = new Date({{epoch}}L);
public final static int major = {{major}};
public final static int minor = {{minor}};
public final static int patch = {{patch}};
public final static String preRelease = "{{preRelease}}";
public final static String buildMeta = "{{buildMeta}}";
public final static String PROJECT = "{{project}}";
public final static Date BUILDDATE = new Date({{epoch}}L);
public final static int MAJOR = {{major}};
public final static int MINOR = {{minor}};
public final static int PATCH = {{patch}};
public final static String PRERELEASE = "{{preRelease}}";
public final static String BUILDMETA = "{{buildMeta}}";
/**
* The full version string.
@ -40,9 +40,9 @@ public final class {{className}} {
* <li><code>1.0.0-alpha+001</code></li>
* </ul>
*/
public final static String version = Integer.toString(major) + '.'
+ Integer.toString(minor) + '.'
+ Integer.toString(patch)
public final static String VERSION = Integer.toString(MAJOR) + '.'
+ Integer.toString(MINOR) + '.'
+ Integer.toString(PATCH)
+ 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.
*/
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.
*/
public static String buildMetaWithPrefix(final String prefix) {
if (buildMeta.length() > 0 && prefix.length() > 0) {
return prefix + buildMeta;
if (BUILDMETA.length() > 0 && prefix.length() > 0) {
return prefix + BUILDMETA;
} 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.
*/
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.
*/
public static String preReleaseWithPrefix(final String prefix) {
if (preRelease.length() > 0 && prefix.length() > 0) {
return prefix + preRelease;
if (PRERELEASE.length() > 0 && prefix.length() > 0) {
return prefix + PRERELEASE;
} else {
return preRelease;
return PRERELEASE;
}
}
}