Skip to content

Commit

Permalink
Remove dependency on immutable collections (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfs authored Aug 26, 2022
1 parent bf9bb5f commit c16ca2a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion AppInspector.CLI/AppInspector.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

<ItemGroup>
<PackageReference Include="DotLiquid" Version="2.2.656" />
<PackageReference Include="Sarif.Sdk" Version="2.4.16" />
<PackageReference Include="Sarif.Sdk" Version="3.1.0" />
<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
Expand Down
51 changes: 26 additions & 25 deletions AppInspector.CLI/Writers/AnalyzeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

namespace Microsoft.ApplicationInspector.CLI
{
using System.Linq;
using Microsoft.ApplicationInspector.Commands;
using Microsoft.ApplicationInspector.RulesEngine;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Text;

Expand Down Expand Up @@ -55,17 +55,17 @@ public AnalyzeTextWriter(TextWriter textWriter, string formatString, ILoggerFact
}


private string StringList(List<string> data)
private string StringList(IEnumerable<string> data)
{
return string.Join(' ', data);
}

private string StringList(ImmutableSortedDictionary<string, int> data)
private string StringList(IDictionary<string, int> data)
{
return string.Join(' ', data.Keys);
}

private string StringList(ImmutableSortedDictionary<string, string> data)
private string StringList(IDictionary<string, string> data)
{
StringBuilder build = new();

Expand Down Expand Up @@ -104,40 +104,41 @@ public void WriteAppMeta(MetaData metaData)
}
//write predefined characteristics
TextWriter.WriteLine(string.Format(MakeHeading("Project Info")));
TextWriter.WriteLine(string.Format("Name: {0}", metaData.ApplicationName + " " + metaData.SourceVersion));
TextWriter.WriteLine(string.Format("Description: {0}", metaData.Description));
TextWriter.WriteLine(string.Format("Source path: {0}", metaData.SourcePath));
TextWriter.WriteLine(string.Format("Authors: {0}", metaData.Authors));
TextWriter.WriteLine(string.Format("Last Updated: {0}", metaData.LastUpdated));
TextWriter.WriteLine(string.Format("Languages: {0}", StringList(metaData.Languages?.ToImmutableSortedDictionary() ?? new Dictionary<string, int>().ToImmutableSortedDictionary())));
TextWriter.WriteLine($"Name: {metaData.ApplicationName + " " + metaData.SourceVersion}");
TextWriter.WriteLine($"Description: {metaData.Description}");
TextWriter.WriteLine($"Source path: {metaData.SourcePath}");
TextWriter.WriteLine($"Authors: {metaData.Authors}");
TextWriter.WriteLine($"Last Updated: {metaData.LastUpdated}");
TextWriter.WriteLine(
$"Languages: {(metaData.Languages is not null ? StringList(metaData.Languages) : string.Empty)}");
TextWriter.WriteLine(string.Format(MakeHeading("Scan Settings")));
TextWriter.WriteLine(string.Format("Date scanned: {0}", metaData.DateScanned));
TextWriter.WriteLine($"Date scanned: {metaData.DateScanned}");
TextWriter.WriteLine(string.Format(MakeHeading("Source Info")));
TextWriter.WriteLine(string.Format("Application type: {0}", StringList(metaData.AppTypes ?? new List<string>())));
TextWriter.WriteLine(string.Format("Package types: {0}", StringList(metaData.PackageTypes ?? new List<string>())));
TextWriter.WriteLine(string.Format("File extensions: {0}", StringList(metaData.FileExtensions ?? new List<string>())));
TextWriter.WriteLine($"Application type: {StringList(metaData.AppTypes ?? new List<string>())}");
TextWriter.WriteLine($"Package types: {StringList(metaData.PackageTypes ?? new List<string>())}");
TextWriter.WriteLine($"File extensions: {StringList(metaData.FileExtensions ?? new List<string>())}");
TextWriter.WriteLine(string.Format(MakeHeading("Detetected Targets")));
TextWriter.WriteLine(string.Format("Output types: {0}", StringList(metaData.Outputs ?? new List<string>())));
TextWriter.WriteLine(string.Format("OS Targets: {0}", StringList(metaData.OSTargets ?? new List<string>())));
TextWriter.WriteLine(string.Format("CPU Targets: {0}", StringList(metaData.CPUTargets ?? new List<string>())));
TextWriter.WriteLine(string.Format("Cloud targets: {0}", StringList(metaData.CloudTargets ?? new List<string>())));
TextWriter.WriteLine($"Output types: {StringList(metaData.Outputs ?? new List<string>())}");
TextWriter.WriteLine($"OS Targets: {StringList(metaData.OSTargets ?? new List<string>())}");
TextWriter.WriteLine($"CPU Targets: {StringList(metaData.CPUTargets ?? new List<string>())}");
TextWriter.WriteLine($"Cloud targets: {StringList(metaData.CloudTargets ?? new List<string>())}");
TextWriter.WriteLine(string.Format(MakeHeading("Stats")));
TextWriter.WriteLine(string.Format("Files analyzed: {0}", metaData.FilesAnalyzed));
TextWriter.WriteLine(string.Format("Files skipped: {0}", metaData.FilesSkipped));
TextWriter.WriteLine(string.Format("Total files: {0}", metaData.TotalFiles));
TextWriter.WriteLine(string.Format("Total matches: {0} in {1} file(s)", metaData.TotalMatchesCount, metaData.FilesAffected));
TextWriter.WriteLine(string.Format("Unique matches: {0}", metaData.UniqueMatchesCount));
TextWriter.WriteLine($"Files analyzed: {metaData.FilesAnalyzed}");
TextWriter.WriteLine($"Files skipped: {metaData.FilesSkipped}");
TextWriter.WriteLine($"Total files: {metaData.TotalFiles}");
TextWriter.WriteLine($"Total matches: {metaData.TotalMatchesCount} in {metaData.FilesAffected} file(s)");
TextWriter.WriteLine($"Unique matches: {metaData.UniqueMatchesCount}");

TextWriter.WriteLine(MakeHeading("UniqueTags"));
foreach (string tag in metaData.UniqueTags ?? new List<string>())
foreach (string tag in metaData.UniqueTags)
{
TextWriter.WriteLine(tag);
}

TextWriter.WriteLine(MakeHeading("Select Counters"));
foreach (MetricTagCounter tagCounter in metaData.TagCounters ?? new List<MetricTagCounter>())
{
TextWriter.WriteLine(string.Format("Tagname: {0}, Count: {1}", tagCounter.Tag, tagCounter.Count));
TextWriter.WriteLine($"Tagname: {tagCounter.Tag}, Count: {tagCounter.Count}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion AppInspector.RulesEngine/AppInspector.RulesEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<ItemGroup>
<PackageReference Include="JsonCons.JsonPath" Version="1.1.0" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.24" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.25" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
2 changes: 1 addition & 1 deletion AppInspector.Tests/AppInspector.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
Expand Down
3 changes: 1 addition & 2 deletions AppInspector/AppInspector.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="DotLiquid" Version="2.2.656" />
<PackageReference Include="Glob" Version="1.1.9" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.24" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.25" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="6.0.1" />

</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion AppInspector/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public int UniqueMatchesCount
/// List of detected programming languages used and count of files
/// </summary>
[JsonProperty(PropertyName = "languages")]
public ImmutableSortedDictionary<string, int>? Languages { get; set; } //unable to init here for constr arg
public IDictionary<string, int>? Languages { get; set; } //unable to init here for constr arg

/// <summary>
/// List of detected tag counters i.e. metrics
Expand Down
3 changes: 1 addition & 2 deletions AppInspector/MetaDataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace Microsoft.ApplicationInspector.Commands
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -187,7 +186,7 @@ public void PrepareReport()
Metadata.Outputs.Sort();
Metadata.Targets.Sort();

Metadata.Languages = Languages.ToImmutableSortedDictionary();
Metadata.Languages = new SortedDictionary<string,int>(Languages);

foreach (MetricTagCounter metricTagCounter in TagCounters.Values)
{
Expand Down

0 comments on commit c16ca2a

Please sign in to comment.