Skip to content

Commit 5fdc9b7

Browse files
committed
Add Tools.Common project
1 parent 730a46c commit 5fdc9b7

File tree

98 files changed

+301368
-11309
lines changed

Some content is hidden

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

98 files changed

+301368
-11309
lines changed

tools/StaticAnalysis/Decorator.cs renamed to tools/Tools.Common/Decorators/Decorator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616

17-
namespace StaticAnalysis
17+
namespace Tools.Common.Decorators
1818
{
1919
/// <summary>
2020
/// Abstract class to implement the Decorator pattern

tools/StaticAnalysis/HelpAnalyzer/ReflectionExtensions.cs renamed to tools/Tools.Common/Extensions/ReflectionExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using System.Management.Automation;
1919
using System.Reflection;
2020

21-
namespace StaticAnalysis.help
21+
namespace Tools.Common.Extensions
2222

2323
{
2424
public static class ReflectionExtensions

tools/StaticAnalysis/EnvironmentHelpers.cs renamed to tools/Tools.Common/Helpers/EnvironmentHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
using System;
1616

17-
namespace StaticAnalysis
17+
namespace Tools.Common.Helpers
1818
{
1919
public static class EnvironmentHelpers
2020
{

tools/StaticAnalysis/AnalysisReport.cs renamed to tools/Tools.Common/Issues/AnalysisReport.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace StaticAnalysis
7+
namespace Tools.Common.Issues
88
{
99
public class AnalysisReport
1010
{
@@ -24,6 +24,6 @@ public List<int> ProblemIdList
2424
public AnalysisReport()
2525
{
2626

27-
}
27+
}
2828
}
2929
}

tools/StaticAnalysis/IReportRecord.cs renamed to tools/Tools.Common/Issues/IReportRecord.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using System.Security.Cryptography.X509Certificates;
16-
17-
namespace StaticAnalysis
15+
namespace Tools.Common.Issues
1816
{
1917
/// <summary>
2018
/// Abstract interface for static analysis reports.

tools/StaticAnalysis/DependencyAnalyzer/AssemblyLoader.cs renamed to tools/Tools.Common/Loaders/AssemblyLoader.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414

1515
using System;
1616
using System.Reflection;
17+
using Tools.Common.Models;
1718

18-
namespace StaticAnalysis.DependencyAnalyzer
19+
namespace Tools.Common.Loaders
1920
{
2021
/// <summary>
2122
/// A class using .Net Remoting to load assemblies and retrieve information in a separate app domain
2223
/// </summary>
2324
public class AssemblyLoader : MarshalByRefObject
2425
{
2526
/// <summary>
26-
/// Load the assembly in the reflection context by name. Will succeed if the referenced assembly name can
27+
/// Load the assembly in the reflection context by name. Will succeed if the referenced assembly name can
2728
/// be found using default assembly loading rules (i.e. it is in the current directory or the GAC)
2829
/// </summary>
2930
/// <param name="assemblyName">The full name of the assembly</param>
30-
/// <returns>Information on the given assembly, if it was loaded successfully, or null if there is an
31+
/// <returns>Information on the given assembly, if it was loaded successfully, or null if there is an
3132
/// assembly loading issue. </returns>
3233
public AssemblyMetadata GetReflectedAssemblyInfo(string assemblyName)
3334
{
Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,50 @@
1818
using System.Linq;
1919
using System.Reflection;
2020
using System.Management.Automation;
21-
using StaticAnalysis.help;
22-
using StaticAnalysis.HelpAnalyzer;
21+
using Tools.Common.Models;
22+
using Tools.Common.Extensions;
23+
using System.IO;
2324

24-
namespace StaticAnalysis.BreakingChangeAnalyzer
25+
namespace Tools.Common.Loaders
2526
{
26-
public class CmdletBreakingChangeLoader : MarshalByRefObject
27+
public class CmdletLoader : MarshalByRefObject
2728
{
2829
public static ModuleMetadata ModuleMetadata;
2930

31+
private static IDictionary<string, Assembly> _assemblyDictionary = null;
32+
33+
public ModuleMetadata GetModuleMetadata(string assemblyPath, List<string> commonOutputFolders)
34+
{
35+
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
36+
{
37+
foreach (var commonOutputFolder in commonOutputFolders)
38+
{
39+
var assemblyName = args.Name.Substring(0, args.Name.IndexOf(","));
40+
var dll = Directory.GetFiles(commonOutputFolder, "*.dll").Where(f => Path.GetFileNameWithoutExtension(f) == assemblyName).FirstOrDefault();
41+
if (dll == null)
42+
{
43+
continue;
44+
}
45+
46+
return Assembly.LoadFrom(dll);
47+
}
48+
49+
return null;
50+
};
51+
52+
return GetModuleMetadata(assemblyPath);
53+
}
54+
3055
/// <summary>
31-
/// Get cmdlets from the given assembly
56+
/// Get the ModuleMetadata from a cmdlet assembly.
3257
/// </summary>
33-
/// <param name="assmeblyPath"></param>
34-
/// <returns></returns>
58+
/// <param name="assmeblyPath">Path to the cmdlet assembly.</param>
59+
/// <returns>ModuleMetadata containing information about the cmdlets found in the given assembly.</returns>
3560
public ModuleMetadata GetModuleMetadata(string assemblyPath)
3661
{
37-
List<CmdletBreakingChangeMetadata> results = new List<CmdletBreakingChangeMetadata>();
62+
List<CmdletMetadata> results = new List<CmdletMetadata>();
3863

3964
ModuleMetadata = new ModuleMetadata();
40-
4165
try
4266
{
4367
var assembly = Assembly.LoadFrom(assemblyPath);
@@ -47,7 +71,7 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
4771
var outputs = type.GetAttributes<OutputTypeAttribute>();
4872
var parameters = type.GetParameters();
4973

50-
var cmdletMetadata = new CmdletBreakingChangeMetadata
74+
var cmdletMetadata = new CmdletMetadata
5175
{
5276
VerbName = cmdlet.VerbName,
5377
NounName = cmdlet.NounName,
@@ -77,12 +101,17 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
77101
cmdletMetadata.OutputTypes.Add(outputMetadata);
78102
}
79103
}
80-
104+
81105
List<Parameter> globalParameters = new List<Parameter>();
82106

83107
foreach (var parameter in parameters)
84108
{
85-
var parameterData = new ParameterMetadata
109+
if (string.Equals(parameter.Name, "Force", StringComparison.OrdinalIgnoreCase) && parameter.PropertyType == typeof(SwitchParameter))
110+
{
111+
cmdletMetadata.HasForceSwitch = true;
112+
}
113+
114+
var parameterData = new Models.ParameterMetadata
86115
{
87116
Type = parameter.PropertyType,
88117
Name = parameter.Name
@@ -93,7 +122,7 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
93122
var aliases = parameter.GetAttributes<AliasAttribute>();
94123
parameterData.AliasList.AddRange(
95124
aliases.SelectMany(a => a.AliasNames));
96-
}
125+
}
97126

98127
if (parameter.HasAttribute<ValidateSetAttribute>())
99128
{
@@ -108,7 +137,7 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
108137
parameterData.ValidateRangeMax = Convert.ToInt64(validateRange.MaxRange);
109138
}
110139

111-
parameterData.ValidateNotNullOrEmpty = parameter.HasAttribute<ValidateNotNullOrEmptyAttribute>();
140+
parameterData.ValidateNotNullOrEmpty = parameter.HasAttribute<ValidateNotNullOrEmptyAttribute>();
112141

113142
cmdletMetadata.Parameters.Add(parameterData);
114143

@@ -118,7 +147,7 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
118147

119148
if (parameterSetMetadata == null)
120149
{
121-
parameterSetMetadata = new ParameterSetMetadata()
150+
parameterSetMetadata = new Models.ParameterSetMetadata()
122151
{
123152
Name = parameterSet.ParameterSetName ?? "__AllParameterSets"
124153
};
@@ -168,7 +197,7 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
168197
.Where(p => p.Name.Equals(cmdletMetadata.DefaultParameterSetName, StringComparison.OrdinalIgnoreCase))
169198
.Any())
170199
{
171-
ParameterSetMetadata defaultSet = new ParameterSetMetadata()
200+
var defaultSet = new Models.ParameterSetMetadata()
172201
{
173202
Name = cmdletMetadata.DefaultParameterSetName
174203
};

tools/StaticAnalysis/Loggers/AnalysisLogger.cs renamed to tools/Tools.Common/Loggers/AnalysisLogger.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
using System.Linq;
1919
using System.Reflection;
2020
using System.Text;
21+
using Tools.Common.Issues;
2122

22-
namespace StaticAnalysis
23+
namespace Tools.Common.Loggers
2324
{
2425
/// <summary>
2526
/// Abstract class to implement the report logging structure
@@ -45,7 +46,7 @@ private static Dictionary<string, AnalysisLogger> LogDictionary
4546
return _logDictionary;
4647
}
4748
}
48-
49+
4950
/// <summary>
5051
/// Factory to get logger
5152
/// </summary>
@@ -95,7 +96,7 @@ public AnalysisLogger(string baseDirectory) : this(baseDirectory, null)
9596

9697
IList<ReportLogger> _loggers = new List<ReportLogger>();
9798
protected virtual IList<ReportLogger> Loggers { get { return _loggers; } }
98-
99+
99100

100101
/// <summary>
101102
/// Write a report file to the given file, using the given file contents.
@@ -112,7 +113,7 @@ public virtual void WriteReport(string name, string contents)
112113
/// </summary>
113114
/// <typeparam name="T">The type of records written to the log</typeparam>
114115
/// <param name="fileName">The filename (without file path) where the report will be written</param>
115-
/// <returns>The given logger. Analyzer may write records to this logger and they will be written to
116+
/// <returns>The given logger. Analyzer may write records to this logger and they will be written to
116117
/// the report file.</returns>
117118
public virtual ReportLogger<T> CreateLogger<T>(string fileName) where T : class, IReportRecord, new()
118119
{
@@ -139,7 +140,7 @@ public virtual void WriteReport(string name, string contents)
139140
return logger;
140141
}
141142

142-
public ReportLogger GetReportLogger(string loggerFileName)
143+
public ReportLogger GetReportLogger(string loggerFileName)
143144
{
144145
return Loggers.Where<ReportLogger>((log) => Path.GetFileName(log.FileName).Equals(loggerFileName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault<ReportLogger>();
145146
}

tools/StaticAnalysis/Loggers/ConsoleLogger.cs renamed to tools/Tools.Common/Loggers/ConsoleLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using System;
1616
using System.IO;
1717

18-
namespace StaticAnalysis
18+
namespace Tools.Common.Loggers
1919
{
2020
/// <summary>
2121
/// Simple class for logging errors and warnings to the console and writing reports to the file system.

tools/StaticAnalysis/Loggers/ReportLogger.cs renamed to tools/Tools.Common/Loggers/ReportLogger.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
using System.Collections.Generic;
1616
using System.IO;
1717
using System.Linq;
18-
using System.Runtime.InteropServices;
18+
using Tools.Common.Decorators;
19+
using Tools.Common.Issues;
1920

20-
namespace StaticAnalysis
21+
namespace Tools.Common.Loggers
2122
{
2223
/// <summary>
2324
/// Abstract report logger - used as an abstraction over typed loggers.

tools/StaticAnalysis/DependencyAnalyzer/AssemblyMetadata.cs renamed to tools/Tools.Common/Models/AssemblyMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
using System.Collections.Generic;
1717
using System.Reflection;
1818

19-
namespace StaticAnalysis.DependencyAnalyzer
19+
namespace Tools.Common.Models
2020
{
2121
/// <summary>
2222
/// Serializable assembly metadata class, used to return assembly information from a remote AppDomain

0 commit comments

Comments
 (0)