From 8af49dc6b7f27261f67018d0b9e5355a4721d76a Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 10 Sep 2019 08:57:04 -0400 Subject: [PATCH] WIP: update version number in ACA banner following upgrade --- .../main/java/hirs/utils/VersionHelper.java | 34 ++++++++++++++----- HIRS_Utils/src/main/resources/VERSION | 1 + .../java/hirs/utils/VersionHelperTest.java | 5 ++- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 120000 HIRS_Utils/src/main/resources/VERSION diff --git a/HIRS_Utils/src/main/java/hirs/utils/VersionHelper.java b/HIRS_Utils/src/main/java/hirs/utils/VersionHelper.java index f8e05c1c..36d4f9be 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/VersionHelper.java +++ b/HIRS_Utils/src/main/java/hirs/utils/VersionHelper.java @@ -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; } } diff --git a/HIRS_Utils/src/main/resources/VERSION b/HIRS_Utils/src/main/resources/VERSION new file mode 120000 index 00000000..a4e94850 --- /dev/null +++ b/HIRS_Utils/src/main/resources/VERSION @@ -0,0 +1 @@ +../../../../VERSION \ No newline at end of file diff --git a/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java b/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java index e18095d0..364a0b55 100644 --- a/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java +++ b/HIRS_Utils/src/test/java/hirs/utils/VersionHelperTest.java @@ -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, ""); } /**