Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PowerShell compatibility rules #1133

Merged
merged 195 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
195 commits
Select commit Hold shift + click to select a range
4e15fdb
Add compatibilty rule serialization types
rjmholt Oct 26, 2018
803602d
Move compatibility checking code into submodule
Nov 5, 2018
01ec192
Create module manifest, change module base dir name
Nov 5, 2018
34ad54b
Move module to new file, change namespaces
Nov 6, 2018
17f007b
Add submodule binplace dir to .gitignore
rjmholt Nov 6, 2018
f22d2c8
Delete binary files
rjmholt Nov 6, 2018
b1d44c7
Fix up lsb info function
rjmholt Nov 6, 2018
1f74cb7
Fixup module, correct names and namespaces
rjmholt Nov 7, 2018
8dbe07b
Remove debugger wait
rjmholt Nov 7, 2018
de0d9cd
Improve architecture handling
rjmholt Nov 7, 2018
2fb7c83
Clean up serialization API
rjmholt Nov 7, 2018
19600ed
Improve module filtering
rjmholt Nov 7, 2018
d60da57
Partial work on query API
rjmholt Nov 9, 2018
b0c345b
Add more query types
rjmholt Nov 13, 2018
212ce88
Update query API, move enums to common
rjmholt Nov 15, 2018
e1d56d1
Add assembly name to type accelerator dictionary
rjmholt Nov 16, 2018
b62e0d0
Add reference to compatibility project in pssa
rjmholt Nov 19, 2018
e2dfa54
Add new command compatibility rule
rjmholt Nov 26, 2018
c4284dd
Add deep clone, basic rule implementation
rjmholt Dec 2, 2018
736f982
Make profiles multi-platform
rjmholt Dec 2, 2018
ccc886d
Fix Platform type name usage
rjmholt Dec 11, 2018
10a5822
Add intersection logic
Dec 13, 2018
c23673b
Change to ICloneable, add some union functionality
Dec 14, 2018
8552e8d
More union implementation
Dec 18, 2018
b248df2
Finish union logic
rjmholt Dec 18, 2018
ba3e4b6
Add combinator methods
Dec 18, 2018
1a16b0a
Fix profile creation, add combinator cmdlet
Dec 19, 2018
4f4b011
Fix intersection logic, module versioning
Dec 19, 2018
0153c4b
Fix various NREs, try to improve profile combination
Dec 20, 2018
632c1df
Replace IDictionary with JsonDictionary
Dec 20, 2018
cb7b433
Change build target properly
Dec 20, 2018
d348f99
Fix broken namespace and build version
rjmholt Dec 20, 2018
1a72a9c
Get output from intersection command
rjmholt Dec 21, 2018
80fa9b6
TODO about intersection
rjmholt Jan 9, 2019
bd62a7e
Fix version intersections
Jan 9, 2019
c07ddaa
Add profiles to the committed assets
Jan 9, 2019
8363929
Add function to generate any_profile config
Jan 10, 2019
07ef2ac
Revert net452 change in order to build
Jan 10, 2019
6ef5bc9
Make profiles single-platform, enable multiple targets
Jan 11, 2019
e973c24
Hook rule into testing
rjmholt Jan 15, 2019
f99d98b
Fix string resources
Jan 15, 2019
496eb27
Hook cross compat up to first test
rjmholt Jan 15, 2019
d3f8260
Add custom diagnostic type for compatibility checking
rjmholt Jan 16, 2019
44e55a0
Begin fixing case sensitivity
Jan 17, 2019
36c2575
Fix case sensitivity in profile union
Jan 17, 2019
c507e39
Fix platform property, make test pass
Jan 17, 2019
bfa892f
Add singleton for performance, change tests to test cases
Jan 18, 2019
d5cbf3d
Add cache clear method for profile loader
Jan 18, 2019
fadd51a
enable building on non-Windows to not target .Net Framework by defaul…
SteveL-MSFT Jan 22, 2019
18cf52e
Make PSScriptAnalyzer build independent of CrossCompatibility build
Jan 23, 2019
c0cc653
Fix dll path issue in psm1
Jan 23, 2019
7c0f594
Add ubuntu 18.04 profiles
Jan 23, 2019
65aff03
Fix root module, fix type names, powershell version may be string
rjmholt Jan 28, 2019
278548d
Make script compatible with PSv3
Jan 28, 2019
ac1c148
Fix v3 compat, add union profile name, begin version work
Jan 29, 2019
dd3bd35
Add PowerShellVersion class
rjmholt Jan 29, 2019
2f5e743
Change PowerShell json to new version type, add test build
Jan 29, 2019
59558ae
Add documentation for UseCompatibleCmdlets2
Jan 29, 2019
b028f87
Remove PS from configuration example
Jan 29, 2019
0505d97
Fix versions + build merge problem, start typename fix
Jan 30, 2019
e36f396
Serialize type names correctly
rjmholt Jan 30, 2019
10fcf67
Make function exports explicit
Jan 30, 2019
f2bc5fe
Fix psd1, add type name normalization functions
Jan 31, 2019
9bde797
Fix name normalization, add type query logic, genericize compatibilit…
rjmholt Jan 31, 2019
6c7c2e8
Fix type query building bug, rename command compat rule, begin type c…
Jan 31, 2019
7f1c4e2
Build out type compatibility check rule
Feb 1, 2019
b081e0d
Use simple typename expansion
Feb 1, 2019
48075c3
Remove unused test assets, add scaffold for type tests, change platfo…
Feb 1, 2019
0df1426
Fix alias glitch, add native commands, move type conversion api
Feb 1, 2019
ad713a0
Add better profiles, add native command tracking, fix union and build
Feb 2, 2019
f05d5ce
Add union profile, move AzF profile out of folder
rjmholt Feb 3, 2019
6963e9b
Move analysis exception to new file/namespace
rjmholt Feb 4, 2019
d2b8cd9
Add -Clean to build script
rjmholt Feb 4, 2019
d1321b8
Use new ending for profile extension
rjmholt Feb 4, 2019
d83b494
Use new structure for native commands
rjmholt Feb 4, 2019
f92c7d6
Add more command tests, fix GAC ignorance in profiler module
rjmholt Feb 4, 2019
8b39577
Fix bugs in profile script, add validation function
rjmholt Feb 5, 2019
65534fe
Fix profiler bugs, remove old profiles
rjmholt Feb 5, 2019
4d4abf2
Ignore lack of profile dir
Feb 5, 2019
414c609
Omit edition on lower PS versions
rjmholt Feb 5, 2019
b88a9dc
Add new profiles, remove intersection logic, fix unions
Feb 5, 2019
f05afa8
Add IDs to profiles for later union autogeneration
Feb 5, 2019
348ec9d
Make profile loader more threadsafe
Feb 5, 2019
086ccb1
Use net452-compatible hashset logic
Feb 5, 2019
d39cc23
Fudge over type compilation bug
Feb 5, 2019
9ac11af
Add types tests, fix command param parsing, fix attribute parsing
rjmholt Feb 5, 2019
94ceced
Update documentation, add types test
rjmholt Feb 5, 2019
ee2f85c
Add copyright headers
rjmholt Feb 5, 2019
7ae557d
Add some doc comments - more to come
rjmholt Feb 6, 2019
36b3604
Add simple syntax compatibility rule
rjmholt Feb 6, 2019
fc20ebe
Add workflow checking
rjmholt Feb 6, 2019
464ade8
Remove parallel and sequence linting
rjmholt Feb 6, 2019
b8c5aab
update .net core version in README.md to match global.json
bergmeister Feb 6, 2019
a335bd3
The engine project does not need a reference to the crosscompat proje…
bergmeister Feb 6, 2019
cc65a3f
Remove example file
Feb 6, 2019
5dee8f6
Fix safe expression evaluation in settings parser
Feb 6, 2019
c1d951a
Remove bad debug code
Feb 6, 2019
1d864a4
Update language in gitignore
Feb 6, 2019
f114942
Add proper resource strings
Feb 6, 2019
5f73e15
Make tests pass
Feb 7, 2019
5f511ca
Remove unneeded bits
Feb 7, 2019
9f7bf8d
Add MEF attributes
Feb 7, 2019
321eb6f
Fix executable name problem
Feb 7, 2019
244ac2e
Use correct report summary switch
Feb 7, 2019
d62179c
Fix test bugs
Feb 7, 2019
373cb62
Tweaks to failing tests
Feb 7, 2019
85bb48a
Add documentation comments to C#
Feb 7, 2019
ffd2816
Remove violations error write in test
Feb 7, 2019
a6121cd
Add debug to csproj const properties
Feb 8, 2019
25d7202
Simplify build macros in the hope that they work now
Feb 8, 2019
e0183f3
Make profile cache case insensitive
rjmholt Feb 8, 2019
27a5013
Add PSV3/4 flags to debug configurations
rjmholt Feb 8, 2019
b05ea4d
Improve new-object correction syntax
rjmholt Feb 8, 2019
79b28af
Add tests for and fix up GetSafeValue implementation
rjmholt Feb 8, 2019
526962e
Move to autogenerated union files
rjmholt Feb 9, 2019
61267ea
Quote paths for testing, add exception to alias tests, remove unused …
rjmholt Feb 9, 2019
4ee27a9
Add command parameter and static type member checking
rjmholt Feb 10, 2019
a170521
Enforce readonly nature of platform object
rjmholt Feb 10, 2019
51abeef
Fix bugs in code and test
rjmholt Feb 10, 2019
b154ef5
Write union profile out on creation
rjmholt Feb 10, 2019
09a6ae0
Add ignore settings for command and type compatibility rules
rjmholt Feb 11, 2019
a59f8f4
Add more testing, fix bugs, renew profiles
rjmholt Feb 12, 2019
b7376f5
Detect dynamic method invocation for ps3 compatibility
rjmholt Feb 12, 2019
1cee8d7
Move from PLINQ to tasks
rjmholt Feb 12, 2019
70ca135
Take out nonfix in command rule, fix build script syntax problem
rjmholt Feb 12, 2019
44b6775
Fix profile union, type compat bugs, add type compat tests
rjmholt Feb 13, 2019
2b2e1b5
Add script test for compatible commands
rjmholt Feb 13, 2019
1b9eedf
Add tests for compatible syntax rule
rjmholt Feb 13, 2019
bdad46f
Add repo-facing tests for UseCompatibleSyntax
rjmholt Feb 13, 2019
fee3cef
Temp test to see ubuntu problem
rjmholt Feb 13, 2019
75a5a20
Fix ubuntu date alias test
rjmholt Feb 13, 2019
52693f6
Fix test failure in PSv3/4
rjmholt Feb 13, 2019
2a5cabf
Make new error messages into resource strings
Feb 14, 2019
6f7572e
Add newtonsoft.json manually in old old powershell versions
Feb 14, 2019
3478c95
Filter diagnostics to omit parse errors
Feb 14, 2019
bf11890
Fix last PSv3/4 specific test
Feb 14, 2019
109b25b
Use better compile-time macro
Feb 14, 2019
fe48e86
Get rid of verbose logging of activator instantiation
Feb 14, 2019
243d6b8
Turn LINQ into lazy static methods
Feb 14, 2019
f01d717
Fix NRE in types, move command query tables to lazy methods
Feb 15, 2019
61056ca
Add CrossCompatibility to AppVeyor build and test
Feb 15, 2019
95cb4f8
Prevent trying to reload CrossCompatibility.dll
Feb 15, 2019
3617926
Add Windows SKU enum to platform query object
Feb 15, 2019
489ed94
Fix problems with CC module in AppVeyor path
rjmholt Feb 15, 2019
258659d
More probing
rjmholt Feb 15, 2019
aa19ea4
Fix CC build condition
rjmholt Feb 15, 2019
eed8449
Add FX to build script params
rjmholt Feb 15, 2019
b150a3e
Attempt to fix Dll binplace issue
rjmholt Feb 15, 2019
c502cb1
Fix typename logic
rjmholt Feb 15, 2019
f558c8d
Fix EOL in files
rjmholt Feb 16, 2019
c7f158b
Remove unused LINQ calls
rjmholt Feb 16, 2019
9f1ee8d
Address some of @JamesWTruher's feedback
rjmholt Feb 16, 2019
63561b5
Better way to get common parameters
rjmholt Feb 17, 2019
34599ec
Address more of @JamesWTruher's feedback
rjmholt Feb 18, 2019
b65f680
Address @bergmeister's add-type feedback
rjmholt Feb 19, 2019
48dce51
Address pipe usage, nasty foreach
rjmholt Feb 19, 2019
171f150
Profiles bundled as a ZIP file
rjmholt Feb 19, 2019
c028a0c
Ignore zip type in build file
rjmholt Feb 19, 2019
f6fe2f4
Ensure zip functions are present
rjmholt Feb 19, 2019
857cd90
Change name of cross compat assembly
Feb 19, 2019
910bff0
Add cross compat asm to signing
Feb 19, 2019
963c163
Address more of @JamesWTruher's feedback
Feb 19, 2019
67a1bd7
Fix build path bug
Feb 20, 2019
014cd7c
Make some profiles optional, improve compat rule docs
rjmholt Feb 21, 2019
cf026bd
Add documentation
rjmholt Feb 22, 2019
c075fc7
Remove defunct anyplatform name
rjmholt Feb 22, 2019
8f4ff3e
Add exclusion parameters to cc module
Feb 25, 2019
d180dce
Add parameter documentation
Feb 25, 2019
6bda8c9
Fix automatic variable detection
Feb 26, 2019
cc03326
Add explicit default case
Feb 26, 2019
d6cc604
Fix tests for fewer rules
Feb 26, 2019
3a3e0a8
Fix type compat test profile bugs
Feb 26, 2019
a73944d
Fix compatibility module bug
Feb 26, 2019
9d38424
Add path exclusions to module
Feb 26, 2019
76ce2cc
Fix linux pscustomobject problem
Feb 26, 2019
9ad6236
Fix profile module bugs, update profiles
Feb 27, 2019
bf8ae6d
Update documentation for profile names
Feb 27, 2019
4d7baff
Rename module and sign
Feb 27, 2019
5fb1e86
Fix build name bug
rjmholt Feb 27, 2019
7df649c
Upgrade docket .NET version
rjmholt Feb 27, 2019
b881b41
Ignore clean error
rjmholt Feb 27, 2019
cb22eec
Add verbose message to release script
rjmholt Feb 27, 2019
68d3a9c
Verbose hack
rjmholt Feb 27, 2019
2c470db
Remove verbose
rjmholt Feb 27, 2019
19902f1
Tweak out copy
rjmholt Feb 27, 2019
ac73104
Fix signing xml
rjmholt Feb 27, 2019
3bd9b68
Fix signing XML
Feb 27, 2019
811b19c
Correct framework signing to net452
Feb 27, 2019
f809e97
Remove AuthenticodeDual
Feb 27, 2019
de673f0
Update signing for PSCompatibilityAnalyzer
Feb 27, 2019
a838929
Update VSCode search exclusion for profiles
Feb 27, 2019
f964820
Fix loading problem in PowerShell 5
Feb 27, 2019
a3f8c22
Fix Add-Type Newtonsoft in PS 5
Feb 27, 2019
245fd55
Add missing copyright headers
Feb 28, 2019
4a62b0b
Add other copyright headers
Feb 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ bld/
# Visual Studo 2015 cache/options directory
.vs/

