Skip to content

Commit f69cc9c

Browse files
authored
dotnet CLI: file-scoped namespaces and namespace adjustments (#47516)
2 parents 9c64e2f + 90d236a commit f69cc9c

File tree

553 files changed

+32761
-33403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

553 files changed

+32761
-33403
lines changed

exclusion.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ crossgen
55
csharp
66
cshtml
77
deserializer
8+
microsoft
89
msbuild
910
muxer
1011
nuget

src/Cli/dotnet/AspNetCoreCertificateGenerator.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
using Microsoft.DotNet.Configurer;
55

6-
namespace Microsoft.DotNet.Cli
6+
namespace Microsoft.DotNet.Cli;
7+
8+
public class AspNetCoreCertificateGenerator : IAspNetCoreCertificateGenerator
79
{
8-
public class AspNetCoreCertificateGenerator : IAspNetCoreCertificateGenerator
10+
public void GenerateAspNetCoreDevelopmentCertificate()
911
{
10-
public void GenerateAspNetCoreDevelopmentCertificate()
11-
{
1212
#if !EXCLUDE_ASPNETCORE
13-
AspNetCore.DeveloperCertificates.XPlat.CertificateGenerator.GenerateAspNetHttpsCertificate();
13+
AspNetCore.DeveloperCertificates.XPlat.CertificateGenerator.GenerateAspNetHttpsCertificate();
1414
#endif
15-
}
1615
}
1716
}

src/Cli/dotnet/AutomaticEncodingRestorer.cs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,58 @@
33

44
using System.Security;
55

6-
namespace Microsoft.DotNet.Cli
6+
namespace Microsoft.DotNet.Cli;
7+
8+
/// <summary>
9+
/// A program can change the encoding of the console which would affect other programs.
10+
/// We would prefer to have a pattern where the program does not affect encoding of other programs.
11+
/// Create this class in a function akin to Main and let it manage the console encoding resources to return it to the state before execution upon destruction.
12+
/// </summary>
13+
internal class AutomaticEncodingRestorer : IDisposable
714
{
8-
/// <summary>
9-
/// A program can change the encoding of the console which would affect other programs.
10-
/// We would prefer to have a pattern where the program does not affect encoding of other programs.
11-
/// Create this class in a function akin to Main and let it manage the console encoding resources to return it to the state before execution upon destruction.
12-
/// </summary>
13-
internal class AutomaticEncodingRestorer : IDisposable
14-
{
15-
Encoding _originalOutputEncoding = null;
16-
Encoding _originalInputEncoding = null;
15+
Encoding _originalOutputEncoding = null;
16+
Encoding _originalInputEncoding = null;
1717

18-
bool outputEncodingAccessible = false;
19-
bool inputEncodingAccessible = false;
18+
bool outputEncodingAccessible = false;
19+
bool inputEncodingAccessible = false;
2020

21-
public AutomaticEncodingRestorer()
21+
public AutomaticEncodingRestorer()
22+
{
23+
try
2224
{
23-
try
25+
if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) // Output + Input Encoding are unavailable on these platforms per docs.
2426
{
25-
if (!OperatingSystem.IsIOS() && !OperatingSystem.IsAndroid() && !OperatingSystem.IsTvOS()) // Output + Input Encoding are unavailable on these platforms per docs.
27+
_originalOutputEncoding = Console.OutputEncoding;
28+
outputEncodingAccessible = true;
29+
if (!OperatingSystem.IsBrowser()) // Input Encoding is also unavailable in this platform.
2630
{
27-
_originalOutputEncoding = Console.OutputEncoding;
28-
outputEncodingAccessible = true;
29-
if (!OperatingSystem.IsBrowser()) // Input Encoding is also unavailable in this platform.
30-
{
31-
_originalInputEncoding = Console.InputEncoding;
32-
inputEncodingAccessible = true;
33-
}
31+
_originalInputEncoding = Console.InputEncoding;
32+
inputEncodingAccessible = true;
3433
}
3534
}
36-
catch (Exception ex) when (ex is IOException || ex is SecurityException)
37-
{
38-
// The encoding is unavailable. Do nothing.
39-
}
4035
}
36+
catch (Exception ex) when (ex is IOException || ex is SecurityException)
37+
{
38+
// The encoding is unavailable. Do nothing.
39+
}
40+
}
4141

42-
public void Dispose()
42+
public void Dispose()
43+
{
44+
try
4345
{
44-
try
46+
if (outputEncodingAccessible)
4547
{
46-
if (outputEncodingAccessible)
47-
{
48-
Console.OutputEncoding = _originalOutputEncoding;
49-
}
50-
if (inputEncodingAccessible)
51-
{
52-
Console.InputEncoding = _originalInputEncoding;
53-
}
48+
Console.OutputEncoding = _originalOutputEncoding;
5449
}
55-
catch (Exception ex) when (ex is IOException || ex is SecurityException)
50+
if (inputEncodingAccessible)
5651
{
57-
// The encoding is unavailable. Do nothing.
52+
Console.InputEncoding = _originalInputEncoding;
5853
}
5954
}
55+
catch (Exception ex) when (ex is IOException || ex is SecurityException)
56+
{
57+
// The encoding is unavailable. Do nothing.
58+
}
6059
}
6160
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.DotNet.BuildServer
4+
namespace Microsoft.DotNet.Cli.BuildServer;
5+
6+
internal class BuildServerException : Exception
57
{
6-
internal class BuildServerException : Exception
8+
public BuildServerException()
79
{
8-
public BuildServerException()
9-
{
10-
}
10+
}
1111

12-
public BuildServerException(string message) : base(message)
13-
{
14-
}
12+
public BuildServerException(string message) : base(message)
13+
{
14+
}
1515

16-
public BuildServerException(string message, Exception innerException) : base(message, innerException)
17-
{
18-
}
16+
public BuildServerException(string message, Exception innerException) : base(message, innerException)
17+
{
1918
}
2019
}

src/Cli/dotnet/BuildServer/BuildServerProvider.cs

Lines changed: 66 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,100 +6,92 @@
66
using Microsoft.DotNet.Configurer;
77
using Microsoft.Extensions.EnvironmentAbstractions;
88

9-
namespace Microsoft.DotNet.BuildServer
9+
namespace Microsoft.DotNet.Cli.BuildServer;
10+
11+
internal class BuildServerProvider(
12+
IFileSystem fileSystem = null,
13+
IEnvironmentProvider environmentProvider = null,
14+
IReporter reporter = null) : IBuildServerProvider
1015
{
11-
internal class BuildServerProvider : IBuildServerProvider
12-
{
13-
public const string PidFileDirectoryVariableName = "DOTNET_BUILD_PIDFILE_DIRECTORY";
14-
private readonly IFileSystem _fileSystem;
15-
private readonly IEnvironmentProvider _environmentProvider;
16-
private readonly IReporter _reporter;
16+
public const string PidFileDirectoryVariableName = "DOTNET_BUILD_PIDFILE_DIRECTORY";
17+
private readonly IFileSystem _fileSystem = fileSystem ?? FileSystemWrapper.Default;
18+
private readonly IEnvironmentProvider _environmentProvider = environmentProvider ?? new EnvironmentProvider();
19+
private readonly IReporter _reporter = reporter ?? Reporter.Error;
1720

18-
public BuildServerProvider(
19-
IFileSystem fileSystem = null,
20-
IEnvironmentProvider environmentProvider = null,
21-
IReporter reporter = null)
21+
public IEnumerable<IBuildServer> EnumerateBuildServers(ServerEnumerationFlags flags = ServerEnumerationFlags.All)
22+
{
23+
if ((flags & ServerEnumerationFlags.MSBuild) == ServerEnumerationFlags.MSBuild)
2224
{
23-
_fileSystem = fileSystem ?? FileSystemWrapper.Default;
24-
_environmentProvider = environmentProvider ?? new EnvironmentProvider();
25-
_reporter = reporter ?? Reporter.Error;
25+
// Yield a single MSBuild server (handles server discovery itself)
26+
// TODO: use pid file enumeration when supported by the server (https://github.com/dotnet/cli/issues/9113)
27+
yield return new MSBuildServer();
2628
}
2729

28-
public IEnumerable<IBuildServer> EnumerateBuildServers(ServerEnumerationFlags flags = ServerEnumerationFlags.All)
30+
if ((flags & ServerEnumerationFlags.VBCSCompiler) == ServerEnumerationFlags.VBCSCompiler)
2931
{
30-
if ((flags & ServerEnumerationFlags.MSBuild) == ServerEnumerationFlags.MSBuild)
31-
{
32-
// Yield a single MSBuild server (handles server discovery itself)
33-
// TODO: use pid file enumeration when supported by the server (https://github.com/dotnet/cli/issues/9113)
34-
yield return new MSBuildServer();
35-
}
36-
37-
if ((flags & ServerEnumerationFlags.VBCSCompiler) == ServerEnumerationFlags.VBCSCompiler)
38-
{
39-
// Yield a single VB/C# compiler (handles server discovery itself)
40-
// TODO: use pid file enumeration when supported by the server (https://github.com/dotnet/cli/issues/9112)
41-
yield return new VBCSCompilerServer();
42-
}
32+
// Yield a single VB/C# compiler (handles server discovery itself)
33+
// TODO: use pid file enumeration when supported by the server (https://github.com/dotnet/cli/issues/9112)
34+
yield return new VBCSCompilerServer();
35+
}
4336

44-
// TODO: remove or amend this check when the following issues are resolved:
45-
// https://github.com/dotnet/cli/issues/9112
46-
// https://github.com/dotnet/cli/issues/9113
47-
if ((flags & ServerEnumerationFlags.Razor) != ServerEnumerationFlags.Razor)
48-
{
49-
yield break;
50-
}
37+
// TODO: remove or amend this check when the following issues are resolved:
38+
// https://github.com/dotnet/cli/issues/9112
39+
// https://github.com/dotnet/cli/issues/9113
40+
if ((flags & ServerEnumerationFlags.Razor) != ServerEnumerationFlags.Razor)
41+
{
42+
yield break;
43+
}
5144

52-
var directory = GetPidFileDirectory();
45+
var directory = GetPidFileDirectory();
5346

54-
if (!_fileSystem.Directory.Exists(directory.Value))
55-
{
56-
yield break;
57-
}
47+
if (!_fileSystem.Directory.Exists(directory.Value))
48+
{
49+
yield break;
50+
}
5851

59-
foreach (var path in _fileSystem.Directory.EnumerateFiles(directory.Value))
52+
foreach (var path in _fileSystem.Directory.EnumerateFiles(directory.Value))
53+
{
54+
if ((flags & ServerEnumerationFlags.Razor) == ServerEnumerationFlags.Razor &&
55+
Path.GetFileName(path).StartsWith(RazorPidFile.FilePrefix))
6056
{
61-
if ((flags & ServerEnumerationFlags.Razor) == ServerEnumerationFlags.Razor &&
62-
Path.GetFileName(path).StartsWith(RazorPidFile.FilePrefix))
57+
var file = ReadRazorPidFile(new FilePath(path));
58+
if (file != null)
6359
{
64-
var file = ReadRazorPidFile(new FilePath(path));
65-
if (file != null)
66-
{
67-
yield return new RazorServer(file);
68-
}
60+
yield return new RazorServer(file);
6961
}
7062
}
7163
}
64+
}
7265

73-
public DirectoryPath GetPidFileDirectory()
66+
public DirectoryPath GetPidFileDirectory()
67+
{
68+
var directory = _environmentProvider.GetEnvironmentVariable(PidFileDirectoryVariableName);
69+
if (!string.IsNullOrEmpty(directory))
7470
{
75-
var directory = _environmentProvider.GetEnvironmentVariable(PidFileDirectoryVariableName);
76-
if (!string.IsNullOrEmpty(directory))
77-
{
78-
return new DirectoryPath(directory);
79-
}
80-
81-
return new DirectoryPath(
82-
Path.Combine(
83-
CliFolderPathCalculator.DotnetUserProfileFolderPath,
84-
"pids",
85-
"build"));
71+
return new DirectoryPath(directory);
8672
}
8773

88-
private RazorPidFile ReadRazorPidFile(FilePath path)
74+
return new DirectoryPath(
75+
Path.Combine(
76+
CliFolderPathCalculator.DotnetUserProfileFolderPath,
77+
"pids",
78+
"build"));
79+
}
80+
81+
private RazorPidFile ReadRazorPidFile(FilePath path)
82+
{
83+
try
8984
{
90-
try
91-
{
92-
return RazorPidFile.Read(path, _fileSystem);
93-
}
94-
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException)
95-
{
96-
_reporter.WriteLine(
97-
string.Format(
98-
LocalizableStrings.FailedToReadPidFile,
99-
path.Value,
100-
ex.Message).Yellow());
101-
return null;
102-
}
85+
return RazorPidFile.Read(path, _fileSystem);
86+
}
87+
catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException)
88+
{
89+
_reporter.WriteLine(
90+
string.Format(
91+
LocalizableStrings.FailedToReadPidFile,
92+
path.Value,
93+
ex.Message).Yellow());
94+
return null;
10395
}
10496
}
10597
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.DotNet.BuildServer
4+
namespace Microsoft.DotNet.Cli.BuildServer;
5+
6+
internal interface IBuildServer
57
{
6-
internal interface IBuildServer
7-
{
8-
int ProcessId { get; }
8+
int ProcessId { get; }
99

10-
string Name { get; }
10+
string Name { get; }
1111

12-
void Shutdown();
13-
}
12+
void Shutdown();
1413
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
namespace Microsoft.DotNet.BuildServer
4+
namespace Microsoft.DotNet.Cli.BuildServer;
5+
6+
[Flags]
7+
internal enum ServerEnumerationFlags
58
{
6-
[Flags]
7-
internal enum ServerEnumerationFlags
8-
{
9-
None = 0,
10-
MSBuild = 1,
11-
VBCSCompiler = 2,
12-
Razor = 4,
13-
All = MSBuild | VBCSCompiler | Razor
14-
}
9+
None = 0,
10+
MSBuild = 1,
11+
VBCSCompiler = 2,
12+
Razor = 4,
13+
All = MSBuild | VBCSCompiler | Razor
14+
}
1515

16-
internal interface IBuildServerProvider
17-
{
18-
IEnumerable<IBuildServer> EnumerateBuildServers(ServerEnumerationFlags flags = ServerEnumerationFlags.All);
19-
}
16+
internal interface IBuildServerProvider
17+
{
18+
IEnumerable<IBuildServer> EnumerateBuildServers(ServerEnumerationFlags flags = ServerEnumerationFlags.All);
2019
}

0 commit comments

Comments
 (0)