Skip to content

Commit d7781ea

Browse files
committed
Issue 11228: Migrate to SnakeYAML Engine
1 parent 2b53c47 commit d7781ea

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ dependencies {
9292
api 'com.github.docker-java:docker-java-transport-zerodep'
9393

9494
shaded 'com.google.guava:guava:33.3.1-jre'
95-
shaded "org.yaml:snakeyaml:2.5"
95+
shaded "org.snakeyaml:snakeyaml-engine:3.0.1"
9696

9797
shaded 'org.glassfish.main.external:trilead-ssh2-repackaged:4.1.2'
9898

core/src/main/java/org/testcontainers/containers/ParsedDockerComposeFile.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
import lombok.Getter;
77
import lombok.extern.slf4j.Slf4j;
88
import org.apache.commons.io.FileUtils;
9+
import org.snakeyaml.engine.v2.api.Load;
10+
import org.snakeyaml.engine.v2.api.LoadSettings;
11+
import org.snakeyaml.engine.v2.constructor.StandardConstructor;
12+
import org.snakeyaml.engine.v2.nodes.Node;
13+
import org.snakeyaml.engine.v2.nodes.Tag;
914
import org.testcontainers.images.ParsedDockerfile;
10-
import org.yaml.snakeyaml.DumperOptions;
11-
import org.yaml.snakeyaml.LoaderOptions;
12-
import org.yaml.snakeyaml.Yaml;
13-
import org.yaml.snakeyaml.constructor.SafeConstructor;
14-
import org.yaml.snakeyaml.nodes.Node;
15-
import org.yaml.snakeyaml.nodes.Tag;
16-
import org.yaml.snakeyaml.representer.Representer;
17-
import org.yaml.snakeyaml.resolver.Resolver;
1815

1916
import java.io.File;
2017
import java.io.FileInputStream;
@@ -42,12 +39,14 @@ class ParsedDockerComposeFile {
4239
private final Map<String, Set<String>> serviceNameToImageNames = new HashMap<>();
4340

4441
ParsedDockerComposeFile(File composeFile) {
45-
// The default is 50 and a big docker-compose.yml file can easily go above that number. 1,000 should give us some room
46-
LoaderOptions options = new LoaderOptions();
47-
options.setMaxAliasesForCollections(1_000);
48-
DumperOptions dumperOptions = new DumperOptions();
49-
50-
SafeConstructor constructor = new SafeConstructor(options) {
42+
LoadSettings loadSettings = LoadSettings
43+
.builder()
44+
// The default is 50 and a big docker-compose.yml file can easily go above that number.
45+
// 1,000 should give us some room
46+
.setMaxAliasesForCollections(1_000)
47+
.build();
48+
49+
StandardConstructor constructor = new StandardConstructor(loadSettings) {
5150
@Override
5251
protected Object constructObject(Node node) {
5352
if (node.getTag().equals(new Tag("!reset"))) {
@@ -56,9 +55,9 @@ protected Object constructObject(Node node) {
5655
return super.constructObject(node);
5756
}
5857
};
59-
Yaml yaml = new Yaml(constructor, new Representer(dumperOptions), dumperOptions, options, new Resolver());
58+
Load load = new Load(loadSettings, constructor);
6059
try (FileInputStream fileInputStream = FileUtils.openInputStream(composeFile)) {
61-
composeFileContent = yaml.load(fileInputStream);
60+
composeFileContent = (Map<String, Object>) load.loadFromInputStream(fileInputStream);
6261
} catch (Exception e) {
6362
throw new IllegalArgumentException("Unable to parse YAML file from " + composeFile.getAbsolutePath(), e);
6463
}

0 commit comments

Comments
 (0)