Skip to content
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

Use yaml instance instead of static variable to enable threadsaftey #1246

Open
wants to merge 2 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 @@ -48,14 +48,12 @@ abstract class ApplicationManifestUtilsCommon {

static final int GIBI = 1_024;

static final Yaml YAML;
static final DumperOptions dumperOptions;

static {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
dumperOptions.setExplicitStart(true);

YAML = new Yaml(dumperOptions);
}

static final Pattern FIND_VARIABLE_REGEX = Pattern.compile("\\(\\(([a-zA-Z]\\w+)\\)\\)");
Expand Down Expand Up @@ -276,10 +274,12 @@ static void asString(

@SuppressWarnings("unchecked")
static Map<String, Object> deserialize(Path path) {
Yaml yaml = new Yaml(dumperOptions);

AtomicReference<Map<String, Object>> root = new AtomicReference<>();

try (InputStream in = Files.newInputStream(path, StandardOpenOption.READ)) {
root.set((Map<String, Object>) YAML.load(in));
root.set((Map<String, Object>) yaml.load(in));
} catch (IOException e) {
throw Exceptions.propagate(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@
* Utilities for dealing with {@link ManifestV3}s. Includes the functionality to transform to and from standard CLI YAML files.
*/
public final class ApplicationManifestUtilsV3 extends ApplicationManifestUtilsCommon {
private static final Yaml YAML;
private static final DumperOptions dumperOptions;

static {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
dumperOptions.setExplicitStart(true);

YAML = new Yaml(dumperOptions);
}

private static final Pattern FIND_VARIABLE_REGEX =
Expand Down Expand Up @@ -104,9 +102,10 @@ public static void write(Path path, ManifestV3 manifest) {
* @param out the {@link OutputStream} to write to
* @param manifest the manifest to write
*/
public static void write(OutputStream out, ManifestV3 manifest) {
public static void write(OutputStream out, ManifestV3 manifest) {
Yaml yaml = new Yaml(dumperOptions);
try (Writer writer = new OutputStreamWriter(out)) {
YAML.dump(toYaml(manifest), writer);
yaml.dump(toYaml(manifest), writer);
} catch (IOException e) {
throw Exceptions.propagate(e);
}
Expand Down