diff --git a/plugins/tasks/ansible/pom.xml b/plugins/tasks/ansible/pom.xml index c4c7d05ede..eaac1baa2e 100644 --- a/plugins/tasks/ansible/pom.xml +++ b/plugins/tasks/ansible/pom.xml @@ -65,10 +65,6 @@ slf4j-api provided - - org.ini4j - ini4j - diff --git a/plugins/tasks/ansible/src/main/java/com/walmartlabs/concord/plugins/ansible/AnsibleConfig.java b/plugins/tasks/ansible/src/main/java/com/walmartlabs/concord/plugins/ansible/AnsibleConfig.java index 93465cc8fd..03baac7464 100644 --- a/plugins/tasks/ansible/src/main/java/com/walmartlabs/concord/plugins/ansible/AnsibleConfig.java +++ b/plugins/tasks/ansible/src/main/java/com/walmartlabs/concord/plugins/ansible/AnsibleConfig.java @@ -21,13 +21,10 @@ */ import com.walmartlabs.concord.common.ConfigurationUtils; -import org.ini4j.Ini; -import org.ini4j.Profile; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; @@ -37,6 +34,7 @@ import static com.walmartlabs.concord.sdk.MapUtils.getMap; import static com.walmartlabs.concord.sdk.MapUtils.getString; +import static java.nio.charset.StandardCharsets.UTF_8; public class AnsibleConfig { @@ -87,7 +85,7 @@ public Path write() { Path cfgPath = getConfigPath(); try { - Files.write(cfgPath, b.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE); + Files.write(cfgPath, b.toString().getBytes(UTF_8), StandardOpenOption.CREATE); } catch (IOException e) { log.error("Configuration write {} error", CFG_FILE_NAME, e); throw new RuntimeException("Configuration write error: " + e.getMessage()); @@ -186,21 +184,43 @@ private static StringBuilder addCfgSection(StringBuilder b, String name, Map> loadFromFile(Path file) { try { - Ini ini = new Ini(); - ini.load(file.toFile()); - - Map> result = new HashMap<>(); - for (Map.Entry e : ini.entrySet()) { - Map section = new HashMap<>(); - for (Map.Entry s : e.getValue().entrySet()) { - section.put(s.getKey(), s.getValue()); - } - result.put(e.getKey(), section); - } - return result; + return parseIniFile(file); } catch (IOException e) { log.error("Configuration parse error: {}", e.getMessage()); throw new RuntimeException("Configuration parse error " + file + ": " + e.getMessage()); } } + + private static Map> parseIniFile(Path file) throws IOException { + Map> result = new HashMap<>(); + Map currentSection = null; + for (String line : Files.readAllLines(file, UTF_8)) { + line = line.trim(); + + if (line.isEmpty() || line.startsWith("#") || line.startsWith(";")) { + continue; + } + + if (line.startsWith("[") && line.endsWith("]")) { + String sectionName = line.substring(1, line.length() - 1).trim(); + currentSection = new HashMap<>(); + result.put(sectionName, currentSection); + continue; + } + + if (currentSection != null && line.contains("=")) { + int equalIndex = line.indexOf("="); + String key = line.substring(0, equalIndex).trim(); + String value = line.substring(equalIndex + 1).trim(); + + if ((value.startsWith("\"") && value.endsWith("\"")) || + (value.startsWith("'") && value.endsWith("'"))) { + value = value.substring(1, value.length() - 1); + } + + currentSection.put(key, value); + } + } + return result; + } } diff --git a/targetplatform/pom.xml b/targetplatform/pom.xml index ac77d3a6ae..bd141fe2c9 100644 --- a/targetplatform/pom.xml +++ b/targetplatform/pom.xml @@ -65,7 +65,6 @@ 4.4.13 4.5.11 2.9.3 - 0.5.4 2.18.3 1.0.39 2.18.3 @@ -989,11 +988,6 @@ config ${config.version} - - org.ini4j - ini4j - ${ini4j.version} - org.javers javers-core