Skip to content

Commit

Permalink
Update to SnakeYaml 2.0 (#12993)
Browse files Browse the repository at this point in the history
* Revert "Downgrade to SnakeYaml 1.33 due incompatibility with Spring 5 (#12921)"

This reverts commit 0a8e6c6.

* Use Correct SafeConstructor
  • Loading branch information
puneetbehl authored May 18, 2023
1 parent 35dd03d commit 96ac170
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,6 @@ subprojects { project ->
documentation
}

configurations {
all {
/*Spring framework {@link org.springframework.beans.factory.config.*/
resolutionStrategy.force 'org.yaml:snakeyaml:1.33'
}
}

ext.isTestSuite = project.name.startsWith("grails-test-suite")
ext.isCiBuild = project.hasProperty("isCiBuild") || System.getenv().get("CI") as Boolean
ext.pomInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ static String convertValidPropertyMethodSuffix(String suffix) {
* @return true if it is a javabean property getter
* @deprecated use {@link #isGetter(String, Class, Class[])} instead because this method has a defect for "is.." method with Boolean return types.
*/
@Deprecated
public static boolean isGetter(String name, Class<?>[] args) {
return isGetter(name, boolean.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.codehaus.groovy.runtime.DefaultGroovyMethods
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor
import org.yaml.snakeyaml.representer.Representer


/**
Expand Down Expand Up @@ -154,7 +157,7 @@ class CodeGenConfig implements Cloneable, ConfigMap {

@CompileDynamic // fails with CompileStatic!
void loadYml(InputStream input) {
Yaml yaml = new Yaml(new SafeConstructor())
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()))
for(Object yamlObject : yaml.loadAll(input)) {
if(yamlObject instanceof Map) { // problem here with CompileStatic
mergeMap((Map)yamlObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import groovy.transform.CompileStatic
import groovy.transform.InheritConstructors
import org.gradle.tooling.ProjectConnection
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor
import org.yaml.snakeyaml.representer.Representer
Expand All @@ -37,7 +38,7 @@ abstract class MapReadingCachedGradleOperation <V> extends CachedGradleOperation
@Override
Map<String, V> readFromCached(File f) {
def map = (Map<String, Object>) f.withReader { BufferedReader r ->
new Yaml(new SafeConstructor()).load(r)
new Yaml(new SafeConstructor(new LoaderOptions())).load(r)
}
Map<String, V> newMap = [:]

Expand All @@ -61,7 +62,7 @@ abstract class MapReadingCachedGradleOperation <V> extends CachedGradleOperation
return [(key):val.toString()]
}
}
new Yaml(new SafeConstructor(), new Representer(), options).dump(toWrite, writer)
new Yaml(new SafeConstructor(new LoaderOptions()), new Representer(options), options).dump(toWrite, writer)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.grails.cli.profile.commands.DefaultMultiStepCommand
import org.grails.cli.profile.commands.script.GroovyScriptCommand
import org.grails.config.NavigableMap
import org.grails.io.support.Resource
import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor

Expand Down Expand Up @@ -110,7 +111,7 @@ abstract class AbstractProfile implements Profile {

protected void initialize() {
def profileYml = profileDir.createRelative("profile.yml")
Map<String, Object> profileConfig = new Yaml(new SafeConstructor()).<Map<String, Object>> load(profileYml.getInputStream())
Map<String, Object> profileConfig = new Yaml(new SafeConstructor(new LoaderOptions())).<Map<String, Object>> load(profileYml.getInputStream())

name = profileConfig.get("name")?.toString()
description = profileConfig.get("description")?.toString() ?: ''
Expand Down Expand Up @@ -140,7 +141,7 @@ abstract class AbstractProfile implements Profile {
else if(fileName.endsWith('.yml')) {
def yamlCommand = profileDir.createRelative("commands/$fileName")
if(yamlCommand.exists()) {
Map<String, Object> data = new Yaml(new SafeConstructor()).<Map>load(yamlCommand.getInputStream())
Map<String, Object> data = new Yaml(new SafeConstructor(new LoaderOptions())).<Map>load(yamlCommand.getInputStream())
Command cmd = new DefaultMultiStepCommand(clsName.toString(), this, data)
Object minArguments = data?.minArguments
cmd.minArguments = minArguments instanceof Integer ? (Integer)minArguments : 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import groovy.transform.ToString
import org.eclipse.aether.graph.Dependency
import org.grails.config.NavigableMap
import org.grails.io.support.Resource
import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor

Expand Down Expand Up @@ -50,7 +51,7 @@ class DefaultFeature implements Feature {
this.name = name
this.location = location
def featureYml = location.createRelative("feature.yml")
Map<String, Object> featureConfig = new Yaml(new SafeConstructor()).<Map<String, Object>>load(featureYml.getInputStream())
Map<String, Object> featureConfig = new Yaml(new SafeConstructor(new LoaderOptions())).<Map<String, Object>>load(featureYml.getInputStream())
configuration.merge(featureConfig)
def dependenciesConfig = configuration.get("dependencies")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.grails.cli.profile.Command
import org.grails.cli.profile.Profile
import org.grails.cli.profile.commands.DefaultMultiStepCommand
import org.grails.io.support.Resource
import org.yaml.snakeyaml.LoaderOptions
import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.SafeConstructor

Expand All @@ -36,7 +37,7 @@ import java.util.regex.Pattern
*/
@CompileStatic
class YamlCommandFactory extends ResourceResolvingCommandFactory<Map> {
protected Yaml yamlParser=new Yaml(new SafeConstructor())
protected Yaml yamlParser=new Yaml(new SafeConstructor(new LoaderOptions()))
// LAX parser for JSON: http://mrhaki.blogspot.ie/2014/08/groovy-goodness-relax-groovy-will-parse.html
protected JsonSlurper jsonSlurper = new JsonSlurper().setType(JsonParserType.LAX)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public static View resolveView(HttpServletRequest request, String viewName, Stri
/**
* @deprecated Does not take into account the url converter
*/
@Deprecated
public static String addViewPrefix(String viewName) {
GrailsWebRequest webRequest = GrailsWebRequest.lookup();
return addViewPrefix(viewName, webRequest != null ? webRequest.getControllerName() : null);
Expand Down

0 comments on commit 96ac170

Please sign in to comment.