From abe78fdb638fb09d1d220e0a7e2ff2ebcf62fde5 Mon Sep 17 00:00:00 2001 From: themooks Date: Sat, 9 Aug 2025 21:59:45 +0200 Subject: [PATCH 1/2] Java SDK: replacing ini4j dependency with commons-configuratioN1 --- .../templates/Configuration.mustache | 51 ++++++++++++++----- resources/sdk/purecloudjava/templates/pom.xml | 8 +-- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/resources/sdk/purecloudjava/templates/Configuration.mustache b/resources/sdk/purecloudjava/templates/Configuration.mustache index 78cbb268b..5ef40e878 100644 --- a/resources/sdk/purecloudjava/templates/Configuration.mustache +++ b/resources/sdk/purecloudjava/templates/Configuration.mustache @@ -6,8 +6,11 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; -import org.ini4j.Ini; +import org.apache.commons.configuration2.INIConfiguration; +import org.apache.commons.configuration2.SubnodeConfiguration; import java.util.Map; +import java.util.HashSet; +import java.util.Set; public class Configuration { private static ApiClient defaultApiClient = null; @@ -196,7 +199,7 @@ public class Configuration { private class ConfigurationParser { private String filePath; private FileFormat fileFormat; - private Ini iniData; + private INIConfiguration iniData; private Map jsonData; public ConfigurationParser(String filePath) { @@ -207,14 +210,25 @@ public class Configuration { private boolean read() { boolean emptyData = true; try { - byte[] data = Files.readAllBytes(Paths.get(filePath)); - String contents = new String(data).replaceAll("\\\\", "/"); - InputStream stream = new ByteArrayInputStream(contents.getBytes()); - - iniData = new Ini(stream); - + iniData = new INIConfiguration(); + FileReader fileReader = new FileReader(filePath); + iniData.read(fileReader); fileFormat = FileFormat.INI; emptyData = iniData.isEmpty(); + if (emptyData == true || iniData.getSections().isEmpty() == true || (iniData.getSections().size() == 1 && iniData.getSections().contains(null))) { + throw new Exception("Empty Ini file"); + } + if (iniData.getSections().contains(null)) { + Set sectionNames = new HashSet<>(); + for (String name : iniData.getSections()) { + if (name != null) { + sectionNames.add(name); + } + } + if (sectionNames.isEmpty()) { + throw new Exception("Empty Ini file"); + } + } } catch (FileNotFoundException e) { return false; } catch (Exception e) { @@ -294,8 +308,11 @@ public class Configuration { private String getIniString(String section, String key) { try { - Ini.Section sectionData = iniData.get(section); - return sectionData.get(key).trim(); + SubnodeConfiguration sectionData = iniData.getSection(section); + if (sectionData == null) { + return ""; + } + return sectionData.getProperty(key).toString().trim(); } catch (Exception e) { return ""; } @@ -303,8 +320,11 @@ public class Configuration { private boolean getIniBool(String section, String key) { try { - Ini.Section sectionData = iniData.get(section); - return Boolean.parseBoolean(sectionData.get(key).trim()); + SubnodeConfiguration sectionData = iniData.getSection(section); + if (sectionData == null) { + return false; + } + return Boolean.parseBoolean(sectionData.getProperty(key).toString().trim()); } catch (Exception e) { return false; } @@ -312,8 +332,11 @@ public class Configuration { private int getIniInt(String section, String key) { try { - Ini.Section sectionData = iniData.get(section); - return Integer.parseInt(sectionData.get(key).trim()); + SubnodeConfiguration sectionData = iniData.getSection(section); + if (sectionData == null) { + return -1; + } + return Integer.parseInt(sectionData.getProperty(key).toString().trim()); } catch (Exception e) { return -1; } diff --git a/resources/sdk/purecloudjava/templates/pom.xml b/resources/sdk/purecloudjava/templates/pom.xml index e9af179eb..92e7f3aee 100644 --- a/resources/sdk/purecloudjava/templates/pom.xml +++ b/resources/sdk/purecloudjava/templates/pom.xml @@ -251,9 +251,9 @@ ${slf4j-version} - org.ini4j - ini4j - ${ini4j-version} + org.apache.commons + commons-configuration2 + ${commons-configuration-version} @@ -365,7 +365,7 @@ 2.14 33.4.8-jre 5.18.0 - 0.5.4 + 2.12.0 4.2.3.Final ${props.name} From 2225b24d554290b63f0b44a6625b84414ee5b516 Mon Sep 17 00:00:00 2001 From: themooks Date: Sun, 10 Aug 2025 08:30:17 +0200 Subject: [PATCH 2/2] Update --- .../sdk/purecloudjava/templates/Configuration.mustache | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/resources/sdk/purecloudjava/templates/Configuration.mustache b/resources/sdk/purecloudjava/templates/Configuration.mustache index 5ef40e878..467348942 100644 --- a/resources/sdk/purecloudjava/templates/Configuration.mustache +++ b/resources/sdk/purecloudjava/templates/Configuration.mustache @@ -215,12 +215,16 @@ public class Configuration { iniData.read(fileReader); fileFormat = FileFormat.INI; emptyData = iniData.isEmpty(); - if (emptyData == true || iniData.getSections().isEmpty() == true || (iniData.getSections().size() == 1 && iniData.getSections().contains(null))) { + if (emptyData == true) { throw new Exception("Empty Ini file"); } - if (iniData.getSections().contains(null)) { + Set iniSections = iniData.getSections(); + if (iniSections.isEmpty() == true || (iniSections.size() == 1 && iniSections.contains(null))) { + throw new Exception("Empty Ini file"); + } + if (iniSections.contains(null)) { Set sectionNames = new HashSet<>(); - for (String name : iniData.getSections()) { + for (String name : iniSections) { if (name != null) { sectionNames.add(name); }