Normalized fields and property names.

This commit is contained in:
Erik C. Thauvin 2017-04-16 14:24:35 -07:00
parent 3f630c1b55
commit 6d76cceeef
5 changed files with 30 additions and 22 deletions

View file

@ -1,7 +1,7 @@
/* /*
* Example.java * Example.java
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -49,7 +49,7 @@ public class Example {
System.out.println("-----------------------------------------------------"); System.out.println("-----------------------------------------------------");
System.out.println(" " + GeneratedVersion.project + ' ' + GeneratedVersion.getVersion()); System.out.println(" " + GeneratedVersion.project + ' ' + GeneratedVersion.version);
System.out.println(" Built on: " + sdf.format(GeneratedVersion.buildDate)); System.out.println(" Built on: " + sdf.format(GeneratedVersion.buildDate));
System.out.println(" Major: " + GeneratedVersion.major); System.out.println(" Major: " + GeneratedVersion.major);

View file

@ -1,7 +1,7 @@
/* /*
* Constants.java * Constants.java
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -43,10 +43,6 @@ public final class Constants {
* The default class name. * The default class name.
*/ */
public static final String DEFAULT_CLASS_NAME = "GeneratedVersion"; public static final String DEFAULT_CLASS_NAME = "GeneratedVersion";
/**
* The default mustache template.
*/
public static final String DEFAULT_TEMPLATE = "version.mustache";
/** /**
* /** * /**
* The default Java mustache template. * The default Java mustache template.
@ -72,6 +68,10 @@ public final class Constants {
* The default patch version. * The default patch version.
*/ */
public static final int DEFAULT_PATCH = 0; public static final int DEFAULT_PATCH = 0;
/**
* The default mustache template.
*/
public static final String DEFAULT_TEMPLATE_NAME = "version.mustache";
/** /**
* The empty string. * The empty string.
*/ */

View file

@ -1,7 +1,7 @@
/* /*
* Version.java * Version.java
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -46,9 +46,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface Version { public @interface Version {
String buildmeta() default Constants.EMPTY; String buildMeta() default Constants.EMPTY;
String buildmetaKey() default Constants.KEY_VERSION_BUILDMETA; String buildMetaKey() default Constants.KEY_VERSION_BUILDMETA;
String className() default Constants.DEFAULT_CLASS_NAME; String className() default Constants.DEFAULT_CLASS_NAME;
@ -64,9 +64,9 @@ public @interface Version {
String patchKey() default Constants.KEY_VERSION_PATCH; String patchKey() default Constants.KEY_VERSION_PATCH;
String prerelease() default Constants.EMPTY; String preRelease() default Constants.EMPTY;
String prereleaseKey() default Constants.KEY_VERSION_PRERELEASE; String preReleaseKey() default Constants.KEY_VERSION_PRERELEASE;
String project() default Constants.EMPTY; String project() default Constants.EMPTY;

View file

@ -1,7 +1,7 @@
/* /*
* VersionInfo.java * VersionInfo.java
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -74,8 +74,8 @@ public class VersionInfo {
major = version.major(); major = version.major();
minor = version.minor(); minor = version.minor();
patch = version.patch(); patch = version.patch();
buildMeta = version.buildmeta(); buildMeta = version.buildMeta();
preRelease = version.prerelease(); preRelease = version.preRelease();
project = version.project(); project = version.project();
className = version.className(); className = version.className();
} }

View file

@ -1,7 +1,7 @@
/* /*
* VersionProcessor.java * VersionProcessor.java
* *
* Copyright (c) 2016, Erik C. Thauvin (erik@thauvin.net) * Copyright (c) 2016-2017, Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -80,7 +80,7 @@ public class VersionProcessor extends AbstractProcessor {
if (propsFile.exists()) { if (propsFile.exists()) {
note("Found properties: " + propsFile); note("Found properties: " + propsFile);
final Properties p = new Properties(); final Properties p = new Properties();
try (FileReader reader = new FileReader(propsFile)) { try (FileReader reader = new FileReader(propsFile)) {
p.load(reader); p.load(reader);
@ -88,8 +88,8 @@ public class VersionProcessor extends AbstractProcessor {
versionInfo.setMajor(parseIntProperty(p, version.majorKey(), Constants.DEFAULT_MAJOR)); versionInfo.setMajor(parseIntProperty(p, version.majorKey(), Constants.DEFAULT_MAJOR));
versionInfo.setMinor(parseIntProperty(p, version.minorKey(), Constants.DEFAULT_MINOR)); versionInfo.setMinor(parseIntProperty(p, version.minorKey(), Constants.DEFAULT_MINOR));
versionInfo.setPatch(parseIntProperty(p, version.patchKey(), Constants.DEFAULT_PATCH)); versionInfo.setPatch(parseIntProperty(p, version.patchKey(), Constants.DEFAULT_PATCH));
versionInfo.setBuildMeta(p.getProperty(version.buildmetaKey(), Constants.EMPTY)); versionInfo.setBuildMeta(p.getProperty(version.buildMetaKey(), Constants.EMPTY));
versionInfo.setPreRelease(p.getProperty(version.prereleaseKey(), Constants.EMPTY)); versionInfo.setPreRelease(p.getProperty(version.preReleaseKey(), Constants.EMPTY));
} }
} else { } else {
error("Could not find: " + propsFile); error("Could not find: " + propsFile);
@ -164,8 +164,8 @@ public class VersionProcessor extends AbstractProcessor {
note("Found version: " + versionInfo.getVersion()); note("Found version: " + versionInfo.getVersion());
final String template; final String template;
if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) && if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) &&
new File(Constants.DEFAULT_TEMPLATE).exists()) { new File(Constants.DEFAULT_TEMPLATE_NAME).exists()) {
template = Constants.DEFAULT_TEMPLATE; template = Constants.DEFAULT_TEMPLATE_NAME;
} else if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) && } else if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) &&
version.type().equals(Constants.KOTLIN_TYPE)) { version.type().equals(Constants.KOTLIN_TYPE)) {
template = Constants.DEFAULT_KOTLIN_TEMPLATE; template = Constants.DEFAULT_KOTLIN_TEMPLATE;
@ -191,7 +191,15 @@ public class VersionProcessor extends AbstractProcessor {
final MustacheFactory mf = new DefaultMustacheFactory(); final MustacheFactory mf = new DefaultMustacheFactory();
final Mustache mustache = mf.compile(template); final Mustache mustache = mf.compile(template);
note("Loaded template: " + mustache.getName()); final String templateName;
if (mustache.getName().equals(Constants.DEFAULT_JAVA_TEMPLATE)) {
templateName = "default (java)";
} else if (mustache.getName().equals(Constants.DEFAULT_KOTLIN_TEMPLATE)) {
templateName = "default (kotlin)";
} else {
templateName = mustache.getName();
}
note("Loaded template: " + templateName);
final FileObject jfo; final FileObject jfo;
if (type.equalsIgnoreCase(Constants.KOTLIN_TYPE)) { if (type.equalsIgnoreCase(Constants.KOTLIN_TYPE)) {