Skip to content

Convert StaticAnalysis to .NET Core #6979

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

Merged
merged 10 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If this issue is not a bug report, please remove the below template

### Module Version

<!-- Please run (Get-Module -Name AzureRM -ListAvailable) to get the version(s) of AzureRM installed on your machine -->
<!-- Please run (Get-Module -ListAvailable) to get the version(s) of all modules, including Azure installed on your machine -->

```powershell
Get-Module -ListAvailable
Expand All @@ -44,7 +44,7 @@ $PSVersionTable

### Debug Output

<!-- Please run the above script with $DebugPreference = "Continue" and paste the resulting debug stream in the below code block -->
<!-- Please run the above script with $DebugPreference='Continue' and paste the resulting debug stream in the below code block -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍


```

Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ before_install:
# https://github.com/travis-ci/travis-ci/issues/1066#issuecomment-383489298
script:
- sudo dotnet msbuild build.proj /t:BuildNetcore /p:Configuration=$CONFIG || travis_terminate 1
- sudo dotnet tools/StaticAnalysis/bin/$CONFIG/netcoreapp2.1/StaticAnalysis.Netcore.dll -p src/Package/$CONFIG -r src/Package -u
- sudo pwsh -NonInteractive -NoLogo -NoProfile -File tools/TestModuleLoading.ps1 || travis_terminate 1
- sudo dotnet test src/Azure.PowerShell.Netcore.Test.sln --filter "AcceptanceType=CheckIn&RunType!=DesktopOnly" --configuration $CONFIG

after_success:
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
docker build . -t $DOCKER_USER/$NAME:$TRAVIS_COMMIT --build-arg CONFIG=$CONFIG;
Expand All @@ -38,7 +39,7 @@ after_success:
docker push $DOCKER_USER/$NAME:$TRAVIS_COMMIT;
docker push $DOCKER_USER/$NAME:$TRAVIS_BRANCH;

