Skip to content
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
34 changes: 29 additions & 5 deletions .build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ task createModule {
elseif ($Configuration -match 'PSv3') {
$destinationDirBinaries = "$destinationDir\PSv3"
}
}
else {
$destinationDirBinaries = $destinationDir
}

CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries
CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries

# copy newtonsoft dll if net451 framework
if ($Framework -eq "net451") {
copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
# copy newtonsoft dll if net451 framework
if ($Framework -eq "net451") {
copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries
}
}
}

Expand Down Expand Up @@ -229,6 +232,27 @@ task newSession {
Start-Process "powershell" -ArgumentList @('-noexit', "-command import-module $modulePath -verbose")
}

$localPSModulePath = $env:PSMODULEPATH -split ";" | Where-Object {$_.StartsWith($HOME)}
$pssaDestModulePath = ''
if ($null -ne $localPSModulePath -and $localPSModulePath.Count -eq 1) {
$pssaDestModulePath = Join-Path $localPSModulePath 'PSScriptAnalyzer'
}

function Test-PSSADestModulePath {
($pssaDestModulePath -ne '') -and (Test-Path $pssaDestModulePath)
}

task uninstall -if {Test-PSSADestModulePath} {
Remove-Item -Force -Recurse $pssaDestModulePath
}

task install -if {Test-Path $modulePath} uninstall, {
Copy-Item `
-Recurse `
-Path $modulePath `
-Destination $pssaDestModulePath
}

# TODO fix building psv3
task release cleanModule, clean, build, createModule, buildDocs
task . build, createModule, newSession
42 changes: 41 additions & 1 deletion Rules/UseIdenticalMandatoryParametersDSC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
#if !CORECLR
using System.ComponentModel.Composition;
#endif
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management.Automation.Language;
using System.Reflection;
using Microsoft.Management.Infrastructure;
using Microsoft.PowerShell.DesiredStateConfiguration.Internal;
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions;
Expand All @@ -40,6 +42,44 @@ public class UseIdenticalMandatoryParametersDSC : IDSCResourceRule
private string fileName;
private IDictionary<string, string> propAttrDict;
private IEnumerable<FunctionDefinitionAst> resourceFunctions;
private Func<string, Tuple<string, Version>, Collection<Exception>, List<CimClass>> dscClassImporter;

/// <summary>
/// Constructs an object of type UseIdenticalMandatoryParametersDSC
/// </summary>
public UseIdenticalMandatoryParametersDSC()
{
var importClassesMethod = typeof(DscClassCache).GetMethod(
"ImportClasses",
BindingFlags.Public | BindingFlags.Static);
if (importClassesMethod != null)
{
// In some version of S.M.A DscClassCache.ImportClasses method takes 4 parameters
// while in others it takes 3.
if (importClassesMethod.GetParameters().Count() == 4)
{
dscClassImporter = (path, moduleInfo, errors) =>
{
return importClassesMethod.Invoke(
null,
new object[] { path, moduleInfo, errors, false }) as List<CimClass>;
};
}
else
{
dscClassImporter = (path, moduleInfo, errors) =>
{
return importClassesMethod.Invoke(
null,
new object[] { path, moduleInfo, errors}) as List<CimClass>;
};
}
}
else
{
dscClassImporter = (path, moduleInfo, errors) => null;
}
}

/// <summary>
/// AnalyzeDSCResource: Analyzes given DSC Resource
Expand Down Expand Up @@ -215,7 +255,7 @@ private IDictionary<string, string> GetKeys(string fileName)
isDSCClassCacheInitialized = true;
}

cimClasses = DscClassCache.ImportClasses(mofFilepath, moduleInfo, errors);
cimClasses = dscClassImporter(mofFilepath, moduleInfo, errors);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Import-Module PSScriptAnalyzer
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
$ruleName = 'PSDSCUseIdenticalMandatoryParametersForDSC'
$resourceBasepath = "$directory\DSCResourceModule\DSCResources"
Expand Down