The version is now calculated internally.

This commit is contained in:
Erik C. Thauvin 2019-04-14 22:25:01 -07:00
parent 909b03e861
commit 6455662d23
10 changed files with 60 additions and 198 deletions

View file

@ -1,53 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<option name="myLocal" value="true" />
<inspection_tool class="FieldMayBeFinal" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="created" />
</inspection_tool>
<inspection_tool class="LocalCanBeFinal" enabled="true" level="WARNING" enabled_by_default="true">
<option name="REPORT_VARIABLES" value="true" />
<option name="REPORT_PARAMETERS" value="false" />
<option name="REPORT_CATCH_PARAMETERS" value="false" />
</inspection_tool>
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="UnnecessarySemicolon" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
</inspection_tool>
</profile>
</component>

View file

@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="PROJECT_PROFILE" value="Erik's Default" />
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View file

@ -55,7 +55,7 @@ public class A {
### Default Template ### Default Template
The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache ) implements the following static fields: The [default template](https://github.com/ethauvin/semver/blob/master/src/main/resources/semver.mustache ) implements the following static variables:
Field | Description | Example Field | Description | Example
:------------------|:---------------------------------|:----------------- :------------------|:---------------------------------|:-----------------
@ -71,13 +71,6 @@ Field | Description | Example
`BUILDMETA_PREFIX` | The metadata prefix. | `+` `BUILDMETA_PREFIX` | The metadata prefix. | `+`
`SEPARATOR` | The version separator. | `.` `SEPARATOR` | The version separator. | `.`
And the following methods/functions:
Method | Description | Example
:------------------------|:----------------------------------------------------------|:--------
`preReleaseWithPrefix()` | Returns the pre-release with a prefix, `-` by default. | `-alpha`
`buildMetaWithPrefix()` | Returns the build metadata with a prefix, `+` by default. | `+001`
### Custom Template ### Custom Template
A very simple custom template might look something like: A very simple custom template might look something like:
@ -91,17 +84,14 @@ import java.util.Date;
public final class {{className}} { public final class {{className}} {
public final static String PROJECT = "{{project}}"; public final static String PROJECT = "{{project}}";
public final static Date DATE = new Date({{epoch}}L); public final static Date DATE = new Date({{epoch}}L);
public final static int MAJOR = {{major}}; public final static String VERSION = "{{semver}}";
public final static int MINOR = {{minor}};
public final static int PATCH = {{patch}};
public final static String PRERELEASE = "{{preRelease}}";
public final static String BUILDMETA = "{{buildMeta}}";
} }
``` ```
The mustache variables automatically filled in by the processor are: The mustache variables automatically filled in by the processor are:
Variable | Description | Type Variable | Description | Type
:----------------------|:----------------------------|:-------- :-----------------------------|:----------------------------|:--------
`{{packageName}}` | The package name. | `String` `{{packageName}}` | The package name. | `String`
`{{className}}` | The class name. | `String` `{{className}}` | The class name. | `String`
`{{project}}` | The project name. | `String` `{{project}}` | The project name. | `String`
@ -114,6 +104,7 @@ Variable | Description | Type
`{{buildMeta}}` | The build metadata version. | `String` `{{buildMeta}}` | The build metadata version. | `String`
`{{buildMetaPrefix}}` | The metadata prefix. | `String` `{{buildMetaPrefix}}` | The metadata prefix. | `String`
`{{separator}}` | The version separator. | `String` `{{separator}}` | The version separator. | `String`
`{{semver}}` or `{{version}}` | The full semantic version. | `String`
Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) Please also look at this [example](https://github.com/ethauvin/mobibot/blob/master/version.mustache) using [`java.time`](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)

View file

@ -14,15 +14,7 @@ public final class {{className}} {
public final static int PATCH = {{patch}}; public final static int PATCH = {{patch}};
public final static String PRERELEASE = "{{preRelease}}"; public final static String PRERELEASE = "{{preRelease}}";
public final static String BUILDMETA = "{{buildMeta}}"; public final static String BUILDMETA = "{{buildMeta}}";
public final static String VERSION = "{{version}}";
/**
* The full semantic version string.
*/
public final static String VERSION = Integer.toString(MAJOR) + '.'
+ Integer.toString(MINOR) + '.'
+ Integer.toString(PATCH)
+ ((!PRERELEASE.isEmpty()) ? "-" + PRERELEASE : "")
+ ((!BUILDMETA.isEmpty()) ? "+" + BUILDMETA : "");
/** /**
* Disables the default constructor. * Disables the default constructor.

View file

@ -26,11 +26,6 @@ object {{className}} {
val PRERELEASE = "{{preRelease}}" val PRERELEASE = "{{preRelease}}"
@JvmField @JvmField
val BUILDMETA = "{{buildMeta}}" val BUILDMETA = "{{buildMeta}}"
/**
* The full semantic version string.
*/
@JvmField @JvmField
val VERSION = ("$MAJOR.$MINOR.$PATCH" + if (PRERELEASE.isNotEmpty()) "-$PRERELEASE" else "" val VERSION = "{{version}}"
+ if (BUILDMETA.isNotEmpty()) "+$BUILDMETA" else "")
} }

