diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 8ff795e..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..dc2dcae --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/README.md b/README.md index 671e572..99162ba 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ public class A { ### Default Template -The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache ) implements the following static fields: +The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache ) implements the following static variables: Field | Description | Example :------------------|:---------------------------------|:----------------- @@ -71,13 +71,6 @@ Field | Description | Example `BUILDMETA_PREFIX` | The metadata prefix. | `+` `SEPARATOR` | The version separator. | `.` -And the following methods/functions: - -Method | Description | Example -:------------------------|:----------------------------------------------------------|:-------- -`preReleaseWithPrefix()` | Returns the pre-release with a prefix, `-` by default. | `-alpha` -`buildMetaWithPrefix()` | Returns the build metadata with a prefix, `+` by default. | `+001` - ### Custom Template A very simple custom template might look something like: @@ -91,29 +84,27 @@ import java.util.Date; public final class {{className}} { public final static String PROJECT = "{{project}}"; public final static Date DATE = new Date({{epoch}}L); - public final static int MAJOR = {{major}}; - public final static int MINOR = {{minor}}; - public final static int PATCH = {{patch}}; - public final static String PRERELEASE = "{{preRelease}}"; - public final static String BUILDMETA = "{{buildMeta}}"; + 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` +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` 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) diff --git a/examples/java/example.mustache b/examples/java/example.mustache index a44fd5d..f09599e 100644 --- a/examples/java/example.mustache +++ b/examples/java/example.mustache @@ -14,15 +14,7 @@ public final class {{className}} { public final static int PATCH = {{patch}}; public final static String PRERELEASE = "{{preRelease}}"; public final static String BUILDMETA = "{{buildMeta}}"; - - /** - * The full semantic version string. - */ - public final static String VERSION = Integer.toString(MAJOR) + '.' - + Integer.toString(MINOR) + '.' - + Integer.toString(PATCH) - + ((!PRERELEASE.isEmpty()) ? "-" + PRERELEASE : "") - + ((!BUILDMETA.isEmpty()) ? "+" + BUILDMETA : ""); + public final static String VERSION = "{{version}}"; /** * Disables the default constructor. diff --git a/examples/kotlin/example.mustache b/examples/kotlin/example.mustache index 1d3a14a..d839096 100644 --- a/examples/kotlin/example.mustache +++ b/examples/kotlin/example.mustache @@ -26,11 +26,6 @@ object {{className}} { val PRERELEASE = "{{preRelease}}" @JvmField val BUILDMETA = "{{buildMeta}}" - - /** - * The full semantic version string. - */ @JvmField - val VERSION = ("$MAJOR.$MINOR.$PATCH" + if (PRERELEASE.isNotEmpty()) "-$PRERELEASE" else "" - + if (BUILDMETA.isNotEmpty()) "+$BUILDMETA" else "") + val VERSION = "{{version}}" } diff --git a/src/main/java/net/thauvin/erik/semver/VersionInfo.java b/src/main/java/net/thauvin/erik/semver/VersionInfo.java index 6f88cf6..0b83a82 100644 --- a/src/main/java/net/thauvin/erik/semver/VersionInfo.java +++ b/src/main/java/net/thauvin/erik/semver/VersionInfo.java @@ -122,7 +122,7 @@ public String getBuildMetaPrefix() { * * @param buildMetaPrefix The meta-data prefix. */ - public void setBuildMetaPrefix(String buildMetaPrefix) { + public void setBuildMetaPrefix(final String buildMetaPrefix) { this.buildMetaPrefix = buildMetaPrefix; } @@ -140,7 +140,7 @@ public String getClassName() { * * @param className The new class name. */ - public void setClassName(String className) { + public void setClassName(final String className) { this.className = className; } @@ -203,7 +203,7 @@ public String getPackageName() { * * @param packageName The new package name. */ - public void setPackageName(String packageName) { + public void setPackageName(final String packageName) { this.packageName = packageName; } @@ -257,7 +257,7 @@ public String getPreReleasePrefix() { * * @param preReleasePrefix The new pre-release prefix. */ - public void setPreReleasePrefix(String preReleasePrefix) { + public void setPreReleasePrefix(final String preReleasePrefix) { this.preReleasePrefix = preReleasePrefix; } @@ -279,6 +279,14 @@ public void setProject(final String project) { this.project = project; } + + /** + * Sames as {@link #getVersion()} + */ + public String getSemver() { + return getVersion(); + } + /** * Returns the version separator. * @@ -289,11 +297,11 @@ public String getSeparator() { } /** - * Setsthe version separtor. + * Sets the version separator. * * @param separator The new version separator. */ - public void setSeparator(String separator) { + public void setSeparator(final String separator) { this.separator = separator; } diff --git a/src/main/java/net/thauvin/erik/semver/package.html b/src/main/java/net/thauvin/erik/semver/package.html index c63dfc0..1b1b126 100644 --- a/src/main/java/net/thauvin/erik/semver/package.html +++ b/src/main/java/net/thauvin/erik/semver/package.html @@ -1,11 +1,12 @@ - - - Semantic Version Annotation Processor - - -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. + + + Semantic Version Annotation Processor + + +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. @since 1.0 - - + + diff --git a/src/main/resources/semver-kt.mustache b/src/main/resources/semver-kt.mustache index bc6d68e..4ade969 100644 --- a/src/main/resources/semver-kt.mustache +++ b/src/main/resources/semver-kt.mustache @@ -32,42 +32,6 @@ object {{className}} { val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}" @JvmField val SEPARATOR = "{{separator}}" - - /** - * The full semantic version string. - */ @JvmField - val VERSION = "$MAJOR$SEPARATOR$MINOR$SEPARATOR$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix() - - /** - * Returns the pre-release version with prefix. - * - * @param prefix The prefix, defaults to [PRERELEASE_PREFIX]. - * @return The pre-release version, if any. - */ - @JvmStatic - @JvmOverloads - fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String { - return if (PRERELEASE.isNotEmpty()) { - "$prefix$PRERELEASE" - } else { - PRERELEASE - } - } - - /** - * Returns the build metadata with prefix. - * - * @param prefix The prefix, defaults to [BUILDMEATA_PREFIX]. - * @return The build metadata, if any. - */ - @JvmStatic - @JvmOverloads - fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String { - return if (BUILDMETA.isNotEmpty()) { - "$prefix$BUILDMETA" - } else { - BUILDMETA - } - } + val VERSION = "{{version}}" } diff --git a/src/main/resources/semver.mustache b/src/main/resources/semver.mustache index 20c08ce..548d540 100644 --- a/src/main/resources/semver.mustache +++ b/src/main/resources/semver.mustache @@ -22,12 +22,7 @@ public final class {{className}} { public final static String BUILDMETA = "{{buildMeta}}"; public final static String BUILDMETA_PREFIX = "{{buildMetaPrefix}}"; public final static String SEPARATOR = "{{separator}}"; - - /** - * The full semantic version string. - */ - public final static String VERSION = Integer.toString(MAJOR) + SEPARATOR + Integer.toString(MINOR) + SEPARATOR - + Integer.toString(PATCH) + preReleaseWithPrefix() + buildMetaWithPrefix(); + public final static String VERSION = "{{version}}"; /** * Disables the default constructor. @@ -35,50 +30,4 @@ public final class {{className}} { private {{className}}() { throw new UnsupportedOperationException("Illegal constructor call."); } - - /** - * Returns the build metadata with {@value #BUILDMETA_PREFIX} prefix. - * - * @return The build metadata, if any. - */ - public static String buildMetaWithPrefix() { - return buildMetaWithPrefix(BUILDMETA_PREFIX); - } - - /** - * Returns the build metadata. - * - * @param prefix Prefix to prepend. - * @return The build metadata, if any. - */ - public static String buildMetaWithPrefix(final String prefix) { - if (BUILDMETA.length() > 0) { - return prefix + BUILDMETA; - } else { - return BUILDMETA; - } - } - - /** - * Returns the pre-release version with {@value #PRERELEASE_PREFIX} prefix. - * - * @return The pre-release version, if any. - */ - public static String preReleaseWithPrefix() { - return preReleaseWithPrefix(PRERELEASE_PREFIX); - } - - /** - * Returns the pre-release version. - * - * @param prefix The prefix to prepend. - * @return The pre-release version, if any. - */ - public static String preReleaseWithPrefix(final String prefix) { - if (PRERELEASE.length() > 0) { - return prefix + PRERELEASE; - } else { - return PRERELEASE; - } - } } diff --git a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java index 470c122..58e4a20 100644 --- a/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java +++ b/src/test/java/net/thauvin/erik/semver/VersionInfoTest.java @@ -90,6 +90,9 @@ public void testGetVersion() { versionInfo.setSeparator("-"); Assert.assertEquals(versionInfo.getVersion(), "3-2-1+001", "getVersion(3-2-1+001)"); + + Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), + "getVersion(3-2-1+001) = getSemver(3-2-1+001) "); } @Test @@ -122,6 +125,8 @@ public void testSetGet() { Assert.assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)"); + Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), "getVersion() = getSemver()"); + versionInfo.setBuildMetaPrefix(""); Assert.assertEquals(versionInfo.getBuildMetaPrefix(), "", "getBuildMetaPrefix( )"); @@ -188,6 +193,9 @@ public void testVersionInfo() { + version.buildMeta(), "getVersion(version)"); + Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), + "getVersion(version) = getSemver(version)"); + Assert.assertEquals(versionInfo.getProject(), version.project(), "getProject(project)"); Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)");