hotfix version check

This commit is contained in:
kirill.labutin 2025-10-06 15:00:39 +03:00
parent c072256b33
commit e6a835d552
1 changed files with 19 additions and 6 deletions

View File

@ -6,7 +6,9 @@ import ru.kirillius.utils.logging.SystemLogger;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
@ -50,18 +52,27 @@ public class AppUpdateService extends AppService {
.build(); .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}. * Determines the current application version using the nearest {@code pom.xml}.
* *
* @return semantic version string or {@code "unknown"} when unavailable. * @return semantic version string or {@code "unknown"} when unavailable.
*/ */
public String getAppVersion() { public String getAppVersion() {
var pomPath = findPomFile();
if (pomPath == null) { try (var input = openPomFile()) {
SystemLogger.error("Unable to locate pom.xml to determine application version", CTX);
return "unknown";
}
try (var input = Files.newInputStream(pomPath)) {
var factory = DocumentBuilderFactory.newInstance(); var factory = DocumentBuilderFactory.newInstance();
try { try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
@ -230,6 +241,8 @@ public class AppUpdateService extends AppService {
return null; 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. * Extracts a version value from the given XML element if present.
*/ */