View file

@ -122,7 +122,7 @@ public class VersionInfo {
* *
* @param buildMetaPrefix The meta-data prefix. * @param buildMetaPrefix The meta-data prefix.
*/ */
public void setBuildMetaPrefix(String buildMetaPrefix) { public void setBuildMetaPrefix(final String buildMetaPrefix) {
this.buildMetaPrefix = buildMetaPrefix; this.buildMetaPrefix = buildMetaPrefix;
} }
@ -140,7 +140,7 @@ public class VersionInfo {
* *
* @param className The new class name. * @param className The new class name.
*/ */
public void setClassName(String className) { public void setClassName(final String className) {
this.className = className; this.className = className;
} }
@ -203,7 +203,7 @@ public class VersionInfo {
* *
* @param packageName The new package name. * @param packageName The new package name.
*/ */
public void setPackageName(String packageName) { public void setPackageName(final String packageName) {
this.packageName = packageName; this.packageName = packageName;
} }
@ -257,7 +257,7 @@ public class VersionInfo {
* *
* @param preReleasePrefix The new pre-release prefix. * @param preReleasePrefix The new pre-release prefix.
*/ */
public void setPreReleasePrefix(String preReleasePrefix) { public void setPreReleasePrefix(final String preReleasePrefix) {
this.preReleasePrefix = preReleasePrefix; this.preReleasePrefix = preReleasePrefix;
} }
@ -279,6 +279,14 @@ public class VersionInfo {
this.project = project; this.project = project;
} }
/**
* Sames as {@link #getVersion()}
*/
public String getSemver() {
return getVersion();
}
/** /**
* Returns the version separator. * Returns the version separator.
* *
@ -289,11 +297,11 @@ public class VersionInfo {
} }
/** /**
* Setsthe version separtor. * Sets the version separator.
* *
* @param separator The new version separator. * @param separator The new version separator.
*/ */
public void setSeparator(String separator) { public void setSeparator(final String separator) {
this.separator = separator; this.separator = separator;
} }

View file

@ -1,11 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> <html lang="en">
<HEAD> <head>
<TITLE>Semantic Version Annotation Processor</TITLE> <title>Semantic Version Annotation Processor</title>
</HEAD> </head>
<BODY> <body>
An annotation processor that automatically generates a <code>GeneratedVersion</code> class containing the semantic version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation. An annotation processor that automatically generates a <code>GeneratedVersion</code> class containing the semantic
version (major, minor, patch, etc.) that is read from a Properties file or defined in the annotation.
@since 1.0 @since 1.0
</BODY> </body>
</HTML> </html>

View file

@ -32,42 +32,6 @@ object {{className}} {
val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}" val BUILDMEATA_PREFIX = "{{buildMetaPrefix}}"
@JvmField @JvmField
val SEPARATOR = "{{separator}}" val SEPARATOR = "{{separator}}"
/**
* The full semantic version string.
*/
@JvmField @JvmField
val VERSION = "$MAJOR$SEPARATOR$MINOR$SEPARATOR$PATCH" + preReleaseWithPrefix() + buildMetaWithPrefix() val VERSION = "{{version}}"
/**
* Returns the pre-release version with prefix.
*
* @param prefix The prefix, defaults to [PRERELEASE_PREFIX].
* @return The pre-release version, if any.
*/
@JvmStatic
@JvmOverloads
fun preReleaseWithPrefix(prefix: String = PRERELEASE_PREFIX): String {
return if (PRERELEASE.isNotEmpty()) {
"$prefix$PRERELEASE"
} else {
PRERELEASE
}
}
/**
* Returns the build metadata with prefix.
*
* @param prefix The prefix, defaults to [BUILDMEATA_PREFIX].
* @return The build metadata, if any.
*/
@JvmStatic
@JvmOverloads
fun buildMetaWithPrefix(prefix: String = BUILDMEATA_PREFIX): String {
return if (BUILDMETA.isNotEmpty()) {
"$prefix$BUILDMETA"
} else {
BUILDMETA
}
}
} }

View file

@ -22,12 +22,7 @@ public final class {{className}} {
public final static String BUILDMETA = "{{buildMeta}}"; public final static String BUILDMETA = "{{buildMeta}}";
public final static String BUILDMETA_PREFIX = "{{buildMetaPrefix}}"; public final static String BUILDMETA_PREFIX = "{{buildMetaPrefix}}";
public final static String SEPARATOR = "{{separator}}"; public final static String SEPARATOR = "{{separator}}";
public final static String VERSION = "{{version}}";
/**
* The full semantic version string.
*/
public final static String VERSION = Integer.toString(MAJOR) + SEPARATOR + Integer.toString(MINOR) + SEPARATOR
+ Integer.toString(PATCH) + preReleaseWithPrefix() + buildMetaWithPrefix();
/** /**
* Disables the default constructor. * Disables the default constructor.
@ -35,50 +30,4 @@ public final class {{className}} {
private {{className}}() { private {{className}}() {
throw new UnsupportedOperationException("Illegal constructor call."); 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) {
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) {
return prefix + PRERELEASE;
} else {
return PRERELEASE;
}
}
} }

View file

@ -90,6 +90,9 @@ public class VersionInfoTest {
versionInfo.setSeparator("-"); versionInfo.setSeparator("-");
Assert.assertEquals(versionInfo.getVersion(), "3-2-1+001", "getVersion(3-2-1+001)"); Assert.assertEquals(versionInfo.getVersion(), "3-2-1+001", "getVersion(3-2-1+001)");
Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(),
"getVersion(3-2-1+001) = getSemver(3-2-1+001) ");
} }
@Test @Test
@ -122,6 +125,8 @@ public class VersionInfoTest {
Assert.assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)"); Assert.assertEquals(versionInfo.getVersion(), "1.2.3-alpha+001", "getVersion(1.2.3-alpha+001)");
Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(), "getVersion() = getSemver()");
versionInfo.setBuildMetaPrefix(""); versionInfo.setBuildMetaPrefix("");
Assert.assertEquals(versionInfo.getBuildMetaPrefix(), "", "getBuildMetaPrefix( )"); Assert.assertEquals(versionInfo.getBuildMetaPrefix(), "", "getBuildMetaPrefix( )");
@ -188,6 +193,9 @@ public class VersionInfoTest {
+ version.buildMeta(), + version.buildMeta(),
"getVersion(version)"); "getVersion(version)");
Assert.assertEquals(versionInfo.getVersion(), versionInfo.getSemver(),
"getVersion(version) = getSemver(version)");
Assert.assertEquals(versionInfo.getProject(), version.project(), "getProject(project)"); Assert.assertEquals(versionInfo.getProject(), version.project(), "getProject(project)");
Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)"); Assert.assertEquals(versionInfo.getClassName(), version.className(), "getClassName(className)");