Added version.projects property.
Added README.md.
This commit is contained in:
parent
aeee81544c
commit
57116e691f
15 changed files with 218 additions and 67 deletions
|
@ -64,6 +64,8 @@ public final class Constants
|
|||
|
||||
public static final String KEY_VERSION_PRERELEASE = "version.prerelease";
|
||||
|
||||
public static final String KEY_VERSION_PROJECT = "version.project";
|
||||
|
||||
public static final String VELOCITY_PROPERTIES = "velocity.properties";
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,6 +71,10 @@ public @interface Version
|
|||
|
||||
String prereleaseKey() default Constants.KEY_VERSION_PRERELEASE;
|
||||
|
||||
String project() default Constants.EMPTY;
|
||||
|
||||
String projectKey() default Constants.KEY_VERSION_PROJECT;
|
||||
|
||||
String properties() default Constants.EMPTY;
|
||||
|
||||
String template() default Constants.DEFAULT_TEMPLATE;
|
||||
|
|
|
@ -54,6 +54,8 @@ public class VersionInfo
|
|||
|
||||
private String prerelease;
|
||||
|
||||
private String project;
|
||||
|
||||
public VersionInfo()
|
||||
{
|
||||
major = Constants.DEFAULT_MAJOR;
|
||||
|
@ -61,6 +63,7 @@ public class VersionInfo
|
|||
patch = Constants.DEFAULT_PATCH;
|
||||
buildmeta = Constants.EMPTY;
|
||||
prerelease = Constants.EMPTY;
|
||||
project = Constants.EMPTY;
|
||||
}
|
||||
|
||||
public VersionInfo(final Version version)
|
||||
|
@ -70,6 +73,7 @@ public class VersionInfo
|
|||
patch = version.patch();
|
||||
buildmeta = version.buildmeta();
|
||||
prerelease = version.prerelease();
|
||||
project = version.project();
|
||||
}
|
||||
|
||||
public String getBuildMetadata()
|
||||
|
@ -127,6 +131,16 @@ public class VersionInfo
|
|||
this.prerelease = prerelease;
|
||||
}
|
||||
|
||||
public String getProject()
|
||||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(String project)
|
||||
{
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public String getVersion()
|
||||
{
|
||||
return "" + major + '.' + minor + '.' + patch + (prerelease.length() > 0 ? '-' + prerelease : "") + (
|
||||
|
|
|
@ -93,6 +93,7 @@ public class VersionProcessor extends AbstractProcessor
|
|||
{
|
||||
p.load(reader);
|
||||
|
||||
versionInfo.setProject(p.getProperty(version.projectKey(), Constants.EMPTY));
|
||||
versionInfo.setMajor(parseIntProperty(p, version.majorKey(), Constants.DEFAULT_MAJOR));
|
||||
versionInfo.setMinor(parseIntProperty(p, version.minorKey(), Constants.DEFAULT_MINOR));
|
||||
versionInfo.setPatch(parseIntProperty(p, version.patchKey(), Constants.DEFAULT_PATCH));
|
||||
|
@ -151,15 +152,15 @@ public class VersionProcessor extends AbstractProcessor
|
|||
@Override
|
||||
public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv)
|
||||
{
|
||||
for (final Element annotatedElement : roundEnv.getElementsAnnotatedWith(Version.class))
|
||||
for (final Element element : roundEnv.getElementsAnnotatedWith(Version.class))
|
||||
{
|
||||
final Version version = annotatedElement.getAnnotation(Version.class);
|
||||
if (annotatedElement.getKind() == ElementKind.CLASS)
|
||||
final Version version = element.getAnnotation(Version.class);
|
||||
if (element.getKind() == ElementKind.CLASS)
|
||||
{
|
||||
final Element enclosing = annotatedElement.getEnclosingElement();
|
||||
if (enclosing.getKind() == ElementKind.PACKAGE)
|
||||
final Element enclosingElement = element.getEnclosingElement();
|
||||
if (enclosingElement.getKind() == ElementKind.PACKAGE)
|
||||
{
|
||||
final PackageElement packageElement = (PackageElement) enclosing;
|
||||
final PackageElement packageElement = (PackageElement) enclosingElement;
|
||||
try
|
||||
{
|
||||
final VersionInfo versionInfo = findValues(version);
|
||||
|
@ -224,6 +225,7 @@ public class VersionProcessor extends AbstractProcessor
|
|||
final VelocityContext vc = new VelocityContext();
|
||||
vc.put("packageName", packageName);
|
||||
vc.put("className", className);
|
||||
vc.put("project", versionInfo.getProject());
|
||||
vc.put("buildmeta", versionInfo.getBuildMetadata());
|
||||
vc.put("epoch", versionInfo.getEpoch());
|
||||
vc.put("patch", versionInfo.getPatch());
|
||||
|
|
|
@ -18,6 +18,7 @@ public final class ${className} {
|
|||
private final static int minor = ${minor};
|
||||
private final static int patch = ${patch};
|
||||
private final static String prerelease = "${prerelease}";
|
||||
private final static String project = "${project}";
|
||||
|
||||
/**
|
||||
* Returns the build date.
|
||||
|
@ -77,6 +78,15 @@ public final class ${className} {
|
|||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the project name.
|
||||
*
|
||||
* @return The project name, if any.
|
||||
*/
|
||||
public static String getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the build metadata.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue