Helper methods for parsing YAML files, with support of goal-based filtering
Ejemplo n.º 1
0
        /// <summary>
        /// Initializes the yaml loader
        /// </summary>
        /// <param name="suiteFactory">Factory interface to create new suite instances</param>
        /// <param name="parametersLoaders">Parameter loader implementations</param>
        /// <param name="output">Output interface to issue warnings</param>
        protected YamlModelLoaderBase(ISuiteFactory suiteFactory, IEnumerable<IYamlProjectParametersLoader> parametersLoaders, IUserOutput output)
        {
            Contract.Requires(suiteFactory != null);
            Contract.Requires(output != null);
            Contract.Ensures(this.suiteFactory == suiteFactory);
            Contract.Ensures(this.parametersLoaders == parametersLoaders);

            this.suiteFactory = suiteFactory;
            this.parametersLoaders = parametersLoaders;
            this.output = output;

            parser = new YamlParser();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the yaml loader
        /// </summary>
        /// <param name="suiteFactory">Factory interface to create new suite instances</param>
        /// <param name="parametersLoaders">Parameter loader implementations</param>
        /// <param name="output">Output interface to issue warnings</param>
        /// <param name="pluginLoader">Plugin loader interface</param>
        /// <param name="environmentVariableContext">Environment variable context</param>
        /// <param name="validator">Suite validator interface</param>
        protected YamlModelLoaderBase(ISuiteFactory suiteFactory, IEnumerable<IYamlProjectParametersLoader> parametersLoaders, IUserOutput output, IPluginLoader pluginLoader, IEnvironmentVariableContext environmentVariableContext, ISuiteValidator validator)
        {
            Contract.Requires(suiteFactory != null);
            Contract.Requires(output != null);
            Contract.Requires(pluginLoader != null);
            Contract.Requires(environmentVariableContext != null);
            Contract.Requires(validator != null);
            Contract.Ensures(this.suiteFactory == suiteFactory);
            Contract.Ensures(this.parametersLoaders == parametersLoaders);

            this.suiteFactory = suiteFactory;
            this.parametersLoaders = parametersLoaders;
            this.output = output;
            this.pluginLoader = pluginLoader;
            this.validator = validator;

            versioningEnvironmentVariableContext = new VersioningEnvironmentVariableContext(environmentVariableContext);
            parser = new YamlParser();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes the yaml loader
        /// </summary>
        /// <param name="suiteFactory">Factory interface to create new suite instances</param>
        /// <param name="parametersLoaders">Parameter loader implementations</param>
        /// <param name="output">Output interface to issue warnings</param>
        /// <param name="pluginLoader">Plugin loader interface</param>
        /// <param name="environmentVariableContext">Environment variable context</param>
        /// <param name="validator">Suite validator interface</param>
        protected YamlModelLoaderBase(ISuiteFactory suiteFactory, IEnumerable <IYamlProjectParametersLoader> parametersLoaders, IUserOutput output, IPluginLoader pluginLoader, IEnvironmentVariableContext environmentVariableContext, ISuiteValidator validator)
        {
            Contract.Requires(suiteFactory != null);
            Contract.Requires(output != null);
            Contract.Requires(pluginLoader != null);
            Contract.Requires(environmentVariableContext != null);
            Contract.Requires(validator != null);
            Contract.Ensures(this.suiteFactory == suiteFactory);
            Contract.Ensures(this.parametersLoaders == parametersLoaders);

            this.suiteFactory      = suiteFactory;
            this.parametersLoaders = parametersLoaders;
            this.output            = output;
            this.pluginLoader      = pluginLoader;
            this.validator         = validator;

            versioningEnvironmentVariableContext = new VersioningEnvironmentVariableContext(environmentVariableContext);
            parser = new YamlParser();
        }
Ejemplo n.º 4
0
        protected bool ParseBool(YamlParser parser, YamlNode value)
        {
            var seq = value as YamlSequenceNode;

            if (seq != null)
            {
                var values = parser.EnumerateNodesOf(seq).OfType <YamlScalarNode>().Select(childValue => ParseBool(parser, childValue)).ToList();
                if (values.Any())
                {
                    return(values.First());
                }

                return(false);
            }

            var scalarValue = (YamlScalarNode)value;

            return("true".Equals(scalarValue.Value, StringComparison.InvariantCultureIgnoreCase) ||
                   "yes".Equals(scalarValue.Value, StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 5
0
 public void Setup()
 {
     parser = new YamlParser();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Applies a parameter definition to the given parameters model.
        ///
        /// <para>This only has to be overridden to provide a custom parameter parsing logic. Otherwise
        /// just override <see cref="YamlProjectParametersLoaderBase{TParamType}.GetActions"/></para>
        /// </summary>
        /// <param name="target">Target model object to be filled</param>
        /// <param name="name">Option name</param>
        /// <param name="value">Option value to be parsed</param>
        /// <param name="parser">Parser to be used</param>
        protected override void TryAddParameter(ReferenceAliases target, string name, YamlNode value, YamlParser parser)
        {
            var references = new HashSet <Reference>();

            var seq = value as YamlSequenceNode;

            if (seq != null)
            {
                foreach (var referenceNode in parser.EnumerateNodesOf(seq))
                {
                    foreach (var reference in referenceLoader.LoadReference(referenceNode))
                    {
                        references.Add(reference);
                    }
                }
            }
            else
            {
                foreach (var reference in referenceLoader.LoadReference(value))
                {
                    references.Add(reference);
                }
            }

            target.Add(name, references);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Gets the mapping table
 ///
 /// <para>The table contains the action to be performed for each supported option key</para>
 /// </summary>
 /// <param name="target">Target model object to be filled</param>
 /// <param name="value">Value to be parsed</param>
 /// <param name="parser">Parser to be used</param>
 /// <returns>Returns the mapping</returns>
 protected override Dictionary <string, Action> GetActions(ReferenceAliases target, YamlNode value, YamlParser parser)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 8
0
 protected override Dictionary <string, Action> GetActions(Tests target, YamlNode value, YamlParser parser)
 {
     return(new Dictionary <string, Action>
     {
         { "enabled-runners", () => target.EnableTestRunners(ParseStringArray(parser, value)) }
     });
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets the mapping table
 ///
 /// <para>The table contains the action to be performed for each supported option key</para>
 /// </summary>
 /// <param name="target">Target model object to be filled</param>
 /// <param name="value">Value to be parsed</param>
 /// <param name="parser">Parser to be used</param>
 /// <returns>Returns the mapping</returns>
 protected abstract Dictionary <string, Action> GetActions(TParamType target, YamlNode value, YamlParser parser);
Ejemplo n.º 10
0
        public virtual IProjectParameters Load(Suite suite, string name, YamlNode value, YamlParser parser)
        {
            this.suite = suite;

            var result  = CreateNewParameters(suite);
            var mapping = value as YamlMappingNode;

            if (mapping != null)
            {
                foreach (var pair in parser.EnumerateNodesOf(mapping))
                {
                    var scalarKey = pair.Key as YamlScalarNode;
                    if (scalarKey != null)
                    {
                        TryAddParameter(result, scalarKey.Value, pair.Value, parser);
                    }
                }
            }
            else
            {
                var hints = new List <string>();

                if (value is YamlSequenceNode)
                {
                    hints.Add("Remove the `-` characters to make it a mapping instead of sequence");
                    output.Warning(String.Format("{0} block (line {1}) is not a mapping node", BlockName, value != null ? value.Start.Line.ToString(CultureInfo.InvariantCulture) : "?"), hints.ToArray());
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Applies a parameter definition to the given parameters model.
        ///
        /// <para>This only has to be overridden to provide a custom parameter parsing logic. Otherwise
        /// just override <see cref="GetActions"/></para>
        /// </summary>
        /// <param name="target">Target model object to be filled</param>
        /// <param name="name">Option name</param>
        /// <param name="value">Option value to be parsed</param>
        /// <param name="parser">Parser to be used</param>
        protected virtual void TryAddParameter(TParamType target, string name, YamlNode value, YamlParser parser)
        {
            var mapping = GetActions(target, value, parser);

            foreach (var pair in mapping)
            {
                if (NameIs(name, pair.Key))
                {
                    pair.Value();
                }
            }
        }
Ejemplo n.º 12
0
        public virtual IProjectParameters Load(Suite suite, string name, YamlNode value, YamlParser parser)
        {
            this.suite = suite;

            var result  = CreateNewParameters(suite);
            var mapping = value as YamlMappingNode;

            if (mapping != null)
            {
                foreach (var pair in parser.EnumerateNodesOf(mapping))
                {
                    var scalarKey = pair.Key as YamlScalarNode;
                    if (scalarKey != null)
                    {
                        TryAddParameter(result, scalarKey.Value, pair.Value, parser);
                    }
                }
            }

            return(result);
        }