# VSCode configuration directory
.vscode/

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
Expand Down Expand Up @@ -212,3 +215,6 @@ PSScriptAnalyzer/

# Test result file
TestResults.xml

# PSCompatibilityAnalyzer module
PSCompatibilityAnalyzer/out/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"powershell.codeFormatting.preset": "Allman",
"[powershell]": {
"files.trimTrailingWhitespace": true
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"/PSCompatibilityAnalyzer/profiles": true,
"/PSCompatibilityAnalyzer/optional_profiles": true
}
}
10 changes: 9 additions & 1 deletion Engine/Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<ItemGroup Condition="'$(TargetFramework)' == 'net452' AND '$(Configuration)' != 'PSV3Release'">
<PackageReference Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'PSV3Release' ">
<DefineConstants>$(DefineConstants);PSV3</DefineConstants>
</PropertyGroup>
Expand All @@ -85,4 +85,12 @@
<DefineConstants>$(DefineConstants);PSV3;PSV4</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'PSV3Debug' ">
<DefineConstants>$(DefineConstants);PSV3</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'PSV4Debug' ">
<DefineConstants>$(DefineConstants);PSV3;PSV4</DefineConstants>
</PropertyGroup>

</Project>
20 changes: 20 additions & 0 deletions Engine/Generic/ConfigurableRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Language;
using System.Reflection;

