diff options
author | Matt Ward <ward.matt@gmail.com> | 2015-04-26 15:59:16 +0300 |
---|---|---|
committer | Matt Ward <ward.matt@gmail.com> | 2015-04-26 15:59:16 +0300 |
commit | aa27f086b0aad8a432a06628ac4b93d8cb41cd0c (patch) | |
tree | 303659abec24b65bb154d5f4f900f7368b070a75 /main/src/addins/MonoDevelop.PackageManagement | |
parent | 192627c34a74d00f73b6f750f928e8007b62a3f8 (diff) |
[NuGet] Open readme.txt when NuGet package is installed.
SharpDevelop will now open the readme.txt file in a NuGet package when
it is explicitly installed or updated. The readme.txt file needs to be
in the root directory of the package. If the NuGet package is being
installed as a dependency of another NuGet package then the readme.txt
will not be opened. If the NuGet package is already installed in
another project then the readme.txt will not be opened.
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
14 files changed, 429 insertions, 8 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeFileService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeFileService.cs index cc98f10229..de138df6cf 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeFileService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakeFileService.cs @@ -58,6 +58,22 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers public void OnFileChanged (string path)
{
}
+
+ public string FileNamePassedToOpenFile;
+ public bool IsOpenFileCalled;
+
+ public void OpenFile (string path)
+ {
+ IsOpenFileCalled = true;
+ FileNamePassedToOpenFile = path;
+ }
+
+ public List<string> ExistingFileNames = new List<string> ();
+
+ public bool FileExists (string path)
+ {
+ return ExistingFileNames.Contains (path);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableInstallPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableInstallPackageAction.cs new file mode 100644 index 0000000000..cd981cf0fb --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableInstallPackageAction.cs @@ -0,0 +1,50 @@ +//
+// TestableInstallPackageAction.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// 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;
+using ICSharpCode.PackageManagement;
+
+namespace MonoDevelop.PackageManagement.Tests.Helpers
+{
+ public class TestableInstallPackageAction : InstallPackageAction
+ {
+ public TestableInstallPackageAction (
+ IPackageManagementProject project,
+ IPackageManagementEvents packageManagementEvents)
+ : base (project, packageManagementEvents)
+ {
+ }
+
+ public OpenPackageReadMeMonitor OpenPackageReadMeMonitor;
+
+ protected override IDisposable CreateOpenPackageReadMeMonitor (string packageId)
+ {
+ OpenPackageReadMeMonitor = base.CreateOpenPackageReadMeMonitor (packageId) as OpenPackageReadMeMonitor;
+ return OpenPackageReadMeMonitor;
+ }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableUpdatePackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableUpdatePackageAction.cs new file mode 100644 index 0000000000..ef2a984f74 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableUpdatePackageAction.cs @@ -0,0 +1,51 @@ +//
+// TestableUpdatePackageAction.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// 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;
+using ICSharpCode.PackageManagement;
+
+namespace MonoDevelop.PackageManagement.Tests.Helpers
+{
+ public class TestableUpdatePackageAction : UpdatePackageAction
+ {
+ public TestableUpdatePackageAction (
+ IPackageManagementProject project,
+ IPackageManagementEvents packageManagementEvents,
+ IFileRemover fileRemover)
+ : base (project, packageManagementEvents, fileRemover)
+ {
+ }
+
+ public OpenPackageReadMeMonitor OpenPackageReadMeMonitor;
+
+ protected override IDisposable CreateOpenPackageReadMeMonitor (string packageId)
+ {
+ OpenPackageReadMeMonitor = base.CreateOpenPackageReadMeMonitor (packageId) as OpenPackageReadMeMonitor;
+ return OpenPackageReadMeMonitor;
+ }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj index 6c184be827..0e9993c766 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.csproj @@ -207,6 +207,9 @@ <Compile Include="MonoDevelop.PackageManagement.Tests\CheckForUpdatesProgressMonitorTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableCheckForUpdatesProgressMonitor.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests\TestableCheckForUpdatesTaskRunner.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests\OpenPackageReadMeMonitorTests.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableInstallPackageAction.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableUpdatePackageAction.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\core\MonoDevelop.Core\MonoDevelop.Core.csproj"> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageActionTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageActionTests.cs index 5273282109..c14c836dfd 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageActionTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/InstallPackageActionTests.cs @@ -39,14 +39,14 @@ namespace MonoDevelop.PackageManagement.Tests {
PackageManagementEvents packageManagementEvents;
FakePackageManagementProject fakeProject;
- InstallPackageAction action;
+ TestableInstallPackageAction action;
InstallPackageHelper installPackageHelper;
void CreateAction ()
{
packageManagementEvents = new PackageManagementEvents ();
fakeProject = new FakePackageManagementProject ();
- action = new InstallPackageAction (fakeProject, packageManagementEvents);
+ action = new TestableInstallPackageAction (fakeProject, packageManagementEvents);
installPackageHelper = new InstallPackageHelper (action);
}
@@ -518,5 +518,16 @@ namespace MonoDevelop.PackageManagement.Tests CollectionAssert.AreEqual (action.Operations, actualOperations);
}
+
+ [Test]
+ public void Execute_PackageInstalledSuccessfully_OpenPackageReadmeMonitorCreated ()
+ {
+ CreateAction ();
+ installPackageHelper.TestPackage.Id = "Test";
+ installPackageHelper.InstallTestPackage();
+
+ Assert.AreEqual ("Test", action.OpenPackageReadMeMonitor.PackageId);
+ Assert.IsTrue (action.OpenPackageReadMeMonitor.IsDisposed);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/OpenPackageReadMeMonitorTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/OpenPackageReadMeMonitorTests.cs new file mode 100644 index 0000000000..386197d56d --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/OpenPackageReadMeMonitorTests.cs @@ -0,0 +1,154 @@ +//
+// OpenPackageReadMeMonitorTests.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// 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;
+using System.IO;
+using NuGet;
+using NUnit.Framework;
+using MonoDevelop.PackageManagement.Tests.Helpers;
+
+namespace MonoDevelop.PackageManagement.Tests
+{
+ [TestFixture]
+ public class OpenPackageReadMeMonitorTests
+ {
+ FakeFileService fileService;
+ FakePackageManagementProject project;
+
+ OpenPackageReadMeMonitor CreateMonitor (string packageId)
+ {
+ fileService = new FakeFileService (null);
+ project = new FakePackageManagementProject ();
+ return new OpenPackageReadMeMonitor (packageId, project, fileService);
+ }
+
+ FakePackage CreatePackageWithFile (string packageId, string fileName)
+ {
+ var package = new FakePackage (packageId);
+ package.AddFile (fileName);
+ return package;
+ }
+
+ PackageOperationEventArgs CreatePackageInstallEventWithFile (string installPath, IPackage package)
+ {
+ return new PackageOperationEventArgs (package, null, installPath);
+ }
+
+ [Test]
+ public void Dispose_PackageInstalledWithReadmeTxt_ReadmeTxtIsOpened ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.1.2.0";
+ string expectedFileOpened = Path.Combine (installPath, "readme.txt");
+
+ using (IDisposable monitor = CreateMonitor ("Test")) {
+ fileService.ExistingFileNames.Add (expectedFileOpened);
+ FakePackage package = CreatePackageWithFile ("Test", "readme.txt");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+ }
+
+ Assert.AreEqual (expectedFileOpened, fileService.FileNamePassedToOpenFile);
+ }
+
+ [Test]
+ public void Dispose_PackageDependencyIsInstalledWithReadmeTxt_ReadmeTxtIsNotOpened ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.Dependency.1.2.0";
+ string expectedFileOpened = Path.Combine (installPath, "readme.txt");
+
+ using (IDisposable monitor = CreateMonitor ("Test")) {
+ fileService.ExistingFileNames.Add (expectedFileOpened);
+ FakePackage package = CreatePackageWithFile ("Test.Dependency", "readme.txt");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+ }
+
+ Assert.IsFalse (fileService.IsOpenFileCalled);
+ }
+
+ [Test]
+ public void Dispose_PackageInstalledWithoutReadmeTxt_ReadmeTxtIsNotOpened ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.1.2.0";
+ string expectedFileOpened = Path.Combine (installPath, "readme.txt");
+
+ using (IDisposable monitor = CreateMonitor ("Test")) {
+ fileService.ExistingFileNames.Add (expectedFileOpened);
+ var package = new FakePackage ("Test");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+ }
+
+ Assert.IsFalse (fileService.IsOpenFileCalled);
+ }
+
+ [Test]
+ public void Dispose_PackageDependencyIsInstalledWithReadmeTxtWithDifferentCase_ReadmeTxtIsOpened ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.1.2.0";
+ string expectedFileOpened = Path.Combine (installPath, "ReadMe.TXT");
+
+ using (IDisposable monitor = CreateMonitor ("Test")) {
+ fileService.ExistingFileNames.Add (expectedFileOpened);
+ FakePackage package = CreatePackageWithFile ("Test", "ReadMe.TXT");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+ }
+
+ Assert.AreEqual (expectedFileOpened, fileService.FileNamePassedToOpenFile);
+ }
+
+ [Test]
+ public void Dispose_PackageInstalledWithReadmeTxtButFileDoesNotExistOnFileSystem_ReadmeTxtIsNotOpened ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.1.2.0";
+ string readmeFileName = Path.Combine (installPath, "readme.txt");
+
+ using (IDisposable monitor = CreateMonitor ("Test")) {
+ FakePackage package = CreatePackageWithFile ("Test", "readme.txt");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+ }
+
+ Assert.IsFalse (fileService.IsOpenFileCalled);
+ }
+
+ [Test]
+ public void Constructor_PackageDependencyIsInstalledWithReadmeTxt_ReadmeTxtIsNotOpenedUntilDisposeIsCalled ()
+ {
+ const string installPath = @"d:\projects\myproject\packages\Test.1.2.0";
+ string expectedFileOpened = Path.Combine (installPath, "ReadMe.TXT");
+
+ OpenPackageReadMeMonitor monitor = CreateMonitor ("Test");
+ fileService.ExistingFileNames.Add (expectedFileOpened);
+ FakePackage package = CreatePackageWithFile ("Test", "ReadMe.TXT");
+ PackageOperationEventArgs e = CreatePackageInstallEventWithFile (installPath, package);
+ project.FirePackageInstalledEvent (e);
+
+ Assert.IsFalse (fileService.IsOpenFileCalled);
+ }
+ }
+}
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UpdatePackageActionTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UpdatePackageActionTests.cs index 0e5bb1185a..dbb47c720c 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UpdatePackageActionTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UpdatePackageActionTests.cs @@ -37,7 +37,7 @@ namespace MonoDevelop.PackageManagement.Tests [TestFixture]
public class UpdatePackageActionTests
{
- UpdatePackageAction action;
+ TestableUpdatePackageAction action;
PackageManagementEvents packageManagementEvents;
FakePackageManagementProject fakeProject;
UpdatePackageHelper updatePackageHelper;
@@ -49,7 +49,7 @@ namespace MonoDevelop.PackageManagement.Tests packageManagementEvents = new PackageManagementEvents ();
fakeProject = new FakePackageManagementProject ();
fileRemover = new FakeFileRemover ();
- action = new UpdatePackageAction (fakeProject, packageManagementEvents, fileRemover);
+ action = new TestableUpdatePackageAction (fakeProject, packageManagementEvents, fileRemover);
updatePackageHelper = new UpdatePackageHelper (action);
}
@@ -474,6 +474,17 @@ namespace MonoDevelop.PackageManagement.Tests Assert.IsFalse (fakeProject.IsUpdatePackageCalled);
AssertMessageIsLogged ("No updates available for 'MyPackage' in project 'MyProject'.");
}
+
+ [Test]
+ public void Execute_PackageUpdatedSuccessfully_OpenPackageReadmeMonitorCreated ()
+ {
+ CreateSolution ();
+ updatePackageHelper.TestPackage.Id = "Test";
+ updatePackageHelper.UpdateTestPackage ();
+
+ Assert.AreEqual ("Test", action.OpenPackageReadMeMonitor.PackageId);
+ Assert.IsTrue (action.OpenPackageReadMeMonitor.IsDisposed);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj index 814e2943d8..e97d869732 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj @@ -368,6 +368,7 @@ <Compile Include="MonoDevelop.PackageManagement\CheckForUpdatesTaskRunner.cs" /> <Compile Include="MonoDevelop.PackageManagement\CheckForUpdatesTask.cs" /> <Compile Include="MonoDevelop.PackageManagement\ProjectReloadedEventArgs.cs" /> + <Compile Include="MonoDevelop.PackageManagement\OpenPackageReadmeMonitor.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" /> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementFileService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementFileService.cs index 59920df241..938562338e 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementFileService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementFileService.cs @@ -35,5 +35,7 @@ namespace ICSharpCode.PackageManagement void RemoveFile(string path);
void RemoveDirectory(string path);
void OnFileChanged(string path);
+ void OpenFile (string path);
+ bool FileExists (string path);
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/InstallPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/InstallPackageAction.cs index 778140286e..571910841c 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/InstallPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/InstallPackageAction.cs @@ -51,8 +51,10 @@ namespace ICSharpCode.PackageManagement protected override void ExecuteCore()
{
- Project.InstallPackage(Package, this);
- OnParentPackageInstalled ();
+ using (IDisposable monitor = CreateOpenPackageReadMeMonitor (Package.Id)) {
+ Project.InstallPackage (Package, this);
+ OnParentPackageInstalled ();
+ }
}
protected override string StartingMessageFormat {
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/OpenPackageReadmeMonitor.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/OpenPackageReadmeMonitor.cs new file mode 100644 index 0000000000..f2c4612759 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/OpenPackageReadmeMonitor.cs @@ -0,0 +1,100 @@ +//
+// OpenPackageReadMeMonitor.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// 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;
+using System.IO;
+using System.Linq;
+using ICSharpCode.PackageManagement;
+using NuGet;
+
+namespace MonoDevelop.PackageManagement
+{
+ public class OpenPackageReadMeMonitor : IDisposable
+ {
+ IPackageManagementProject project;
+ IPackageManagementFileService fileService;
+
+ public OpenPackageReadMeMonitor (
+ string packageId,
+ IPackageManagementProject project,
+ IPackageManagementEvents packageManagementEvents)
+ : this (packageId, project, new PackageManagementFileService (packageManagementEvents))
+ {
+ }
+
+ public OpenPackageReadMeMonitor (
+ string packageId,
+ IPackageManagementProject project,
+ IPackageManagementFileService fileService)
+ {
+ PackageId = packageId;
+ this.project = project;
+ this.fileService = fileService;
+ project.PackageInstalled += PackageInstalled;
+ }
+
+ public string PackageId { get; private set; }
+
+ public bool IsDisposed { get; private set; }
+
+ string ReadMeFile { get; set; }
+
+ public void Dispose ()
+ {
+ if (IsDisposed) {
+ return;
+ }
+
+ IsDisposed = true;
+ project.PackageInstalled -= PackageInstalled;
+ OpenReadMeFile ();
+ }
+
+ void PackageInstalled (object sender, PackageOperationEventArgs e)
+ {
+ if (e.Package.Id != PackageId) {
+ return;
+ }
+
+ ReadMeFile = FindReadMeFileInPackage (e.InstallPath, e.Package);
+ }
+
+ string FindReadMeFileInPackage (string installPath, IPackage package)
+ {
+ return package.GetFiles ()
+ .Where (file => "readme.txt".Equals (file.Path, StringComparison.OrdinalIgnoreCase))
+ .Select (file => Path.Combine (installPath, file.Path))
+ .FirstOrDefault ();
+ }
+
+ void OpenReadMeFile ()
+ {
+ if ((ReadMeFile != null) && fileService.FileExists (ReadMeFile)) {
+ fileService.OpenFile (ReadMeFile);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementFileService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementFileService.cs index 990ddabfdc..e222021128 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementFileService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementFileService.cs @@ -29,6 +29,7 @@ using System;
using System.IO;
using MonoDevelop.Core;
+using MonoDevelop.Ide;
namespace ICSharpCode.PackageManagement
{
@@ -62,5 +63,17 @@ namespace ICSharpCode.PackageManagement {
packageManagementEvents.OnFileChanged (path);
}
+
+ public bool FileExists (string path)
+ {
+ return File.Exists (path);
+ }
+
+ public void OpenFile (string path)
+ {
+ DispatchService.GuiSyncDispatch (() => {
+ IdeApp.Workbench.OpenDocument (path, null, true);
+ });
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs index c957f7c8e5..5ecc13cd24 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs @@ -248,5 +248,10 @@ namespace ICSharpCode.PackageManagement }
return PackageVersion;
}
+
+ protected virtual IDisposable CreateOpenPackageReadMeMonitor (string packageId)
+ {
+ return new OpenPackageReadMeMonitor (packageId, Project, packageManagementEvents);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UpdatePackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UpdatePackageAction.cs index 1126025531..3cce200b0a 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UpdatePackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UpdatePackageAction.cs @@ -74,8 +74,10 @@ namespace ICSharpCode.PackageManagement protected override void ExecuteCore()
{
if (ShouldUpdatePackage ()) {
- using (IDisposable monitor = CreateFileMonitor ()) {
- Project.UpdatePackage (Package, this);
+ using (IDisposable readmeMonitor = CreateOpenPackageReadMeMonitor (Package.Id)) {
+ using (IDisposable monitor = CreateFileMonitor ()) {
+ Project.UpdatePackage (Package, this);
+ }
}
OnParentPackageInstalled ();
} else {
|