Skip to content

Commit 6adda0e

Browse files
authored
IProjectManagerFactory now returns IBaseProjectManager instead of BaseProjectManager (#417)
1 parent 7ed7c08 commit 6adda0e

File tree

14 files changed

+41
-30
lines changed

14 files changed

+41
-30
lines changed

src/Shared.CLI/Helpers/OutputBuilder/SarifOutputBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Microsoft.CST.OpenSource.Shared
44
{
5+
using Contracts;
56
using Microsoft.CodeAnalysis.Sarif;
67
using Microsoft.CST.OpenSource.PackageManagers;
78
using Newtonsoft.Json;
@@ -26,7 +27,7 @@ public SarifOutputBuilder(SarifVersion version)
2627
/// <returns>Location list with single location object</returns>
2728
public static List<Location> BuildPurlLocation(PackageURL purl)
2829
{
29-
BaseProjectManager? projectManager = ProjectManagerFactory.ConstructPackageManager(purl, null);
30+
IBaseProjectManager? projectManager = ProjectManagerFactory.ConstructPackageManager(purl, null);
3031
if (projectManager == null)
3132
{
3233
Logger.Debug("Cannot determine the package type");

src/Shared.CLI/Helpers/PackageDownloader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Microsoft.CST.OpenSource
44
{
5+
using Contracts;
56
using Extensions;
67
using Microsoft.CST.OpenSource.Helpers;
78
using Microsoft.CST.OpenSource.PackageManagers;
@@ -293,7 +294,7 @@ public async Task<List<PackageURL>> GetPackageVersionsToProcess(PackageURL purl)
293294
// folders created
294295
private List<string> downloadPaths { get; set; } = new List<string>();
295296

296-
private BaseProjectManager? packageManager { get; set; }
297+
private IBaseProjectManager? packageManager { get; set; }
297298
public List<PackageURL> PackageVersions { get; set; }
298299
}
299300
}

src/Shared.CLI/Helpers/RepoSearch.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Microsoft.CST.OpenSource.Shared
44
{
5+
using Contracts;
56
using Microsoft.CST.OpenSource.PackageManagers;
67
using PackageUrl;
78
using System;
@@ -59,7 +60,7 @@ public async Task<Dictionary<PackageURL, double>> ResolvePackageLibraryAsync(Pac
5960
Logger.Debug("Searching for source code for: {0}", purlNoVersion.ToString());
6061

6162
// Get the correct project manager using the factory.
62-
BaseProjectManager? projectManager = _projectManagerFactory.CreateProjectManager(purl);
63+
IBaseProjectManager? projectManager = _projectManagerFactory.CreateProjectManager(purl);
6364

6465
if (projectManager != null)
6566
{

src/Shared/Contracts/IProjectManagerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ public interface IProjectManagerFactory
1313
/// <param name="purl">The <see cref="PackageURL"/> for the package to create the project manager for.</param>
1414
/// <param name="destinationDirectory">The new destination directory, if provided.</param>
1515
/// <returns>The implementation of <see cref="BaseProjectManager"/> for this <paramref name="purl"/>'s type.</returns>
16-
BaseProjectManager? CreateProjectManager(PackageURL purl, string destinationDirectory = ".");
16+
IBaseProjectManager? CreateProjectManager(PackageURL purl, string destinationDirectory = ".");
1717
}

src/Shared/PackageManagers/ProjectManagerFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static Dictionary<string, ConstructProjectManager> GetDefaultManagers(IHt
132132
}
133133

134134
/// <inheritdoc />
135-
public BaseProjectManager? CreateProjectManager(PackageURL purl, string destinationDirectory = ".")
135+
public IBaseProjectManager? CreateProjectManager(PackageURL purl, string destinationDirectory = ".")
136136
{
137137
ConstructProjectManager? projectManager = _projectManagers.GetValueOrDefault(purl.Type);
138138

@@ -147,7 +147,7 @@ public static Dictionary<string, ConstructProjectManager> GetDefaultManagers(IHt
147147
/// <param name="overrideManagers"> If provided, will set the project manager dictionary instead of using the defaults.</param>
148148
/// <param name="destinationDirectory">The new destination directory, if provided.</param>
149149
/// <returns>A new <see cref="BaseProjectManager"/> implementation.</returns>
150-
public static BaseProjectManager? ConstructPackageManager(PackageURL packageUrl, IHttpClientFactory? httpClientFactory = null, Dictionary<string, ConstructProjectManager>? overrideManagers = null, string destinationDirectory = ".")
150+
public static IBaseProjectManager? ConstructPackageManager(PackageURL packageUrl, IHttpClientFactory? httpClientFactory = null, Dictionary<string, ConstructProjectManager>? overrideManagers = null, string destinationDirectory = ".")
151151
{
152152
if (overrideManagers != null && overrideManagers.Any())
153153
{

src/oss-diff/DiffTool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace Microsoft.CST.OpenSource.DiffTool
2222
{
23+
using Contracts;
2324
using Microsoft.CST.OpenSource.Helpers;
2425
using Microsoft.CST.OpenSource.PackageManagers;
2526
using PackageUrl;
@@ -120,7 +121,7 @@ public async Task<IOutputBuilder> DiffProjects(Options options)
120121
try
121122
{
122123
PackageURL purl1 = new PackageURL(options.Targets.First());
123-
BaseProjectManager? manager = ProjectManagerFactory.CreateProjectManager(purl1, options.DownloadDirectory ?? Path.GetTempPath());
124+
IBaseProjectManager? manager = ProjectManagerFactory.CreateProjectManager(purl1, options.DownloadDirectory ?? Path.GetTempPath());
124125

125126
if (manager is not null)
126127
{
@@ -154,7 +155,7 @@ public async Task<IOutputBuilder> DiffProjects(Options options)
154155
try
155156
{
156157
PackageURL purl2 = new PackageURL(options.Targets.Last());
157-
BaseProjectManager? manager2 = ProjectManagerFactory.CreateProjectManager(purl2, options.DownloadDirectory ?? Path.GetTempPath());
158+
IBaseProjectManager? manager2 = ProjectManagerFactory.CreateProjectManager(purl2, options.DownloadDirectory ?? Path.GetTempPath());
158159

159160
if (manager2 is not null)
160161
{

src/oss-find-squats-lib/FindPackageSquats.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Microsoft.CST.OpenSource.FindSquats
44
{
5+
using Contracts;
56
using ExtensionMethods;
67
using Microsoft.CST.OpenSource;
78
using Microsoft.CST.OpenSource.Exceptions;
@@ -19,7 +20,7 @@ public class FindPackageSquats : OssGadgetLib
1920
/// </summary>
2021
public PackageURL PackageUrl { get; }
2122

22-
public BaseProjectManager? ProjectManager { get; }
23+
public IBaseProjectManager? ProjectManager { get; }
2324

2425
public FindPackageSquats(ProjectManagerFactory projectManagerFactory, PackageURL packageUrl)
2526
: base(projectManagerFactory)

src/oss-find-squats-lib/MutateExtension.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Microsoft.CST.OpenSource.FindSquats.ExtensionMethods
44
{
5+
using Contracts;
56
using Extensions;
67
using Microsoft.CST.OpenSource.FindSquats.Mutators;
78
using Microsoft.CST.OpenSource.PackageManagers;
@@ -94,7 +95,7 @@ public static class MutateExtension
9495
/// </summary>
9596
/// <param name="manager"></param>
9697
/// <returns>An IEnumerable of the recommended IMutators.</returns>
97-
public static IEnumerable<IMutator> GetDefaultMutators(this BaseProjectManager manager) => manager switch
98+
public static IEnumerable<IMutator> GetDefaultMutators(this IBaseProjectManager manager) => manager switch
9899
{
99100
NuGetProjectManager => NugetMutators,
100101
NPMProjectManager => NpmMutators,
@@ -110,7 +111,7 @@ public static class MutateExtension
110111
/// <param name="purl">The Target package to check for squats.</param>
111112
/// <param name="options">The options for enumerating squats.</param>
112113
/// <returns>An <see cref="IDictionary{T, V}"/> where the key is the mutated name, and the value is a <see cref="IList{Mutation}"/> representing each candidate squat.</returns>
113-
public static IDictionary<string, IList<Mutation>>? EnumerateSquatCandidates(this BaseProjectManager manager, PackageURL purl, MutateOptions? options = null)
114+
public static IDictionary<string, IList<Mutation>>? EnumerateSquatCandidates(this IBaseProjectManager manager, PackageURL purl, MutateOptions? options = null)
114115
{
115116
return manager.EnumerateSquatCandidates(purl, manager.GetDefaultMutators(), options);
116117
}
@@ -124,7 +125,7 @@ public static class MutateExtension
124125
/// <param name="mutators">The mutators to use. Will ignore the default set of mutators.</param>
125126
/// <param name="options">The options for enumerating squats.</param>
126127
/// <returns>An <see cref="IDictionary{T, V}"/> where the key is the mutated name, and the value is a <see cref="IList{Mutation}"/> representing each candidate squat.</returns>
127-
public static IDictionary<string, IList<Mutation>>? EnumerateSquatCandidates(this BaseProjectManager manager, PackageURL purl, IEnumerable<IMutator> mutators, MutateOptions? options = null)
128+
public static IDictionary<string, IList<Mutation>>? EnumerateSquatCandidates(this IBaseProjectManager manager, PackageURL purl, IEnumerable<IMutator> mutators, MutateOptions? options = null)
128129
{
129130
if (purl.Name is null || purl.Type is null)
130131
{
@@ -164,7 +165,7 @@ public static class MutateExtension
164165
/// <param name="candidateMutations">The <see cref="IList{Mutation}"/> representing each squatting candidate.</param>
165166
/// <param name="options">The options for enumerating through existing squats.</param>
166167
/// <returns>An <see cref="IAsyncEnumerable{FindPackageSquatResult}"/> with the packages that exist which match one of the <paramref name="candidateMutations"/>.</returns>
167-
public static async IAsyncEnumerable<FindPackageSquatResult> EnumerateExistingSquatsAsync(this BaseProjectManager manager, PackageURL purl, IDictionary<string, IList<Mutation>>? candidateMutations, MutateOptions? options = null)
168+
public static async IAsyncEnumerable<FindPackageSquatResult> EnumerateExistingSquatsAsync(this IBaseProjectManager manager, PackageURL purl, IDictionary<string, IList<Mutation>>? candidateMutations, MutateOptions? options = null)
168169
{
169170
if (purl.Name is null || purl.Type is null)
170171
{

src/oss-health/HealthMetrics.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Microsoft.CST.OpenSource.Health
1515
{
16+
using Contracts;
1617
using PackageUrl;
1718

1819
public class HealthMetrics
@@ -43,7 +44,7 @@ public void Normalize()
4344

4445
public List<Result> toSarif()
4546
{
46-
BaseProjectManager? projectManager = ProjectManagerFactory.ConstructPackageManager(purl, null);
47+
IBaseProjectManager? projectManager = ProjectManagerFactory.ConstructPackageManager(purl, null);
4748

4849
if (projectManager == null)
4950
{

src/oss-health/HealthTool.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Microsoft.CST.OpenSource
1313
{
14+
using Contracts;
1415
using Microsoft.CST.OpenSource.PackageManagers;
1516
using PackageUrl;
1617

@@ -26,7 +27,7 @@ public HealthTool() : this(new ProjectManagerFactory())
2627
}
2728
public async Task<HealthMetrics?> CheckHealth(PackageURL purl)
2829
{
29-
BaseProjectManager? packageManager = ProjectManagerFactory.CreateProjectManager(purl);
30+
IBaseProjectManager? packageManager = ProjectManagerFactory.CreateProjectManager(purl);
3031

3132
if (packageManager != null)
3233
{

0 commit comments

Comments
 (0)