Skip to content

Commit 522c59b

Browse files
authored
Merge pull request Azure#6979 from cormacpayne/static-analysis-netcore
Convert StaticAnalysis to .NET Core
2 parents 125812d + f4848ec commit 522c59b

File tree

414 files changed

+2741
-120
lines changed

Some content is hidden

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

414 files changed

+2741
-120
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ before_install:
2525
# https://github.com/travis-ci/travis-ci/issues/1066#issuecomment-383489298
2626
script:
2727
- sudo dotnet msbuild build.proj /t:BuildNetcore /p:Configuration=$CONFIG || travis_terminate 1
28+
- sudo dotnet tools/StaticAnalysis/bin/$CONFIG/netcoreapp2.1/StaticAnalysis.Netcore.dll -p src/Package/$CONFIG -r src/Package -u
2829
- sudo pwsh -NonInteractive -NoLogo -NoProfile -File tools/TestModuleLoading.ps1 || travis_terminate 1
2930
- sudo dotnet test src/Azure.PowerShell.Netcore.Test.sln --filter "AcceptanceType=CheckIn&RunType!=DesktopOnly" --configuration $CONFIG
30-
31+
3132
after_success:
3233
- if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
3334
docker build . -t $DOCKER_USER/$NAME:$TRAVIS_COMMIT --build-arg CONFIG=$CONFIG;
@@ -38,7 +39,7 @@ after_success:
3839
docker push $DOCKER_USER/$NAME:$TRAVIS_COMMIT;
3940
docker push $DOCKER_USER/$NAME:$TRAVIS_BRANCH;
4041

41-
if [ "$TRAVIS_BRANCH" == "master" ]; then
42+
if [ "$TRAVIS_BRANCH" == "master" ]; then
4243
docker tag $DOCKER_USER/$NAME:$TRAVIS_COMMIT $DOCKER_USER/$NAME:latest;
4344
docker push $DOCKER_USER/$NAME:latest;
4445
fi;

Azure.PowerShell.Netcore.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.DeviceProvisioning
119119
EndProject
120120
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Commands.PolicyInsights.Netcore", "src\ResourceManager\PolicyInsights\Commands.PolicyInsights\Commands.PolicyInsights.Netcore.csproj", "{A0574194-976A-486A-B589-07B2E50CA6EF}"
121121
EndProject
122+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tools.Common.Netcore", "tools\Tools.Common\Tools.Common.Netcore.csproj", "{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}"
123+
EndProject
124+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StaticAnalysis.Netcore", "tools\StaticAnalysis\StaticAnalysis.Netcore.csproj", "{493FA948-DA9C-47CD-8385-3C0261377D86}"
125+
EndProject
122126
Global
123127
GlobalSection(SolutionConfigurationPlatforms) = preSolution
124128
Debug|Any CPU = Debug|Any CPU
@@ -825,6 +829,30 @@ Global
825829
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x64.Build.0 = Release|Any CPU
826830
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x86.ActiveCfg = Release|Any CPU
827831
{A0574194-976A-486A-B589-07B2E50CA6EF}.Release|x86.Build.0 = Release|Any CPU
832+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
833+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
834+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x64.ActiveCfg = Debug|Any CPU
835+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x64.Build.0 = Debug|Any CPU
836+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x86.ActiveCfg = Debug|Any CPU
837+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Debug|x86.Build.0 = Debug|Any CPU
838+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
839+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|Any CPU.Build.0 = Release|Any CPU
840+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x64.ActiveCfg = Release|Any CPU
841+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x64.Build.0 = Release|Any CPU
842+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x86.ActiveCfg = Release|Any CPU
843+
{EE2A4BB9-2ECB-4CAE-AD82-C4882B6ECDE0}.Release|x86.Build.0 = Release|Any CPU
844+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
845+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
846+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x64.ActiveCfg = Debug|Any CPU
847+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x64.Build.0 = Debug|Any CPU
848+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x86.ActiveCfg = Debug|Any CPU
849+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Debug|x86.Build.0 = Debug|Any CPU
850+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
851+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|Any CPU.Build.0 = Release|Any CPU
852+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x64.ActiveCfg = Release|Any CPU
853+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x64.Build.0 = Release|Any CPU
854+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.ActiveCfg = Release|Any CPU
855+
{493FA948-DA9C-47CD-8385-3C0261377D86}.Release|x86.Build.0 = Release|Any CPU
828856
EndGlobalSection
829857
GlobalSection(SolutionProperties) = preSolution
830858
HideSolutionNode = FALSE

build.proj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,13 @@
617617

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

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

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

src/Common/Commands.Common.Storage.Management/Common.Storage.Management.Netcore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
2625
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
2726
<PackageReference Include="System.Collections.NonGeneric" Version="4.3.0" />
2827
</ItemGroup>

src/Common/Commands.Common.Storage/Common.Storage.Netcore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
3029
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
3130
</ItemGroup>
3231

