Skip to content

Commit 969ad1b

Browse files
authored
Tidy interfaces just a bit (#1044)
* Use ISet instead of HashSet in IConformanceEnforcer * Use IList instead of List in interfaces * Use IDictionary instead of Dictionary in ILicenseInformationFetcher * Rename GenerationResult back to GeneratorResult
1 parent 0b1f302 commit 969ad1b

22 files changed

+70
-70
lines changed

src/Microsoft.Sbom.Api/Executors/ComponentDetectionBaseWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ async Task Scan(string path)
141141
{
142142
licenseInformationRetrieved = true;
143143

144-
List<string> apiResponses;
144+
IList<string> apiResponses;
145145

146146
apiResponses = await licenseInformationFetcher.FetchLicenseInformationAsync(listOfComponentsForApi, configuration.LicenseInformationTimeoutInSeconds.Value);
147147

src/Microsoft.Sbom.Api/Executors/GenerationResult.cs renamed to src/Microsoft.Sbom.Api/Executors/GeneratorResult.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ namespace Microsoft.Sbom.Api.Workflows.Helpers;
1111
/// <summary>
1212
/// Result from GenerateAsync
1313
/// </summary>
14-
public class GenerationResult
14+
public class GeneratorResult
1515
{
16-
public List<FileValidationResult> Errors { get; }
16+
public IList<FileValidationResult> Errors { get; }
1717

18-
public IReadOnlyDictionary<IManifestToolJsonSerializer, List<JsonDocument>> SerializerToJsonDocuments { get; }
18+
public IReadOnlyDictionary<IManifestToolJsonSerializer, IList<JsonDocument>> SerializerToJsonDocuments { get; }
1919

2020
public IReadOnlyDictionary<ISbomConfig, bool> JsonArrayStartedForConfig { get; }
2121

@@ -25,7 +25,7 @@ public class GenerationResult
2525
/// <param name="errors">List of FileValidationResult errors.</param>
2626
/// <param name="serializerToJsonDocuments">Dictionary to map serializer to the JSON document that should be written to it.</param>
2727
/// <param name="jsonArrayStartedForConfig">This value determines whether a JSON array for a section is started for the specified config. This is only used for SPDX 2.2 SBOM generation.</param>
28-
public GenerationResult(List<FileValidationResult> errors, IReadOnlyDictionary<IManifestToolJsonSerializer, List<JsonDocument>> serializerToJsonDocuments, IReadOnlyDictionary<ISbomConfig, bool> jsonArrayStartedForConfig)
28+
public GeneratorResult(IList<FileValidationResult> errors, IReadOnlyDictionary<IManifestToolJsonSerializer, IList<JsonDocument>> serializerToJsonDocuments, IReadOnlyDictionary<ISbomConfig, bool> jsonArrayStartedForConfig)
2929
{
3030
Errors = errors;
3131
SerializerToJsonDocuments = serializerToJsonDocuments;

src/Microsoft.Sbom.Api/Executors/IJsonSerializationStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ internal interface IJsonSerializationStrategy
5959
/// <param name="sbomConfig"></param>
6060
public void EndGraphArray(ISbomConfig sbomConfig);
6161

62-
public void WriteJsonObjectsToManifest(GenerationResult generationResult, ISbomConfig config, ISet<string> elementsSpdxIdList);
62+
public void WriteJsonObjectsToManifest(GeneratorResult generatorResult, ISbomConfig config, ISet<string> elementsSpdxIdList);
6363
}

src/Microsoft.Sbom.Api/Executors/ILicenseInformationFetcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ public interface ILicenseInformationFetcher
1515
/// </summary>
1616
/// <param name="scannedComponents"> An IEnumerable of ScannedComponents given by the Component Detection libraries after a scan is completed.</param>
1717
/// <returns></returns>
18-
public List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents);
18+
public IList<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents);
1919

2020
/// <summary>
2121
/// Calls the ClearlyDefined API to get the license information for the list of components.
2222
/// </summary>
2323
/// <param name="listOfComponentsForApi"> A list of strings formatted into a list of strings that can be used to call the batch ClearlyDefined API.</param>
2424
/// <param name="timeoutInSeconds">Timeout in seconds to use when making web requests. Caller owns sanitizing this value</param>
2525
/// <returns></returns>
26-
public Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds);
26+
public Task<IList<string>> FetchLicenseInformationAsync(IList<string> listOfComponentsForApi, int timeoutInSeconds);
2727

