Skip to content

Commit

Permalink
removed IGeneratedSymbolMacro<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
vlada-shubina committed Nov 9, 2022
1 parent b75852f commit 8d6f53f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions
/// <summary>
/// An interface for macros created that can create the config from other config (deffered config).
/// </summary>
[Obsolete("Use IGeneratedSymbolConfig{T} instead.")]
[Obsolete("Use IGeneratedSymbolConfig instead.")]
public interface IDeferredMacro : IMacro
{
/// <summary>
/// Creates <see cref="IMacroConfig"/> from <paramref name="rawConfig"/>.
/// </summary>
/// <remarks>
/// Deprecated as <see cref="IMacro"/> can process only own configuration. Use generic version of interface and <see cref="IGeneratedSymbolMacro{T}.CreateConfig(IEngineEnvironmentSettings, IGeneratedSymbolConfig)"/> instead.
/// Deprecated as <see cref="IMacro"/> can process only own configuration.
/// </remarks>
[Obsolete("Use IGeneratedSymbolConfig{T}.Evaluate or IGeneratedSymbolConfig{T}.CreateConfig instead")]
[Obsolete("Use IMacro{T}.Evaluate or IGeneratedSymbolConfig.Evaluate instead for generated symbol instead.")]
IMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings, IMacroConfig rawConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions
{
/// <summary>
/// Represents the configuration of <see cref="IGeneratedSymbolMacro"/> and <see cref="IGeneratedSymbolMacro{T}"/>.
/// Represents the configuration of <see cref="IGeneratedSymbolMacro"/>.
/// </summary>
public interface IGeneratedSymbolConfig : IMacroConfig
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Core.Contracts;

namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions
{
/// <summary>
/// An interface for macro created via generated symbols.
/// </summary>
public interface IGeneratedSymbolMacro : IMacro
{
/// <summary>
/// Evaluates macro defined via generated symbol (<see cref="IGeneratedSymbolConfig"/>).
/// The result of macro evaluation is modification of variable collection <paramref name="variables"/>.
/// </summary>
void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables, IGeneratedSymbolConfig generatedSymbolConfig);
}

/// <summary>
/// An interface for macro created via generated symbols, that can create config from generated symbol config (<see cref="IGeneratedSymbolConfig"/>).
/// </summary>
/// <typeparam name="T">The type of macro config.</typeparam>
public interface IGeneratedSymbolMacro<T> : IGeneratedSymbolMacro, IMacro<T>
where T : IMacroConfig
public interface IGeneratedSymbolMacro : IMacro<IGeneratedSymbolConfig>
{
/// <summary>
/// Creates macro config from <see cref="IGeneratedSymbolConfig"/>.
/// </summary>
T CreateConfig(IEngineEnvironmentSettings environmentSettings, IGeneratedSymbolConfig generatedSymbolConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public IMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings,
return CreateConfig(deferredConfig);
}

public T CreateConfig(IEngineEnvironmentSettings environmentSettings, IGeneratedSymbolConfig deferredConfig) => CreateConfig(deferredConfig);

public void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IGeneratedSymbolConfig deferredConfig)
{
Evaluate(environmentSettings, vars, CreateConfig(deferredConfig));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolConfig.DataType.get -> string!
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolConfig.Parameters.get -> System.Collections.Generic.IReadOnlyDictionary<string!, string!>!
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolMacro
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolMacro.Evaluate(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings! environmentSettings, Microsoft.TemplateEngine.Core.Contracts.IVariableCollection! variables, Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolConfig! generatedSymbolConfig) -> void
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolMacro<T>
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolMacro<T>.CreateConfig(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings! environmentSettings, Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IGeneratedSymbolConfig! generatedSymbolConfig) -> T
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro<T>
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions.IMacro<T>.Evaluate(Microsoft.TemplateEngine.Abstractions.IEngineEnvironmentSettings! environmentSettings, Microsoft.TemplateEngine.Core.Contracts.IVariableCollection! variables, T config) -> void
Microsoft.TemplateEngine.Orchestrator.RunnableProjects.ConfigModel.TemplateConfigModel.Identity.get -> string!
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Linq;
using System.Net.NetworkInformation;
using Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Abstractions;
using Microsoft.TemplateEngine.TestHelper;
using Xunit;

Expand All @@ -16,8 +18,13 @@ public void TestAllComponents()

IOrderedEnumerable<string> expectedTypeNames = assemblyCatalog
.Where(pair => !pair.Item1.IsGenericType)
//obsolete type kept for backward compatibiility.
#pragma warning disable CS0618 // Type or member is obsolete
.Where(pair => pair.Item1 != typeof(IDeferredMacro))
#pragma warning restore CS0618 // Type or member is obsolete
.Select(pair => pair.Item1.FullName + ";" + pair.Item2.GetType().FullName)
.OrderBy(name => name);

IOrderedEnumerable<string> actualTypeNames = Components.AllComponents.Select(t => t.Type.FullName + ";" + t.Instance.GetType().FullName).OrderBy(name => name);

Assert.Equal(expectedTypeNames, actualTypeNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,25 @@ public void CanLogWarning_OnUnknownMacro()
Assert.Equal("Generated symbol 's': type 'fail' is unknown, processing is skipped.", loggedMessages.Single(m => m.Item1 == LogLevel.Warning).Item2);
}

private class FailMacro : IMacro<FailMacroConfig>, IGeneratedSymbolMacro<FailMacroConfig>
private class FailMacro : IMacro<FailMacroConfig>, IGeneratedSymbolMacro
{
public string Type => "fail";

public Guid Id { get; } = new Guid("{3DBC6AAB-5D13-40E9-9EC8-0467A7AA7335}");

public FailMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings, IGeneratedSymbolConfig generatedSymbolConfig) => throw new TemplateAuthoringException("bad config");

public void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables, FailMacroConfig config) => throw new Exception("Failed to evaluate");

public void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables, IGeneratedSymbolConfig generatedSymbolConfig) => throw new Exception("Failed to evaluate");

public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig config) => throw new Exception("Failed to evaluate");
}

private class FailConfigMacro : IMacro<FailMacroConfig>, IGeneratedSymbolMacro<FailMacroConfig>
private class FailConfigMacro : IMacro<FailMacroConfig>, IGeneratedSymbolMacro
{
public string Type => "fail";

public Guid Id { get; } = new Guid("{3DBC6AAB-5D13-40E9-9EC8-0467A7AA7335}");

public FailMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings, IGeneratedSymbolConfig generatedSymbolConfig) => throw new TemplateAuthoringException("bad config");

public void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables, FailMacroConfig config) => throw new Exception("Failed to evaluate");

public void Evaluate(IEngineEnvironmentSettings environmentSettings, IVariableCollection variables, IGeneratedSymbolConfig generatedSymbolConfig) => throw new TemplateAuthoringException("bad config");
Expand Down

0 comments on commit 8d6f53f

Please sign in to comment.