From 5e3ab59dada1ecd90164242fa5b676fc6b88fed8 Mon Sep 17 00:00:00 2001 From: chubtub <43381989+chubtub@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:36:01 -0500 Subject: [PATCH] Clean up Main class for readability --- .../src/main/java/hirs/swid/Main.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java b/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java index eed95b4a..688be2fb 100644 --- a/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java +++ b/tools/tcg_rim_tool/src/main/java/hirs/swid/Main.java @@ -31,17 +31,7 @@ public class Main { String version = new String(content); System.out.println("TCG rimtool version: " + version); } catch (IOException e) { - System.out.println("Installation file VERSION not found."); - String filename = new File(Main.class.getProtectionDomain() - .getCodeSource() - .getLocation() - .getPath()).getName(); - Pattern pattern = Pattern.compile("(?<=tcg_rim_tool-)[0-9]\\.[0-9]\\.[0-9]"); - Matcher matcher = pattern.matcher(filename); - if (matcher.find()) { - System.out.println("TCG rimtool version: " + matcher.group()); - } - + parseVersionFromJar(); } } else { if (!commander.getVerifyFile().isEmpty()) { @@ -127,4 +117,21 @@ public class Main { } } } + + /** + * This method parses the version number from the jar filename in the absence of + * the VERSION file expected with an rpm installation. + */ + private static void parseVersionFromJar() { + System.out.println("Installation file VERSION not found."); + String filename = new File(Main.class.getProtectionDomain() + .getCodeSource() + .getLocation() + .getPath()).getName(); + Pattern pattern = Pattern.compile("(?<=tcg_rim_tool-)[0-9]\\.[0-9]\\.[0-9]"); + Matcher matcher = pattern.matcher(filename); + if (matcher.find()) { + System.out.println("TCG rimtool version: " + matcher.group()); + } + } }