WIP: update version number in ACA banner following upgrade

This commit is contained in:
chubtub 2019-09-10 08:57:04 -04:00
parent b140ab46e9
commit 8af49dc6b7
3 changed files with 29 additions and 11 deletions

View File

@ -1,12 +1,13 @@
package hirs.utils;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.File;
import java.io.IOException;
import java.net.URL;
/**
* Utility class to get the current version from the VERSION file.
@ -32,7 +33,8 @@ public final class VersionHelper {
/**
* Get the current version of HIRS_Portal that is installed.
*
* @param filename that contains the version
* @param filename
* that contains the version
* @return A string representing the current version.
*/
public static String getVersion(final String filename) {
@ -43,14 +45,30 @@ public final class VersionHelper {
} catch (IOException | IllegalArgumentException e) {
LOGGER.warn("Error reading version", e);
version = "";
} catch (NullPointerException e) {
LOGGER.warn("File not found: " + filename);
version = "";
}
return version;
}
private static String getFileContents(final String filename)
throws IOException {
/**
* Read the symbolic link to VERSION in the top level HIRS directory.
* @param filename "VERSION"
* @return the version number from the file
* @throws IOException
*/
private static String getFileContents(final String filename) throws IOException {
URL url = Resources.getResource(filename);
return Resources.toString(url, Charsets.UTF_8).trim();
File versionFileLink = new File(VersionHelper.class.getClassLoader()
.getResource(filename).getFile());
String versionFilePath = versionFileLink.getCanonicalPath();
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(versionFilePath), "UTF-8"));
String version = reader.readLine();
reader.close();
return version;
}
}

View File

@ -0,0 +1 @@
../../../../VERSION

View File

@ -14,9 +14,8 @@ public class VersionHelperTest {
@Test
public void testGetVersionFail() {
String actual = VersionHelper.getVersion("somefile");
Assert.assertTrue(actual.startsWith(
""));
String version = VersionHelper.getVersion("somefile");
Assert.assertEquals(version, "");
}
/**