Skip to content

Commit

Permalink
internal/load-version-from-file (#488)
Browse files Browse the repository at this point in the history
* Load version from the specific file and show content in the root endpoint.

* Fixed checkstyle issue

* DO not log anything if the VERSION file does not exist. Added VERSION file path into cfg property.

* Append every line into final String.
  • Loading branch information
milanmajchrak committed Jun 19, 2024
1 parent 8a21ff1 commit 9a45f30
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@

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

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

import org.apache.commons.lang3.StringUtils;
import org.dspace.app.rest.model.RootRest;
import org.dspace.services.ConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -19,6 +26,7 @@
*/
@Component
public class RootConverter {
private static final Logger log = LoggerFactory.getLogger(RootConverter.class);

@Autowired
private ConfigurationService configurationService;
Expand All @@ -29,6 +37,37 @@ public RootRest convert() {
rootRest.setDspaceUI(configurationService.getProperty("dspace.ui.url"));
rootRest.setDspaceServer(configurationService.getProperty("dspace.server.url"));
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,8 @@ public class RootRest extends RestAddressableModel {
private String dspaceServer;
private String dspaceVersion;

private String buildVersion;

public String getCategory() {
return CATEGORY;
}
Expand Down Expand Up @@ -67,6 +69,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 @@ -76,6 +86,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 @@ -88,6 +99,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/clarin-dspace.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,7 @@ file.preview.enabled = false
### Storage service ###
# Synchronization is NOT enabled by default
sync.storage.service.enabled = true


### The build version is stored in the specific file ###
build.version.file.path = dspace/config/VERSION_D.txt

0 comments on commit 9a45f30

Please sign in to comment.