From e6a835d5522cbd49e66744eae9519abd2e9037ea Mon Sep 17 00:00:00 2001 From: "kirill.labutin" Date: Mon, 6 Oct 2025 15:00:39 +0300 Subject: [PATCH] hotfix version check --- .../pf/sdn/core/AppUpdateService.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/ru/kirillius/pf/sdn/core/AppUpdateService.java b/core/src/main/java/ru/kirillius/pf/sdn/core/AppUpdateService.java index 5412d99..4508a9b 100644 --- a/core/src/main/java/ru/kirillius/pf/sdn/core/AppUpdateService.java +++ b/core/src/main/java/ru/kirillius/pf/sdn/core/AppUpdateService.java @@ -6,7 +6,9 @@ import ru.kirillius.utils.logging.SystemLogger; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilderFactory; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; @@ -50,18 +52,27 @@ public class AppUpdateService extends AppService { .build(); } + private InputStream openPomFile() throws IOException { + + var stream = getClass().getClassLoader().getResourceAsStream(hardcodedPomPath); + if (stream == null) { + var pomPath = findPomFile(); + if (pomPath == null) { + throw new FileNotFoundException("Unable to locate pom.xml to determine application version"); + } + return Files.newInputStream(pomPath); + } + return stream; + } + /** * Determines the current application version using the nearest {@code pom.xml}. * * @return semantic version string or {@code "unknown"} when unavailable. */ public String getAppVersion() { - var pomPath = findPomFile(); - if (pomPath == null) { - SystemLogger.error("Unable to locate pom.xml to determine application version", CTX); - return "unknown"; - } - try (var input = Files.newInputStream(pomPath)) { + + try (var input = openPomFile()) { var factory = DocumentBuilderFactory.newInstance(); try { factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); @@ -230,6 +241,8 @@ public class AppUpdateService extends AppService { return null; } + private final static String hardcodedPomPath = "META-INF/maven/ru.kirillius/pf-sdn.app/pom.xml"; + /** * Extracts a version value from the given XML element if present. */