Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@

# CS1591: Missing XML comment for publicly visible type or member
dotnet_diagnostic.CS1591.severity = suggestion

# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true

# Missing usings should be reported as error (IDE0005)
dotnet_diagnostic.IDE0005.severity = error
1 change: 1 addition & 0 deletions src/AggregateConfigBuildTask.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29D0AE56-C184-4741-824F-521198552928}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
EndProjectSection
EndProject
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CA1027</NoWarn>
</PropertyGroup>

</Project>
16 changes: 8 additions & 8 deletions src/Contracts/InputOutputEnums.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
namespace AggregateConfigBuildTask.Contracts
{
public enum OutputTypeEnum
public enum OutputType
{
Json,
Arm,
Json = 0,
Arm = 1,
ArmParameter = Arm,
Yml,
Yml = 2,
Yaml = Yml
}

public enum InputTypeEnum
public enum InputType
{
Json,
Arm,
Json = 0,
Arm = 1,
ArmParameter = Arm,
Yml,
Yml = 2,
Yaml = Yml
}
}
13 changes: 13 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Deterministic>true</Deterministic>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" />
<GlobalPackageReference Include="ReferenceTrimmer" Version="3.3.6" />
<GlobalPackageReference Include="Roslynator.Analyzers" Version="4.12.4" />
</ItemGroup>
</Project>
16 changes: 8 additions & 8 deletions src/Task/AggregateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AggregateConfig : Task
[Required]
public string OutputType { get; set; }

public bool AddSourceProperty { get; set; } = false;
public bool AddSourceProperty { get; set; }

public string[] AdditionalProperties { get; set; }

Expand All @@ -48,18 +48,18 @@ public override bool Execute()

OutputFile = Path.GetFullPath(OutputFile);

if (!Enum.TryParse(OutputType, true, out OutputTypeEnum outputType) ||
!Enum.IsDefined(typeof(OutputTypeEnum), outputType))
if (!Enum.TryParse(OutputType, true, out OutputType outputType) ||
!Enum.IsDefined(typeof(OutputType), outputType))
{
Log.LogError("Invalid OutputType: {0}. Available options: {1}", OutputType, string.Join(", ", Enum.GetNames(typeof(OutputTypeEnum))));
Log.LogError("Invalid OutputType: {0}. Available options: {1}", OutputType, string.Join(", ", Enum.GetNames(typeof(OutputType))));
return false;
}

InputTypeEnum inputType = InputTypeEnum.Yaml;
InputType inputType = Contracts.InputType.Yaml;
if (!string.IsNullOrEmpty(InputType) &&
(!Enum.TryParse(InputType, true, out inputType) || !Enum.IsDefined(typeof(InputTypeEnum), inputType)))
(!Enum.TryParse(InputType, true, out inputType) || !Enum.IsDefined(typeof(InputType), inputType)))
{
Log.LogError("Invalid InputType: {0}. Available options: {1}", InputType, string.Join(", ", Enum.GetNames(typeof(InputTypeEnum))));
Log.LogError("Invalid InputType: {0}. Available options: {1}", InputType, string.Join(", ", Enum.GetNames(typeof(InputType))));
return false;
}

Expand Down Expand Up @@ -103,7 +103,7 @@ private void EmitHeader()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion;

Log.LogMessage($"AggregateConfig Version: {informationalVersion}");
Log.LogMessage(MessageImportance.High, $"AggregateConfig Version: {informationalVersion}");
}
}
}
4 changes: 1 addition & 3 deletions src/Task/AggregateConfigBuildTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Deterministic>true</Deterministic>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<SourceLinkCreate>true</SourceLinkCreate>
<NoWarn>NU5100</NoWarn>
<NoWarn>NU5100,CA1031,CA1819</NoWarn>
</PropertyGroup>

<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
Expand Down
18 changes: 9 additions & 9 deletions src/Task/FileHandlers/ArmParametersFileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ namespace AggregateConfigBuildTask.FileHandlers
{
public class ArmParametersFileHandler : IOutputWriter, IInputReader
{
readonly IFileSystem fileSystem;
private readonly IFileSystem fileSystem;

private readonly JsonSerializerOptions jsonOptions = new JsonSerializerOptions { WriteIndented = true };

internal ArmParametersFileHandler(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
}

/// <inheritdoc/>
public ValueTask<JsonElement> ReadInput(string inputPath)
public async ValueTask<JsonElement> ReadInput(string inputPath)
{
using (var stream = fileSystem.OpenRead(inputPath))
{
using (var jsonDoc = JsonDocument.Parse(stream))
using (var jsonDoc = await JsonDocument.ParseAsync(stream).ConfigureAwait(false))
{
if (jsonDoc.RootElement.TryGetProperty("parameters", out JsonElement parameters))
{
Expand All @@ -41,10 +43,10 @@ public ValueTask<JsonElement> ReadInput(string inputPath)
}

var modifiedJson = modifiedParameters.ToJsonString();
return new ValueTask<JsonElement>(Task.FromResult(JsonSerializer.Deserialize<JsonElement>(modifiedJson)));
return JsonSerializer.Deserialize<JsonElement>(modifiedJson);
}

return new ValueTask<JsonElement>(Task.FromResult(jsonDoc.RootElement.Clone()));
return jsonDoc.RootElement.Clone();
}
}
}
Expand Down Expand Up @@ -74,8 +76,6 @@ public void WriteOutput(JsonElement? mergedData, string outputPath)
["contentVersion"] = "1.0.0.0",
["parameters"] = parameters
};

