From 36c3093cdc4a585710f7c45cd4bf55948f90df55 Mon Sep 17 00:00:00 2001 From: "im.b" Date: Mon, 8 Jan 2024 16:24:35 +0900 Subject: [PATCH] Change yaml parser --- ngrinder-controller/build.gradle | 2 +- .../service/GitHubFileEntryService.java | 35 ++++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/ngrinder-controller/build.gradle b/ngrinder-controller/build.gradle index a0dace928..1faa1c1f0 100644 --- a/ngrinder-controller/build.gradle +++ b/ngrinder-controller/build.gradle @@ -59,7 +59,7 @@ dependencies { implementation (group: "jaxen", name: "jaxen", version: "1.1.4") implementation (group: "com.beust", name: "jcommander", version: "1.32") implementation (group: "org.pf4j", name: "pf4j", version: "3.0.1") - implementation (group: "org.yaml", name: "snakeyaml", version: "1.25") + implementation (group: "com.esotericsoftware.yamlbeans", name: "yamlbeans", version: "1.17") implementation (group: "commons-collections", name: "commons-collections", version: "3.2.1") implementation (group: "org.reflections", name: "reflections", version: "0.9.9") implementation (group: "com.hazelcast", name: "hazelcast", version: hazelcast_version) diff --git a/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java b/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java index f9529cd7f..d96b3f74f 100644 --- a/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java +++ b/ngrinder-controller/src/main/java/org/ngrinder/script/service/GitHubFileEntryService.java @@ -1,5 +1,6 @@ package org.ngrinder.script.service; +import com.esotericsoftware.yamlbeans.YamlReader; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; @@ -26,7 +27,6 @@ import org.tmatesoft.svn.core.SVNURL; import org.tmatesoft.svn.core.auth.BasicAuthenticationManager; import org.tmatesoft.svn.core.wc.*; -import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.FileNotFoundException; @@ -278,25 +278,26 @@ public Set getAllGitHubConfig(User user) throws FileNotFoundExcept return getAllGithubConfig(gitConfigYaml); } - private Set getAllGithubConfig(FileEntry gitConfigYaml) { + protected Set getAllGithubConfig(FileEntry gitConfigYaml) { Set gitHubConfig = new HashSet<>(); - // Yaml is not thread safe. so create it every time. - Yaml yaml = new Yaml(); - Iterable> gitConfigs = cast(yaml.loadAll(gitConfigYaml.getContent())); - for (Map configMap : gitConfigs) { - if (configMap == null) { - continue; - } - configMap.put("revision", gitConfigYaml.getRevision()); - GitHubConfig config = objectMapper.convertValue(configMap, GitHubConfig.class); + try (YamlReader reader = new YamlReader(gitConfigYaml.getContent())) { + Map gitConfigMap = cast(reader.read()); + while (gitConfigMap != null) { + gitConfigMap.put("revision", gitConfigYaml.getRevision()); + GitHubConfig config = objectMapper.convertValue(gitConfigMap, GitHubConfig.class); + + if (gitHubConfig.contains(config)) { + throw new InvalidGitHubConfigurationException("GitHub configuration '" + + config.getName() + "' is duplicated.\nPlease check your .gitconfig.yml"); + } - if (gitHubConfig.contains(config)) { - throw new InvalidGitHubConfigurationException("GitHub configuration '" - + config.getName() + "' is duplicated.\nPlease check your .gitconfig.yml"); - } + gitHubConfig.add(config); - gitHubConfig.add(config); - } + gitConfigMap = cast(reader.read()); + } + } catch (IOException e) { + throw new InvalidGitHubConfigurationException("Fail to read GitHub configuration.", e); + } return gitHubConfig; }