From 87ddaec8b89b05d3985d48da25e99fef151244be Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 5 Apr 2019 23:12:33 -0700 Subject: [PATCH] Updated examples. --- .../annotation-processor/java/build.gradle | 9 ++++ .../java/com/example/GeneratedVersion.java | 46 ++++++------------- .../src/main/java/com/example/Example.java | 21 ++++++++- .../java/version.properties | 7 +-- .../kotlin/build.gradle.kts | 11 +++++ .../src/main/kotlin/com/example/Main.kt | 12 +++++ .../kotlin/version.properties | 7 +-- examples/java/version.properties | 4 +- examples/kotlin/version.properties | 4 +- version.properties | 7 +++ 10 files changed, 84 insertions(+), 44 deletions(-) create mode 100644 version.properties diff --git a/examples/annotation-processor/java/build.gradle b/examples/annotation-processor/java/build.gradle index cf43ee1..fe32be4 100644 --- a/examples/annotation-processor/java/build.gradle +++ b/examples/annotation-processor/java/build.gradle @@ -28,6 +28,15 @@ repositories { jcenter() } +run { + doFirst { + println "Version: $version" + } + +// args = ['example.properties'] + args = ['version.properties'] +} + semver { // properties = "example.properties" // keysPrefix = "example." diff --git a/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java b/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java index 5edfa5e..0a8bf0a 100644 --- a/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java +++ b/examples/annotation-processor/java/src/generated/java/com/example/GeneratedVersion.java @@ -12,45 +12,27 @@ import java.util.Date; * @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 = ""; - public final static Date BUILDDATE = new Date(1554010641988L); + public final static String PROJECT = "Java Annotation Example"; + public final static Date BUILDDATE = new Date(1554530172611L); public final static int MAJOR = 2; - public final static int MINOR = 1; - public final static int PATCH = 2; + public final static int MINOR = 4; + public final static int PATCH = 0; public final static String PRERELEASE = ""; + public final static String PRERELEASE_PREFIX = "-"; public final static String BUILDMETA = ""; + public final static String BUILDMETA_PREFIX = "+"; + public final static String SEPARATOR = "."; /** - * The full version string. - *

- * Formatted as: - *

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

- * For example: - *

+ * The full semantic version string. */ - public final static String VERSION = Integer.toString(MAJOR) + '.' - + Integer.toString(MINOR) + '.' - + Integer.toString(PATCH) - + preReleaseWithPrefix() + buildMetaWithPrefix(); + public final static String VERSION = Integer.toString(MAJOR) + SEPARATOR + Integer.toString(MINOR) + SEPARATOR + + Integer.toString(PATCH) + preReleaseWithPrefix() + buildMetaWithPrefix(); /** * Disables the default constructor. - * - * @throws UnsupportedOperationException If the constructor is called. */ - private GeneratedVersion() - throws UnsupportedOperationException { + private GeneratedVersion() { throw new UnsupportedOperationException("Illegal constructor call."); } @@ -70,7 +52,7 @@ public final class GeneratedVersion { * @return The build metadata, if any. */ public static String buildMetaWithPrefix(final String prefix) { - if (BUILDMETA.length() > 0 && prefix.length() > 0) { + if (BUILDMETA.length() > 0) { return prefix + BUILDMETA; } else { return BUILDMETA; @@ -93,10 +75,10 @@ public final class GeneratedVersion { * @return The pre-release version, if any. */ public static String preReleaseWithPrefix(final String prefix) { - if (PRERELEASE.length() > 0 && prefix.length() > 0) { + if (PRERELEASE.length() > 0) { return prefix + PRERELEASE; } else { return PRERELEASE; } } -} \ No newline at end of file +} diff --git a/examples/annotation-processor/java/src/main/java/com/example/Example.java b/examples/annotation-processor/java/src/main/java/com/example/Example.java index 6992ac9..723f398 100644 --- a/examples/annotation-processor/java/src/main/java/com/example/Example.java +++ b/examples/annotation-processor/java/src/main/java/com/example/Example.java @@ -2,6 +2,12 @@ package com.example; import net.thauvin.erik.semver.Version; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + import java.text.SimpleDateFormat; @Version(properties = "version.properties") @@ -11,12 +17,12 @@ import java.text.SimpleDateFormat; // preReleaseKey = "release", // buildMetaKey = "meta") public class Example { - public static void main(final String... args) { + public static void main(String... args) throws IOException { final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z"); System.out.println("-----------------------------------------------------"); - System.out.println(" Version:" + GeneratedVersion.PROJECT + ' ' + GeneratedVersion.VERSION); + System.out.println(" Version: " + GeneratedVersion.PROJECT + ' ' + GeneratedVersion.VERSION); System.out.println(" Built on: " + sdf.format(GeneratedVersion.BUILDDATE)); System.out.println(" Major: " + GeneratedVersion.MAJOR); @@ -26,5 +32,16 @@ public class Example { System.out.println(" BuildMetaData: " + GeneratedVersion.BUILDMETA); System.out.println("-----------------------------------------------------"); + + if (args.length == 1) { + final Path path = Paths.get(args[0]); + if (Files.exists(path)) { + final List content = Files.readAllLines(path); + System.out.println("> cat " + path.getFileName()); + for (final String line : content) { + System.out.println(line); + } + } + } } } diff --git a/examples/annotation-processor/java/version.properties b/examples/annotation-processor/java/version.properties index 8626f6d..2712834 100644 --- a/examples/annotation-processor/java/version.properties +++ b/examples/annotation-processor/java/version.properties @@ -1,7 +1,8 @@ #Generated by the Semver Plugin for Gradle -#Thu Dec 20 12:09:42 PST 2018 +#Fri Apr 05 22:56:10 PDT 2019 version.buildmeta= version.major=2 -version.minor=1 -version.patch=2 +version.minor=4 +version.patch=0 version.prerelease= +version.project=Java Example diff --git a/examples/annotation-processor/kotlin/build.gradle.kts b/examples/annotation-processor/kotlin/build.gradle.kts index fe60d1e..f461a68 100644 --- a/examples/annotation-processor/kotlin/build.gradle.kts +++ b/examples/annotation-processor/kotlin/build.gradle.kts @@ -31,6 +31,17 @@ application { mainClassName = "com.example.Main" } +tasks { + "run"(JavaExec::class) { + doFirst { + println("Verion: $version") + } + +// args = listOf("example.properties") + args = listOf("version.properties") + } +} + semver { // properties = "example.properties" // keysPrefix = "example." diff --git a/examples/annotation-processor/kotlin/src/main/kotlin/com/example/Main.kt b/examples/annotation-processor/kotlin/src/main/kotlin/com/example/Main.kt index e3d1cfb..cc503f1 100644 --- a/examples/annotation-processor/kotlin/src/main/kotlin/com/example/Main.kt +++ b/examples/annotation-processor/kotlin/src/main/kotlin/com/example/Main.kt @@ -1,6 +1,7 @@ package com.example import net.thauvin.erik.semver.Version +import java.io.File import java.text.SimpleDateFormat @Version(properties = "version.properties", type = "kt") @@ -28,6 +29,17 @@ class Main { println(" BuildMetaData: ${GeneratedVersion.BUILDMETA}") println("-----------------------------------------------------") + + if (args.size == 1) { + File(args[0]).apply { + if (exists()) { + println("> cat $name") + forEachLine { + println(it) + } + } + } + } } } } diff --git a/examples/annotation-processor/kotlin/version.properties b/examples/annotation-processor/kotlin/version.properties index e83411b..87dbec4 100644 --- a/examples/annotation-processor/kotlin/version.properties +++ b/examples/annotation-processor/kotlin/version.properties @@ -1,7 +1,8 @@ #Generated by the Semver Plugin for Gradle -#Thu Nov 29 20:35:47 PST 2018 +#Fri Apr 05 22:56:48 PDT 2019 version.buildmeta= version.major=11 -version.minor=2 -version.patch=4 +version.minor=7 +version.patch=0 version.prerelease= +version.project=Kotlin Example diff --git a/examples/java/version.properties b/examples/java/version.properties index 00dcbb0..7793f40 100644 --- a/examples/java/version.properties +++ b/examples/java/version.properties @@ -1,6 +1,6 @@ #Generated by the Semver Plugin for Gradle -#Thu Nov 29 20:33:16 PST 2018 -version.buildmeta=20180713152249 +#Fri Apr 05 22:54:31 PDT 2019 +version.buildmeta=20190405225431 version.major=1 version.minor=1 version.patch=8 diff --git a/examples/kotlin/version.properties b/examples/kotlin/version.properties index 72fca8e..b305433 100644 --- a/examples/kotlin/version.properties +++ b/examples/kotlin/version.properties @@ -1,6 +1,6 @@ #Generated by the Semver Plugin for Gradle -#Thu Dec 20 12:18:04 PST 2018 -version.buildmeta=20181101185038 +#Fri Apr 05 22:55:25 PDT 2019 +version.buildmeta=20190405225525 version.major=1 version.minor=2 version.patch=4 diff --git a/version.properties b/version.properties new file mode 100644 index 0000000..cacc7cd --- /dev/null +++ b/version.properties @@ -0,0 +1,7 @@ +#Generated by the Semver Plugin for Gradle +#Fri Apr 05 22:53:26 PDT 2019 +version.buildmeta= +version.major=1 +version.minor=0 +version.patch=0 +version.prerelease=