From a0ba8ed2769896e6892d824e00416ea3d7d9a354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Ladst=C3=A4tter?= Date: Sun, 3 Sep 2023 20:41:34 +0200 Subject: [PATCH] #149: adds build information to about screen --- app/pom.xml | 4 +++ .../scala/app/logorrr/util/CpResource.scala | 18 +---------- .../main/scala/app/logorrr/util/ImageCp.scala | 18 +++++++++++ .../app/logorrr/views/about/AboutScreen.scala | 31 +++++++++++++++++-- .../app/logorrr/views/menubar/HelpMenu.scala | 2 +- core/pom.xml | 1 + pom.xml | 22 +++++++++++++ 7 files changed, 76 insertions(+), 20 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 7dcbfeaa..94511501 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -83,6 +83,10 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + net.alchim31.maven scala-maven-plugin diff --git a/app/src/main/scala/app/logorrr/util/CpResource.scala b/app/src/main/scala/app/logorrr/util/CpResource.scala index ce20ac68..59a19537 100644 --- a/app/src/main/scala/app/logorrr/util/CpResource.scala +++ b/app/src/main/scala/app/logorrr/util/CpResource.scala @@ -1,19 +1,3 @@ package app.logorrr.util -import java.io.InputStream - -abstract class CpResource(value: String) { - - /** - * returns a inputstream handle to this classpath address - * - * @param clazz class whose classloader is used to load the resource - * @return - */ - def inputStream(clazz: Class[_]): InputStream = { - val r = clazz.getResourceAsStream(value) - require(Option(r).isDefined, s"'$value' does not exist.") - r - } - -} +abstract class CpResource(value: String) diff --git a/app/src/main/scala/app/logorrr/util/ImageCp.scala b/app/src/main/scala/app/logorrr/util/ImageCp.scala index d7c87644..1ad62d14 100644 --- a/app/src/main/scala/app/logorrr/util/ImageCp.scala +++ b/app/src/main/scala/app/logorrr/util/ImageCp.scala @@ -2,6 +2,24 @@ package app.logorrr.util import javafx.scene.image.{Image, ImageView} +import java.util.Properties + + +case class PropsCp(classPathResource : String) extends CpResource(classPathResource) { + + def asProperties(clazz: Class[_]): Properties = { + val properties = new Properties() + val is = clazz.getResourceAsStream(classPathResource) + try { + properties.load(is) + } finally { + Option(is).foreach(_.close) + } + properties + } + +} + case class ImageCp(value: String, width: Int, height: Int) extends CpResource(value) { def imageView(): ImageView = new ImageView(new Image(value, width, height, true, true, true)) diff --git a/app/src/main/scala/app/logorrr/views/about/AboutScreen.scala b/app/src/main/scala/app/logorrr/views/about/AboutScreen.scala index b144ecc5..26df1e4b 100644 --- a/app/src/main/scala/app/logorrr/views/about/AboutScreen.scala +++ b/app/src/main/scala/app/logorrr/views/about/AboutScreen.scala @@ -1,11 +1,14 @@ package app.logorrr.views.about import app.logorrr.meta.AppMeta -import app.logorrr.util.{HLink, ImageCp, LogoRRRFonts} +import app.logorrr.util.{HLink, ImageCp, LogoRRRFonts, PropsCp} import javafx.geometry.{Insets, Pos} import javafx.scene.control._ import javafx.scene.image.ImageView -import javafx.scene.layout.{BorderPane, VBox} +import javafx.scene.layout.{BorderPane, HBox, VBox} + +import java.time.format.DateTimeFormatter +import java.time.{Instant, ZoneId} object AboutScreen { @@ -34,6 +37,26 @@ object AboutScreen { } +object BuildProps { + + lazy val Instance = new BuildProps +} + +class BuildProps { + lazy val buildProps = PropsCp("/build.properties").asProperties(getClass) + + lazy val githash = buildProps.getProperty("revision") + + lazy val timestamp: String = { + val PATTERN_FORMAT = "dd.MM.yyyy" + val formatter = DateTimeFormatter.ofPattern(PATTERN_FORMAT) + .withZone(ZoneId.systemDefault()); + val i = Instant.ofEpochMilli(buildProps.getProperty("timestamp").toLong) + formatter.format(i) + } + +} + class AboutScreen extends BorderPane { private def mkLogo(): ImageView = AboutScreen.logo.imageView() @@ -44,5 +67,9 @@ class AboutScreen extends BorderPane { setTop(mkHeader()) setLeft(mkLogo()) setRight(new AboutScreen.HLinkView(AboutScreen.links)) + val hBox = new HBox() + hBox.setAlignment(Pos.CENTER_LEFT) + hBox.getChildren.add(new Label(BuildProps.Instance.timestamp + " " + BuildProps.Instance.githash)) + setBottom(hBox) } diff --git a/app/src/main/scala/app/logorrr/views/menubar/HelpMenu.scala b/app/src/main/scala/app/logorrr/views/menubar/HelpMenu.scala index 4e871429..2bf00971 100644 --- a/app/src/main/scala/app/logorrr/views/menubar/HelpMenu.scala +++ b/app/src/main/scala/app/logorrr/views/menubar/HelpMenu.scala @@ -23,7 +23,7 @@ object HelpMenu { val stage = new Stage() stage.initModality(Modality.APPLICATION_MODAL) stage.setTitle(s"About ${AppMeta.fullAppNameWithVersion}") - val scene = new Scene(new AboutScreen, 440, 210) + val scene = new Scene(new AboutScreen, 440, 250) stage.setScene(scene) stage.setOnCloseRequest(_ => stage.close()) stage.showAndWait() diff --git a/core/pom.xml b/core/pom.xml index 7ed6e499..2511cb75 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -26,6 +26,7 @@ + net.alchim31.maven scala-maven-plugin diff --git a/pom.xml b/pom.xml index 2ade10f6..3c752616 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,12 @@ ${jdk.home}/bin/jpackage + + scm:git:https://github.com/rladstaetter/LogoRRR.git + scm:git:https://github.com/rladstaetter/LogoRRR.git + HEAD + + OS.windows @@ -234,6 +240,22 @@ + + org.codehaus.mojo + buildnumber-maven-plugin + 3.1.0 + + + generate-resources + + create-metadata + + + true + + + + org.apache.maven.plugins