From fbede2207ccf6ad68eb3adf82831a3582c7c0e1b Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 12 Apr 2017 19:28:59 -0700 Subject: [PATCH] Added semver annotation processor. --- kobalt/src/Build.kt | 58 ++++--- .../java/com/example/GeneratedVersion.java | 157 ++++++++++++++++++ src/main/java/com/example/Main.java | 5 +- 3 files changed, 196 insertions(+), 24 deletions(-) create mode 100644 src/generated/java/com/example/GeneratedVersion.java diff --git a/kobalt/src/Build.kt b/kobalt/src/Build.kt index fcb87df..723b234 100644 --- a/kobalt/src/Build.kt +++ b/kobalt/src/Build.kt @@ -1,17 +1,20 @@ import com.beust.kobalt.* -import com.beust.kobalt.plugin.apt.* -import com.beust.kobalt.plugin.packaging.* -import com.beust.kobalt.plugin.publish.* -import com.beust.kobalt.plugin.application.* -import com.beust.kobalt.plugin.java.* +import com.beust.kobalt.plugin.application.application +import com.beust.kobalt.plugin.apt.apt +import com.beust.kobalt.plugin.packaging.assemble +import com.beust.kobalt.plugin.packaging.install +import com.beust.kobalt.plugin.publish.autoGitTag +import com.beust.kobalt.plugin.publish.bintray import org.apache.maven.model.* val bs = buildScript { repos() } -val processorJar = file("K:\\java\\semver\\deploy\\semver-0.9.7.jar") +val processorJar = "net.thauvin.erik:semver:0.9.6-beta" +val mainClassName = "com.example.Main" +val lib = "lib" val p = project { @@ -37,17 +40,10 @@ val p = project { }) } - sourceDirectories { - path("src/main/java") - } - - sourceDirectoriesTest { - path("src/test/java") - } - dependencies { - apt(processorJar) - compile("org.apache.velocity:velocity:1.7", processorJar) + apt(processorJar) + compile("org.twitter4j:twitter4j-core:4.0.6") + compileOnly(processorJar) } dependenciesTest { @@ -57,13 +53,13 @@ val p = project { assemble { jar { - } - } - - install { - libDir = "deploy" - collect(compileDependencies).forEach { - copy(it.absolutePath, to("${libDir}/lib")) + manifest { + attributes("Main-Class", mainClassName) + attributes("Class-Path", + collect(compileDependencies) + .map { it.file.name } + .joinToString(" ./$lib/", prefix = ". ./$lib/")) + } } } @@ -71,6 +67,22 @@ val p = project { mainClass = "com.example.Main" } + install { + target = "deploy" + include(from("kobaltBuild/libs"), to(target), glob("**/*")) + collect(compileDependencies).forEach { + copy(from(it.file.absolutePath), to("$target/$lib")) + } + } + + apt { + outputDir = "src/generated/java/" + } + + application { + mainClass = mainClassName + } + autoGitTag { enabled = true message = "Version $version" diff --git a/src/generated/java/com/example/GeneratedVersion.java b/src/generated/java/com/example/GeneratedVersion.java new file mode 100644 index 0000000..75d2688 --- /dev/null +++ b/src/generated/java/com/example/GeneratedVersion.java @@ -0,0 +1,157 @@ +/* + * This file is automatically generated. + * Do not modify! -- ALL CHANGES WILL BE ERASED! + */ +package com.example; + +import java.util.Date; + +/** + * Provides semantic version information. + * + * @author Semantic Version + * Annotation Processor + */ +public final class GeneratedVersion { + private final static String buildmeta = ""; + private final static Date date = new Date(1492033276280L); + private final static int major = 1; + private final static int minor = 0; + private final static int patch = 0; + private final static String prerelease = "beta"; + private final static String project = ""; + + /** + * Disables the default constructor. + * + * @throws UnsupportedOperationException If the constructor is called. + */ + private GeneratedVersion() + throws UnsupportedOperationException { + throw new UnsupportedOperationException("Illegal constructor call."); + } + + /** + * Returns the build date. + * + * @return The build date. + */ + public static Date getBuildDate() { + return date; + } + + /** + * Returns the project name. + * + * @return The project name, if any. + */ + public static String getProject() { + return project; + } + + /** + * Returns the full version string. + *

+ * Formatted as: + *

+ * MAJOR.MINOR.PATCH[-PRERELEASE][+BUILDMETADATA] + *
+ *

+ * For example: + *

+ * + * @return The version string. + */ + public static String getVersion() { + return Integer.toString(getMajor()) + '.' + + Integer.toString(getMinor()) + '.' + + Integer.toString(getPatch()) + + getPreRelease(true) + getBuildMetadata(true); + } + + /** + * Returns the major version. + * + * @return The major version. + */ + public static int getMajor() { + return major; + } + + /** + * Returns the minor version. + * + * @return The minor version. + */ + public static int getMinor() { + return minor; + } + + /** + * Returns the patch version. + * + * @return The patch version. + */ + public static int getPatch() { + return patch; + } + + /** + * Returns the pre-release version. + * + * @param isHyphen Prepend a hyphen, if true. + * @return The pre-release version, if any. + */ + public static String getPreRelease(final boolean isHyphen) { + if (prerelease.length() > 0) { + if (isHyphen) { + return '-' + prerelease; + } else { + return prerelease; + } + } + + return ""; + } + + /** + * Returns the pre-release version. + * + * @return The pre-release version, if any. + */ + public static String getPreRelease() { + return getPreRelease(false); + } + + /** + * Returns the build metadata. + * + * @param isPlus Prepend a plus sign, if true. + * @return The build metadata, if any. + */ + public static String getBuildMetadata(final boolean isPlus) { + if (buildmeta.length() > 0) { + if (isPlus) { + return '+' + buildmeta; + } else { + return buildmeta; + } + } + + return ""; + } + + /** + * Returns the build metadata. + * + * @return The build metadata, if any. + */ + public static String getBuildMetadata() { + return getBuildMetadata(false); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/Main.java b/src/main/java/com/example/Main.java index c07945d..9ad5eeb 100644 --- a/src/main/java/com/example/Main.java +++ b/src/main/java/com/example/Main.java @@ -1,7 +1,10 @@ package com.example; +import net.thauvin.erik.semver.Version; + +@Version(major = 1, minor = 0, patch = 0, prerelease = "beta") class Main { public static void main(String[] argv) { - System.out.println("\n\nHello Java world from Kobalt\n\n"); + System.out.println(GeneratedVersion.getVersion()); } } \ No newline at end of file