Skip to content

Commit 1252ea2

Browse files
KasinhouMatus Kasakclaude
authored
JCU/Expose buildVersion on REST root — serving side (#813) (#1417)
* Expose buildVersion on REST root (serving side of deployed-version info) (#813) The Docker build already generates dspace/config/VERSION_D.txt (docker.yml + reusable-docker-build.yml), but nothing exposed it. Add the serving side to match dtq-dev so /server/api reports which commit is deployed: - dspace.cfg: build.version.file.path points at the generated file. - RootConverter reads that file and sets RootRest.buildVersion. - RootRest gains the buildVersion field (getter/setter, equals/hashCode). - dspace/config/VERSION_D.txt committed as an empty placeholder (overwritten at build). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Fix checkstyle import order in RootConverter (java.io before jakarta) (#813) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Align build.version comment in dspace.cfg with dtq-dev Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Matus Kasak <matus.kasak@dataquest.sk> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent eda7f25 commit 1252ea2

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

dspace-server-webapp/src/main/java/org/dspace/app/rest/converter/RootConverter.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
import static org.dspace.app.util.Util.getSourceVersion;
1111

12+
import java.io.BufferedReader;
13+
import java.io.FileReader;
14+
import java.io.IOException;
15+
1216
import jakarta.servlet.http.HttpServletRequest;
1317
import org.apache.commons.lang3.StringUtils;
1418
import org.dspace.app.rest.model.RootRest;
@@ -39,8 +43,37 @@ public RootRest convert(HttpServletRequest request) {
3943
rootRest.setDspaceServer(dspaceUrl);
4044
}
4145
rootRest.setDspaceVersion("DSpace " + getSourceVersion());
46+
rootRest.setBuildVersion(getBuildVersion());
4247
return rootRest;
4348
}
4449

50+
/**
51+
* Read the build version from the `build.version.file.path` property
52+
*
53+
* @return content of the version file
54+
*/
55+
private String getBuildVersion() {
56+
String bVersionFilePath = configurationService.getProperty("build.version.file.path");
57+
58+
if (StringUtils.isBlank(bVersionFilePath)) {
59+
return "Unknown";
60+
}
61+
62+
StringBuilder buildVersion = new StringBuilder();
63+
try {
64+
FileReader fileReader = new FileReader(bVersionFilePath);
65+
BufferedReader bufferedReader = new BufferedReader(fileReader);
4566

67+
String line;
68+
// Read each line from the file until the end of the file is reached
69+
while ((line = bufferedReader.readLine()) != null) {
70+
buildVersion.append(line);
71+
}
72+
73+
} catch (IOException e) {
74+
// Empty - do not log anything
75+
}
76+
77+
return buildVersion.toString();
78+
}
4679
}

dspace-server-webapp/src/main/java/org/dspace/app/rest/model/RootRest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class RootRest extends RestAddressableModel {
2222
private String dspaceName;
2323
private String dspaceServer;
2424
private String dspaceVersion;
25+
private String buildVersion;
2526

2627
public String getCategory() {
2728
return CATEGORY;
@@ -76,6 +77,14 @@ public void setDspaceVersion(String dspaceVersion) {
7677
this.dspaceVersion = dspaceVersion;
7778
}
7879

80+
public String getBuildVersion() {
81+
return buildVersion;
82+
}
83+
84+
public void setBuildVersion(String buildVersion) {
85+
this.buildVersion = buildVersion;
86+
}
87+
7988
@Override
8089
public boolean equals(Object object) {
8190
return (object instanceof RootRest &&
@@ -85,6 +94,7 @@ public boolean equals(Object object) {
8594
.append(this.getDspaceUI(), ((RootRest) object).getDspaceUI())
8695
.append(this.getDspaceName(), ((RootRest) object).getDspaceName())
8796
.append(this.getDspaceServer(), ((RootRest) object).getDspaceServer())
97+
.append(this.getBuildVersion(), ((RootRest) object).getBuildVersion())
8898
.isEquals());
8999
}
90100

@@ -97,6 +107,7 @@ public int hashCode() {
97107
.append(this.getDspaceName())
98108
.append(this.getDspaceUI())
99109
.append(this.getDspaceServer())
110+
.append(this.getBuildVersion())
100111
.toHashCode();
101112
}
102113
}

dspace/config/VERSION_D.txt

Whitespace-only changes.

dspace/config/dspace.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ dspace.ui.url = http://localhost:4000
4242
dspace.name = DSpace Jihočeské Univerzity v Českých Budějovicích
4343
dspace.shortname = DSpace
4444

45+
### The build version is stored in the specific file ###
46+
build.version.file.path = ${dspace.dir}/config/VERSION_D.txt
47+
4548
# Assetstore configurations have moved to config/modules/assetstore.cfg
4649
# and config/spring/api/bitstore.xml.
4750
# Additional storage options (e.g. Amazon S3) are available in `assetstore.cfg`

0 commit comments

Comments
 (0)