Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 2ce1a82

Browse files
committed
Log messages in Package Management Console.
The Package Management Console now shows messages logged during the execution of the install, uninstall or update cmdlets. The messages logged are the same ones that Visual Studio shows in its console.
1 parent d96bfb3 commit 2ce1a82

17 files changed

Lines changed: 336 additions & 5 deletions

src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/InstallPackageCmdlet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ protected override void ProcessRecord()
6666
{
6767
ThrowErrorIfProjectNotOpen();
6868
using (IConsoleHostFileConflictResolver resolver = CreateFileConflictResolver()) {
69-
InstallPackage();
69+
using (IDisposable logger = ConsoleHost.CreateLogger(this)) {
70+
InstallPackage();
71+
}
7072
}
7173
}
7274

src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/PackageManagementCmdlet.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace ICSharpCode.PackageManagement.Cmdlets
2727
{
28-
public abstract class PackageManagementCmdlet : PSCmdlet, ITerminatingCmdlet, IPackageScriptSession, IPackageScriptRunner
28+
public abstract class PackageManagementCmdlet : PSCmdlet, ITerminatingCmdlet, IPackageScriptSession, IPackageScriptRunner, ICmdletLogger
2929
{
3030
IPackageManagementConsoleHost consoleHost;
3131
ICmdletTerminatingError terminatingError;
@@ -114,5 +114,10 @@ public void Run(IPackageScript script)
114114
script.Run(this);
115115
}
116116
}
117+
118+
void ICmdletLogger.WriteLine(string message)
119+
{
120+
Host.UI.WriteLine(message);
121+
}
117122
}
118123
}

src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/UninstallPackageCmdlet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ public UninstallPackageCmdlet(
5959
protected override void ProcessRecord()
6060
{
6161
ThrowErrorIfProjectNotOpen();
62-
UninstallPackage();
62+
using (IDisposable logger = ConsoleHost.CreateLogger(this)) {
63+
UninstallPackage();
64+
}
6365
}
6466

6567
void UninstallPackage()

src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/UpdatePackageCmdlet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ protected override void ProcessRecord()
7373
{
7474
ThrowErrorIfProjectNotOpen();
7575
using (IConsoleHostFileConflictResolver resolver = CreateFileConflictResolver()) {
76-
RunUpdate();
76+
using (IDisposable logger = ConsoleHost.CreateLogger(this)) {
77+
RunUpdate();
78+
}
7779
}
7880
}
7981

src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/InstallPackageCmdletTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,5 +321,19 @@ public void ProcessRecord_SourceRepositoryIsOperationAware_InstallOperationStart
321321

322322
operationAwareRepository.AssertOperationWasStartedAndDisposed(RepositoryOperationNames.Install, "Test");
323323
}
324+
325+
[Test]
326+
public void ProcessRecord_PackageIdSpecified_ConsoleHostLoggerIsDisposed()
327+
{
328+
CreateCmdletWithoutActiveProject();
329+
AddDefaultProjectToConsoleHost();
330+
AddPackageSourceToConsoleHost();
331+
SetIdParameter("Test");
332+
333+
RunCmdlet();
334+
335+
fakeConsoleHost.AssertLoggerIsDisposed();
336+
Assert.AreEqual(cmdlet, fakeConsoleHost.CmdletLoggerUsedToCreateLogger);
337+
}
324338
}
325339
}

src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/UninstallPackageCmdletTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,22 @@ public void ProcessRecord_PackageIdSpecified_CmdletUsedAsScriptRunner()
237237
RunCmdlet();
238238

239239
IPackageScriptRunner scriptRunner = uninstallPackageAction.PackageScriptRunner;
240-
240+
241241
Assert.AreEqual(cmdlet, scriptRunner);
242242
}
243+
244+
[Test]
245+
public void ProcessRecord_PackageIdSpecified_ConsoleHostLoggerIsDisposed()
246+
{
247+
CreateCmdletWithoutActiveProject();
248+
AddDefaultProjectToConsoleHost();
249+
AddPackageSourceToConsoleHost();
250+
SetIdParameter("Test");
251+
252+
RunCmdlet();
253+
254+
fakeConsoleHost.AssertLoggerIsDisposed();
255+
Assert.AreEqual(cmdlet, fakeConsoleHost.CmdletLoggerUsedToCreateLogger);
256+
}
243257
}
244258
}

