diff --git a/build.gradle b/build.gradle index 39cf4499c73..4b4cc12a202 100644 --- a/build.gradle +++ b/build.gradle @@ -68,12 +68,6 @@ ext { names : ['grails-async', 'grails-events'], modules: ['gpars', 'rxjava', 'rxjava2'] ], - snakeyaml : [ - version: snakeyamlVersion, - group : 'org.yaml', - names : ['snakeyaml'], - modules: [''] - ], spock : [ version: spockVersion, group : 'org.spockframework', diff --git a/gradle.properties b/gradle.properties index e287aea6b32..40b7c5155a2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,6 @@ concurrentlinkedhashmapVersion=1.4.2 springLoadedVersion=1.2.8.RELEASE jnaVersion=4.2.2 slf4jVersion=1.7.25 -snakeyamlVersion=2.2 directoryWatcherVersion=0.5.1 junitVersion=4.12 caffeineVersion=2.6.2 diff --git a/grails-bootstrap/build.gradle b/grails-bootstrap/build.gradle index 3a2acf66258..700b33f111b 100644 --- a/grails-bootstrap/build.gradle +++ b/grails-bootstrap/build.gradle @@ -3,7 +3,7 @@ import org.apache.tools.ant.filters.ReplaceTokens dependencies { compile ( "org.codehaus.groovy:groovy-xml:$groovyVersion" ) compile ( "org.codehaus.groovy:groovy-templates:$groovyVersion" ) - compile "org.yaml:snakeyaml:$snakeyamlVersion" + compile "org.yaml:snakeyaml:1.14" compileOnly("io.methvin:directory-watcher:0.3.0") compileOnly("org.fusesource.jansi:jansi:$jansiVersion") diff --git a/grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy b/grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy index f4b08f49dbf..c3fc4cf90d8 100644 --- a/grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy +++ b/grails-bootstrap/src/main/groovy/grails/util/Metadata.groovy @@ -22,9 +22,7 @@ import org.grails.config.NavigableMap import org.grails.io.support.FileSystemResource import org.grails.io.support.Resource import org.grails.io.support.UrlResource -import org.yaml.snakeyaml.LoaderOptions import org.yaml.snakeyaml.Yaml -import org.yaml.snakeyaml.constructor.SafeConstructor import java.lang.ref.Reference import java.lang.ref.SoftReference @@ -169,7 +167,7 @@ class Metadata extends NavigableMap implements ConfigMap { } private Object loadYml(InputStream input) { - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())) + Yaml yaml = new Yaml() def loadedYaml = yaml.loadAll(input) List result = [] for(Object yamlObject : loadedYaml) { diff --git a/grails-bootstrap/src/main/groovy/org/grails/config/CodeGenConfig.groovy b/grails-bootstrap/src/main/groovy/org/grails/config/CodeGenConfig.groovy index b7eb5aa5514..35f1dd32753 100644 --- a/grails-bootstrap/src/main/groovy/org/grails/config/CodeGenConfig.groovy +++ b/grails-bootstrap/src/main/groovy/org/grails/config/CodeGenConfig.groovy @@ -22,9 +22,7 @@ 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.LoaderOptions import org.yaml.snakeyaml.Yaml -import org.yaml.snakeyaml.constructor.SafeConstructor /** @@ -154,7 +152,7 @@ class CodeGenConfig implements Cloneable, ConfigMap { @CompileDynamic // fails with CompileStatic! void loadYml(InputStream input) { - Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions())) + Yaml yaml = new Yaml() for(Object yamlObject : yaml.loadAll(input)) { if(yamlObject instanceof Map) { // problem here with CompileStatic mergeMap((Map)yamlObject) diff --git a/grails-core/src/main/groovy/org/springframework/beans/factory/config/YamlProcessor.java b/grails-core/src/main/groovy/org/springframework/beans/factory/config/YamlProcessor.java deleted file mode 100644 index 74e2238be1a..00000000000 --- a/grails-core/src/main/groovy/org/springframework/beans/factory/config/YamlProcessor.java +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Copyright 2002-2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.beans.factory.config; - -import java.io.IOException; -import java.io.Reader; -import java.util.AbstractMap; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.yaml.snakeyaml.LoaderOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; -import org.yaml.snakeyaml.nodes.MappingNode; -import org.yaml.snakeyaml.parser.ParserException; -import org.yaml.snakeyaml.reader.UnicodeReader; - -import org.springframework.core.CollectionFactory; -import org.springframework.core.io.Resource; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -/** - * Base class for YAML factories. - * - * @author Dave Syer - * @author Juergen Hoeller - * @since 4.1 - */ -public abstract class YamlProcessor { - - private final Log logger = LogFactory.getLog(getClass()); - - private ResolutionMethod resolutionMethod = ResolutionMethod.OVERRIDE; - - private Resource[] resources = new Resource[0]; - - private List documentMatchers = Collections.emptyList(); - - private boolean matchDefault = true; - - - /** - * A map of document matchers allowing callers to selectively use only - * some of the documents in a YAML resource. In YAML documents are - * separated by --- lines, and each document is converted - * to properties before the match is made. E.g. - *
-     * environment: dev
-     * url: https://dev.bar.com
-     * name: Developer Setup
-     * ---
-     * environment: prod
-     * url:https://foo.bar.com
-     * name: My Cool App
-     * 
- * when mapped with - *
-     * setDocumentMatchers(properties ->
-     *     ("prod".equals(properties.getProperty("environment")) ? MatchStatus.FOUND : MatchStatus.NOT_FOUND));
-     * 
- * would end up as - *
-     * environment=prod
-     * url=https://foo.bar.com
-     * name=My Cool App
-     * 
- */ - public void setDocumentMatchers(DocumentMatcher... matchers) { - this.documentMatchers = Arrays.asList(matchers); - } - - /** - * Flag indicating that a document for which all the - * {@link #setDocumentMatchers(DocumentMatcher...) document matchers} abstain will - * nevertheless match. Default is {@code true}. - */ - public void setMatchDefault(boolean matchDefault) { - this.matchDefault = matchDefault; - } - - /** - * Method to use for resolving resources. Each resource will be converted to a Map, - * so this property is used to decide which map entries to keep in the final output - * from this factory. Default is {@link ResolutionMethod#OVERRIDE}. - */ - public void setResolutionMethod(ResolutionMethod resolutionMethod) { - Assert.notNull(resolutionMethod, "ResolutionMethod must not be null"); - this.resolutionMethod = resolutionMethod; - } - - /** - * Set locations of YAML {@link Resource resources} to be loaded. - * @see ResolutionMethod - */ - public void setResources(Resource... resources) { - this.resources = resources; - } - - - /** - * Provide an opportunity for subclasses to process the Yaml parsed from the supplied - * resources. Each resource is parsed in turn and the documents inside checked against - * the {@link #setDocumentMatchers(DocumentMatcher...) matchers}. If a document - * matches it is passed into the callback, along with its representation as Properties. - * Depending on the {@link #setResolutionMethod(ResolutionMethod)} not all of the - * documents will be parsed. - * @param callback a callback to delegate to once matching documents are found - * @see #createYaml() - */ - protected void process(MatchCallback callback) { - Yaml yaml = createYaml(); - for (Resource resource : this.resources) { - boolean found = process(callback, yaml, resource); - if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND && found) { - return; - } - } - } - - /** - * Create the {@link Yaml} instance to use. - */ - protected Yaml createYaml() { - return new Yaml(new StrictMapAppenderConstructor()); - } - - private boolean process(MatchCallback callback, Yaml yaml, Resource resource) { - int count = 0; - try { - if (logger.isDebugEnabled()) { - logger.debug("Loading from YAML: " + resource); - } - Reader reader = new UnicodeReader(resource.getInputStream()); - try { - for (Object object : yaml.loadAll(reader)) { - if (object != null && process(asMap(object), callback)) { - count++; - if (this.resolutionMethod == ResolutionMethod.FIRST_FOUND) { - break; - } - } - } - if (logger.isDebugEnabled()) { - logger.debug("Loaded " + count + " document" + (count > 1 ? "s" : "") + - " from YAML resource: " + resource); - } - } - finally { - reader.close(); - } - } - catch (IOException ex) { - handleProcessError(resource, ex); - } - return (count > 0); - } - - private void handleProcessError(Resource resource, IOException ex) { - if (this.resolutionMethod != ResolutionMethod.FIRST_FOUND && - this.resolutionMethod != ResolutionMethod.OVERRIDE_AND_IGNORE) { - throw new IllegalStateException(ex); - } - if (logger.isWarnEnabled()) { - logger.warn("Could not load map from " + resource + ": " + ex.getMessage()); - } - } - - @SuppressWarnings("unchecked") - private Map asMap(Object object) { - // YAML can have numbers as keys - Map result = new LinkedHashMap(); - if (!(object instanceof Map)) { - // A document can be a text literal - result.put("document", object); - return result; - } - - Map map = (Map) object; - for (Map.Entry entry : map.entrySet()) { - Object value = entry.getValue(); - if (value instanceof Map) { - value = asMap(value); - } - Object key = entry.getKey(); - if (key instanceof CharSequence) { - result.put(key.toString(), value); - } - else { - // It has to be a map key in this case - result.put("[" + key.toString() + "]", value); - } - } - return result; - } - - private boolean process(Map map, MatchCallback callback) { - Properties properties = CollectionFactory.createStringAdaptingProperties(); - properties.putAll(getFlattenedMap(map)); - - if (this.documentMatchers.isEmpty()) { - if (logger.isDebugEnabled()) { - logger.debug("Merging document (no matchers set): " + map); - } - callback.process(properties, map); - return true; - } - - MatchStatus result = MatchStatus.ABSTAIN; - for (DocumentMatcher matcher : this.documentMatchers) { - MatchStatus match = matcher.matches(properties); - result = MatchStatus.getMostSpecific(match, result); - if (match == MatchStatus.FOUND) { - if (logger.isDebugEnabled()) { - logger.debug("Matched document with document matcher: " + properties); - } - callback.process(properties, map); - return true; - } - } - - if (result == MatchStatus.ABSTAIN && this.matchDefault) { - if (logger.isDebugEnabled()) { - logger.debug("Matched document with default matcher: " + map); - } - callback.process(properties, map); - return true; - } - - if (logger.isDebugEnabled()) { - logger.debug("Unmatched document: " + map); - } - return false; - } - - /** - * Return a flattened version of the given map, recursively following any nested Map - * or Collection values. Entries from the resulting map retain the same order as the - * source. When called with the Map from a {@link MatchCallback} the result will - * contain the same values as the {@link MatchCallback} Properties. - * @param source the source map - * @return a flattened map - * @since 4.1.3 - */ - protected final Map getFlattenedMap(Map source) { - Map result = new LinkedHashMap(); - buildFlattenedMap(result, source, null); - return result; - } - - private void buildFlattenedMap(Map result, Map source, String path) { - for (Map.Entry entry : source.entrySet()) { - String key = entry.getKey(); - if (StringUtils.hasText(path)) { - if (key.startsWith("[")) { - key = path + key; - } - else { - key = path + '.' + key; - } - } - Object value = entry.getValue(); - if (value instanceof String) { - result.put(key, value); - } - else if (value instanceof Map) { - // Need a compound key - @SuppressWarnings("unchecked") - Map map = (Map) value; - buildFlattenedMap(result, map, key); - } - else if (value instanceof Collection) { - // Need a compound key - @SuppressWarnings("unchecked") - Collection collection = (Collection) value; - int count = 0; - for (Object object : collection) { - buildFlattenedMap(result, - Collections.singletonMap("[" + (count++) + "]", object), key); - } - } - else { - result.put(key, (value != null ? value : "")); - } - } - } - - - /** - * Callback interface used to process the YAML parsing results. - */ - public interface MatchCallback { - - /** - * Process the given representation of the parsing results. - * @param properties the properties to process (as a flattened - * representation with indexed keys in case of a collection or map) - * @param map the result map (preserving the original value structure - * in the YAML document) - */ - void process(Properties properties, Map map); - } - - - /** - * Strategy interface used to test if properties match. - */ - public interface DocumentMatcher { - - /** - * Test if the given properties match. - * @param properties the properties to test - * @return the status of the match - */ - MatchStatus matches(Properties properties); - } - - - /** - * Status returned from {@link DocumentMatcher#matches(java.util.Properties)} - */ - public enum MatchStatus { - - /** - * A match was found. - */ - FOUND, - - /** - * No match was found. - */ - NOT_FOUND, - - /** - * The matcher should not be considered. - */ - ABSTAIN; - - /** - * Compare two {@link MatchStatus} items, returning the most specific status. - */ - public static MatchStatus getMostSpecific(MatchStatus a, MatchStatus b) { - return (a.ordinal() < b.ordinal() ? a : b); - } - } - - - /** - * Method to use for resolving resources. - */ - public enum ResolutionMethod { - - /** - * Replace values from earlier in the list. - */ - OVERRIDE, - - /** - * Replace values from earlier in the list, ignoring any failures. - */ - OVERRIDE_AND_IGNORE, - - /** - * Take the first resource in the list that exists and use just that. - */ - FIRST_FOUND - } - - - /** - * A specialized {@link Constructor} that checks for duplicate keys. - */ - protected static class StrictMapAppenderConstructor extends Constructor { - - // Declared as public for use in subclasses - public StrictMapAppenderConstructor() { - super(new LoaderOptions()); - } - - @Override - protected Map constructMapping(MappingNode node) { - try { - return super.constructMapping(node); - } - catch (IllegalStateException ex) { - throw new ParserException("while parsing MappingNode", - node.getStartMark(), ex.getMessage(), node.getEndMark()); - } - } - - @Override - protected Map createDefaultMap(int initSize) { - final Map delegate = super.createDefaultMap(initSize); - return new AbstractMap() { - @Override - public Object put(Object key, Object value) { - if (delegate.containsKey(key)) { - throw new IllegalStateException("Duplicate key: " + key); - } - return delegate.put(key, value); - } - @Override - public Set> entrySet() { - return delegate.entrySet(); - } - }; - } - } - -} diff --git a/grails-core/src/main/groovy/org/springframework/boot/env/YamlPropertySourceLoader.java b/grails-core/src/main/groovy/org/springframework/boot/env/YamlPropertySourceLoader.java deleted file mode 100644 index f751f9dbe0e..00000000000 --- a/grails-core/src/main/groovy/org/springframework/boot/env/YamlPropertySourceLoader.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.env; - -import java.io.IOException; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Properties; -import java.util.regex.Pattern; - -import org.yaml.snakeyaml.DumperOptions; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.nodes.Tag; -import org.yaml.snakeyaml.representer.Representer; -import org.yaml.snakeyaml.resolver.Resolver; - -import org.springframework.beans.factory.config.YamlProcessor; -import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; -import org.springframework.boot.yaml.SpringProfileDocumentMatcher; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.PropertySource; -import org.springframework.core.io.Resource; -import org.springframework.util.ClassUtils; - -/** - * Strategy to load '.yml' (or '.yaml') files into a {@link PropertySource}. - * - * @author Dave Syer - * @author Phillip Webb - * @author Andy Wilkinson - * @since 1.0.0 - */ -public class YamlPropertySourceLoader implements PropertySourceLoader { - - @Override - public String[] getFileExtensions() { - return new String[] { "yml", "yaml" }; - } - - @Override - public PropertySource load(String name, Resource resource, String profile) throws IOException { - if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) { - Processor processor = new Processor(resource, profile); - Map source = processor.process(); - if (!source.isEmpty()) { - return new MapPropertySource(name, source); - } - } - return null; - } - - /** - * {@link YamlProcessor} to create a {@link Map} containing the property values. - * Similar to {@link YamlPropertiesFactoryBean} but retains the order of entries. - */ - private static class Processor extends YamlProcessor { - - Processor(Resource resource, String profile) { - if (profile == null) { - setMatchDefault(true); - setDocumentMatchers(new SpringProfileDocumentMatcher()); - } - else { - setMatchDefault(false); - setDocumentMatchers(new SpringProfileDocumentMatcher(profile)); - } - setResources(resource); - } - - @Override - protected Yaml createYaml() { - return new Yaml(new StrictMapAppenderConstructor(), new Representer(new DumperOptions()), new DumperOptions(), new Resolver() { - @Override - public void addImplicitResolver(Tag tag, Pattern regexp, String first) { - if (tag == Tag.TIMESTAMP) { - return; - } - super.addImplicitResolver(tag, regexp, first); - } - }); - } - - public Map process() { - final Map result = new LinkedHashMap(); - process(new MatchCallback() { - @Override - public void process(Properties properties, Map map) { - result.putAll(getFlattenedMap(map)); - } - }); - return result; - } - - } - -} diff --git a/grails-docs/build.gradle b/grails-docs/build.gradle index b99e78fa1cd..d51d86657ea 100644 --- a/grails-docs/build.gradle +++ b/grails-docs/build.gradle @@ -9,7 +9,7 @@ dependencies { "org.slf4j:jcl-over-slf4j:$slf4jVersion", "org.apache.ant:ant:$antVersion", 'org.grails:grails-gdoc-engine:1.0.1', - "org.yaml:snakeyaml:$snakeyamlVersion", + 'org.yaml:snakeyaml:1.14', "org.codehaus.groovy:groovy-ant:$groovyVersion" compile 'org.asciidoctor:asciidoctorj:1.5.4' diff --git a/grails-docs/src/main/groovy/grails/doc/DocPublisher.groovy b/grails-docs/src/main/groovy/grails/doc/DocPublisher.groovy index e8faf7fe023..a744763b0bc 100644 --- a/grails-docs/src/main/groovy/grails/doc/DocPublisher.groovy +++ b/grails-docs/src/main/groovy/grails/doc/DocPublisher.groovy @@ -24,9 +24,7 @@ import org.apache.commons.logging.LogFactory import org.radeox.api.engine.WikiRenderEngine import org.radeox.engine.context.BaseInitialRenderContext import org.radeox.engine.context.BaseRenderContext -import org.yaml.snakeyaml.LoaderOptions import org.yaml.snakeyaml.Yaml -import org.yaml.snakeyaml.constructor.SafeConstructor import java.util.regex.Pattern @@ -266,7 +264,7 @@ class DocPublisher { def legacyLinks = [:] if (legacyLinksFile.exists()) { legacyLinksFile.withInputStream { input -> - legacyLinks = new Yaml(new SafeConstructor(new LoaderOptions())).load(input) + legacyLinks = new Yaml().load(input) } } @@ -538,7 +536,7 @@ class DocPublisher { } else if(propertiesFile.name.endsWith('.yml')) { propertiesFile.withInputStream { input -> - def ymls = new Yaml(new SafeConstructor(new LoaderOptions())).loadAll(input) + def ymls = new Yaml().loadAll(input) for(yml in ymls) { if(yml instanceof Map) { def config = yml.grails?.doc diff --git a/grails-docs/src/main/groovy/grails/doc/internal/YamlTocStrategy.groovy b/grails-docs/src/main/groovy/grails/doc/internal/YamlTocStrategy.groovy index 07689b58c4c..55f8f30554d 100644 --- a/grails-docs/src/main/groovy/grails/doc/internal/YamlTocStrategy.groovy +++ b/grails-docs/src/main/groovy/grails/doc/internal/YamlTocStrategy.groovy @@ -1,14 +1,12 @@ package grails.doc.internal -import org.yaml.snakeyaml.LoaderOptions import org.yaml.snakeyaml.Yaml -import org.yaml.snakeyaml.constructor.SafeConstructor /** * Class representing a Grails user guide table of contents defined in YAML. */ class YamlTocStrategy { - private final parser = new Yaml(new SafeConstructor(new LoaderOptions())) + private final parser = new Yaml() private resourceChecker private String ext = ".gdoc" diff --git a/grails-shell/src/main/groovy/org/grails/cli/gradle/cache/MapReadingCachedGradleOperation.groovy b/grails-shell/src/main/groovy/org/grails/cli/gradle/cache/MapReadingCachedGradleOperation.groovy index fa0adaef5cc..de1343a2a8c 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/gradle/cache/MapReadingCachedGradleOperation.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/gradle/cache/MapReadingCachedGradleOperation.groovy @@ -20,10 +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 /** @@ -38,7 +35,7 @@ abstract class MapReadingCachedGradleOperation extends CachedGradleOperation @Override Map readFromCached(File f) { def map = (Map) f.withReader { BufferedReader r -> - new Yaml(new SafeConstructor(new LoaderOptions())).load(r) + new Yaml().load(r) } Map newMap = [:] @@ -62,7 +59,7 @@ abstract class MapReadingCachedGradleOperation extends CachedGradleOperation return [(key):val.toString()] } } - new Yaml(new SafeConstructor(new LoaderOptions()), new Representer(options), options).dump(toWrite, writer) + new Yaml(options).dump(toWrite, writer) } } diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy index 35cc6fd3e6b..31c33064530 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/AbstractProfile.groovy @@ -33,9 +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 /** * Abstract implementation of the profile class @@ -109,7 +107,7 @@ abstract class AbstractProfile implements Profile { protected void initialize() { def profileYml = profileDir.createRelative("profile.yml") - Map profileConfig = new Yaml(new SafeConstructor(new LoaderOptions())).> load(profileYml.getInputStream()) + def profileConfig = (Map) new Yaml().loadAs(profileYml.getInputStream(), Map) name = profileConfig.get("name")?.toString() description = profileConfig.get("description")?.toString() ?: '' @@ -139,7 +137,7 @@ abstract class AbstractProfile implements Profile { else if(fileName.endsWith('.yml')) { def yamlCommand = profileDir.createRelative("commands/$fileName") if(yamlCommand.exists()) { - Map data = new Yaml(new SafeConstructor(new LoaderOptions())).load(yamlCommand.getInputStream()) + def data = new Yaml().loadAs(yamlCommand.getInputStream(), Map.class) Command cmd = new DefaultMultiStepCommand(clsName.toString(), this, data) Object minArguments = data?.minArguments cmd.minArguments = minArguments instanceof Integer ? (Integer)minArguments : 1 diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/DefaultFeature.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/DefaultFeature.groovy index bc1b99655f5..fe8cd4fe04b 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/DefaultFeature.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/DefaultFeature.groovy @@ -23,9 +23,7 @@ import org.eclipse.aether.artifact.DefaultArtifact 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 /** @@ -50,7 +48,7 @@ class DefaultFeature implements Feature { this.name = name this.location = location def featureYml = location.createRelative("feature.yml") - Map featureConfig = new Yaml(new SafeConstructor(new LoaderOptions())).>load(featureYml.getInputStream()) + def featureConfig = (Map) new Yaml().loadAs(featureYml.getInputStream(), Map) configuration.merge(featureConfig) def dependencyMap = configuration.get("dependencies") diff --git a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/YamlCommandFactory.groovy b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/YamlCommandFactory.groovy index 3917920bb05..ab7bff35aa2 100644 --- a/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/YamlCommandFactory.groovy +++ b/grails-shell/src/main/groovy/org/grails/cli/profile/commands/factory/YamlCommandFactory.groovy @@ -22,9 +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 import java.util.regex.Pattern @@ -37,7 +35,7 @@ import java.util.regex.Pattern */ @CompileStatic class YamlCommandFactory extends ResourceResolvingCommandFactory { - protected Yaml yamlParser=new Yaml(new SafeConstructor(new LoaderOptions())) + protected Yaml yamlParser=new Yaml() // 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)