From 479a770eec5a78c5981fae90c6cf11fd4179d984 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 26 Apr 2017 16:57:37 -0700 Subject: [PATCH] Updated example to use new template. --- .../erik/semver/example/GeneratedVersion.java | 103 ++++++++++++++++++ .../thauvin/erik/semver/example/Example.java | 14 +-- 2 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java diff --git a/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java b/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java new file mode 100644 index 0000000..e45b467 --- /dev/null +++ b/example/src/generated/java/net/thauvin/erik/semver/example/GeneratedVersion.java @@ -0,0 +1,103 @@ +/* + * This file is automatically generated. + * Do not modify! -- ALL CHANGES WILL BE ERASED! + */ +package net.thauvin.erik.semver.example; + +import java.util.Date; + +/** + * Provides semantic version information. + * + * @author Semantic Version + * Annotation Processor + */ +public final class GeneratedVersion { + public final static String PRERELEASE_PREFIX = "-"; + public final static String BUILDMETA_PREFIX = "+"; + + public final static String PROJECT = "Example"; + public final static Date BUILDDATE = new Date(1493251035937L); + public final static int MAJOR = 2; + public final static int MINOR = 17; + public final static int PATCH = 52; + public final static String PRERELEASE = "beta"; + public final static String BUILDMETA = "007"; + + /** + * The full version string. + *

+ * Formatted as: + *

+ * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA] + *
+ *

+ * For example: + *

+ */ + public final static String VERSION = Integer.toString(MAJOR) + '.' + + Integer.toString(MINOR) + '.' + + Integer.toString(PATCH) + + preReleaseWithPrefix() + buildMetaWithPrefix(); + + /** + * Disables the default constructor. + * + * @throws UnsupportedOperationException If the constructor is called. + */ + private GeneratedVersion() + throws UnsupportedOperationException { + 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 && prefix.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 && prefix.length() > 0) { + return prefix + PRERELEASE; + } else { + return PRERELEASE; + } + } +} \ No newline at end of file diff --git a/example/src/main/java/net/thauvin/erik/semver/example/Example.java b/example/src/main/java/net/thauvin/erik/semver/example/Example.java index 801d2d8..d4e81a0 100644 --- a/example/src/main/java/net/thauvin/erik/semver/example/Example.java +++ b/example/src/main/java/net/thauvin/erik/semver/example/Example.java @@ -49,14 +49,14 @@ public class Example { System.out.println("-----------------------------------------------------"); - System.out.println(" " + GeneratedVersion.project + ' ' + GeneratedVersion.version); + System.out.println(" " + GeneratedVersion.PROJECT + ' ' + GeneratedVersion.VERSION); - System.out.println(" Built on: " + sdf.format(GeneratedVersion.buildDate)); - System.out.println(" Major: " + GeneratedVersion.major); - System.out.println(" Minor: " + GeneratedVersion.minor); - System.out.println(" Patch: " + GeneratedVersion.patch); - System.out.println(" PreRelease: " + GeneratedVersion.preRelease); - System.out.println(" BuildMetaData: " + GeneratedVersion.buildMeta); + System.out.println(" Built on: " + sdf.format(GeneratedVersion.BUILDDATE)); + System.out.println(" Major: " + GeneratedVersion.MAJOR); + System.out.println(" Minor: " + GeneratedVersion.MINOR); + System.out.println(" Patch: " + GeneratedVersion.PATCH); + System.out.println(" PreRelease: " + GeneratedVersion.PRERELEASE); + System.out.println(" BuildMetaData: " + GeneratedVersion.BUILDMETA); System.out.println("-----------------------------------------------------"); }