Updated examples.
This commit is contained in:
parent
e2f55f33e2
commit
87ddaec8b8
10 changed files with 84 additions and 44 deletions
|
@ -28,6 +28,15 @@ repositories {
|
|||
jcenter()
|
||||
}
|
||||
|
||||
run {
|
||||
doFirst {
|
||||
println "Version: $version"
|
||||
}
|
||||
|
||||
// args = ['example.properties']
|
||||
args = ['version.properties']
|
||||
}
|
||||
|
||||
semver {
|
||||
// properties = "example.properties"
|
||||
// keysPrefix = "example."
|
||||
|
|
|
@ -12,45 +12,27 @@ import java.util.Date;
|
|||
* @author <a href="https://github.com/ethauvin/semver">Semantic Version Annotation Processor</a>
|
||||
*/
|
||||
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.
|
||||
* <p>
|
||||
* Formatted as:
|
||||
* <blockquote>
|
||||
* <code>MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA]</code>
|
||||
* </blockquote>
|
||||
* <p>
|
||||
* For example:
|
||||
* <ul>
|
||||
* <li><code>1.0.0</code></li>
|
||||
* <li><code>1.0.0-beta</code></li>
|
||||
* <li><code>1.0.0+20160124144700</code></li>
|
||||
* <li><code>1.0.0-alpha+001</code></li>
|
||||
* </ul>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> content = Files.readAllLines(path);
|
||||
System.out.println("> cat " + path.getFileName());
|
||||
for (final String line : content) {
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
7
version.properties
Normal file
7
version.properties
Normal file
|
@ -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=
|
Loading…
Add table
Add a link
Reference in a new issue