public void UnknownFormNameForDerivedSymbolValueDoesNotThrow() { string templateJson = @" { ""name"": ""TestTemplate"", ""identity"": ""TestTemplate"", ""symbols"": { ""original"": { ""type"": ""parameter"", ""replaces"": ""whatever"", }, ""myDerivedSym"": { ""type"": ""derived"", ""valueSource"": ""original"", ""valueTransform"": ""fakeForm"", ""replaces"": ""something"" } } } "; JObject configObj = JObject.Parse(templateJson); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(EngineEnvironmentSettings, configObj); IGlobalRunConfig runConfig = null; try { runConfig = ((IRunnableProjectConfig)configModel).OperationConfig; } catch { Assert.True(false, "Should not throw on unknown value form name"); } Assert.NotNull(runConfig); }
internal GlobalRunSpec( IDirectory templateRoot, IComponentManager componentManager, IParameterSet parameters, IVariableCollection variables, IGlobalRunConfig globalConfig, IReadOnlyList <KeyValuePair <string, IGlobalRunConfig> > fileGlobConfigs, IReadOnlyList <string> ignoreFileNames) { EnsureOperationConfigs(componentManager); RootVariableCollection = variables; IgnoreFileNames = ignoreFileNames; Operations = ResolveOperations(globalConfig, templateRoot, variables, parameters); List <KeyValuePair <IPathMatcher, IRunSpec> > specials = new List <KeyValuePair <IPathMatcher, IRunSpec> >(); if (fileGlobConfigs != null) { foreach (KeyValuePair <string, IGlobalRunConfig> specialEntry in fileGlobConfigs) { IReadOnlyList <IOperationProvider> specialOps = null; if (specialEntry.Value != null) { specialOps = ResolveOperations(specialEntry.Value, templateRoot, variables, parameters); } RunSpec spec = new RunSpec(specialOps, specialEntry.Value.VariableSetup.FallbackFormat); specials.Add(new KeyValuePair <IPathMatcher, IRunSpec>(new GlobbingPatternMatcher(specialEntry.Key), spec)); } } Special = specials; }
// Note the deferred-config macros (generated) are part of the runConfig.Macros // and not in the ComputedMacros. // Possibly make a separate property for the deferred-config macros private static void ProcessMacros(IComponentManager componentManager, IGlobalRunConfig runConfig, IParameterSet parameters) { if (runConfig.Macros != null) { IVariableCollection varsForMacros = VariableCollection.SetupVariables(parameters, runConfig.VariableSetup); MacrosOperationConfig macroProcessor = new MacrosOperationConfig(); macroProcessor.ProcessMacros(componentManager, runConfig.Macros, varsForMacros, parameters); } if (runConfig.ComputedMacros != null) { IVariableCollection varsForMacros = VariableCollection.SetupVariables(parameters, runConfig.VariableSetup); MacrosOperationConfig macroProcessor = new MacrosOperationConfig(); macroProcessor.ProcessMacros(componentManager, runConfig.ComputedMacros, varsForMacros, parameters); } }
// Returns a list of operations which contains the custom operations and the default operations. // If there are custom Conditional operations, don't include the default Conditionals. // // Note: we may need a more robust filtering mechanism in the future. private static IReadOnlyList <IOperationProvider> ResolveOperations(IGlobalRunConfig runConfig, IDirectory templateRoot, IVariableCollection variables, IParameterSet parameters) { IReadOnlyList <IOperationProvider> customOperations = SetupCustomOperations(runConfig.CustomOperations, templateRoot, variables); IReadOnlyList <IOperationProvider> defaultOperations = SetupOperations(templateRoot.MountPoint.EnvironmentSettings, parameters, runConfig); List <IOperationProvider> operations = new List <IOperationProvider>(customOperations); if (customOperations.Any(x => x is Conditional)) { operations.AddRange(defaultOperations.Where(op => !(op is Conditional))); } else { operations.AddRange(defaultOperations); } return(operations); }
public void UnknownFormNameOnParameterSymbolDoesNotThrow() { string templateJson = @" { ""name"": ""TestTemplate"", ""identity"": ""TestTemplate"", ""symbols"": { ""mySymbol"": { ""type"": ""parameter"", ""replaces"": ""whatever"", ""forms"": { ""global"": [ ""fakeName"" ], } } } } "; JObject configObj = JObject.Parse(templateJson); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(EngineEnvironmentSettings, configObj); IGlobalRunConfig runConfig = null; try { runConfig = ((IRunnableProjectConfig)configModel).OperationConfig; } catch { Assert.True(false, "Should not throw on unknown value form name"); } Assert.NotNull(runConfig); Assert.Equal(1, runConfig.Macros.Count(m => m.VariableName.StartsWith("mySymbol"))); var mySymbolMacro = runConfig.Macros.Single(m => m.VariableName.StartsWith("mySymbol")); Assert.True(mySymbolMacro is ProcessValueFormMacroConfig); ProcessValueFormMacroConfig identityFormConfig = mySymbolMacro as ProcessValueFormMacroConfig; Assert.Equal("identity", identityFormConfig.FormName); }
public GlobalRunSpec( IDirectory templateRoot, IComponentManager componentManager, IParameterSet parameters, IVariableCollection variables, IGlobalRunConfig globalConfig, IReadOnlyList <KeyValuePair <string, IGlobalRunConfig> > fileGlobConfigs, IReadOnlyDictionary <string, IReadOnlyList <IOperationProvider> > localizationOperations, string placeholderFilename) { EnsureOperationConfigs(componentManager); RootVariableCollection = variables; LocalizationOperations = localizationOperations; PlaceholderFilename = placeholderFilename; Operations = ResolveOperations(globalConfig, templateRoot, variables, parameters); List <KeyValuePair <IPathMatcher, IRunSpec> > specials = new List <KeyValuePair <IPathMatcher, IRunSpec> >(); if (fileGlobConfigs != null) { foreach (KeyValuePair <string, IGlobalRunConfig> specialEntry in fileGlobConfigs) { IReadOnlyList <IOperationProvider> specialOps = null; IVariableCollection specialVariables = variables; if (specialEntry.Value != null) { specialOps = ResolveOperations(specialEntry.Value, templateRoot, variables, parameters); specialVariables = VariableCollection.SetupVariables(templateRoot.MountPoint.EnvironmentSettings, parameters, specialEntry.Value.VariableSetup); } RunSpec spec = new RunSpec(specialOps, specialVariables ?? variables, specialEntry.Value.VariableSetup.FallbackFormat); specials.Add(new KeyValuePair <IPathMatcher, IRunSpec>(new GlobbingPatternMatcher(specialEntry.Key), spec)); } } Special = specials; }
private static IReadOnlyList <IOperationProvider> SetupOperations(IEngineEnvironmentSettings environmentSettings, IParameterSet parameters, IGlobalRunConfig runConfig) { // default operations List <IOperationProvider> operations = new List <IOperationProvider>(); operations.AddRange(runConfig.Operations); // replacements if (runConfig.Replacements != null) { foreach (IReplacementTokens replaceSetup in runConfig.Replacements) { IOperationProvider replacement = ReplacementConfig.Setup(environmentSettings, replaceSetup, parameters); if (replacement != null) { operations.Add(replacement); } } } if (runConfig.VariableSetup.Expand) { operations?.Add(new ExpandVariables(null)); } return(operations); }
private static void ProcessMacros(IEngineEnvironmentSettings environmentSettings, IGlobalRunConfig runConfig, IParameterSet parameters) { if (runConfig.Macros != null) { IVariableCollection varsForMacros = SetupVariables(environmentSettings, parameters, runConfig.VariableSetup); MacrosOperationConfig macroProcessor = new MacrosOperationConfig(); macroProcessor.ProcessMacros(environmentSettings, runConfig.Macros, varsForMacros, parameters); } if (runConfig.ComputedMacros != null) { IVariableCollection varsForMacros = SetupVariables(environmentSettings, parameters, runConfig.VariableSetup); MacrosOperationConfig macroProcessor = new MacrosOperationConfig(); macroProcessor.ProcessMacros(environmentSettings, runConfig.ComputedMacros, varsForMacros, parameters); } }