Added packageName annotation element.

This commit is contained in:
Erik C. Thauvin 2017-04-26 11:19:01 -07:00
parent 2810a402b0
commit c65c0033e2
4 changed files with 19 additions and 13 deletions

View file

@ -112,18 +112,19 @@ Please also look at this [example](https://github.com/ethauvin/mobibot/blob/mast
The following annotation elements and properties are available:
Element | Property | Description | Default
:------------|:---------------------|:----------------------------------|:----------------
`project` | `version.project` | The project name. |
`major` | `version.major` | The major version number. | `1`
`minor` | `version.major` | The minor version number. | `0`
`patch` | `version.patch` | The patch version number. | `0`
`preRelease` | `version.prerelease` | The pre-release version. |
`buildMeta` | `version.buildmeta` | The build metadata version. |
`className` | | The name of the generated class. | `GeneratedVersion`
`properties` | | The properties file. |
`template` | | The template file. | `version.mustache`
`type` | | Either `java` or `kt` for Kotlin. | `java`
Element | Property | Description | Default
:-------------|:---------------------|:----------------------------------|:-------------------------
`project` | `version.project` | The project name. |
`major` | `version.major` | The major version number. | `1`
`minor` | `version.major` | The minor version number. | `0`
`patch` | `version.patch` | The patch version number. | `0`
`preRelease` | `version.prerelease` | The pre-release version. |
`buildMeta` | `version.buildmeta` | The build metadata version. |
`packageName` | | The package name. | _Same as annotated class_
`className` | | The name of the generated class. | `GeneratedVersion`
`properties` | | The properties file. |
`template` | | The template file. | `version.mustache`
`type` | | Either `java` or `kt` for Kotlin. | `java`
In order to easily incorporate with existing projects, the property keys may be assigned custom values:

View file

@ -62,6 +62,8 @@ public @interface Version {
int patch() default Constants.DEFAULT_PATCH;
String packageName() default Constants.EMPTY;
String patchKey() default Constants.KEY_VERSION_PATCH;
String preRelease() default Constants.EMPTY;

View file

@ -78,6 +78,7 @@ public class VersionInfo {
preRelease = version.preRelease();
project = version.project();
className = version.className();
packageName = version.packageName();
}
/**

View file

@ -156,7 +156,9 @@ public class VersionProcessor extends AbstractProcessor {
final PackageElement packageElement = (PackageElement) enclosingElement;
try {
final VersionInfo versionInfo = findValues(version);
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
if (version.packageName().equals(Constants.EMPTY)) {
versionInfo.setPackageName(packageElement.getQualifiedName().toString());
}
note("Found version: " + versionInfo.getVersion());
final String template;
if (version.template().equals(Constants.DEFAULT_JAVA_TEMPLATE) &&