src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/UpdatePackageCmdletTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,5 +832,19 @@ public void ProcessRecord_UpdateAllPackagesIsSolutionAndTwoUpdateActionsAndSourc
832832

833833
operationAwareRepository.AssertOperationWasStartedAndDisposed(RepositoryOperationNames.Update, "Test2");
834834
}
835+
836+
[Test]
837+
public void ProcessRecord_PackageIdSpecified_ConsoleHostLoggerIsDisposed()
838+
{
839+
CreateCmdletWithoutActiveProject();
840+
AddDefaultProjectToConsoleHost();
841+
AddPackageSourceToConsoleHost();
842+
SetIdParameter("Test");
843+
844+
RunCmdlet();
845+
846+
fakeConsoleHost.AssertLoggerIsDisposed();
847+
Assert.AreEqual(cmdlet, fakeConsoleHost.CmdletLoggerUsedToCreateLogger);
848+
}
835849
}
836850
}

src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<RequiredTargetFramework>3.5</RequiredTargetFramework>
5959
</Reference>
6060
<Reference Include="System.Drawing" />
61+
<Reference Include="System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
6162
<Reference Include="System.Windows.Forms" />
6263
<Reference Include="System.Xaml">
6364
<RequiredTargetFramework>4.0</RequiredTargetFramework>
@@ -243,13 +244,15 @@
243244
<Compile Include="Src\Scripting\ConsoleHostFileConflictResolver.cs" />
244245
<Compile Include="Src\Scripting\FileConflictAction.cs" />
245246
<Compile Include="Src\Scripting\GlobalMSBuildProjectCollection.cs" />
247+
<Compile Include="Src\Scripting\ICmdletLogger.cs" />
246248
<Compile Include="Src\Scripting\IConsoleHostFileConflictResolver.cs" />
247249
<Compile Include="Src\Scripting\IGlobalMSBuildProjectCollection.cs" />
248250
<Compile Include="Src\Scripting\MSBuildProjectImportsMerger.cs" />
249251
<Compile Include="Src\Scripting\MSBuildProjectImportsMergeResult.cs" />
250252
<Compile Include="Src\Scripting\MSBuildProjectPropertiesMerger.cs" />
251253
<Compile Include="Src\Scripting\MSBuildProjectPropertiesMergeResult.cs" />
252254
<Compile Include="Src\Scripting\NullGlobalMSBuildProjectCollection.cs" />
255+
<Compile Include="Src\Scripting\PackageManagementConsoleHostLogger.cs" />
253256
<Compile Include="Src\Scripting\RunAllProjectPackageScriptsAction.cs" />
254257
<Compile Include="Src\ServiceWithWorkbenchOwner.cs" />
255258
<Compile Include="Src\SettingsProvider.cs" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Management.Automation;
21+
22+
namespace ICSharpCode.PackageManagement.Scripting
23+
{
24+
public interface ICmdletLogger
25+
{
26+
void WriteError(ErrorRecord error);
27+
void WriteLine(string message);
28+
void WriteVerbose(string message);
29+
void WriteWarning(string message);
30+
}
31+
}

src/AddIns/Misc/PackageManagement/Project/Src/Scripting/IPackageManagementConsoleHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public interface IPackageManagementConsoleHost : IDisposable
4242
void SetDefaultRunspace();
4343

4444
IConsoleHostFileConflictResolver CreateFileConflictResolver(FileConflictAction fileConflictAction);
45+
IDisposable CreateLogger(ICmdletLogger logger);
4546

4647
IPackageManagementProject GetProject(string packageSource, string projectName);
4748
IPackageManagementProject GetProject(IPackageRepository sourceRepository, string projectName);

0 commit comments

Comments
 (0)