Skip to content

Commit 3e41ca3

Browse files
committed
Minor code cleanup
1 parent d23e7c7 commit 3e41ca3

File tree

67 files changed

+305
-472
lines changed

Some content is hidden

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

67 files changed

+305
-472
lines changed

src/DependenciesPackager/CrossGenToolFileNames.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,14 @@ public static CrossGenTool GetCrossGenTool(string runtimeMoniker)
2525
// eliminate the architecture part from the runtime monitor: debian8-x64 => debian8
2626
var platform = runtimeMoniker.Substring(0, runtimeMoniker.Length - 4);
2727

28-
CrossGenTool result;
29-
if (_executables.TryGetValue(platform, out result))
30-
{
31-
return result;
32-
}
33-
else
34-
{
35-
return null;
36-
}
28+
return _executables.TryGetValue(platform, out var result) ? result : null;
3729
}
3830

3931
public static IEnumerable<string> FindAllCrossGen(string searchPath) =>
4032
_executables.Values.Select(f => f.CrossGen).Distinct()
4133
.SelectMany(f => Directory.GetFiles(searchPath, f, SearchOption.AllDirectories));
4234

43-
public static IEnumerable<string> FindAllClrJIT(string searchPath) =>
35+
public static IEnumerable<string> FindAllClrJit(string searchPath) =>
4436
_executables.Values.Select(f => f.ClrJit).Distinct()
4537
.SelectMany(f => Directory.GetFiles(searchPath, f, SearchOption.AllDirectories));
4638

src/DependenciesPackager/CrossgenContext.cs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.Extensions.Logging;
5-
using NugetReferenceResolver;
64
using System;
75
using System.Collections.Generic;
86
using System.IO;
97
using System.Linq;
108
using System.Text;
119
using System.Threading.Tasks;
10+
using Microsoft.Extensions.Logging;
11+
using NugetReferenceResolver;
1212