Expand Down Expand Up @@ -118,6 +119,13 @@ private void SetDefaultValues()

private void SetValue(PropertyInfo property, object value)
{
if (IsArray(property.PropertyType, out Type elementType))
{
object newArray = LanguagePrimitives.ConvertTo(value, elementType.MakeArrayType());
property.SetValue(this, newArray);
return;
}

// TODO Check if type is convertible
property.SetValue(this, Convert.ChangeType(value, property.PropertyType));
}
Expand Down Expand Up @@ -145,5 +153,17 @@ private Object GetDefaultValue(PropertyInfo property)

return ((ConfigurableRulePropertyAttribute)attr).DefaultValue;
}

private static bool IsArray(Type propertyType, out Type elementType)
{
if (propertyType.IsArray)
{
elementType = propertyType.GetElementType();
return true;
}

elementType = null;
return false;
}
}
}
7 changes: 7 additions & 0 deletions Engine/Generic/ConfigurableRulePropertyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
[AttributeUsage(AttributeTargets.Property)]
public class ConfigurableRulePropertyAttribute : Attribute
{
// TODO: Remove this parameter or make it optional.
// Properties already have a way to specify default values in C#.
// Having this prevents using null (which may be legitimate)
// or values from other assemblies, and overrides the constructor,
// which just makes life harder.

/// <summary>
/// Default value of the property that the attribute decorates.
/// </summary>
Expand All @@ -22,6 +28,7 @@ public class ConfigurableRulePropertyAttribute : Attribute
/// <param name="defaultValue"></param>
public ConfigurableRulePropertyAttribute(object defaultValue)
{
// TODO: null is a legitimate value and should be allowed.
if (defaultValue == null)
{
throw new ArgumentNullException(nameof(defaultValue), Strings.ConfigurableScriptRuleNRE);
Expand Down
15 changes: 8 additions & 7 deletions Engine/PSScriptAnalyzer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition
throw "Minimum supported version of PSScriptAnalyzer for PowerShell Core is 6.0.2 but current version is '$($PSVersionTable.PSVersion)'. Please update PowerShell Core."
}
}
else {
if ($PSVersionTable.PSVersion.Major -eq 3) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'PSv3'
}
elseif ($PSVersionTable.PSVersion.Major -eq 4) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'PSv4'
}
elseif ($PSVersionTable.PSVersion.Major -eq 5) {
# Without this, PSSA tries to load this from $PSHome
Add-Type -Path "$PSScriptRoot/Newtonsoft.Json.dll"
}
elseif ($PSVersionTable.PSVersion.Major -le 4) {
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath "PSv$($PSVersionTable.PSVersion.Major)"
# Without this, PSSA tries to load this from $PSHome
Add-Type -Path "$binaryModuleRoot/Newtonsoft.Json.dll"
}