if [ "$TRAVIS_BRANCH" == "master" ]; then
if [ "$TRAVIS_BRANCH" == "master" ]; then
docker tag $DOCKER_USER/$NAME:$TRAVIS_COMMIT $DOCKER_USER/$NAME:latest;
docker push $DOCKER_USER/$NAME:latest;
fi;
Expand Down
28 changes: 28 additions & 0 deletions Azure.PowerShell.Netcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.DeviceProvisioning
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.PolicyInsights.Netcore", "src\ResourceManager\PolicyInsights\Commands.PolicyInsights\Commands.PolicyInsights.Netcore.csproj", "{A0574194-976A-486A-B589-07B2E50CA6EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Common.Netcore", "tools\Tools.Common\Tools.Common.Netcore.csproj", "{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticAnalysis.Netcore", "tools\StaticAnalysis\StaticAnalysis.Netcore.csproj", "{493FA948-DA9C-47CD-8385-3C0261377D86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -825,6 +829,30 @@ Global
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x64.Build.0 = Release|Any CPU
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x86.ActiveCfg = Release|Any CPU
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x86.Build.0 = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x64.ActiveCfg = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x64.Build.0 = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x86.ActiveCfg = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x86.Build.0 = Debug|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|Any CPU.Build.0 = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x64.ActiveCfg = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x64.Build.0 = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x86.ActiveCfg = Release|Any CPU
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x86.Build.0 = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x64.ActiveCfg = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x64.Build.0 = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x86.ActiveCfg = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x86.Build.0 = Debug|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|Any CPU.Build.0 = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x64.ActiveCfg = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x64.Build.0 = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.ActiveCfg = Release|Any CPU
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 5 additions & 2 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,13 @@

<Message Importance="high" Text="Running dependency analysis..." />

<Exec Command="$(MSBuildProjectDirectory)\src\Package\StaticAnalysis.exe $(MSBuildProjectDirectory)\src\Package\$(Configuration) $(MSBuildProjectDirectory)\src\Package true $(SkipHelp) @(ModulesChanged)"
<PropertyGroup>
<SkipHelpValue Condition=" '$(SkipHelp)' == 'true' ">-s</SkipHelpValue>
</PropertyGroup>
<Exec Command="$(MSBuildProjectDirectory)\src\Package\StaticAnalysis.exe -p $(MSBuildProjectDirectory)\src\Package\$(Configuration) -r $(MSBuildProjectDirectory)\src\Package $(SkipHelpValue) -m @(ModulesChanged)"
Condition="'$(Scope)' != 'Stack'"/>

<Exec Command="$(PackageDirectory)\StaticAnalysis.exe $(StackPackageFolder)\$(Configuration) $(StackPackageFolder)"
<Exec Command="$(PackageDirectory)\StaticAnalysis.exe -p $(StackPackageFolder)\$(Configuration) -r $(StackPackageFolder)"
Condition="'$(Scope)' == 'Stack'"
ContinueOnError="True"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common projects aren't used... why the change(s)?

<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common projects aren't used... why the change(s)?

<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ItemGroup>
<PackageReference Include="Azure.Batch" Version="8.1.1" />
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="4.2.0" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="1.1.0" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the downgrade?

<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ RequiredAssemblies = '.\Microsoft.Azure.PowerShell.Authentication.Abstractions.d
'.\Microsoft.Rest.ClientRuntime.Azure.dll',
'.\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll',
'.\Microsoft.WindowsAzure.Storage.dll',
'.\Microsoft.Azure.Management.Storage.dll', '.\Newtonsoft.Json.dll',
'.\Newtonsoft.Json.dll',
'.\Microsoft.Azure.PowerShell.Aks.dll',
'.\Microsoft.Azure.PowerShell.Strategies.dll'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.18.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ PowerShellVersion = '5.1'
RequiredModules = @(@{ModuleName = 'Az.Profile'; ModuleVersion = '0.1.0'; })

# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = '.\Microsoft.Azure.Management.Storage.dll'
RequiredAssemblies = '.\Microsoft.Azure.Management.Storage.dll',
'.\Microsoft.WindowsAzure.Storage.dll'

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()
Expand All @@ -67,8 +68,7 @@ FormatsToProcess = '.\Microsoft.Azure.Commands.Management.Storage.format.ps1xml'
'.\Microsoft.WindowsAzure.Commands.Storage.format.ps1xml', '.\Microsoft.WindowsAzure.Commands.Storage.generated.format.ps1xml'

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('.\Microsoft.Azure.Commands.Management.Storage.dll',
'.\Microsoft.WindowsAzure.Storage.dll', '.\Microsoft.WindowsAzure.Commands.Storage.dll')
NestedModules = @('.\Microsoft.Azure.Commands.Management.Storage.dll', '.\Microsoft.WindowsAzure.Commands.Storage.dll')

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,12 @@ public void Analyze(
{
issueLogger.Decorator.AddDecorator(a => a.AssemblyFileName = assemblyFileName, "AssemblyFileName");
processedHelpFiles.Add(assemblyFileName);
var proxy = EnvironmentHelpers.CreateProxy<CmdletLoader>(directory, out _appDomain);
var proxy =
#if !NETSTANDARD
EnvironmentHelpers.CreateProxy<CmdletLoader>(directory, out _appDomain);
#else
new CmdletLoader();
#endif
var newModuleMetadata = proxy.GetModuleMetadata(assemblyFile, requiredModules);

string fileName = assemblyFileName + ".json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

#if !NETSTANDARD
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
#endif
using StaticAnalysis.BreakingChangeAnalyzer;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -129,7 +131,11 @@ public void Analyze(IEnumerable<string> cmdletProbingDirs, Func<IEnumerable<stri
if (File.Exists(cmdletFileFullPath))
{
var proxy =
#if !NETSTANDARD
EnvironmentHelpers.CreateProxy<CmdletBreakingChangeAttributeLoader>(directory, out _appDomain);
#else
new CmdletBreakingChangeAttributeLoader();
#endif
var cmdletDataForModule = proxy.GetModuleBreakingChangeAttributes(cmdletFileFullPath);

//If there is nothing in this module just onctinue
Expand Down Expand Up @@ -226,11 +232,13 @@ private void LogBreakingChangesInModule(BreakingChangeAttributesInModule moduleD
foreach (BreakingChangeAttributesInCmdlet cmdletData in moduleData.CmdletList)
{
textForBreakingChangesInModule += string.Format(BREAKING_CHANGE_CMDLET_HEADER_FORMAT_STRING, cmdletData.CmdletName);
#if !NETSTANDARD
foreach (GenericBreakingChangeAttribute attribute in cmdletData.BreakingChangeAttributes)
{
textForBreakingChangesInModule += attribute.GetBreakingChangeTextFromAttribute(cmdletData.CmdletType, true) + "\n\n";
}
}
#endif
}

//Now that we have the text, add it to the log file
logger.LogMessage(textForBreakingChangesInModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
using System.Linq;
using System.Reflection;
using System.Management.Automation;
#if !NETSTANDARD
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
#endif
using Tools.Common.Extensions;

namespace StaticAnalysis.BreakingChangeAttributesAnalyzer
Expand All @@ -38,7 +40,9 @@ public class BreakingChangeAttributesInCmdlet
{
public Type CmdletType { get; set; }
public string CmdletName { get; set; }
#if !NETSTANDARD
public List<GenericBreakingChangeAttribute> BreakingChangeAttributes { get; set; }
#endif
}

public class CmdletBreakingChangeAttributeLoader : MarshalByRefObject
Expand All @@ -58,15 +62,19 @@ public BreakingChangeAttributesInModule GetModuleBreakingChangeAttributes(string
foreach (var type in assembly.GetCmdletTypes())
{
var cmdlet = type.GetAttribute<CmdletAttribute>();
#if !NETSTANDARD
var attributes = type.GetAttributes<GenericBreakingChangeAttribute>();

if (attributes != null && (attributes.Count() > 0)) { }
#endif
var cmdletMetadata = new BreakingChangeAttributesInCmdlet
{
CmdletType = type,
CmdletName = cmdlet.VerbName + "-" + cmdlet.NounName,
#if !NETSTANDARD
BreakingChangeAttributes = attributes.ToList()
};
#endif
};

results.Add(cmdletMetadata);
}
Expand Down
61 changes: 0 additions & 61 deletions tools/StaticAnalysis/CmdlineArgParsing/StaticAnalysisArgs.cs

This file was deleted.

17 changes: 14 additions & 3 deletions tools/StaticAnalysis/DependencyAnalyzer/DependencyAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DependencyAnalyzer : IStaticAnalyzer
"Microsoft.Management.Infrastructure",
"Microsoft.Build",
"Microsoft.Build.Framework",
"Microsoft.Win32.Primitives",
"WindowsBase"
};

Expand All @@ -62,6 +63,8 @@ public class DependencyAnalyzer : IStaticAnalyzer
private ReportLogger<ExtraAssembly> _extraAssemblyLogger;
private ReportLogger<DependencyMap> _dependencyMapLogger;

private bool _isNetcore;

public DependencyAnalyzer()
{
Name = "Dependency Analyzer";
Expand Down Expand Up @@ -109,6 +112,7 @@ public void Analyze(IEnumerable<string> directories, IEnumerable<String> modules
_missingAssemblyLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
_extraAssemblyLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
_dependencyMapLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
_isNetcore = directoryPath.Contains("Az.");
ProcessDirectory(directoryPath);
_versionConflictLogger.Decorator.Remove("Directory");
_missingAssemblyLogger.Decorator.Remove("Directory");
Expand Down Expand Up @@ -241,15 +245,20 @@ private static bool RequiresExactVersionMatch(AssemblyRecord name)

private static bool IsFrameworkAssembly(AssemblyName name)
{
return name.Name.StartsWith("System") || name.Name.Equals("mscorlib")
return name.Name.StartsWith("System") || name.Name.Equals("mscorlib") || name.Name.Equals("netstandard")
|| FrameworkAssemblies.Contains(name.Name);
}

private void ProcessDirectory(string directoryPath)
{
var savedDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(directoryPath);
_loader = EnvironmentHelpers.CreateProxy<AssemblyLoader>(directoryPath, out _testDomain);
_loader =
#if !NETSTANDARD
EnvironmentHelpers.CreateProxy<AssemblyLoader>(directoryPath, out _testDomain);
#else
new AssemblyLoader();
#endif
foreach (var file in Directory.GetFiles(directoryPath).Where(file => file.EndsWith(".dll")))
{
AssemblyRecord assembly = CreateAssemblyRecord(file);
Expand Down Expand Up @@ -294,7 +303,9 @@ private void ProcessDirectory(string directoryPath)

FindExtraAssemblies();

#if !NETSTANDARD
AppDomain.Unload(_testDomain);
#endif
Directory.SetCurrentDirectory(savedDirectory);
}

Expand Down Expand Up @@ -356,7 +367,7 @@ private void CheckAssemblyReference(AssemblyName reference, AssemblyRecord paren
parent.Name)
});
}
else
else if (_isNetcore && stored.Version < reference.Version)
{
var minVersion = (stored.Version < reference.Version) ? stored.Version : reference.Version;
_versionConflictLogger.LogRecord(new AssemblyVersionConflict()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Directory","AssemblyName","Expected Version","Actual Version","Parent Assembly","Severity","ProblemId","Description","Remediation"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
"Microsoft.Azure.Commands.Aks.dll","Microsoft.Azure.Commands.Aks.GetAzureRmAks","Get-AzureRmAks","0","1020","The cmdlet 'Get-AzureRmAks' no longer has output type 'System.Collections.Generic.List`1[Microsoft.Azure.Commands.Aks.Models.PSKubernetesCluster]'.","Make cmdlet 'Get-AzureRmAks' return type 'System.Collections.Generic.List`1[Microsoft.Azure.Commands.Aks.Models.PSKubernetesCluster]'."
1 change: 1 addition & 0 deletions tools/StaticAnalysis/Exceptions/Az.Aks/ExtraAssemblies.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Directory","AssemblyName","Severity","ProblemId","Description","Remediation"
1 change: 1 addition & 0 deletions tools/StaticAnalysis/Exceptions/Az.Aks/HelpIssues.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Assembly","HelpFile","Target","Severity","ProblemId","Description","Remediation"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"Directory","Assembly Name","Assembly Version","Referencing Assembly","Severity","ProblemId","Description","Remediation"
Loading