public ICreationEffects GetCreationEffects(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.IgnoreFileNames); List <IFileChange2> changes = new List <IFileChange2>(); foreach (FileSourceMatchInfo source in template.Config.Sources) { runSpec.SetupFileSource(source); changes.AddRange(orchestrator.GetFileChanges(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), targetDirectory, source.Target)); } return(new CreationEffects2 { FileChanges = changes, CreationResult = GetCreationResult(environmentSettings, template, variables) }); }
public Task <ICreationResult> CreateAsync( IEngineEnvironmentSettings environmentSettings, IRunnableProjectConfig runnableProjectConfig, IDirectory templateSourceRoot, IParameterSet parameters, string targetDirectory, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ProcessMacros(environmentSettings, runnableProjectConfig.OperationConfig, parameters); IVariableCollection variables = SetupVariables(environmentSettings, parameters, runnableProjectConfig.OperationConfig.VariableSetup); runnableProjectConfig.Evaluate(parameters, variables); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(environmentSettings.Host.Logger, environmentSettings.Host.FileSystem); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(templateSourceRoot, environmentSettings.Components, parameters, variables, runnableProjectConfig.OperationConfig, runnableProjectConfig.SpecialOperationConfig, runnableProjectConfig.IgnoreFileNames); foreach (FileSourceMatchInfo source in runnableProjectConfig.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); orchestrator.Run(runSpec, templateSourceRoot.DirectoryInfo(source.Source), target); } return(Task.FromResult(GetCreationResult(environmentSettings.Host.Logger, runnableProjectConfig, variables))); }
public Task <ICreationResult> CreateAsync(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.PlaceholderFilename); foreach (FileSource source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); orchestrator.Run(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target); } // todo: add anything else we'd want to report to the broker return(Task.FromResult <ICreationResult>(new CreationResult() { PostActions = PostAction.ListFromModel(environmentSettings, template.Config.PostActionModel, variables), PrimaryOutputs = CreationPath.ListFromModel(environmentSettings, template.Config.PrimaryOutputs, variables) })); }
public IReadOnlyList <IFileChange> GetFileChanges(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.PlaceholderFilename); List <IFileChange> changes = new List <IFileChange>(); foreach (FileSource source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); changes.AddRange(orchestrator.GetFileChanges(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target)); } return(changes); }
public Task Create(ITemplate template, IParameterSet parameters) { RunnableProjectTemplate tmplt = (RunnableProjectTemplate)template; RunnableProjectOrchestrator o = new RunnableProjectOrchestrator(); GlobalRunSpec configRunSpec = new GlobalRunSpec(new FileSource(), tmplt.ConfigFile.Parent, parameters, tmplt.Config.Config, tmplt.Config.Special); IOperationProvider[] providers = configRunSpec.Operations.ToArray(); foreach (KeyValuePair <IPathMatcher, IRunSpec> special in configRunSpec.Special) { if (special.Key.IsMatch(".netnew.json")) { providers = special.Value.GetOperations(providers).ToArray(); break; } } IRunnableProjectConfig m = tmplt.Config.ReprocessWithParameters(parameters, configRunSpec.RootVariableCollection, tmplt.ConfigFile, providers); foreach (FileSource source in m.Sources) { GlobalRunSpec runSpec = new GlobalRunSpec(source, tmplt.ConfigFile.Parent, parameters, m.Config, m.Special); string target = Path.Combine(Directory.GetCurrentDirectory(), source.Target); o.Run(runSpec, tmplt.ConfigFile.Parent.GetDirectoryAtRelativePath(source.Source), target); } return(Task.FromResult(true)); }
public Task <ICreationEffects> GetCreationEffectsAsync( IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, string targetDirectory, CancellationToken cancellationToken) { RunnableProjectConfig templateConfig = (RunnableProjectConfig)templateData; if (templateData.TemplateSourceRoot is null) { throw new InvalidOperationException($"{nameof(templateData.TemplateSourceRoot)} cannot be null to continue."); } ProcessMacros(environmentSettings, templateConfig.OperationConfig, parameters); IVariableCollection variables = SetupVariables(environmentSettings, parameters, templateConfig.OperationConfig.VariableSetup); templateConfig.Evaluate(parameters, variables); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(environmentSettings.Host.Logger, environmentSettings.Host.FileSystem); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(templateData.TemplateSourceRoot, environmentSettings.Components, parameters, variables, templateConfig.OperationConfig, templateConfig.SpecialOperationConfig, templateConfig.IgnoreFileNames); List <IFileChange2> changes = new List <IFileChange2>(); foreach (FileSourceMatchInfo source in templateConfig.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); IReadOnlyList <IFileChange2> fileChanges = orchestrator.GetFileChanges(runSpec, templateData.TemplateSourceRoot.DirectoryInfo(source.Source), target); //source and target paths in the file changes are returned relative to source passed //GetCreationEffects method should return the source paths relative to template source root (location of .template.config folder) and target paths relative to output path and not relative to certain source //add source and target used to file changes to be returned as the result changes.AddRange( fileChanges.Select( fileChange => new FileChange( Path.Combine(source.Source, fileChange.SourceRelativePath), Path.Combine(source.Target, fileChange.TargetRelativePath), fileChange.ChangeKind, #pragma warning disable CS0618 // Type or member is obsolete fileChange.Contents))); #pragma warning restore CS0618 // Type or member is obsolete } return(Task.FromResult((ICreationEffects) new CreationEffects2(changes, GetCreationResult(environmentSettings.Host.Logger, templateConfig, variables)))); }
/// <summary> /// Performs the dry-run of the template instantiation to evaluate the primary outputs, post actions to be applied and file changes to be made when executing the template with specified parameters. /// </summary> /// <param name="environmentSettings">environment settings</param> /// <param name="templateData">the template to be executed</param> /// <param name="parameters">the parameters to be used on template execution</param> /// <param name="componentManager">the instance of component manager</param> /// <param name="targetDirectory">the output path for the template</param> /// <returns>the primary outputs, post actions and file changes that will be made when executing the template with specified parameters.</returns> public ICreationEffects GetCreationEffects(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator2 basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.IgnoreFileNames); List <IFileChange2> changes = new List <IFileChange2>(); foreach (FileSourceMatchInfo source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); IReadOnlyList <IFileChange2> fileChanges = orchestrator.GetFileChanges(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target); //source and target paths in the file changes are returned relative to source passed //GetCreationEffects method should return the source paths relative to template source root (location of .template.config folder) and target paths relative to output path and not relative to certain source //add source and target used to file changes to be returned as the result changes.AddRange( fileChanges.Select( fileChange => new FileChange( Path.Combine(source.Source, fileChange.SourceRelativePath), Path.Combine(source.Target, fileChange.TargetRelativePath), fileChange.ChangeKind, fileChange.Contents))); } return(new CreationEffects2 { FileChanges = changes, CreationResult = GetCreationResult(environmentSettings, template, variables) }); }
public Task <ICreationResult> CreateAsync(IEngineEnvironmentSettings environmentSettings, ITemplate templateData, IParameterSet parameters, IComponentManager componentManager, string targetDirectory) { RunnableProjectTemplate template = (RunnableProjectTemplate)templateData; ProcessMacros(environmentSettings, componentManager, template.Config.OperationConfig, parameters); IVariableCollection variables = VariableCollection.SetupVariables(environmentSettings, parameters, template.Config.OperationConfig.VariableSetup); template.Config.Evaluate(parameters, variables, template.ConfigFile); IOrchestrator basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); GlobalRunSpec runSpec = new GlobalRunSpec(template.TemplateSourceRoot, componentManager, parameters, variables, template.Config.OperationConfig, template.Config.SpecialOperationConfig, template.Config.LocalizationOperations, template.Config.IgnoreFileNames); foreach (FileSourceMatchInfo source in template.Config.Sources) { runSpec.SetupFileSource(source); string target = Path.Combine(targetDirectory, source.Target); orchestrator.Run(runSpec, template.TemplateSourceRoot.DirectoryInfo(source.Source), target); } return(Task.FromResult(GetCreationResult(environmentSettings, template, variables))); }