$binaryModulePath = Join-Path -Path $binaryModuleRoot -ChildPath 'Microsoft.Windows.PowerShell.ScriptAnalyzer.dll'
Expand Down
40 changes: 19 additions & 21 deletions Engine/ScriptAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -876,39 +876,37 @@ private IEnumerable<T> GetInterfaceImplementationsFromAssembly<T>() where T : cl

private IEnumerable<T> GetInterfaceImplementationsFromAssembly<T>(string ruleDllPath) where T : class
{
var fileName = Path.GetFileNameWithoutExtension(ruleDllPath);
string fileName = Path.GetFileNameWithoutExtension(ruleDllPath);
var assemblyName = new AssemblyName(fileName);
outputWriter.WriteVerbose(string.Format("Loading Assembly:{0}", assemblyName.FullName));

var dll = Assembly.Load(assemblyName);
var rules = new List<T>();
Assembly dll = Assembly.Load(assemblyName);

if (dll == null)
{
outputWriter.WriteVerbose(string.Format("Cannot load {0}", ruleDllPath));
return rules;
return Enumerable.Empty<T>();
}
foreach (var type in dll.ExportedTypes)

var rules = new List<T>();
foreach (Type type in dll.ExportedTypes)
rjmholt marked this conversation as resolved.
Show resolved Hide resolved
{
var typeInfo = type.GetTypeInfo();
if (!typeInfo.IsInterface
&& !typeInfo.IsAbstract
&& typeInfo.ImplementedInterfaces.Contains(typeof(T)))
if (type.IsInterface
|| type.IsAbstract
|| !typeof(T).IsAssignableFrom(type))
{
continue;
}

var rule = Activator.CreateInstance(type) as T;
if (rule == null)
{
outputWriter.WriteVerbose(
string.Format(
rjmholt marked this conversation as resolved.
Show resolved Hide resolved
"Creating Instance of {0}", type.Name));

var ruleObj = Activator.CreateInstance(type);
T rule = ruleObj as T;
if (rule == null)
{
outputWriter.WriteVerbose(
string.Format(
"Cannot cast instance of type {0} to {1}", type.Name, typeof(T).GetTypeInfo().Name));
continue;
}
rules.Add(rule);
"Cannot cast instance of type {0} to {1}", type.Name, typeof(T).GetTypeInfo().Name));
continue;
}
rules.Add(rule);
}
return rules;
}
Expand Down
Loading