Skip to content

Disable snakeyml warning for duplicate keys #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.Map;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;

/**
Expand Down Expand Up @@ -76,7 +77,30 @@ public class Configuration {

public final Report report;

private static final Yaml yaml = new Yaml();
private static Yaml yaml = new Yaml(defaultLoaderOptions());

/**
* Custom loader options to disable warning for duplicate key (which is not helpful, because
* it's intended behaviour to merge keys from multiple files)
*/
private static LoaderOptions defaultLoaderOptions() {
LoaderOptions loaderOptions = new LoaderOptions();

loaderOptions.setAllowDuplicateKeys(true);

return loaderOptions;
}

/**
* Used to disable warnings on duplicate keys. Occurs when providing an additional configuration file.
*/
static void disableWarnOnDuplicateKeys() {
LoaderOptions loaderOptions = defaultLoaderOptions();

loaderOptions.setWarnOnDuplicateKeys(false);

yaml = new Yaml(loaderOptions);
}

public static Configuration fromDefaultConfig() {
return fromInputStream(resourceAsStream(DEFAULT_CONFIG), DEFAULT_SUCCESS_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@

public class BenchmarkScoreTest {

private static final String SEP = System.getProperty("line.separator");
private static final String SEP = System.lineSeparator();
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final PrintStream originalOut = System.out;

@BeforeEach
public void setUpStreams() {
System.setOut(new PrintStream(outContent));
Configuration.disableWarnOnDuplicateKeys();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public void setUp() {

out = new ByteArrayOutputStream();
System.setOut(new PrintStream(out));

Configuration.disableWarnOnDuplicateKeys();
}

@Test
Expand Down