Skip to content

Post-release serialization of cmdlets for breaking change tool #3403

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 4 commits into from
Feb 8, 2017
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,46 @@ public void Analyze(

foreach (var directory in probingDirectories)
{
var index = Path.GetFileName(directory).IndexOf(".");
var service = Path.GetFileName(directory).Substring(index + 1);
var service = Path.GetFileName(directory);

var helpFiles = Directory.EnumerateFiles(directory, "*.dll-Help.xml")
.Where(f => !processedHelpFiles.Contains(Path.GetFileName(f),
StringComparer.OrdinalIgnoreCase)).ToList();
var manifestFiles = Directory.EnumerateFiles(directory, "*.psd1").ToList();

if (helpFiles.Count > 1)
if (manifestFiles.Count > 1)
{
helpFiles = helpFiles.Where(f => Path.GetFileName(f).IndexOf(service) >= 0).ToList();
manifestFiles = manifestFiles.Where(f => Path.GetFileName(f).IndexOf(service) >= 0).ToList();
}

if (helpFiles.Any())
if (manifestFiles.Count == 0)
{
Directory.SetCurrentDirectory(directory);
foreach (var helpFile in helpFiles)
continue;
}

var psd1 = manifestFiles.FirstOrDefault();

var parentDirectory = Directory.GetParent(psd1);
var psd1FileName = Path.GetFileName(psd1);

PowerShell powershell = PowerShell.Create();
powershell.AddScript("Import-LocalizedData -BaseDirectory " + parentDirectory +
" -FileName " + psd1FileName +
" -BindingVariable ModuleMetadata; $ModuleMetadata.NestedModules");

var cmdletResult = powershell.Invoke();
var cmdletFiles = cmdletResult.Select(c => c.ToString().Substring(2));

if (cmdletFiles.Any())
{
foreach (var cmdletFileName in cmdletFiles)
{
var cmdletFile = helpFile.Substring(0, helpFile.Length - "-Help.xml".Length);
var helpFileName = Path.GetFileName(helpFile);
var cmdletFileName = Path.GetFileName(cmdletFile);
if (File.Exists(cmdletFile))
var cmdletFileFullPath = Path.Combine(directory, Path.GetFileName(cmdletFileName));

if (File.Exists(cmdletFileFullPath))
{
issueLogger.Decorator.AddDecorator(a => a.AssemblyFileName = cmdletFileName, "AssemblyFileName");
processedHelpFiles.Add(helpFileName);
issueLogger.Decorator.AddDecorator(a => a.AssemblyFileName = cmdletFileFullPath, "AssemblyFileName");
processedHelpFiles.Add(cmdletFileName);
var proxy =
EnvironmentHelpers.CreateProxy<CmdletBreakingChangeLoader>(directory, out _appDomain);
var newModuleMetadata = proxy.GetModuleMetadata(cmdletFile);
var newModuleMetadata = proxy.GetModuleMetadata(cmdletFileFullPath);

string fileName = cmdletFileName + ".json";
string executingPath =
Expand All @@ -129,8 +142,28 @@ public void Analyze(

if (cmdletFilter != null)
{
string output = "Before filter\nOld module cmdlet count: " + oldModuleMetadata.Cmdlets.Count +
"\nNew module cmdlet count: " + newModuleMetadata.Cmdlets.Count;

output += "\nCmdlet file: " + cmdletFileFullPath;

oldModuleMetadata.FilterCmdlets(cmdletFilter);
newModuleMetadata.FilterCmdlets(cmdletFilter);

output += "\nAfter filter\nOld module cmdlet count: " + oldModuleMetadata.Cmdlets.Count +
"\nNew module cmdlet count: " + newModuleMetadata.Cmdlets.Count;

foreach (var cmdlet in oldModuleMetadata.Cmdlets)
{
output += "\n\tOld cmdlet - " + cmdlet.Name;
}

foreach (var cmdlet in newModuleMetadata.Cmdlets)
{
output += "\n\tNew cmdlet - " + cmdlet.Name;
}

issueLogger.WriteMessage(output + "\n");
}

RunBreakingChangeChecks(oldModuleMetadata, newModuleMetadata, issueLogger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ public ModuleMetadata GetModuleMetadata(string assemblyPath)
results.Add(cmdletMetadata);
}
}
catch
catch (Exception ex)
{
throw ex;
}

ModuleMetadata.Cmdlets = results;
Expand Down
5 changes: 4 additions & 1 deletion tools/StaticAnalysis/BreakingChangeAnalyzer/TypeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public TypeMetadata(Type inputType)
}

// Add the property to the dictionary
_properties.Add(property.Name, propertyType.ToString());
if (!_properties.ContainsKey(property.Name))
{
_properties.Add(property.Name, propertyType.ToString());
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions tools/StaticAnalysis/Exceptions/BreakingChangeIssues.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.Auditing.Cmdlet.RemoveSqlDatabaseAuditing","Remove-AzureRmSqlDatabaseAuditing","0","1010","The cmdlet 'Remove-AzureRmSqlDatabaseAuditing' no longer supports the alias 'Remove-AzureRmSqlDatabaseAuditing'.","Add the alias 'Remove-AzureRmSqlDatabaseAuditing back to the cmdlet 'Remove-AzureRmSqlDatabaseAuditing'."
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.NewAzureSqlDatabaseImport","New-AzureRmSqlDatabaseImport","0","2020","The cmdlet 'New-AzureRmSqlDatabaseImport' no longer supports the type 'Int32' for parameter 'DatabaseMaxSizeBytes'.","Change the type for parameter 'DatabaseMaxSizeBytes' back to 'Int32'."
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like Azure.AnalysisServices did not make it in.

Copy link
Member

Choose a reason for hiding this comment

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

Also Commands.ResourceManager.Cmdlets is not included. We should look at all our commands dlls and compare them to the list in SerializedCmdflets to ensure there are no other omissions.

Note: this is OK to merge as is, but we must add serializations for the additional assemblies ASAP.

Copy link
Member Author

Choose a reason for hiding this comment

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

@markcowl fixed

"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.ImportExport.Cmdlet.NewAzureSqlDatabaseImport","New-AzureRmSqlDatabaseImport","0","2020","The cmdlet 'New-AzureRmSqlDatabaseImport' no longer supports the type 'Int32' for parameter 'DatabaseMaxSizeBytes'.","Change the type for parameter 'DatabaseMaxSizeBytes' back to 'Int32'."
Loading