src/ResourceManager/AzureBatch/Commands.Batch/Commands.Batch.Netcore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ItemGroup>
3131
<PackageReference Include="Azure.Batch" Version="8.1.1" />
3232
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="4.2.0" />
33-
<PackageReference Include="Microsoft.Extensions.Primitives" Version="2.1.1" />
33+
<PackageReference Include="Microsoft.Extensions.Primitives" Version="1.1.0" />
3434
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
3535
</ItemGroup>
3636

src/ResourceManager/Profile/Commands.Profile/Az.Profile.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ RequiredAssemblies = '.\Microsoft.Azure.PowerShell.Authentication.Abstractions.d
7676
'.\Microsoft.Rest.ClientRuntime.Azure.dll',
7777
'.\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll',
7878
'.\Microsoft.WindowsAzure.Storage.dll',
79-
'.\Microsoft.Azure.Management.Storage.dll', '.\Newtonsoft.Json.dll',
79+
'.\Newtonsoft.Json.dll',
8080
'.\Microsoft.Azure.PowerShell.Aks.dll',
8181
'.\Microsoft.Azure.PowerShell.Strategies.dll'
8282

src/ResourceManager/Sql/Commands.Sql/Commands.Sql.Netcore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.18.0-preview" />
32+
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="7.1.0-preview" />
3233
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />
3334
</ItemGroup>
3435

src/ResourceManager/Storage/Commands.Management.Storage/Az.Storage.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ PowerShellVersion = '5.1'
5454
RequiredModules = @(@{ModuleName = 'Az.Profile'; ModuleVersion = '0.1.0'; })
5555

5656
# Assemblies that must be loaded prior to importing this module
57-
RequiredAssemblies = '.\Microsoft.Azure.Management.Storage.dll'
57+
RequiredAssemblies = '.\Microsoft.Azure.Management.Storage.dll',
58+
'.\Microsoft.WindowsAzure.Storage.dll'
5859

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

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

7373
# 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.
7474
FunctionsToExport = @()