var jsonOptions = new JsonSerializerOptions { WriteIndented = true };
var jsonContent = JsonSerializer.Serialize(armTemplate, jsonOptions);
fileSystem.WriteAllText(outputPath, jsonContent);
}
Expand All @@ -90,7 +90,7 @@ public void WriteOutput(JsonElement? mergedData, string outputPath)
/// </summary>
/// <param name="value">The JsonElement value to evaluate.</param>
/// <returns>A string representing the ARM template parameter type.</returns>
private string GetParameterType(JsonElement value)
private static string GetParameterType(JsonElement value)
{
switch (value.ValueKind)
{
Expand All @@ -115,7 +115,7 @@ private string GetParameterType(JsonElement value)
}
}

private JsonNode ConvertElementToNode(JsonElement element)
private static JsonNode ConvertElementToNode(JsonElement element)
{
// Use GetRawText to get the JSON string representation of the JsonElement
var jsonString = element.GetRawText();
Expand Down
24 changes: 12 additions & 12 deletions src/Task/FileHandlers/FileHandlerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ namespace AggregateConfigBuildTask.FileHandlers
{
public static class FileHandlerFactory
{
internal static IOutputWriter GetOutputWriter(IFileSystem fileSystem, OutputTypeEnum format)
internal static IOutputWriter GetOutputWriter(IFileSystem fileSystem, OutputType format)
{
switch (format)
{
case OutputTypeEnum.Json:
case OutputType.Json:
return new JsonFileHandler(fileSystem);
case OutputTypeEnum.Yaml:
case OutputType.Yaml:
return new YamlFileHandler(fileSystem);
case OutputTypeEnum.Arm:
case OutputType.Arm:
return new ArmParametersFileHandler(fileSystem);
default:
throw new ArgumentException("Unsupported format");
}
}

internal static IInputReader GetInputReader(IFileSystem fileSystem, InputTypeEnum format)
internal static IInputReader GetInputReader(IFileSystem fileSystem, InputType format)
{
switch (format)
{
case InputTypeEnum.Yaml:
case InputType.Yaml:
return new YamlFileHandler(fileSystem);
case InputTypeEnum.Json:
case InputType.Json:
return new JsonFileHandler(fileSystem);
case InputTypeEnum.Arm:
case InputType.Arm:
return new ArmParametersFileHandler(fileSystem);
default:
throw new ArgumentException("Unsupported input format");
}
}

internal static List<string> GetExpectedFileExtensions(InputTypeEnum inputType)
internal static List<string> GetExpectedFileExtensions(InputType inputType)
{
switch (inputType)
{
case InputTypeEnum.Json:
case InputType.Json:
return new List<string> { ".json" };
case InputTypeEnum.Yaml:
case InputType.Yaml:
return new List<string> { ".yml", ".yaml" };
case InputTypeEnum.Arm:
case InputType.Arm:
return new List<string> { ".json" };
default:
throw new ArgumentException("Unsupported input type");
Expand Down
3 changes: 2 additions & 1 deletion src/Task/FileHandlers/JsonFileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class JsonFileHandler : IOutputWriter, IInputReader
{
readonly IFileSystem fileSystem;

private readonly JsonSerializerOptions jsonOptions = new JsonSerializerOptions { WriteIndented = true };

internal JsonFileHandler(IFileSystem fileSystem)
{
this.fileSystem = fileSystem;
Expand All @@ -24,7 +26,6 @@ public ValueTask<JsonElement> ReadInput(string inputPath)
/// <inheritdoc/>
public void WriteOutput(JsonElement? mergedData, string outputPath)
{
var jsonOptions = new JsonSerializerOptions { WriteIndented = true };
var jsonContent = JsonSerializer.Serialize(mergedData, jsonOptions);
fileSystem.WriteAllText(outputPath, jsonContent);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Task/FileSystem/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AggregateConfigBuildTask
{
internal class FileSystem : IFileSystem
internal sealed class FileSystem : IFileSystem
{
/// <inheritdoc/>
public string[] GetFiles(string path, string searchPattern)
Expand Down
7 changes: 4 additions & 3 deletions src/Task/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ public static Dictionary<string, string> ParseAdditionalProperties(string[] prop
{
var additionalPropertiesDict = new Dictionary<string, string>();
const string unicodeEscape = "\u001F";
char[] split = new[] { '=' };

if (properties != null)
{
foreach (var property in properties)
{
var sanitizedProperty = property.Replace(@"\=", unicodeEscape);

var keyValue = sanitizedProperty.Split(new[] { '=' }, 2);
var keyValue = sanitizedProperty.Split(split, 2);

if (keyValue.Length == 2)
{
Expand All @@ -104,10 +105,10 @@ public static async Task<JsonElement> ConvertObjectToJsonElement(object value)

using (var memoryStream = new MemoryStream())
{
await JsonSerializer.SerializeAsync(memoryStream, value);
await JsonSerializer.SerializeAsync(memoryStream, value).ConfigureAwait(false);
memoryStream.Seek(0, SeekOrigin.Begin);

using (var jsonDocument = await JsonDocument.ParseAsync(memoryStream))
using (var jsonDocument = await JsonDocument.ParseAsync(memoryStream).ConfigureAwait(false))
{
return jsonDocument.RootElement.Clone();
}
Expand Down
Loading