Fail fast and include pakcage.json

This commit is contained in:
2026-01-06 03:40:05 +01:00
parent e886a3600b
commit c67fdb94f2
2 changed files with 22 additions and 16 deletions

11
pom.xml
View File

@@ -128,6 +128,17 @@
</dependencies> </dependencies>
<build> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>package.json</include>
</includes>
</resource>
</resources>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@@ -62,12 +62,11 @@ public class VersionService {
} }
private String resolveClientVersion() { private String resolveClientVersion() {
String packageJsonVersion = getPackageJsonVersion(); try {
if (packageJsonVersion != null && !packageJsonVersion.isBlank()) { return getPackageJsonVersion();
return packageJsonVersion; } catch (IOException e) {
throw new IllegalStateException("Client manifest is missing", e);
} }
return serverVersion;
} }
private String normalizeReleaseVersion(String baseVersion) { private String normalizeReleaseVersion(String baseVersion) {
@@ -159,13 +158,12 @@ public class VersionService {
return null; return null;
} }
private String getPackageJsonVersion() { private String getPackageJsonVersion() throws IOException {
Path packageJsonPath = Paths.get("package.json"); Path packageJsonPath = Paths.get("package.json");
if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) { if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) {
return null; return null;
} }
try {
String packageJson = Files.readString(packageJsonPath, StandardCharsets.UTF_8); String packageJson = Files.readString(packageJsonPath, StandardCharsets.UTF_8);
Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson); Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson);
if (matcher.find()) { if (matcher.find()) {
@@ -174,9 +172,6 @@ public class VersionService {
return version.trim(); return version.trim();
} }
} }
} catch (IOException e) {
LOG.warn("Unable to read version from package.json", e);
}
return null; return null;
} }