tools/StaticAnalysis/BreakingChangeAnalyzer/BreakingChangeAnalyzer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ public void Analyze(
158158
{
159159
issueLogger.Decorator.AddDecorator(a => a.AssemblyFileName = assemblyFileName, "AssemblyFileName");
160160
processedHelpFiles.Add(assemblyFileName);
161-
var proxy = EnvironmentHelpers.CreateProxy<CmdletLoader>(directory, out _appDomain);
161+
var proxy =
162+
#if !NETSTANDARD
163+
EnvironmentHelpers.CreateProxy<CmdletLoader>(directory, out _appDomain);
164+
#else
165+
new CmdletLoader();
166+
#endif
162167
var newModuleMetadata = proxy.GetModuleMetadata(assemblyFile, requiredModules);
163168

164169
string fileName = assemblyFileName + ".json";

tools/StaticAnalysis/BreakingChangeAttributesAnalyzer/BreakingChangeAttributesAnalyzer.cs

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

15+
#if !NETSTANDARD
1516
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
17+
#endif
1618
using StaticAnalysis.BreakingChangeAnalyzer;
1719
using System;
1820
using System.Collections.Generic;
@@ -129,7 +131,11 @@ public void Analyze(IEnumerable<string> cmdletProbingDirs, Func<IEnumerable<stri
129131
if (File.Exists(cmdletFileFullPath))
130132
{
131133
var proxy =
134+
#if !NETSTANDARD
132135
EnvironmentHelpers.CreateProxy<CmdletBreakingChangeAttributeLoader>(directory, out _appDomain);
136+
#else
137+
new CmdletBreakingChangeAttributeLoader();
138+
#endif
133139
var cmdletDataForModule = proxy.GetModuleBreakingChangeAttributes(cmdletFileFullPath);
134140

135141
//If there is nothing in this module just onctinue
@@ -226,11 +232,13 @@ private void LogBreakingChangesInModule(BreakingChangeAttributesInModule moduleD
226232
foreach (BreakingChangeAttributesInCmdlet cmdletData in moduleData.CmdletList)
227233
{
228234
textForBreakingChangesInModule += string.Format(BREAKING_CHANGE_CMDLET_HEADER_FORMAT_STRING, cmdletData.CmdletName);
235+
#if !NETSTANDARD
229236
foreach (GenericBreakingChangeAttribute attribute in cmdletData.BreakingChangeAttributes)
230237
{
231238
textForBreakingChangesInModule += attribute.GetBreakingChangeTextFromAttribute(cmdletData.CmdletType, true) + "\n\n";
232239
}
233-
}
240+
#endif
241+
}
234242

235243
//Now that we have the text, add it to the log file
236244
logger.LogMessage(textForBreakingChangesInModule);

tools/StaticAnalysis/BreakingChangeAttributesAnalyzer/CmdletBreakingChangeAttributeLoader.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
using System.Linq;
1919
using System.Reflection;
2020
using System.Management.Automation;
21+
#if !NETSTANDARD
2122
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
23+
#endif
2224
using Tools.Common.Extensions;
2325

2426
namespace StaticAnalysis.BreakingChangeAttributesAnalyzer
@@ -38,7 +40,9 @@ public class BreakingChangeAttributesInCmdlet
3840
{
3941
public Type CmdletType { get; set; }
4042
public string CmdletName { get; set; }
43+
#if !NETSTANDARD
4144
public List<GenericBreakingChangeAttribute> BreakingChangeAttributes { get; set; }
45+
#endif
4246
}
4347

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

6368
if (attributes != null && (attributes.Count() > 0)) { }
69+
#endif
6470
var cmdletMetadata = new BreakingChangeAttributesInCmdlet
6571
{
6672
CmdletType = type,
6773
CmdletName = cmdlet.VerbName + "-" + cmdlet.NounName,
74+
#if !NETSTANDARD
6875
BreakingChangeAttributes = attributes.ToList()
69-
};
76+
#endif
77+
};
7078

7179
results.Add(cmdletMetadata);
7280
}

tools/StaticAnalysis/CmdlineArgParsing/StaticAnalysisArgs.cs

Lines changed: 0 additions & 61 deletions
This file was deleted.

tools/StaticAnalysis/DependencyAnalyzer/DependencyAnalyzer.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class DependencyAnalyzer : IStaticAnalyzer
4444
"Microsoft.Management.Infrastructure",
4545
"Microsoft.Build",
4646
"Microsoft.Build.Framework",
47+
"Microsoft.Win32.Primitives",
4748
"WindowsBase"
4849
};
4950

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

66+
private bool _isNetcore;
67+
6568
public DependencyAnalyzer()
6669
{
6770
Name = "Dependency Analyzer";
@@ -109,6 +112,7 @@ public void Analyze(IEnumerable<string> directories, IEnumerable<String> modules
109112
_missingAssemblyLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
110113
_extraAssemblyLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
111114
_dependencyMapLogger.Decorator.AddDecorator(r => { r.Directory = directoryPath; }, "Directory");
115+
_isNetcore = directoryPath.Contains("Az.");
112116
ProcessDirectory(directoryPath);
113117
_versionConflictLogger.Decorator.Remove("Directory");
114118
_missingAssemblyLogger.Decorator.Remove("Directory");
@@ -241,15 +245,20 @@ private static bool RequiresExactVersionMatch(AssemblyRecord name)
241245

242246
private static bool IsFrameworkAssembly(AssemblyName name)
243247
{
244-
return name.Name.StartsWith("System") || name.Name.Equals("mscorlib")
248+
return name.Name.StartsWith("System") || name.Name.Equals("mscorlib") || name.Name.Equals("netstandard")
245249
|| FrameworkAssemblies.Contains(name.Name);
246250
}
247251

248252
private void ProcessDirectory(string directoryPath)
249253
{
250254
var savedDirectory = Directory.GetCurrentDirectory();
251255
Directory.SetCurrentDirectory(directoryPath);
252-
_loader = EnvironmentHelpers.CreateProxy<AssemblyLoader>(directoryPath, out _testDomain);
256+
_loader =
257+
#if !NETSTANDARD
258+
EnvironmentHelpers.CreateProxy<AssemblyLoader>(directoryPath, out _testDomain);
259+
#else
260+
new AssemblyLoader();
261+
#endif
253262
foreach (var file in Directory.GetFiles(directoryPath).Where(file => file.EndsWith(".dll")))
254263
{
255264
AssemblyRecord assembly = CreateAssemblyRecord(file);
@@ -294,7 +303,9 @@ private void ProcessDirectory(string directoryPath)
294303

295304
FindExtraAssemblies();
296305

306+
#if !NETSTANDARD
297307
AppDomain.Unload(_testDomain);
308+
#endif
298309
Directory.SetCurrentDirectory(savedDirectory);
299310
}
300311

@@ -356,7 +367,7 @@ private void CheckAssemblyReference(AssemblyName reference, AssemblyRecord paren
356367
parent.Name)
357368
});
358369
}
359-
else
370+
else if (_isNetcore && stored.Version < reference.Version)
360371
{
361372
var minVersion = (stored.Version < reference.Version) ? stored.Version : reference.Version;
362373
_versionConflictLogger.LogRecord(new AssemblyVersionConflict()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Directory","AssemblyName","Expected Version","Actual Version","Parent Assembly","Severity","ProblemId","Description","Remediation"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
2+
"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]'."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Directory","AssemblyName","Severity","ProblemId","Description","Remediation"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Assembly","HelpFile","Target","Severity","ProblemId","Description","Remediation"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Directory","Assembly Name","Assembly Version","Referencing Assembly","Severity","ProblemId","Description","Remediation"

0 commit comments

Comments
 (0)