Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.RootRest;
Expand Down Expand Up @@ -39,8 +43,37 @@ public RootRest convert(HttpServletRequest request) {
rootRest.setDspaceServer(dspaceUrl);
}
rootRest.setDspaceVersion("DSpace " + getSourceVersion());
rootRest.setBuildVersion(getBuildVersion());
return rootRest;
}

/**
* Read the build version from the `build.version.file.path` property
*
* @return content of the version file
*/
private String getBuildVersion() {
String bVersionFilePath = configurationService.getProperty("build.version.file.path");

if (StringUtils.isBlank(bVersionFilePath)) {
return "Unknown";
}

StringBuilder buildVersion = new StringBuilder();
try {
FileReader fileReader = new FileReader(bVersionFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;
// Read each line from the file until the end of the file is reached
while ((line = bufferedReader.readLine()) != null) {
buildVersion.append(line);
}

} catch (IOException e) {
// Empty - do not log anything
}

return buildVersion.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class RootRest extends RestAddressableModel {
private String dspaceName;
private String dspaceServer;
private String dspaceVersion;
private String buildVersion;

public String getCategory() {
return CATEGORY;
Expand Down Expand Up @@ -76,6 +77,14 @@ public void setDspaceVersion(String dspaceVersion) {
this.dspaceVersion = dspaceVersion;
}

public String getBuildVersion() {
return buildVersion;
}

public void setBuildVersion(String buildVersion) {
this.buildVersion = buildVersion;
}

@Override
public boolean equals(Object object) {
return (object instanceof RootRest &&
Expand All @@ -85,6 +94,7 @@ public boolean equals(Object object) {
.append(this.getDspaceUI(), ((RootRest) object).getDspaceUI())
.append(this.getDspaceName(), ((RootRest) object).getDspaceName())
.append(this.getDspaceServer(), ((RootRest) object).getDspaceServer())
.append(this.getBuildVersion(), ((RootRest) object).getBuildVersion())
.isEquals());
}

Expand All @@ -97,6 +107,7 @@ public int hashCode() {
.append(this.getDspaceName())
.append(this.getDspaceUI())
.append(this.getDspaceServer())
.append(this.getBuildVersion())
.toHashCode();
}
}
Empty file added dspace/config/VERSION_D.txt
Empty file.
4 changes: 4 additions & 0 deletions dspace/config/dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dspace.ui.url = http://localhost:4000
dspace.name = DSpace Jihočeské Univerzity v Českých Budějovicích
dspace.shortname = DSpace

### The build version is stored in the specific file (issue #813) ###
### Exposed as `buildVersion` on the REST root endpoint (/server/api). ###
build.version.file.path = ${dspace.dir}/config/VERSION_D.txt

# Assetstore configurations have moved to config/modules/assetstore.cfg
# and config/spring/api/bitstore.xml.
# Additional storage options (e.g. Amazon S3) are available in `assetstore.cfg`
Expand Down
Loading