Skip to content

Commit 1990af9

Browse files
committed
ansible-tasks: remove ini4j dependency
1 parent 2034ae3 commit 1990af9

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

plugins/tasks/ansible/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@
6565
<artifactId>slf4j-api</artifactId>
6666
<scope>provided</scope>
6767
</dependency>
68-
<dependency>
69-
<groupId>org.ini4j</groupId>
70-
<artifactId>ini4j</artifactId>
71-
</dependency>
7268

7369
<!-- Immutables -->
7470
<dependency>

plugins/tasks/ansible/src/main/java/com/walmartlabs/concord/plugins/ansible/AnsibleConfig.java

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
*/
2222

2323
import com.walmartlabs.concord.common.ConfigurationUtils;
24-
import org.ini4j.Ini;
25-
import org.ini4j.Profile;
2624
import org.slf4j.Logger;
2725
import org.slf4j.LoggerFactory;
2826

2927
import java.io.IOException;
30-
import java.nio.charset.StandardCharsets;
3128
import java.nio.file.Files;
3229
import java.nio.file.Path;
3330
import java.nio.file.StandardOpenOption;
@@ -37,6 +34,7 @@
3734

3835
import static com.walmartlabs.concord.sdk.MapUtils.getMap;
3936
import static com.walmartlabs.concord.sdk.MapUtils.getString;
37+
import static java.nio.charset.StandardCharsets.UTF_8;
4038

4139
public class AnsibleConfig {
4240

@@ -87,7 +85,7 @@ public Path write() {
8785

8886
Path cfgPath = getConfigPath();
8987
try {
90-
Files.write(cfgPath, b.toString().getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE);
88+
Files.write(cfgPath, b.toString().getBytes(UTF_8), StandardOpenOption.CREATE);
9189
} catch (IOException e) {
9290
log.error("Configuration write {} error", CFG_FILE_NAME, e);
9391
throw new RuntimeException("Configuration write error: " + e.getMessage());
@@ -186,21 +184,43 @@ private static StringBuilder addCfgSection(StringBuilder b, String name, Map<Str
186184

187185
private Map<String, Map<String, Object>> loadFromFile(Path file) {
188186
try {
189-
Ini ini = new Ini();
190-
ini.load(file.toFile());
191-
192-
Map<String, Map<String, Object>> result = new HashMap<>();
193-
for (Map.Entry<String, Profile.Section> e : ini.entrySet()) {
194-
Map<String, Object> section = new HashMap<>();
195-
for (Map.Entry<String, String> s : e.getValue().entrySet()) {
196-
section.put(s.getKey(), s.getValue());
197-
}
198-
result.put(e.getKey(), section);
199-
}
200-
return result;
187+
return parseIniFile(file);
201188
} catch (IOException e) {
202189
log.error("Configuration parse error: {}", e.getMessage());
203190
throw new RuntimeException("Configuration parse error " + file + ": " + e.getMessage());
204191
}
205192
}
193+
194+
private static Map<String, Map<String, Object>> parseIniFile(Path file) throws IOException {
195+
Map<String, Map<String, Object>> result = new HashMap<>();
196+
Map<String, Object> currentSection = null;
197+
for (String line : Files.readAllLines(file, UTF_8)) {
198+
line = line.trim();
199+
200+
if (line.isEmpty() || line.startsWith("#") || line.startsWith(";")) {
201+
continue;
202+
}
203+
204+
if (line.startsWith("[") && line.endsWith("]")) {
205+
String sectionName = line.substring(1, line.length() - 1).trim();
206+
currentSection = new HashMap<>();
207+
result.put(sectionName, currentSection);
208+
continue;
209+
}
210+
211+
if (currentSection != null && line.contains("=")) {
212+
int equalIndex = line.indexOf("=");
213+
String key = line.substring(0, equalIndex).trim();
214+
String value = line.substring(equalIndex + 1).trim();
215+
216+
if ((value.startsWith("\"") && value.endsWith("\"")) ||
217+
(value.startsWith("'") && value.endsWith("'"))) {
218+
value = value.substring(1, value.length() - 1);
219+
}
220+
221+
currentSection.put(key, value);
222+
}
223+
}
224+
return result;
225+
}
206226
}

targetplatform/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<httpcore.version>4.4.13</httpcore.version>
6666
<httpmime.version>4.5.11</httpmime.version>
6767
<immutables.version>2.9.3</immutables.version>
68-
<ini4j.version>0.5.4</ini4j.version>
6968
<jackson.databind.version>2.18.3</jackson.databind.version>
7069
<jackson.jsonschema.version>1.0.39</jackson.jsonschema.version>
7170
<jackson.version>2.18.3</jackson.version>
@@ -989,11 +988,6 @@
989988
<artifactId>config</artifactId>
990989
<version>${config.version}</version>
991990
</dependency>
992-
<dependency>
993-
<groupId>org.ini4j</groupId>
994-
<artifactId>ini4j</artifactId>
995-
<version>${ini4j.version}</version>
996-
</dependency>
997991
<dependency>
998992
<groupId>org.javers</groupId>
999993
<artifactId>javers-core</artifactId>

0 commit comments

Comments
 (0)