1313
namespace DependenciesPackager
1414
{
@@ -21,7 +21,7 @@ internal class CrossgenContext
2121
private IEnumerable<PackageEntry> _packagesToCrossGen = Enumerable.Empty<PackageEntry>();
2222
private IEnumerable<PackageEntry> _referenceAssemblyPaths = Enumerable.Empty<PackageEntry>();
2323

24-
public IEnumerable<PackageAssembly> _crossGenAssets;
24+
private IEnumerable<PackageAssembly> _crossGenAssets;
2525
private string _clrJitPath;
2626
private string _crossgenExecutable;
2727

@@ -185,12 +185,13 @@ private CrossGenResult CrossgenAssembly(PackageEntry package, PackageAssembly as
185185
var assemblyPath = Path.GetFullPath(asset.ResolvedPath);
186186
var arguments = $"@\"{_responseFilePath}\" /JITPath \"{_clrJitPath}\" /in \"{assemblyPath}\" /out \"{targetPath}\"";
187187

188-
var crossGen = new CrossGenResult();
189-
crossGen.CrossGenArgumentsMessage = $@"Crossgen assembly
188+
var crossGen = new CrossGenResult
189+
{
190+
CrossGenArgumentsMessage = $@"Crossgen assembly
190191
assembly: {assemblyPath}
191192
output: {targetPath}
192-
arguments: {arguments}";
193-
193+
arguments: {arguments}"
194+
};
194195
var stdout = new StringBuilder();
195196
var stderr = new StringBuilder();
196197

@@ -278,7 +279,7 @@ public void PrintFailedCrossgenedPackages()
278279
if (firstFalingAsset)
279280
{
280281
firstFalingAsset = false;
281-
_logger.LogInformation(package.Library.Identity.ToString() + ":");
282+
_logger.LogInformation(package.Library.Identity + ":");
282283
}
283284

284285
if (exclusions.Contains(assetResult.Key.FileName, StringComparer.OrdinalIgnoreCase))
@@ -343,17 +344,18 @@ private DirectoryInfo CreateAssetSubDirectory(string cacheBasePath, PackageEntry
343344
public void CreateResponseFile()
344345
{
345346
_responseFilePath = Path.Combine(_destinationFolder, "aspnet-crossgen.rsp");
346-
var lines = new List<string>();
347-
lines.Add("/Platform_Assemblies_Paths");
348-
lines.Add("\"" + string.Join(
347+
var lines = new List<string>
348+
{
349+
"/Platform_Assemblies_Paths",
350+
"\"" + string.Join(
349351
Path.PathSeparator.ToString(),
350-
_referenceAssemblyPaths.SelectMany(e => e.Assets.Select(a => GetCleanedUpDirectoryPath(a)))) + "\"");
351-
lines.Add("/App_paths");
352-
lines.Add(
352+
_referenceAssemblyPaths.SelectMany(e => e.Assets.Select(GetCleanedUpDirectoryPath))) + "\"",
353+
"/App_paths",
353354
"\"" +
354-
string.Join(Path.PathSeparator.ToString(), _packagesToCrossGen.SelectMany(e => e.Assets.Select(a => GetCleanedUpDirectoryPath(a)))) +
355-
"\"");
356-
lines.Add("/ReadyToRun");
355+
string.Join(Path.PathSeparator.ToString(), _packagesToCrossGen.SelectMany(e => e.Assets.Select(GetCleanedUpDirectoryPath))) +
356+
"\"",
357+
"/ReadyToRun"
358+
};
357359
File.WriteAllLines(_responseFilePath, lines);
358360
}
359361

src/DependenciesPackager/OutputFilesContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.Extensions.Logging;
54
using System;
65
using System.Collections.Generic;
76
using System.IO;
87
using System.IO.Compression;
98
using System.Linq;
109
using System.Reflection.PortableExecutable;
1110
using System.Text;
11+
using Microsoft.Extensions.Logging;
1212

1313
namespace DependenciesPackager
1414
{
1515
internal class OutputFilesContext : IDisposable
1616
{
1717
private const int CrossGenFlag = 4;
18-
private ILogger _logger;
18+
private readonly ILogger _logger;
1919

2020
public OutputFilesContext(
2121
string destination,
@@ -66,7 +66,7 @@ public void PrintStatistics()
6666
{
6767
var buffer = new StringBuilder();
6868
buffer.Clear();
69-
buffer.AppendLine($"The following files are not crossgened.");
69+
buffer.AppendLine("The following files are not crossgened.");
7070

7171
foreach (var file in notCrossgend)
7272
{

src/DependenciesPackager/ProcessRunner.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ internal class ProcessRunner
1313
private readonly string _arguments;
1414
private readonly string _exePath;
1515
private readonly IDictionary<string, string> _environment = new Dictionary<string, string>();
16-
private Process _process = null;
17-
private object _writeLock = new object();
16+
private Process _process;
17+
private readonly object _writeLock = new object();
1818
private string _workingDirectory;
1919

2020
public ProcessRunner(
@@ -36,13 +36,13 @@ public ProcessRunner(
3636

3737
public ProcessRunner WriteErrorsToConsole()
3838
{
39-
OnError = s => Console.WriteLine(s);
39+
OnError = Console.WriteLine;
4040
return this;
4141
}
4242

4343
public ProcessRunner WriteOutputToConsole()
4444
{
45-
OnOutput = s => Console.WriteLine(s);
45+
OnOutput = Console.WriteLine;
4646
return this;
4747
}
4848

@@ -96,9 +96,11 @@ public int Run()
9696
}
9797

9898
var processInfo = CreateProcessInfo();
99-
_process = new Process();
100-
_process.StartInfo = processInfo;
101-
_process.EnableRaisingEvents = true;
99+
_process = new Process
100+
{
101+
StartInfo = processInfo,
102+
EnableRaisingEvents = true
103+
};
102104
_process.ErrorDataReceived += (s, e) => OnError(e.Data);
103105
_process.OutputDataReceived += (s, e) => OnOutput(e.Data);
104106
_process.Start();

src/DependenciesPackager/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.Extensions.CommandLineUtils;
5-
using Microsoft.Extensions.Logging;
6-
using NuGet.Frameworks;
7-
using NuGet.ProjectModel;
8-
using NugetReferenceResolver;
94
using System;
105
using System.Collections.Generic;
116
using System.IO;
127
using System.Linq;
138
using System.Threading;
9+
using Microsoft.Extensions.CommandLineUtils;
10+
using Microsoft.Extensions.Logging;
11+
using NugetReferenceResolver;
12+
using NuGet.Frameworks;
13+
using NuGet.ProjectModel;
1414

1515
namespace DependenciesPackager
1616
{
1717
class Program
1818
{
19-
private static readonly IEnumerable<NuGetFramework> FrameworkConfigurations =
19+
private static readonly IEnumerable<NuGetFramework> _frameworkConfigurations =
2020
new[] { FrameworkConstants.CommonFrameworks.NetCoreApp10 };
2121

2222
private const int Ok = 0;
@@ -77,9 +77,10 @@ public Program(
7777

7878
static int Main(string[] args)
7979
{
80-
var app = new CommandLineApplication();
81-
app.Name = "DependenciesPackager";
82-
80+
var app = new CommandLineApplication
81+
{
82+
Name = "DependenciesPackager"
83+
};
8384
app.HelpOption("-?|-h|--help");
8485

8586
var projectCsproj = app.Option(
@@ -202,7 +203,7 @@ private int Execute()
202203
var graph = PackageGraph.Create(format.Read(GetAssetsFile()), "netcoreapp1.1");
203204
var outputs = new List<OutputFilesContext>();
204205

205-
foreach (var framework in FrameworkConfigurations)
206+
foreach (var framework in _frameworkConfigurations)
206207
{
207208
foreach (var runtime in _optRuntime.Values)
208209
{

src/Internal.AspNetCore.BuildTools.Tasks/GenerateResxDesignerFiles.cs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ private static class Metadata
3737
public const string WithCulture = "WithCulture";
3838
}
3939

40-
private static Regex _namedParameterMatcher = new Regex(@"\{([a-z]\w+)\}", RegexOptions.IgnoreCase);
41-
private static Regex _numberParameterMatcher = new Regex(@"\{(\d+)\}");
42-
private List<ITaskItem> _createdFiles = new List<ITaskItem>();
40+
private static readonly Regex _namedParameterMatcher = new Regex(@"\{([a-z]\w+)\}", RegexOptions.IgnoreCase);
41+
private static readonly Regex _numberParameterMatcher = new Regex(@"\{(\d+)\}");
42+
private readonly List<ITaskItem> _createdFiles = new List<ITaskItem>();
4343

4444
/// <summary>
4545
/// <para>
@@ -102,7 +102,7 @@ public override bool Execute()
102102
return true;
103103
}
104104

105-
private bool GenerateCsharp(string resxFile, string outputFileName, string manifestName)
105+
private void GenerateCsharp(string resxFile, string outputFileName, string manifestName)
106106
{
107107
if (string.IsNullOrEmpty(outputFileName))
108108
{
@@ -122,7 +122,7 @@ private bool GenerateCsharp(string resxFile, string outputFileName, string manif
122122
if (!File.Exists(resxFile))
123123
{
124124
Log.LogError("'{0}' does not exist", resxFile);
125-
return false;
125+
return;
126126
}
127127

128128
var xml = XDocument.Load(resxFile);
@@ -135,7 +135,7 @@ private bool GenerateCsharp(string resxFile, string outputFileName, string manif
135135
var name = entry.Attribute("name").Value;
136136
var value = entry.Element("value").Value;
137137

138-
bool usingNamedArgs = true;
138+
var usingNamedArgs = true;
139139
var match = _namedParameterMatcher.Matches(value);
140140
if (match.Count == 0)
141141
{
@@ -219,11 +219,8 @@ private static string GetString(string name, params string[] formatterNames)
219219
}");
220220

221221
}
222-
223-
return true;
224222
}
225223

226-
227224
private static void RenderHeader(TextWriter writer, ResourceData resourceString)
228225
{
229226
writer.WriteLine("/// <summary>");
@@ -238,7 +235,7 @@ private static void RenderProperty(TextWriter writer, ResourceData resourceStrin
238235
{
239236
writer.WriteLine("internal static string {0}", resourceString.Name);
240237
writer.WriteLine("{");
241-
using (var indent = writer.Indent(4))
238+
using (var indent = writer.Indent())
242239
{
243240
indent.WriteLine($@"get => GetString(""{resourceString.Name}"");");
244241
}
@@ -249,7 +246,7 @@ private static void RenderFormatMethod(TextWriter writer, ResourceData resourceS
249246
{
250247
writer.WriteLine($"internal static string Format{resourceString.Name}({resourceString.Parameters})");
251248

252-
using (var indent = writer.Indent(4))
249+
using (var indent = writer.Indent())
253250
{
254251
if (resourceString.Arguments.Count > 0)
255252
{
@@ -273,25 +270,13 @@ private class ResourceData
273270

274271
public bool UsingNamedArgs { get; set; }
275272

276-
public string FormatArguments
277-
{
278-
get { return string.Join(", ", Arguments.Select(a => "\"" + a + "\"")); }
279-
}
273+
public string FormatArguments => string.Join(", ", Arguments.Select(a => "\"" + a + "\""));
280274

281-
public string ArgumentNames
282-
{
283-
get { return string.Join(", ", Arguments.Select(GetArgName)); }
284-
}
275+
public string ArgumentNames => string.Join(", ", Arguments.Select(GetArgName));
285276

286-
public string Parameters
287-
{
288-
get { return string.Join(", ", Arguments.Select(a => "object " + GetArgName(a))); }
289-
}
277+
public string Parameters => string.Join(", ", Arguments.Select(a => "object " + GetArgName(a)));
290278

291-
public string GetArgName(string name)
292-
{
293-
return UsingNamedArgs ? name : 'p' + name;
294-
}
279+
private string GetArgName(string name) => UsingNamedArgs ? name : 'p' + name;
295280
}
296281
}
297282
}

src/Internal.AspNetCore.BuildTools.Tasks/GetGitCommitInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.IO;
56
using Microsoft.AspNetCore.BuildTools.Utilities;
67
using Microsoft.Build.Framework;
@@ -62,11 +63,11 @@ public override bool Execute()
6263
}
6364

6465
var content = File.ReadAllText(headFile).Trim();
65-
if (content.StartsWith(HeadContentStart))
66+
if (content.StartsWith(HeadContentStart, StringComparison.OrdinalIgnoreCase))
6667
{
6768
return ResolveFromBranch(content);
6869
}
69-
else if (content.Length == CommitShaLength)
70+
if (content.Length == CommitShaLength)
7071
{
7172
return ResolveFromDetachedHead(content);
7273
}

src/Internal.AspNetCore.BuildTools.Tasks/SetEnvironmentVariable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using Microsoft.Build.Utilities;
65
using Microsoft.Build.Framework;
6+
using Microsoft.Build.Utilities;
77

88
namespace Microsoft.AspNetCore.BuildTools
99
{

src/Internal.AspNetCore.BuildTools.Tasks/UnzipArchive.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Collections.Generic;
45
using System.IO;
56
using System.IO.Compression;
6-
using System.Collections.Generic;
77
using Microsoft.Build.Framework;
88
using Microsoft.Build.Utilities;
9-
109
using ZipArchiveStream = System.IO.Compression.ZipArchive;
1110
using IOFile = System.IO.File;
1211

0 commit comments

Comments
 (0)