From 374b7ea7d7b0237989b1107156b24c11a48a846a Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Wed, 21 Dec 2022 23:10:39 +0100 Subject: [PATCH] New Property class generation integrated. --- pom.xml | 2 +- .../java/de/kreth/invoice/Application.java | 24 ++---- .../kreth/invoice/views/FooterComponent.java | 76 +++++-------------- 3 files changed, 23 insertions(+), 79 deletions(-) diff --git a/pom.xml b/pom.xml index d4179f1..22e6738 100644 --- a/pom.xml +++ b/pom.xml @@ -200,7 +200,7 @@ de.kreth.property2java PropertyToJavaGenerator - 2.0.1-SNAPSHOT + 2.0.2 diff --git a/src/main/java/de/kreth/invoice/Application.java b/src/main/java/de/kreth/invoice/Application.java index b60d628..59dc078 100644 --- a/src/main/java/de/kreth/invoice/Application.java +++ b/src/main/java/de/kreth/invoice/Application.java @@ -1,18 +1,17 @@ package de.kreth.invoice; -import java.util.PropertyResourceBundle; -import java.util.ResourceBundle; - import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.context.annotation.Bean; import com.vaadin.flow.component.dependency.NpmPackage; import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.server.PWA; import com.vaadin.flow.theme.Theme; +import de.kreth.property2java.processor.Format; +import de.kreth.property2java.processor.GenerateProperty2Java; + /** * The entry point of the Spring Boot application. * @@ -24,27 +23,14 @@ import com.vaadin.flow.theme.Theme; @Theme(value = "trainerinvoice") @PWA(name = "trainerinvoice", shortName = "trainerinvoice", offlineResources = {}) @NpmPackage(value = "line-awesome", version = "1.3.0") +@GenerateProperty2Java(resources = { "version.properties", + "localization.properties" }, format = Format.WithInnerPropertyLoader) public class Application extends SpringBootServletInitializer implements AppShellConfigurator { private static final long serialVersionUID = 8632833774084603989L; - private static ResourceBundle bundle = null; public static void main(String[] args) { SpringApplication.run(Application.class, args); } - public static String getString(Localization_Properties property) { - if (bundle == null) { - bundle = resourceBundle(); - } - - return property.getString(bundle::getString); - } - - @Bean - static ResourceBundle resourceBundle() { - - ResourceBundle bundle = PropertyResourceBundle.getBundle("localization"); - return bundle; - } } diff --git a/src/main/java/de/kreth/invoice/views/FooterComponent.java b/src/main/java/de/kreth/invoice/views/FooterComponent.java index 3fcad89..607f9a8 100644 --- a/src/main/java/de/kreth/invoice/views/FooterComponent.java +++ b/src/main/java/de/kreth/invoice/views/FooterComponent.java @@ -3,13 +3,10 @@ package de.kreth.invoice.views; import static de.kreth.invoice.Version_Properties.BUILD_DATETIME; import static de.kreth.invoice.Version_Properties.PROJECT_VERSION; -import java.io.IOException; -import java.net.URL; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,8 +14,6 @@ import org.slf4j.LoggerFactory; import com.vaadin.flow.component.formlayout.FormLayout; import com.vaadin.flow.component.html.Label; -import de.kreth.invoice.Version_Properties; - public class FooterComponent extends FormLayout { private static final long serialVersionUID = 4845822203421115202L; @@ -26,68 +21,31 @@ public class FooterComponent extends FormLayout { private static final Logger LOGGER = LoggerFactory .getLogger(FooterComponent.class); - private static final Properties VERSION = new Properties(); - static { - String path = "/version.properties"; - try { - recursivelyLoadPropFromPath(FooterComponent.class, path, 0); - } catch (Exception e) { - LOGGER.error("Error loading version properties file = " + path - + ", cause: " + e.getMessage()); - } - } - - private static void recursivelyLoadPropFromPath( - Class thisClass, String path, int level) - throws IOException { - - URL resource = thisClass.getResource(path); - if (resource != null) { - VERSION.load(resource.openStream()); - LOGGER.info("Successfully loaded version info from " + resource); - } else if (level < 4) { - recursivelyLoadPropFromPath(thisClass, "/.." + path, level + 1); - } else { - throw new IOException("File not Found in any subdir of " + path); - } - - } - public FooterComponent() { Label copyright = new Label("\u00a9 Markus Kreth\u00A0"); copyright.addClassName("formlayout-spacing"); add(copyright); - if (propertiesLoaded()) { - - String dateTimeProperty = getString(BUILD_DATETIME); - SimpleDateFormat sourceFormat = new SimpleDateFormat( - "yyyy-MM-dd HH:mm:ss"); - try { - Date date = sourceFormat.parse(dateTimeProperty); - dateTimeProperty = DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, DateFormat.SHORT).format(date); - } catch (ParseException e) { - LOGGER.warn( - "Unable to parse dateTimeProperty=" + dateTimeProperty, - e); - } - Label vers = new Label( - "\u00A0Version: " + getString(PROJECT_VERSION)); - Label buildTime = new Label("\u00A0Build: " + dateTimeProperty); - vers.addClassName("formlayout-spacing"); - buildTime.addClassName("formlayout-spacing"); - add(vers, buildTime); + String dateTimeProperty = BUILD_DATETIME.getText(); + SimpleDateFormat sourceFormat = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss"); + try { + Date date = sourceFormat.parse(dateTimeProperty); + dateTimeProperty = DateFormat.getDateTimeInstance( + DateFormat.MEDIUM, DateFormat.SHORT).format(date); + } catch (ParseException e) { + LOGGER.warn( + "Unable to parse dateTimeProperty=" + dateTimeProperty, + e); } + Label vers = new Label( + "\u00A0Version: " + PROJECT_VERSION.getText()); + Label buildTime = new Label("\u00A0Build: " + dateTimeProperty); + vers.addClassName("formlayout-spacing"); + buildTime.addClassName("formlayout-spacing"); + add(vers, buildTime); } - private boolean propertiesLoaded() { - return !VERSION.isEmpty() && !getString(BUILD_DATETIME).contains("${"); - } - - private String getString(Version_Properties prop) { - return prop.getText(); - } }