2828
/// <summary>
2929
/// Gets the dictionary of licenses that were fetched from the ClearlyDefined API.
@@ -36,14 +36,14 @@ public interface ILicenseInformationFetcher
3636
/// </summary>
3737
/// <param name="httpResponse"> The response from a ClearlyDefined API request.</param>
3838
/// <returns></returns>
39-
public Dictionary<string, string> ConvertClearlyDefinedApiResponseToList(string httpResponseContent);
39+
public IDictionary<string, string> ConvertClearlyDefinedApiResponseToList(string httpResponseContent);
4040

4141
/// <summary>
4242
/// Appends the licenses from the partialLicenseDictionary to the licenseDictionary.
4343
/// We only request license information for 400 components at a time so we can end up with multiple responses. This function is used to combine the responses into a single dictionary.
4444
/// </summary>
4545
/// <param name="partialLicenseDictionary"> A dictionary of licenses and component names in the {name@version, license} format</param>
46-
public void AppendLicensesToDictionary(Dictionary<string, string> partialLicenseDictionary);
46+
public void AppendLicensesToDictionary(IDictionary<string, string> partialLicenseDictionary);
4747

4848
/// <summary>
4949
/// Gets the license from the licenseDictionary.

src/Microsoft.Sbom.Api/Executors/ILicenseInformationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ namespace Microsoft.Sbom.Api.Executors;
88

99
public interface ILicenseInformationService
1010
{
11-
public Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi, int timeoutInSeconds);
11+
public Task<IList<string>> FetchLicenseInformationFromAPI(IList<string> listOfComponentsForApi, int timeoutInSeconds);
1212
}

src/Microsoft.Sbom.Api/Executors/LicenseInformationFetcher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public LicenseInformationFetcher(ILogger log, IRecorder recorder, ILicenseInform
2828
this.licenseInformationService = licenseInformationService ?? throw new ArgumentNullException(nameof(licenseInformationService));
2929
}
3030

