private static IDictionary <string, string> Read(ICakeEnvironment environment, string text) { var tokens = ConfigurationTokenizer.Tokenize(text); var section = string.Empty; var result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); while (tokens.Current != null) { switch (tokens.Current.Kind) { case ConfigurationTokenKind.Section: section = ParseSection(tokens); break; case ConfigurationTokenKind.Value: var pair = ParseKeyAndValue(tokens, section); result[pair.Key] = environment.ExpandEnvironmentVariables(pair.Value); break; default: throw new InvalidOperationException("Encountered unexpected token."); } } return(result); }
private void AnalyzeCallback(IScriptAnalyzerContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var path = context.Current.Path; // Read the source. _log.Debug("Analyzing {0}...", path.FullPath); var lines = ReadLines(path); // Iterate all lines in the script. foreach (var line in lines) { string replacement = null; if (!_lineProcessors.Any(p => p.Process(context, _environment.ExpandEnvironmentVariables(line), out replacement))) { context.AddScriptLine(line); } else { // Add replacement or comment out processed lines to keep line data. context.AddScriptLine(replacement ?? string.Concat("// ", line)); } } }
/// <summary> /// Expands all environment variables in the provided <see cref="DirectoryPath"/>. /// </summary> /// <example> /// <code> /// var path = new DirectoryPath("%APPDATA%"); /// var expanded = path.ExpandEnvironmentVariables(environment); /// </code> /// </example> /// <param name="path">The directory to expand.</param> /// <param name="environment">The environment.</param> /// <returns>A new <see cref="DirectoryPath"/> with each environment variable replaced by its value.</returns> public static DirectoryPath ExpandEnvironmentVariables(this DirectoryPath path, ICakeEnvironment environment) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } var result = environment.ExpandEnvironmentVariables(path.FullPath); return(new DirectoryPath(result)); }
private void ModuleAnalyzeCallback(IScriptAnalyzerContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } // Iterate all lines in the script. var lines = ReadLines(context.Current.Path); foreach (var line in lines) { foreach (var processor in _defaultProcessors) { if (processor.Process(context, _environment.ExpandEnvironmentVariables(line), out var _)) { break; } } } }