Added new example with custom properties and template.
This commit is contained in:
parent
0fb4324d8d
commit
f801ce03fe
28 changed files with 533 additions and 65 deletions
|
@ -4,7 +4,8 @@ plugins {
|
|||
id 'com.github.ben-manes.versions' version '0.21.0'
|
||||
}
|
||||
|
||||
// ./gradlew
|
||||
// ./gradlew run
|
||||
// ./gradlew runExample
|
||||
|
||||
defaultTasks 'run'
|
||||
|
||||
|
@ -15,7 +16,7 @@ targetCompatibility = 1.8
|
|||
|
||||
compileJava.options.annotationProcessorGeneratedSourcesDirectory = file("${projectDir}/src/generated/java")
|
||||
|
||||
mainClassName = 'com.example.Example'
|
||||
mainClassName = 'com.example.App'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
@ -26,3 +27,10 @@ dependencies {
|
|||
annotationProcessor semverProcessor
|
||||
compileOnly semverProcessor
|
||||
}
|
||||
|
||||
task runExample(type: JavaExec) {
|
||||
group = 'application'
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
|
||||
main = 'com.example.Example'
|
||||
}
|
||||
|
|
|
@ -10,11 +10,6 @@ import java.util.Date;
|
|||
public final class {{className}} {
|
||||
public static final String PROJECT = "{{project}}";
|
||||
public static final Date BUILDDATE = new Date({{epoch}}L);
|
||||
public static final int MAJOR = {{major}};
|
||||
public static final int MINOR = {{minor}};
|
||||
public static final int PATCH = {{patch}};
|
||||
public static final String PRERELEASE = "{{preRelease}}";
|
||||
public static final String BUILDMETA = "{{buildMeta}}";
|
||||
public static final String VERSION = "{{version}}";
|
||||
|
||||
/**
|
||||
|
|
9
examples/java/example.properties
Normal file
9
examples/java/example.properties
Normal file
|
@ -0,0 +1,9 @@
|
|||
#Generated by the Semver Plugin for Gradle
|
||||
#Sat Apr 27 17:04:13 PDT 2019
|
||||
example.buildmeta=T800
|
||||
example.major=8
|
||||
example.minor=4
|
||||
example.patch=97
|
||||
example.prerelease=alpha
|
||||
example.project=Java Example
|
||||
example.semver=8.4.97-alpha+T800
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* This file is automatically generated.
|
||||
* Do not modify! -- ALL CHANGES WILL BE ERASED!
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public final class ExampleVersion {
|
||||
public static final String PROJECT = "Java Example";
|
||||
public static final Date BUILDDATE = new Date(1556420335650L);
|
||||
public static final String VERSION = "8.4.97-alpha+T800";
|
||||
|
||||
/**
|
||||
* Disables the default constructor.
|
||||
*/
|
||||
private ExampleVersion() {
|
||||
throw new UnsupportedOperationException("Illegal constructor call.");
|
||||
}
|
||||
}
|
|
@ -6,15 +6,23 @@ package com.example;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Provides semantic version information.
|
||||
*
|
||||
* @author <a href="https://github.com/ethauvin/semver">Semantic Version Annotation Processor</a>
|
||||
*/
|
||||
public final class GeneratedVersion {
|
||||
public final static String PROJECT = "Java Example";
|
||||
public final static Date BUILDDATE = new Date(1555703771370L);
|
||||
public final static int MAJOR = 2;
|
||||
public final static int MINOR = 0;
|
||||
public final static int PATCH = 52;
|
||||
public final static String PROJECT = "Java App";
|
||||
public final static Date BUILDDATE = new Date(1556420335600L);
|
||||
public final static int MAJOR = 11;
|
||||
public final static int MINOR = 11;
|
||||
public final static int PATCH = 20;
|
||||
public final static String PRERELEASE = "beta";
|
||||
public final static String PRERELEASE_PREFIX = "-";
|
||||
public final static String BUILDMETA = "007";
|
||||
public final static String VERSION = "2.0.52-beta+007";
|
||||
public final static String BUILDMETA_PREFIX = "+";
|
||||
public final static String SEPARATOR = ".";
|
||||
public final static String VERSION = "11.11.20-beta+007";
|
||||
|
||||
/**
|
||||
* Disables the default constructor.
|
||||
|
|
31
examples/java/src/main/java/com/example/App.java
Normal file
31
examples/java/src/main/java/com/example/App.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package com.example;
|
||||
|
||||
import net.thauvin.erik.semver.Version;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
@Version(properties = "version.properties")
|
||||
public final class App {
|
||||
/**
|
||||
* Command line interface.
|
||||
*
|
||||
* @param args The command line parameters.
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z", Locale.US);
|
||||
|
||||
System.out.println("-----------------------------------------------------");
|
||||
|
||||
System.out.println(" Version: " + 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("-----------------------------------------------------");
|
||||
}
|
||||
}
|
|
@ -3,24 +3,25 @@ package com.example;
|
|||
import net.thauvin.erik.semver.Version;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
//@Version(properties = "version.properties", template = "example.mustache")
|
||||
@Version(properties = "version.properties")
|
||||
public class Example {
|
||||
@Version(properties = "example.properties", template = "example.mustache", className = "ExampleVersion",
|
||||
keysPrefix = "example.")
|
||||
public final class Example {
|
||||
/**
|
||||
* Command line interface.
|
||||
*
|
||||
* @param args The command line parameters.
|
||||
*/
|
||||
public static void main(final String... args) {
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy 'at' HH:mm:ss z");
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
|
||||
|
||||
System.out.println("-----------------------------------------------------");
|
||||
System.out.println("-- From Example -------------------------------------");
|
||||
|
||||
System.out.println(" Version: " + 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(" " + ExampleVersion.PROJECT + ' ' + ExampleVersion.VERSION
|
||||
+ " (" + sdf.format(ExampleVersion.BUILDDATE) + ')');
|
||||
|
||||
System.out.println("-----------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#Generated by the Semver Plugin for Gradle
|
||||
#Sat Mar 30 15:48:08 PDT 2019
|
||||
#Sat Apr 27 17:05:34 PDT 2019
|
||||
version.buildmeta=007
|
||||
version.major=2
|
||||
version.minor=0
|
||||
version.patch=52
|
||||
version.major=11
|
||||
version.minor=11
|
||||
version.patch=20
|
||||
version.prerelease=beta
|
||||
version.project=Java Example
|
||||
version.project=Java App
|
||||
version.semver=11.11.20-beta+007
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue