Skip to content

Fix parse errors caused by missing dsc resouces #524

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 24 commits into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cba1f64
Add module dependency handler for missing modules
Apr 28, 2016
f3cde07
Fix parse error caused by missing dsc module
Apr 29, 2016
ea3c0ad
Change copy directory implementation in module handler
Apr 29, 2016
4ad4dca
Check for module presence before copying
May 3, 2016
e81cc3b
Improve module name comparison in module handler
May 4, 2016
6e8097f
Modify PSModulePath in module dependency handler
May 4, 2016
ce31b43
Add a switch to resolve dsc module dependency
May 4, 2016
ddae10f
Add TrySaveModule method to ModuleDependencyHandler class
May 4, 2016
a5bd6fd
Change SaveModule implementation
May 4, 2016
9411a82
Clean up ModuleDependencyHandler implementation
May 10, 2016
d1293c1
Add tests for ModuleDependencyHandler
May 10, 2016
0d984bd
Resolve merge conflict
May 10, 2016
a470e16
Remove redundancies from ModuleDependencyHandler
May 10, 2016
fd3a306
Use IDisposable pattern while creating PowerShell objects
May 12, 2016
ccdb0e0
Set environment variable differently in module handler tests
May 12, 2016
73d63ee
Use IDisposable pattern for ModuleDependencyHandler
May 12, 2016
66eeb9d
Rename DSC in switch name to Dsc and change module handler usage
May 12, 2016
9b02e80
Parse an array of module names for import-dscresource
May 16, 2016
750f8a4
Add repository parameter to save module
May 16, 2016
60fe6c9
Move module handler initialization outside scriptanalyzer class
May 17, 2016
09588c2
Fix failing tests
May 17, 2016
5081eda
Rename ResolveDscResourceDependency to SaveDscResourceDependency
May 17, 2016
38e3708
Add test to check SaveDscResourceDependency parameter
May 17, 2016
2458eae
Fix failing tests
May 17, 2016
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
55 changes: 39 additions & 16 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Threading.Tasks;
using System.Collections.Concurrent;
using System.Threading;
using System.Management.Automation.Runspaces;

namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands
{
Expand All @@ -44,7 +45,7 @@ public class InvokeScriptAnalyzerCommand : PSCmdlet, IOutputWriter
[Parameter(Position = 0,
ParameterSetName = "File",
Mandatory = true,
ValueFromPipeline = true,
ValueFromPipeline = true,
ValueFromPipelineByPropertyName = true)]
[ValidateNotNull]
[Alias("PSPath")]
Expand Down Expand Up @@ -188,6 +189,16 @@ public object Settings

private bool stopProcessing;

/// <summary>
/// Resolve DSC resource dependency
/// </summary>
[Parameter(Mandatory = false)]
public SwitchParameter SaveDscResourceDependency
{
get { return saveDscResourceDependency; }
set { saveDscResourceDependency = value; }
}
private bool saveDscResourceDependency;
#endregion Parameters

#region Overrides
Expand Down Expand Up @@ -227,18 +238,22 @@ protected override void ProcessRecord()
return;
}

if (String.Equals(this.ParameterSetName, "File", StringComparison.OrdinalIgnoreCase))
// TODO Support dependency resolution for analyzing script definitions
if (saveDscResourceDependency)
{
// throws Item Not Found Exception
Collection<PathInfo> paths = this.SessionState.Path.GetResolvedPSPathFromPSPath(path);
foreach (PathInfo p in paths)
using (var rsp = RunspaceFactory.CreateRunspace())
{
ProcessPathOrScriptDefinition(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(p.Path));
rsp.Open();
using (var moduleHandler = new ModuleDependencyHandler(rsp))
{
ScriptAnalyzer.Instance.ModuleHandler = moduleHandler;
ProcessInput();
}
}
}
else if (String.Equals(this.ParameterSetName, "ScriptDefinition", StringComparison.OrdinalIgnoreCase))
else
{
ProcessPathOrScriptDefinition(scriptDefinition);
ProcessInput();
}
}

Expand All @@ -257,30 +272,38 @@ protected override void StopProcessing()
#endregion

#region Methods

private void ProcessPathOrScriptDefinition(string pathOrScriptDefinition)
private void ProcessInput()
{
IEnumerable<DiagnosticRecord> diagnosticsList = Enumerable.Empty<DiagnosticRecord>();

if (String.Equals(this.ParameterSetName, "File", StringComparison.OrdinalIgnoreCase))
{
diagnosticsList = ScriptAnalyzer.Instance.AnalyzePath(pathOrScriptDefinition, this.recurse);
// throws Item Not Found Exception
Collection<PathInfo> paths = this.SessionState.Path.GetResolvedPSPathFromPSPath(path);
foreach (PathInfo p in paths)
{
diagnosticsList = ScriptAnalyzer.Instance.AnalyzePath(
this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(p.Path),
this.recurse);
WriteToOutput(diagnosticsList);
}
}
else if (String.Equals(this.ParameterSetName, "ScriptDefinition", StringComparison.OrdinalIgnoreCase))
{
diagnosticsList = ScriptAnalyzer.Instance.AnalyzeScriptDefinition(pathOrScriptDefinition);
diagnosticsList = ScriptAnalyzer.Instance.AnalyzeScriptDefinition(scriptDefinition);
WriteToOutput(diagnosticsList);
}
}

//Output through loggers
private void WriteToOutput(IEnumerable<DiagnosticRecord> diagnosticRecords)
{
foreach (ILogger logger in ScriptAnalyzer.Instance.Loggers)
{
foreach (DiagnosticRecord diagnostic in diagnosticsList)
foreach (DiagnosticRecord diagnostic in diagnosticRecords)
{
logger.LogObject(diagnostic, this);
}
}
}

#endregion
}
}
Loading