diff options
author | Matt Ward <ward.matt@gmail.com> | 2015-02-25 12:21:47 +0300 |
---|---|---|
committer | Matt Ward <ward.matt@gmail.com> | 2015-02-25 12:21:47 +0300 |
commit | 7890147ce8540b136ea8945183fd7fe1ad9e7704 (patch) | |
tree | 224e8cec7794840db12aeb4b94ac65605fb71ec4 /main/src/addins/MonoDevelop.PackageManagement | |
parent | 7c8e80199bcefb78b74fa9e4b56632eb23c8a1c5 (diff) | |
parent | fc6cc602a44046fd9e26d76c769719d767eb9e1b (diff) |
Merge branch 'nuget-detect-target-framework-change'
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
7 files changed, 174 insertions, 1 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProjectService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProjectService.cs index c428fdf10d..a562f08514 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProjectService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProjectService.cs @@ -86,6 +86,15 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers SolutionUnloaded (this, new EventArgs ());
}
}
+
+ public event EventHandler<ProjectReloadedEventArgs> ProjectReloaded;
+
+ public void RaiseProjectReloadedEvent (IDotNetProject oldProject, IDotNetProject newProject)
+ {
+ if (ProjectReloaded != null) {
+ ProjectReloaded (this, new ProjectReloadedEventArgs (oldProject, newProject));
+ }
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectTargetFrameworkMonitorTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectTargetFrameworkMonitorTests.cs index 575a7a1cce..3965e6b550 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectTargetFrameworkMonitorTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ProjectTargetFrameworkMonitorTests.cs @@ -26,6 +26,7 @@ using System;
using System.Collections.Generic;
+using MonoDevelop.Core.Assemblies;
using MonoDevelop.PackageManagement.Tests.Helpers;
using NUnit.Framework;
@@ -80,6 +81,18 @@ namespace MonoDevelop.PackageManagement.Tests return project;
}
+ FakeDotNetProject CreateProjectWithTargetFramework (string targetFramework)
+ {
+ var project = new FakeDotNetProject ();
+ project.TargetFrameworkMoniker = TargetFrameworkMoniker.Parse (targetFramework);
+ return project;
+ }
+
+ void RaiseProjectReloadedEvent (FakeDotNetProject oldProject, FakeDotNetProject newProject)
+ {
+ projectService.RaiseProjectReloadedEvent (oldProject, newProject);
+ }
+
[Test]
public void ProjectTargetFrameworkChanged_ProjectTargetFrameworkChanged_EventFires ()
{
@@ -183,6 +196,48 @@ namespace MonoDevelop.PackageManagement.Tests Assert.AreEqual (0, eventArgs.Count);
}
+
+ [Test]
+ public void ProjectReloaded_TargetFrameworkChanged_EventFires ()
+ {
+ CreateProjectTargetFrameworkMonitor ();
+ FakeDotNetProject project = LoadSolutionWithOneProject ();
+ FakeDotNetProject reloadedProject = CreateProjectWithTargetFramework (".NETFramework,Version=v2.0");
+ CaptureProjectTargetFrameworkChangedEvents ();
+
+ RaiseProjectReloadedEvent (project, reloadedProject);
+
+ Assert.AreEqual (1, eventArgs.Count);
+ Assert.AreEqual (reloadedProject, eventArgs [0].Project);
+ }
+
+ [Test]
+ public void ProjectReloaded_TargetFrameworkNotChanged_EventDoesNotFire ()
+ {
+ CreateProjectTargetFrameworkMonitor ();
+ FakeDotNetProject project = LoadSolutionWithOneProject ();
+ var reloadedProject = new FakeDotNetProject ();
+ reloadedProject.TargetFrameworkMoniker = project.TargetFrameworkMoniker;
+ CaptureProjectTargetFrameworkChangedEvents ();
+
+ RaiseProjectReloadedEvent (project, reloadedProject);
+
+ Assert.AreEqual (0, eventArgs.Count);
+ }
+
+ [Test]
+ public void ProjectReloaded_TargetFrameworkNullInReloadedProject_EventDoesNotFire ()
+ {
+ CreateProjectTargetFrameworkMonitor ();
+ FakeDotNetProject project = LoadSolutionWithOneProject ();
+ var reloadedProject = new FakeDotNetProject ();
+ reloadedProject.TargetFrameworkMoniker = null;
+ CaptureProjectTargetFrameworkChangedEvents ();
+
+ RaiseProjectReloadedEvent (project, reloadedProject);
+
+ Assert.AreEqual (0, eventArgs.Count);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj index 9a83d33622..814e2943d8 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj @@ -367,6 +367,7 @@ <Compile Include="MonoDevelop.PackageManagement\CheckForUpdatesProgressMonitor.cs" /> <Compile Include="MonoDevelop.PackageManagement\CheckForUpdatesTaskRunner.cs" /> <Compile Include="MonoDevelop.PackageManagement\CheckForUpdatesTask.cs" /> + <Compile Include="MonoDevelop.PackageManagement\ProjectReloadedEventArgs.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" /> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementProjectService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementProjectService.cs index 21603b0998..57feeb967c 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementProjectService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementProjectService.cs @@ -37,6 +37,7 @@ namespace ICSharpCode.PackageManagement {
event EventHandler SolutionLoaded;
event EventHandler SolutionUnloaded;
+ event EventHandler<ProjectReloadedEventArgs> ProjectReloaded;
IProject CurrentProject { get; }
ISolution OpenSolution { get; }
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProjectService.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProjectService.cs index 22340f706c..9a1aa7aebb 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProjectService.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementProjectService.cs @@ -45,6 +45,8 @@ namespace ICSharpCode.PackageManagement public event EventHandler SolutionLoaded;
+ ISolution openSolution;
+
void OnSolutionLoaded (Solution solution)
{
OpenSolution = new SolutionProxy (solution);
@@ -80,7 +82,21 @@ namespace ICSharpCode.PackageManagement }
}
- public ISolution OpenSolution { get; private set; }
+ public ISolution OpenSolution {
+ get { return openSolution; }
+
+ private set {
+ if (openSolution != null) {
+ openSolution.Solution.SolutionItemAdded -= SolutionItemAdded;
+ }
+
+ openSolution = value;
+
+ if (openSolution != null) {
+ openSolution.Solution.SolutionItemAdded += SolutionItemAdded;
+ }
+ }
+ }
public IEnumerable<IDotNetProject> GetOpenProjects ()
{
@@ -100,5 +116,21 @@ namespace ICSharpCode.PackageManagement return String.Empty;
//return CustomToolsService.GetCompatibleCustomToolNames(projectItem).FirstOrDefault();
}
+
+ public event EventHandler<ProjectReloadedEventArgs> ProjectReloaded;
+
+ void SolutionItemAdded (object sender, SolutionItemChangeEventArgs e)
+ {
+ if (!e.Reloading)
+ return;
+
+ var handler = ProjectReloaded;
+ if (handler != null) {
+ ProjectReloadedEventArgs reloadedEventArgs = ProjectReloadedEventArgs.Create (e);
+ if (reloadedEventArgs != null) {
+ handler (this, reloadedEventArgs);
+ }
+ }
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectReloadedEventArgs.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectReloadedEventArgs.cs new file mode 100644 index 0000000000..9438a2f268 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectReloadedEventArgs.cs @@ -0,0 +1,59 @@ +//
+// ProjectReloadedEventArgs.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 MonoDevelop.Projects;
+
+namespace MonoDevelop.PackageManagement
+{
+ public class ProjectReloadedEventArgs : EventArgs
+ {
+ public static ProjectReloadedEventArgs Create (SolutionItemChangeEventArgs eventArgs)
+ {
+ DotNetProject newProject = eventArgs.SolutionItem as DotNetProject;
+ DotNetProject oldProject = eventArgs.ReplacedItem as DotNetProject;
+ if (eventArgs.Reloading && (newProject != null) && (oldProject != null)) {
+ return new ProjectReloadedEventArgs (oldProject, newProject);
+ }
+ return null;
+ }
+
+ public ProjectReloadedEventArgs (DotNetProject oldProject, DotNetProject newProject)
+ : this (new DotNetProjectProxy (oldProject), new DotNetProjectProxy (newProject))
+ {
+ }
+
+ public ProjectReloadedEventArgs (IDotNetProject oldProject, IDotNetProject newProject)
+ {
+ OldProject = oldProject;
+ NewProject = newProject;
+ }
+
+ public IDotNetProject OldProject { get; private set; }
+ public IDotNetProject NewProject { get; private set; }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectTargetFrameworkMonitor.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectTargetFrameworkMonitor.cs index 5b675fe768..8170cf5a17 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectTargetFrameworkMonitor.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProjectTargetFrameworkMonitor.cs @@ -44,6 +44,7 @@ namespace MonoDevelop.PackageManagement projectService.SolutionLoaded += SolutionLoaded;
projectService.SolutionUnloaded += SolutionUnloaded;
+ projectService.ProjectReloaded += ProjectReloaded;
}
public event EventHandler<ProjectTargetFrameworkChangedEventArgs> ProjectTargetFrameworkChanged;
@@ -90,6 +91,21 @@ namespace MonoDevelop.PackageManagement OnProjectTargetFrameworkChanged (e.Project);
}
}
+
+ void ProjectReloaded (object sender, ProjectReloadedEventArgs e)
+ {
+ if (HasTargetFrameworkChanged (e.NewProject, e.OldProject)) {
+ OnProjectTargetFrameworkChanged (e.NewProject);
+ }
+ }
+
+ static bool HasTargetFrameworkChanged (IDotNetProject newProject, IDotNetProject oldProject)
+ {
+ if (newProject.TargetFrameworkMoniker != null) {
+ return !newProject.TargetFrameworkMoniker.Equals (oldProject.TargetFrameworkMoniker);
+ }
+ return false;
+ }
}
}
|