Skip to content

Commit 39ce146

Browse files
committed
Use factory methods instead of fluent. Get rid of GenAPIConfiguration, split it into two separate classes.
1 parent aee4c66 commit 39ce146

File tree

13 files changed

+606
-698
lines changed

13 files changed

+606
-698
lines changed

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI.Task/GenAPITask.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.Build.Framework;
5+
using Microsoft.CodeAnalysis;
6+
using Microsoft.DotNet.ApiSymbolExtensions;
57
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
68
using Microsoft.NET.Build.Tasks;
79

@@ -62,20 +64,20 @@ public class GenAPITask : TaskBase
6264
/// <inheritdoc />
6365
protected override void ExecuteCore()
6466
{
65-
GenAPIConfiguration config = GenAPIConfiguration.GetBuilder()
66-
.WithAssembliesPaths(Assemblies)
67-
.WithAssemblyReferencesPaths(AssemblyReferences)
68-
.WithRespectInternals(RespectInternals)
69-
.Build();
67+
(IAssemblySymbolLoader loader, Dictionary<string, IAssemblySymbol> assemblySymbols) = AssemblyLoaderFactory.CreateFromFiles(
68+
assembliesPaths: Assemblies ?? throw new NullReferenceException("Assemblies cannot be null."),
69+
assemblyReferencesPaths: AssemblyReferences,
70+
RespectInternals);
7071

7172
GenAPIApp.Run(new MSBuildLog(Log),
72-
config.AssemblySymbols,
73+
loader,
74+
assemblySymbols,
7375
OutputPath,
74-
config.Loader,
75-
GenAPIConfiguration.GetSymbolFilterFromFiles(ExcludeApiFiles, respectInternals: RespectInternals),
76-
GenAPIConfiguration.GetAttributeFilterFromPaths(ExcludeAttributesFiles, respectInternals: RespectInternals),
77-
GenAPIConfiguration.GetFormattedHeader(HeaderFile),
76+
HeaderFile,
7877
ExceptionMessage,
78+
ExcludeApiFiles,
79+
ExcludeAttributesFiles,
80+
RespectInternals,
7981
IncludeAssemblyAttributes);
8082
}
8183
}

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI.Tool/Program.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using System.CommandLine.Parsing;
66
using System.Diagnostics;
77
using System.Reflection;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.DotNet.ApiSymbolExtensions;
810
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
911

1012
namespace Microsoft.DotNet.GenAPI.Tool
@@ -97,23 +99,24 @@ static int Main(string[] args)
9799

98100
rootCommand.SetAction((ParseResult parseResult) =>
99101
{
100-
GenAPIConfiguration config = GenAPIConfiguration.GetBuilder()
101-
.WithAssembliesPaths(parseResult.GetValue(assembliesOption)!)
102-
.WithAssemblyReferencesPaths(parseResult.GetValue(assemblyReferencesOption))
103-
.WithRespectInternals(parseResult.GetValue(respectInternalsOption))
104-
.Build();
105-
106102
bool respectInternals = parseResult.GetValue(respectInternalsOption);
107103

104+
(IAssemblySymbolLoader loader, Dictionary<string, IAssemblySymbol> assemblySymbols) = AssemblyLoaderFactory.CreateFromFiles(
105+
assembliesPaths: parseResult.GetValue(assembliesOption) ?? throw new NullReferenceException("No assemblies provided."),
106+
assemblyReferencesPaths: parseResult.GetValue(assemblyReferencesOption),
107+
respectInternals);
108+
108109
GenAPIApp.Run(new ConsoleLog(MessageImportance.Normal),
109-
config.AssemblySymbols,
110-
parseResult.GetValue(outputPathOption),
111-
config.Loader,
112-
GenAPIConfiguration.GetSymbolFilterFromFiles(parseResult.GetValue(excludeApiFilesOption), respectInternals),
113-
GenAPIConfiguration.GetAttributeFilterFromPaths(parseResult.GetValue(excludeAttributesFilesOption), respectInternals),
114-
GenAPIConfiguration.GetFormattedHeader(parseResult.GetValue(headerFileOption)),
115-
parseResult.GetValue(exceptionMessageOption),
116-
parseResult.GetValue(includeAssemblyAttributesOption));
110+
loader,
111+
assemblySymbols,
112+
parseResult.GetValue(outputPathOption),
113+
parseResult.GetValue(headerFileOption),
114+
parseResult.GetValue(exceptionMessageOption),
115+
parseResult.GetValue(excludeApiFilesOption),
116+
parseResult.GetValue(excludeAttributesFilesOption),
117+
respectInternals,
118+
parseResult.GetValue(includeAssemblyAttributesOption)
119+
);
117120
});
118121

119122
return rootCommand.Parse(args).Invoke();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.DotNet.ApiSymbolExtensions;
6+
using Microsoft.DotNet.ApiSymbolExtensions.Filtering;
7+
using Microsoft.DotNet.GenAPI.Filtering;
8+
9+
namespace Microsoft.DotNet.GenAPI;
10+
11+
public class AssemblyLoaderFactory
12+
{
13+
public static (IAssemblySymbolLoader, Dictionary<string, IAssemblySymbol>) CreateFromFiles(string[] assembliesPaths, string[]? assemblyReferencesPaths, bool respectInternals = false)
14+
{
15+
AssemblySymbolLoader loader;
16+
Dictionary<string, IAssemblySymbol> assemblySymbols;
17+
18+
if (assembliesPaths.Length == 0)
19+
{
20+
CreateWithNoAssemblies();
21+
}
22+
23+
bool atLeastOneReferencePath = assemblyReferencesPaths?.Count() > 0;
24+
loader = new AssemblySymbolLoader(resolveAssemblyReferences: atLeastOneReferencePath, respectInternals);
25+
if (atLeastOneReferencePath)
26+
{
27+
loader.AddReferenceSearchPaths(assemblyReferencesPaths!);
28+
}
29+
assemblySymbols = new Dictionary<string, IAssemblySymbol>(loader.LoadAssembliesAsDictionary(assembliesPaths));
30+
31+
return (loader, assemblySymbols);
32+
}
33+
34+
public static (IAssemblySymbolLoader, Dictionary<string, IAssemblySymbol>) CreateWithNoAssemblies(bool respectInternals = false) =>
35+
(new AssemblySymbolLoader(resolveAssemblyReferences: true, includeInternalSymbols: respectInternals), new Dictionary<string, IAssemblySymbol>());
36+
}

0 commit comments

Comments
 (0)