31-
public List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents)
31+
public IList<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent> scannedComponents)
3232
{
3333
var listOfComponentsForApi = new List<string>();
3434

@@ -82,13 +82,13 @@ public List<string> ConvertComponentsToListForApi(IEnumerable<ScannedComponent>
8282
return listOfComponentsForApi;
8383
}
8484

85-
public async Task<List<string>> FetchLicenseInformationAsync(List<string> listOfComponentsForApi, int timeoutInSeconds)
85+
public async Task<IList<string>> FetchLicenseInformationAsync(IList<string> listOfComponentsForApi, int timeoutInSeconds)
8686
{
8787
return await licenseInformationService.FetchLicenseInformationFromAPI(listOfComponentsForApi, timeoutInSeconds);
8888
}
8989

9090
// Will attempt to extract license information from a clearlyDefined batch API response. Will always return a dictionary which may be empty depending on the response.
91-
public Dictionary<string, string> ConvertClearlyDefinedApiResponseToList(string httpResponseContent)
91+
public IDictionary<string, string> ConvertClearlyDefinedApiResponseToList(string httpResponseContent)
9292
{
9393
var extractedLicenses = new Dictionary<string, string>();
9494

@@ -142,7 +142,7 @@ public ConcurrentDictionary<string, string> GetLicenseDictionary()
142142
return licenseDictionary;
143143
}
144144

145-
public void AppendLicensesToDictionary(Dictionary<string, string> partialLicenseDictionary)
145+
public void AppendLicensesToDictionary(IDictionary<string, string> partialLicenseDictionary)
146146
{
147147
foreach (var kvp in partialLicenseDictionary)
148148
{

src/Microsoft.Sbom.Api/Executors/LicenseInformationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public LicenseInformationService(ILogger log, IRecorder recorder, HttpClient htt
2828
this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
2929
}
3030

31-
public async Task<List<string>> FetchLicenseInformationFromAPI(List<string> listOfComponentsForApi, int timeoutInSeconds)
31+
public async Task<IList<string>> FetchLicenseInformationFromAPI(IList<string> listOfComponentsForApi, int timeoutInSeconds)
3232
{
3333
var batchSize = 500;
3434
var responses = new List<HttpResponseMessage>();

src/Microsoft.Sbom.Api/Executors/Spdx22SerializationStrategy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ public void EndGraphArray(ISbomConfig sbomConfig)
7676
/// <summary>
7777
/// Writes the json objects to the manifest in SPDX 2.2 format.
7878
/// </summary>
79-
/// <param name="generationResult"></param>
79+
/// <param name="generatorResult"></param>
8080
/// <param name="config"></param>
8181
/// <param name="elementsSpdxIdList">Not used for deduplication. Only used for >= SPDX 3.0.</param>
82-
public void WriteJsonObjectsToManifest(GenerationResult generationResult, ISbomConfig config, ISet<string> elementsSpdxIdList)
82+
public void WriteJsonObjectsToManifest(GeneratorResult generatorResult, ISbomConfig config, ISet<string> elementsSpdxIdList)
8383
{
8484
var serializer = config.JsonSerializer;
8585

86-
if (generationResult.SerializerToJsonDocuments.TryGetValue(serializer, out var jsonDocuments))
86+
if (generatorResult.SerializerToJsonDocuments.TryGetValue(serializer, out var jsonDocuments))
8787
{
8888
if (jsonDocuments.Count > 0)
8989
{
@@ -94,7 +94,7 @@ public void WriteJsonObjectsToManifest(GenerationResult generationResult, ISbomC
9494
}
9595
}
9696

97-
var jsonArrayStarted = generationResult.JsonArrayStartedForConfig[config];
97+
var jsonArrayStarted = generatorResult.JsonArrayStartedForConfig[config];
9898
if (jsonArrayStarted)
9999
{
100100
config.JsonSerializer.EndJsonArray();

src/Microsoft.Sbom.Api/Executors/Spdx30SerializationStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ public void EndGraphArray(ISbomConfig sbomConfig)
8787
/// <summary>
8888
/// Writes the JSON objects in SPDX 3.0 format.
8989
/// </summary>
90-
/// <param name="generationResult"></param>
90+
/// <param name="generatorResult"></param>
9191
/// <param name="config"></param>
9292
/// <param name="elementsSpdxIdList">Hashes for deduplication in SPDX 3.0.</param>
93-
public void WriteJsonObjectsToManifest(GenerationResult generationResult, ISbomConfig config, ISet<string> elementsSpdxIdList)
93+
public void WriteJsonObjectsToManifest(GeneratorResult generatorResult, ISbomConfig config, ISet<string> elementsSpdxIdList)
9494
{
9595
var serializer = config.JsonSerializer;
9696

97-
if (generationResult.SerializerToJsonDocuments.TryGetValue(serializer, out var jsonDocuments))
97+
if (generatorResult.SerializerToJsonDocuments.TryGetValue(serializer, out var jsonDocuments))
9898
{
9999
foreach (var jsonDocument in jsonDocuments)
100100
{

src/Microsoft.Sbom.Api/Workflows/Helpers/ExternalDocumentReferenceGenerator.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ExternalDocumentReferenceGenerator(
3636
this.recorder = recorder ?? throw new ArgumentNullException(nameof(recorder));
3737
}
3838

39-
public async Task<GenerationResult> GenerateAsync(IEnumerable<ISbomConfig> targetConfigs, ISet<string> elementsSpdxIdList)
39+
public async Task<GeneratorResult> GenerateAsync(IEnumerable<ISbomConfig> targetConfigs, ISet<string> elementsSpdxIdList)
4040
{
4141
using (recorder.TraceEvent(Events.ExternalDocumentReferenceGeneration))
4242
{
@@ -50,7 +50,7 @@ public async Task<GenerationResult> GenerateAsync(IEnumerable<ISbomConfig> targe
5050
if (!externalDocumentReferenceSourcesProvider.Any())
5151
{
5252
log.Debug($"No source providers found for {ProviderType.ExternalDocumentReference}");
53-
return new GenerationResult(totalErrors, jsonDocumentCollection.SerializersToJson, jsonArrayStartedForConfig);
53+
return new GeneratorResult(totalErrors, jsonDocumentCollection.SerializersToJson, jsonArrayStartedForConfig);
5454
}
5555

5656
// Write the start of the array, if supported.
@@ -83,16 +83,16 @@ public async Task<GenerationResult> GenerateAsync(IEnumerable<ISbomConfig> targe
8383
}
8484
}
8585

86-
var generationResult = new GenerationResult(totalErrors, jsonDocumentCollection.SerializersToJson, jsonArrayStartedForConfig);
86+
var generatorResult = new GeneratorResult(totalErrors, jsonDocumentCollection.SerializersToJson, jsonArrayStartedForConfig);
8787
foreach (var config in targetConfigs)
8888
{
8989
var serializationStrategy = JsonSerializationStrategyFactory.GetStrategy(config.ManifestInfo.Version);
90-
serializationStrategy.WriteJsonObjectsToManifest(generationResult, config, elementsSpdxIdList);
90+
serializationStrategy.WriteJsonObjectsToManifest(generatorResult, config, elementsSpdxIdList);
9191
}
9292

9393
jsonDocumentCollection.DisposeAllJsonDocuments();
9494

95-
return generationResult;
95+
return generatorResult;
9696
}
9797
}
9898
}

0 commit comments

Comments
 (0)