Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit a491c77

Browse files
committed
Show Title and Version of package in Status
1 parent 8523269 commit a491c77

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ compileTestKotlin {
2828
}
2929

3030
group 'de.debuglevel.sparkmicroserviceutils'
31-
version '0.0.14'
31+
version '0.0.16'
3232

3333
sourceCompatibility = 1.8
3434

@@ -91,6 +91,7 @@ bintray {
9191
key = System.getenv('BINTRAY_API_KEY')
9292
publications = ['javaMaven']
9393
publish = true
94+
override = true
9495
pkg {
9596
repo = 'maven'
9697
name = 'sparkmicroserviceutils'

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip

src/main/kotlin/de/debuglevel/microservices/utils/status/Status.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,31 @@ var status = "up"
1111

1212
/**
1313
* Sets a path to /status/ which returns a JSON object about the current server status and environment information
14+
* @param clazz A class of the package to show the "version" and "title" attributes for (usually a class of your microservice).
1415
*/
15-
fun status() {
16+
fun status(clazz: Class<*>) {
1617
logger.info("Activating path /status/")
1718

1819
Spark.path("/status") {
1920
get("/") {
2021
logger.info("Got request for /status/")
2122

2223
type(contentType = "application/json")
23-
buildStatusJson()
24+
buildStatusJson(clazz)
2425
}
2526
}
2627
}
2728

28-
private fun buildStatusJson(): String {
29+
/**
30+
* @param clazz A class of the package to show the "version" and "title" attributes for.
31+
*/
32+
private fun buildStatusJson(clazz: Class<*>): String {
2933
return """
3034
{
3135
"status":"$status",
3236
"uptime":"${getUptime()}",
37+
"version":"${Version.getVersion(clazz)}",
38+
"title":"${Version.getTitle(clazz)}",
3339
"jvmName":"${ManagementFactory.getRuntimeMXBean().name}",
3440
"jvmSpecName":"${ManagementFactory.getRuntimeMXBean().specName}",
3541
"jvmSpecVendor":"${ManagementFactory.getRuntimeMXBean().specVendor}",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package de.debuglevel.microservices.utils.status
2+
3+
object Version {
4+
/**
5+
* Gets the version (as defined in the MANIFEST.MF) of a package which contains a class.
6+
*
7+
* Depending on the method of creating a shadowed/fat jar, this may always be the value of the main package even if the class does not belong to the main package.
8+
*
9+
* @param clazz A class of the package to inspect
10+
*/
11+
fun getVersion(clazz: Class<*>) = clazz.getPackage().implementationVersion ?: "unknown version"
12+
13+
/**
14+
* Gets the title (as defined in the MANIFEST.MF) of a package which contains a class.
15+
*
16+
* Depending on the method of creating a shadowed/fat jar, this may always be the value of the main package even if the class does not belong to the main package.
17+
*
18+
* @param clazz A class of the package to inspect
19+
*/
20+
fun getTitle(clazz: Class<*>) = clazz.getPackage().implementationTitle ?: "unknown title"
21+
}

0 commit comments

Comments
 (0)