From: David ‘Bombe’ Roden Date: Sat, 7 Oct 2017 15:54:02 +0000 (+0200) Subject: Only parse the version once X-Git-Tag: 0.9.7^2~3 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=43a2d59f2439428544a6eb858b734e3058ee3ac8;p=Sone.git Only parse the version once --- diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index 60e4292..19db006 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -172,7 +172,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr } public static String getPluginVersion() { - net.pterodactylus.sone.main.Version version = VersionParserKt.parseVersion(); + net.pterodactylus.sone.main.Version version = VersionParserKt.getParsedVersion(); return (version == null) ? "unknown" : version.getNice(); } diff --git a/src/main/kotlin/net/pterodactylus/sone/main/VersionParser.kt b/src/main/kotlin/net/pterodactylus/sone/main/VersionParser.kt index 09e91bd..4ba14f8 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/VersionParser.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/VersionParser.kt @@ -9,6 +9,8 @@ fun parseVersion(file: String = "/version.yaml"): Version? = objectMapper.readValue(it, Version::class.java) } +val parsedVersion by lazy { parseVersion() } + private val objectMapper = ObjectMapper(YAMLFactory()) @NoArg diff --git a/src/test/kotlin/net/pterodactylus/sone/main/VersionParserTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/VersionParserTest.kt index 93861a0..f1702ce 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/VersionParserTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/VersionParserTest.kt @@ -29,4 +29,11 @@ class VersionParserTest { assertThat(version.nice, equalTo("0.9.6-466-g43f3e1c")) } + @Test + fun `parsed version is created correctly`() { + val version = parsedVersion!! + assertThat(version.id, equalTo("43f3e1c3a0f487e37e5851a2cc72756d271c7571")) + assertThat(version.nice, equalTo("0.9.6-466-g43f3e1c")) + } + }