diff --git a/Engine/Commands/InvokeFormatterCommand.cs b/Engine/Commands/InvokeFormatterCommand.cs
index 5d9723df0..23d19284c 100644
--- a/Engine/Commands/InvokeFormatterCommand.cs
+++ b/Engine/Commands/InvokeFormatterCommand.cs
@@ -1,18 +1,8 @@
-//
-// Copyright (c) Microsoft Corporation.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
using System;
using System.Globalization;
-using System.Linq;
using System.Management.Automation;
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
@@ -91,7 +81,7 @@ protected override void BeginProcessing()
this.range = Range == null ? null : new Range(Range[0], Range[1], Range[2], Range[3]);
try
{
- inputSettings = PSSASettings.Create(Settings, this.MyInvocation.PSScriptRoot, this);
+ inputSettings = PSSASettings.Create(Settings, this.MyInvocation.PSScriptRoot, this, GetResolvedProviderPathFromPSPath);
}
catch (Exception e)
{
diff --git a/Engine/Commands/InvokeScriptAnalyzerCommand.cs b/Engine/Commands/InvokeScriptAnalyzerCommand.cs
index 7f7a76a41..bef7a7b78 100644
--- a/Engine/Commands/InvokeScriptAnalyzerCommand.cs
+++ b/Engine/Commands/InvokeScriptAnalyzerCommand.cs
@@ -1,32 +1,16 @@
-//
-// Copyright (c) Microsoft Corporation.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-using System.Text.RegularExpressions;
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
using System;
-using System.ComponentModel;
+using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Management.Automation;
-using System.Management.Automation.Language;
-using System.IO;
-using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
-using System.Threading.Tasks;
-using System.Collections.Concurrent;
-using System.Threading;
using System.Management.Automation.Runspaces;
-using System.Collections;
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
{
@@ -296,7 +280,8 @@ protected override void BeginProcessing()
var settingsObj = PSSASettings.Create(
settings,
processedPaths == null || processedPaths.Count == 0 ? null : processedPaths[0],
- this);
+ this,
+ GetResolvedProviderPathFromPSPath);
if (settingsObj != null)
{
ScriptAnalyzer.Instance.UpdateSettings(settingsObj);
diff --git a/Engine/Generic/PathResolver.cs b/Engine/Generic/PathResolver.cs
new file mode 100644
index 000000000..86e2b7ab4
--- /dev/null
+++ b/Engine/Generic/PathResolver.cs
@@ -0,0 +1,19 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic
+{
+ internal static class PathResolver
+ {
+ ///
+ /// A shim around the GetResolvedProviderPathFromPSPath method from PSCmdlet to resolve relative path including wildcard support.
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ internal delegate GetResolvedProviderPathFromPSPathDelegate GetResolvedProviderPathFromPSPath(@string input, out ProviderInfo output);
+ }
+}
diff --git a/Engine/Settings.cs b/Engine/Settings.cs
index c34631183..0947b77d8 100644
--- a/Engine/Settings.cs
+++ b/Engine/Settings.cs
@@ -1,21 +1,15 @@
-//
-// Copyright (c) Microsoft Corporation.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
+using System.Management.Automation;
using System.Management.Automation.Language;
using System.Reflection;
@@ -183,8 +177,10 @@ public static string GetSettingPresetFilePath(string settingPreset)
/// An input object of type Hashtable or string.
/// The path in which to search for a settings file.
/// An output writer.
+ /// The GetResolvedProviderPathFromPSPath method from PSCmdlet to resolve relative path including wildcard support.
/// An object of Settings type.
- public static Settings Create(object settingsObj, string cwd, IOutputWriter outputWriter)
+ internal static Settings Create(object settingsObj, string cwd, IOutputWriter outputWriter,
+ PathResolver.GetResolvedProviderPathFromPSPath> getResolvedProviderPathFromPSPathDelegate)
{
object settingsFound;
var settingsMode = FindSettingsMode(settingsObj, cwd, out settingsFound);
@@ -206,11 +202,13 @@ public static Settings Create(object settingsObj, string cwd, IOutputWriter outp
case SettingsMode.Preset:
case SettingsMode.File:
+ var resolvedPath = getResolvedProviderPathFromPSPathDelegate(settingsFound.ToString(), out ProviderInfo providerInfo).Single();
+ settingsFound = resolvedPath;
outputWriter?.WriteVerbose(
String.Format(
CultureInfo.CurrentCulture,
Strings.SettingsUsingFile,
- (string)settingsFound));
+ resolvedPath));
break;
case SettingsMode.Hashtable:
diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1
index 2b03bc5e1..1be59e7bf 100644
--- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1
+++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1
@@ -385,6 +385,18 @@ Describe "Test CustomizedRulePath" {
if (!$testingLibraryUsage)
{
Context "When used from settings file" {
+ It "Should process relative settings path" {
+ try {
+ $initialLocation = Get-Location
+ Set-Location $PSScriptRoot
+ $warnings = Invoke-ScriptAnalyzer -ScriptDefinition 'gci' -Settings .\SettingsTest\..\SettingsTest\Project1\PSScriptAnalyzerSettings.psd1
+ $warnings.Count | Should -Be 1
+ }
+ finally {
+ Set-Location $initialLocation
+ }
+ }
+
It "Should use the CustomRulePath parameter" {
$settings = @{
CustomRulePath = "$directory\CommunityAnalyzerRules"