New Property class generation integrated.

master
Markus Kreth 3 years ago
parent ddf835fb5c
commit 374b7ea7d7
  1. 2
      pom.xml
  2. 24
      src/main/java/de/kreth/invoice/Application.java
  3. 76
      src/main/java/de/kreth/invoice/views/FooterComponent.java

@ -200,7 +200,7 @@
<dependency>
<groupId>de.kreth.property2java</groupId>
<artifactId>PropertyToJavaGenerator</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.0.2</version>
</dependency>
</dependencies>

@ -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;
}
}

@ -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<FooterComponent> 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();
}
}

Loading…
Cancel
Save