diff options
author | Greg Munn <greg@sgmunn.com> | 2015-08-13 20:01:11 +0300 |
---|---|---|
committer | Greg Munn <greg@sgmunn.com> | 2015-08-13 20:01:11 +0300 |
commit | 062394b63d9307db52c4b16722ea5c08b856727b (patch) | |
tree | d598f044d6adae41986277bb3526f48b5ef500cf /main/src/addins/MonoDevelop.PackageManagement | |
parent | af9e7a1927542c1203652d63ac56569fb8046d58 (diff) | |
parent | 6e0f0a9547094cfa6d9b5fc6a151691b667c4d3c (diff) |
Merge branch 'master' into insights-integration-v1
Conflicts:
version-checks
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
19 files changed, 442 insertions, 34 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs index 8be17a5dfa..b4e225fdcf 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageManagementProject.cs @@ -92,7 +92,10 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers public List<FakeUpdatePackageAction> FakeUpdatePackageActionsCreated =
new List<FakeUpdatePackageAction> ();
- public string Name { get; set; }
+ public string Name {
+ get { return FakeDotNetProject.Name; }
+ set { FakeDotNetProject.Name = value; }
+ }
public bool IsPackageInstalled (string packageId)
{
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 0e9993c766..ec5a0df98e 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 @@ -210,6 +210,8 @@ <Compile Include="MonoDevelop.PackageManagement.Tests\OpenPackageReadMeMonitorTests.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableInstallPackageAction.cs" /> <Compile Include="MonoDevelop.PackageManagement.Tests.Helpers\TestableUpdatePackageAction.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests\FilePathExtensionsTests.cs" /> + <Compile Include="MonoDevelop.PackageManagement.Tests\DotNetProjectExtensionsTests.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/BackgroundPackageActionRunnerTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/BackgroundPackageActionRunnerTests.cs index 1d8f5b7e51..cc692abc1d 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/BackgroundPackageActionRunnerTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/BackgroundPackageActionRunnerTests.cs @@ -282,14 +282,14 @@ namespace MonoDevelop.PackageManagement.Tests }
[Test]
- public void Run_OneInstallActionWithPowerShellScripts_WarningReportedToProgressMonitor ()
+ public void Run_OneInstallActionWithPowerShellScripts_WarningNotReportedToProgressMonitor ()
{
CreateRunner ();
AddInstallActionWithPowerShellScript ();
Run ();
- Assert.AreEqual ("Warning", progressMonitor.ReportedWarningMessage);
+ Assert.IsNull (progressMonitor.ReportedWarningMessage);
}
[Test]
@@ -300,7 +300,7 @@ namespace MonoDevelop.PackageManagement.Tests Run ();
- progressMonitor.AssertMessageIsLogged ("Test Package contains PowerShell scripts which will not be run.");
+ progressMonitor.AssertMessageIsLogged ("WARNING: Test Package contains PowerShell scripts which will not be run.");
}
[Test]
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/DotNetProjectExtensionsTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/DotNetProjectExtensionsTests.cs new file mode 100644 index 0000000000..a0d6d171cc --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/DotNetProjectExtensionsTests.cs @@ -0,0 +1,135 @@ +//
+// DotNetProjectExtensionsTests.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.Collections.Generic;
+using ICSharpCode.PackageManagement;
+using MonoDevelop.PackageManagement.Tests.Helpers;
+using NUnit.Framework;
+
+namespace MonoDevelop.PackageManagement.Tests
+{
+ [TestFixture]
+ public class DotNetProjectExtensionsTests
+ {
+ List<string> existingFiles;
+ FakeDotNetProject project;
+
+ [SetUp]
+ public void Init ()
+ {
+ existingFiles = new List<string> ();
+ DotNetProjectExtensions.FileExists = existingFiles.Contains;
+ }
+
+ void CreateProject (string fileName, string projectName)
+ {
+ project = new FakeDotNetProject (fileName.ToNativePath ()) {
+ Name = projectName
+ };
+ }
+
+ void AddExistingFile (string fileName)
+ {
+ existingFiles.Add (fileName.ToNativePath ());
+ }
+
+ [Test]
+ public void GetPackagesConfigFilePath_ProjectPackagesConfigFileDoesNotExist_ReturnsDefaultPackagesConfigFile ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "MyProject");
+
+ string fileName = project.GetPackagesConfigFilePath ();
+
+ Assert.AreEqual (@"d:\projects\packages.config".ToNativePath (), fileName);
+ }
+
+ [Test]
+ public void GetPackagesConfigFilePath_ProjectPackagesConfigFileExists_ReturnsPackagesConfigFileNamedAfterProject ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "MyProject");
+ AddExistingFile (@"d:\projects\packages.MyProject.config");
+
+ string fileName = project.GetPackagesConfigFilePath ();
+
+ Assert.AreEqual (@"d:\projects\packages.MyProject.config".ToNativePath (), fileName);
+ }
+
+ [Test]
+ public void GetPackagesConfigFilePath_ProjectNameHasSpaceProjectPackagesConfigFileExists_ReturnsPackagesConfigFileNamedAfterProject ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "My Project");
+ AddExistingFile (@"d:\projects\packages.My_Project.config");
+
+ string fileName = project.GetPackagesConfigFilePath ();
+
+ Assert.AreEqual (@"d:\projects\packages.My_Project.config".ToNativePath (), fileName);
+ }
+
+ [Test]
+ public void HasPackages_PackagesConfigFileDoesNotExist_ReturnsFalse ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "MyProject");
+
+ bool result = project.HasPackages ();
+
+ Assert.IsFalse (result);
+ }
+
+ [Test]
+ public void HasPackages_PackagesConfigFileExistsInProjectDirectory_ReturnsTrue ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "MyProject");
+ AddExistingFile (@"d:\projects\packages.config");
+
+ bool result = project.HasPackages ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void HasPackages_ProjectPackagesConfigFileExistsInProjectDirectory_ReturnsTrue ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "MyProject");
+ AddExistingFile (@"d:\projects\packages.MyProject.config");
+
+ bool result = project.HasPackages ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void HasPackages_ProjectNameHasSpaceAndProjectPackagesConfigFileExistsInProjectDirectory_ReturnsTrue ()
+ {
+ CreateProject (@"d:\projects\MyProject.csproj", "My Project");
+ AddExistingFile (@"d:\projects\packages.My_Project.config");
+
+ bool result = project.HasPackages ();
+
+ Assert.IsTrue (result);
+ }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/FilePathExtensionsTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/FilePathExtensionsTests.cs new file mode 100644 index 0000000000..c3af8c2487 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/FilePathExtensionsTests.cs @@ -0,0 +1,111 @@ +//
+// FilePathExtensionsTests.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 MonoDevelop.Core;
+using MonoDevelop.PackageManagement.Tests.Helpers;
+using NUnit.Framework;
+
+namespace MonoDevelop.PackageManagement.Tests
+{
+ [TestFixture]
+ public class FilePathExtensionsTests
+ {
+ FilePath CreateFilePath (string fileName)
+ {
+ return new FilePath (fileName.ToNativePath ());
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_Null_ReturnsFalse ()
+ {
+ FilePath nullPath = null;
+ bool result = nullPath.IsPackagesConfigFileName ();
+
+ Assert.IsFalse (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_TextFile_ReturnsFalse ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\foo.txt");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsFalse (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_PackagesConfigFile_ReturnsTrue ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\packages.config");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_PackagesConfigFileInUpperCase_ReturnsTrue ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\PACKAGES.CONFIG");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_PackagesConfigFileNamedAfterProject_ReturnsTrue ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\packages.MyProject.config");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_PackagesConfigFileNamedAfterProjectInDifferentCase_ReturnsTrue ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\PACKAGES.MyProject.CONFIG");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsTrue (result);
+ }
+
+ [Test]
+ public void IsPackagesConfigFileName_PackagesConfigFileNamedAfterProjectButStartsWithProjectName_ReturnsFalse ()
+ {
+ FilePath filePath = CreateFilePath (@"d:\projects\MyProject.packages.config");
+
+ bool result = filePath.IsPackagesConfigFileName ();
+
+ Assert.IsFalse (result);
+ }
+ }
+}
+
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 b8261410a8..584bf146be 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 @@ -484,7 +484,7 @@ namespace MonoDevelop.PackageManagement.Tests }
[Test]
- public void Execute_PackageBeingInstalledHasPowerShellScripts_WarningAboutPowerShellScriptsIsLogged ()
+ public void Execute_PackageBeingInstalledHasPowerShellScripts_MessageAboutPowerShellScriptsIsLogged ()
{
CreateAction ();
FakePackage expectedPackage = fakeProject.FakeSourceRepository.AddFakePackageWithVersion ("Test", "1.0");
@@ -493,16 +493,16 @@ namespace MonoDevelop.PackageManagement.Tests action.PackageId = expectedPackage.Id;
action.PackageVersion = expectedPackage.Version;
fakeProject.FakeInstallOperations.Add (operation);
- string messageLogged = null;
+ var messagesLogged = new List<string> ();
packageManagementEvents.PackageOperationMessageLogged += (sender, e) => {
- if (e.Message.Level == MessageLevel.Warning) {
- messageLogged = e.Message.ToString ();
+ if (e.Message.Level == MessageLevel.Info) {
+ messagesLogged.Add (e.Message.ToString ());
}
};
action.Execute ();
- Assert.AreEqual ("Test Package contains PowerShell scripts which will not be run.", messageLogged);
+ Assert.That (messagesLogged, Contains.Item ("WARNING: Test Package contains PowerShell scripts which will not be run."));
}
[Test]
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs index 9d67d3f590..fd3280c147 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/MonoDevelopProjectSystemTests.cs @@ -1133,17 +1133,24 @@ namespace MonoDevelop.PackageManagement.Tests }
[Test]
- public void RemoveImport_ImportAlreadyAddedToBottomOfProject_ProjectBuilderIsDisposed ()
+ public void RemoveImport_ImportAlreadyAddedToBottomOfProject_ImportRemovedEventIsFired ()
{
CreateTestProject (@"d:\projects\MyProject\MyProject\MyProject.csproj");
CreateProjectSystem (project);
string targetPath = @"d:\projects\MyProject\packages\Foo.0.1\build\Foo.targets".ToNativePath ();
projectSystem.AddImport (targetPath, ProjectImportLocation.Bottom);
+ const string expectedImportRemoved = @"..\packages\Foo.0.1\build\Foo.targets";
+ DotNetProjectImportEventArgs eventArgs = null;
+ projectSystem.PackageManagementEvents.ImportRemoved += (sender, e) => {
+ eventArgs = e;
+ };
projectSystem.RemoveImport (targetPath);
- AssertImportRemoved (@"..\packages\Foo.0.1\build\Foo.targets");
- Assert.IsTrue (project.IsProjectBuilderDisposed);
+ AssertImportRemoved (expectedImportRemoved);
+ Assert.IsFalse (project.IsProjectBuilderDisposed);
+ Assert.AreEqual (project, eventArgs.Project);
+ Assert.AreEqual (expectedImportRemoved, eventArgs.Import);
}
[Test]
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UninstallPackageActionTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UninstallPackageActionTests.cs index 885c10c377..948780a2ab 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UninstallPackageActionTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/UninstallPackageActionTests.cs @@ -24,8 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-using System;
using System.Collections.Generic;
+using System.Linq;
using ICSharpCode.PackageManagement;
using MonoDevelop.PackageManagement.Tests.Helpers;
using NuGet;
@@ -246,22 +246,22 @@ namespace MonoDevelop.PackageManagement.Tests }
[Test]
- public void Execute_PackageHasPowerShellUninstallScript_PowerShellWarningLogged ()
+ public void Execute_PackageHasPowerShellUninstallScript_PowerShellInfoLogged ()
{
CreateAction ();
FakePackage package = FakePackage.CreatePackageWithVersion ("Test", "1.0");
action.Package = package;
package.AddFile (@"tools\uninstall.ps1");
- string messageLogged = null;
+ var messagesLogged = new List<string> ();
packageManagementEvents.PackageOperationMessageLogged += (sender, e) => {
- if (e.Message.Level == MessageLevel.Warning) {
- messageLogged = e.Message.ToString ();
+ if (e.Message.Level == MessageLevel.Info) {
+ messagesLogged.Add (e.Message.ToString ());
}
};
action.Execute ();
- Assert.AreEqual ("Test Package contains PowerShell scripts which will not be run.", messageLogged);
+ Assert.That (messagesLogged, Contains.Item ("WARNING: Test Package contains PowerShell scripts which will not be run."));
}
[Test]
@@ -271,16 +271,14 @@ namespace MonoDevelop.PackageManagement.Tests FakePackage package = FakePackage.CreatePackageWithVersion ("Test", "1.0");
action.Package = package;
package.AddFile (@"tools\install.ps1");
- bool messageLogged = false;
+ var messagesLogged = new List<string> ();
packageManagementEvents.PackageOperationMessageLogged += (sender, e) => {
- if (e.Message.Level == MessageLevel.Warning) {
- messageLogged = true;
- }
+ messagesLogged.Add (e.Message.ToString ());
};
action.Execute ();
- Assert.IsFalse (messageLogged);
+ Assert.IsFalse (messagesLogged.Any (message => message.Contains ("PowerShell")));
}
}
}
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 e72db1df04..15c0419c37 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 @@ -635,6 +635,22 @@ namespace MonoDevelop.PackageManagement.Tests Assert.IsFalse (fileService.IsOpenFileCalled);
Assert.IsTrue (monitor.IsDisposed);
}
+
+ [Test]
+ public void Execute_PackagesConfigFileNamedAfterProjectDeletedDuringUpdate_FileServicePackagesConfigFileDeletionIsCancelled ()
+ {
+ CreateSolution ();
+ action.Package = new FakePackage ("Test");
+ string expectedFileName = @"d:\projects\MyProject\packages.MyProject.config".ToNativePath ();
+ bool? fileRemovedResult = null;
+ fakeProject.UpdatePackageAction = (p, a) => {
+ fileRemovedResult = packageManagementEvents.OnFileRemoving (expectedFileName);
+ };
+ action.Execute ();
+
+ Assert.AreEqual (expectedFileName, fileRemover.FileRemoved);
+ Assert.IsFalse (fileRemovedResult.Value);
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj index 5daefefbb1..2ef5d70c2c 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.csproj @@ -375,6 +375,7 @@ <Compile Include="MonoDevelop.PackageManagement\DotNetProjectReferenceEventArgs.cs" /> <Compile Include="MonoDevelop.PackageManagement\LocalCopyReferenceMaintainer.cs" /> <Compile Include="MonoDevelop.PackageManagement\DotNetSolutionEventArgs.cs" /> + <Compile Include="MonoDevelop.PackageManagement\DotNetProjectImportEventArgs.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="MonoDevelop.PackageManagement.addin.xml" /> diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs index 3d38c585c2..13c5aefb37 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectExtensions.cs @@ -27,11 +27,11 @@ //
using System;
+using System.Collections.Generic;
+using System.Linq;
using System.IO;
-using MonoDevelop.Core;
using MonoDevelop.PackageManagement;
using MonoDevelop.Projects;
-using MonoDevelop.Projects.Formats.MSBuild;
using NuGet;
namespace ICSharpCode.PackageManagement
@@ -40,7 +40,9 @@ namespace ICSharpCode.PackageManagement {
public static readonly Guid WebApplication = Guid.Parse("{349C5851-65DF-11DA-9384-00065B846F21}");
public static readonly Guid WebSite = Guid.Parse("{E24C65DC-7377-472B-9ABA-BC803B73C61A}");
-
+
+ public static Func<string, bool> FileExists = File.Exists;
+
public static bool IsWebProject(this IDotNetProject project)
{
return project.HasProjectType(WebApplication) || project.HasProjectType(WebSite);
@@ -82,22 +84,62 @@ namespace ICSharpCode.PackageManagement public static bool HasPackages (this DotNetProject project)
{
- return File.Exists (project.GetPackagesConfigFilePath ());
+ return HasPackages (project.BaseDirectory, project.Name);
}
public static string GetPackagesConfigFilePath (this DotNetProject project)
{
- return Path.Combine (project.BaseDirectory, Constants.PackageReferenceFile);
+ return GetPackagesConfigFilePath (project.BaseDirectory, project.Name);
}
public static bool HasPackages (this IDotNetProject project)
{
- return File.Exists (project.GetPackagesConfigFilePath ());
+ return AnyFileExists (GetPossiblePackagesConfigFilePaths (project.BaseDirectory, project.Name));
+ }
+
+ static bool HasPackages (string projectDirectory, string projectName)
+ {
+ return AnyFileExists (GetPossiblePackagesConfigFilePaths (projectDirectory, projectName));
+ }
+
+ static bool AnyFileExists (IEnumerable<string> files)
+ {
+ return files.Any (FileExists);
+ }
+
+ static IEnumerable<string> GetPossiblePackagesConfigFilePaths (string projectDirectory, string projectName)
+ {
+ yield return GetNonDefaultProjectPackagesConfigFilePath (projectDirectory, projectName);
+ yield return GetDefaultPackagesConfigFilePath (projectDirectory);
+ }
+
+ static string GetNonDefaultProjectPackagesConfigFilePath (string projectDirectory, string projectName)
+ {
+ return Path.Combine (projectDirectory, GetNonDefaultProjectPackagesConfigFileName (projectName));
+ }
+
+ static string GetNonDefaultProjectPackagesConfigFileName (string projectName)
+ {
+ return "packages." + projectName.Replace (' ', '_') + ".config";
+ }
+
+ static string GetDefaultPackagesConfigFilePath (string projectDirectory)
+ {
+ return Path.Combine (projectDirectory, Constants.PackageReferenceFile);
}
public static string GetPackagesConfigFilePath (this IDotNetProject project)
{
- return Path.Combine (project.BaseDirectory, Constants.PackageReferenceFile);
+ return GetPackagesConfigFilePath (project.BaseDirectory, project.Name);
+ }
+
+ static string GetPackagesConfigFilePath (string projectDirectory, string projectName)
+ {
+ string nonDefaultPackagesConfigFilePath = GetNonDefaultProjectPackagesConfigFilePath (projectDirectory, projectName);
+ if (FileExists (nonDefaultPackagesConfigFilePath)) {
+ return nonDefaultPackagesConfigFilePath;
+ }
+ return GetDefaultPackagesConfigFilePath (projectDirectory);
}
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectImportEventArgs.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectImportEventArgs.cs new file mode 100644 index 0000000000..cf0b696498 --- /dev/null +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/DotNetProjectImportEventArgs.cs @@ -0,0 +1,43 @@ +//
+// DotNetProjectImportEventArgs.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;
+
+namespace MonoDevelop.PackageManagement
+{
+ public class DotNetProjectImportEventArgs : EventArgs
+ {
+ public DotNetProjectImportEventArgs (IDotNetProject project, string import)
+ {
+ Project = project;
+ Import = import;
+ }
+
+ public IDotNetProject Project { get; private set; }
+ public string Import { get; private set; }
+ }
+}
+
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/FilePathExtensions.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/FilePathExtensions.cs index 38faa5f7de..7c6cd512b7 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/FilePathExtensions.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/FilePathExtensions.cs @@ -38,7 +38,14 @@ namespace MonoDevelop.PackageManagement return false;
}
- return Constants.PackageReferenceFile.Equals (filePath.FileName, StringComparison.OrdinalIgnoreCase);
+ return Constants.PackageReferenceFile.Equals (filePath.FileName, StringComparison.OrdinalIgnoreCase) ||
+ IsProjectSpecificPackagesConfigFile (filePath.FileName);
+ }
+
+ static bool IsProjectSpecificPackagesConfigFile (FilePath filePath)
+ {
+ return filePath.Extension.Equals (".config", StringComparison.OrdinalIgnoreCase) &&
+ filePath.FileNameWithoutExtension.StartsWith ("packages.", StringComparison.OrdinalIgnoreCase);
}
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementEvents.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementEvents.cs index 5b0bb4fb1f..c830df588d 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementEvents.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/IPackageManagementEvents.cs @@ -54,6 +54,7 @@ namespace ICSharpCode.PackageManagement event EventHandler<PackageRestoredEventArgs> PackageRestored;
event EventHandler<DotNetProjectReferenceEventArgs> ReferenceAdding;
event EventHandler<DotNetProjectReferenceEventArgs> ReferenceRemoving;
+ event EventHandler<DotNetProjectImportEventArgs> ImportRemoved;
void OnPackageOperationsStarting();
void OnPackageOperationsFinished();
@@ -72,6 +73,7 @@ namespace ICSharpCode.PackageManagement void OnPackageRestored (IPackage package);
void OnReferenceAdding (ProjectReference reference);
void OnReferenceRemoving (ProjectReference reference);
+ void OnImportRemoved (IDotNetProject project, string import);
[Obsolete]
void OnParentPackageInstalled (IPackage package, IPackageManagementProject project);
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEvents.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEvents.cs index f6462784f2..fa67203211 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEvents.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEvents.cs @@ -209,5 +209,14 @@ namespace ICSharpCode.PackageManagement ReferenceAdding (this, new DotNetProjectReferenceEventArgs (reference));
}
}
+
+ public event EventHandler<DotNetProjectImportEventArgs> ImportRemoved;
+
+ public void OnImportRemoved (IDotNetProject project, string import)
+ {
+ if (ImportRemoved != null) {
+ ImportRemoved (this, new DotNetProjectImportEventArgs (project, import));
+ }
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEventsMonitor.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEventsMonitor.cs index 39df61d6e9..5e8ec633b8 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEventsMonitor.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementEventsMonitor.cs @@ -45,6 +45,7 @@ namespace MonoDevelop.PackageManagement string currentProgressOperation;
List<FileEventArgs> fileChangedEvents = new List<FileEventArgs> ();
List<IPackageManagementProject> projectsRequiringTypeSystemRefresh = new List<IPackageManagementProject> ();
+ ISolution solutionContainingProjectBuildersToDispose;
public PackageManagementEventsMonitor (
IProgressMonitor progressMonitor,
@@ -60,12 +61,14 @@ namespace MonoDevelop.PackageManagement packageManagementEvents.AcceptLicenses += AcceptLicenses;
packageManagementEvents.FileChanged += FileChanged;
packageManagementEvents.ParentPackageInstalled += PackageInstalled;
+ packageManagementEvents.ImportRemoved += ImportRemoved;
progressProvider.ProgressAvailable += ProgressAvailable;
}
public void Dispose ()
{
progressProvider.ProgressAvailable -= ProgressAvailable;
+ packageManagementEvents.ImportRemoved -= ImportRemoved;
packageManagementEvents.ParentPackageInstalled -= PackageInstalled;
packageManagementEvents.FileChanged -= FileChanged;
packageManagementEvents.AcceptLicenses -= AcceptLicenses;
@@ -73,6 +76,7 @@ namespace MonoDevelop.PackageManagement packageManagementEvents.PackageOperationMessageLogged -= PackageOperationMessageLogged;
NotifyFilesChanged ();
+ UnloadMSBuildHost ();
RefreshTypeSystem ();
}
@@ -232,6 +236,23 @@ namespace MonoDevelop.PackageManagement return (operation.Action == PackageAction.Install) &&
operation.Package.GetBuildFiles ().Any ();
}
+
+ void ImportRemoved (object sender, DotNetProjectImportEventArgs e)
+ {
+ solutionContainingProjectBuildersToDispose = e.Project.ParentSolution;
+ }
+
+ void UnloadMSBuildHost ()
+ {
+ if (solutionContainingProjectBuildersToDispose == null)
+ return;
+
+ GuiSyncDispatch (() => {
+ foreach (IDotNetProject project in solutionContainingProjectBuildersToDispose.GetAllProjects ()) {
+ project.DisposeProjectBuilder ();
+ }
+ });
+ }
}
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs index fa01bc2a1a..e7ed10250a 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ProcessPackageAction.cs @@ -140,8 +140,8 @@ namespace ICSharpCode.PackageManagement void ReportPowerShellScriptWarning ()
{
- string message = GettextCatalog.GetString ("{0} Package contains PowerShell scripts which will not be run.", GetPackageId ());
- packageManagementEvents.OnPackageOperationMessageLogged (MessageLevel.Warning, message);
+ string message = GettextCatalog.GetString ("WARNING: {0} Package contains PowerShell scripts which will not be run.", GetPackageId ());
+ packageManagementEvents.OnPackageOperationMessageLogged (MessageLevel.Info, message);
}
void CheckLicenses ()
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SharpDevelopProjectSystem.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SharpDevelopProjectSystem.cs index 87c1707789..4684a24b57 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SharpDevelopProjectSystem.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/SharpDevelopProjectSystem.cs @@ -426,9 +426,10 @@ namespace ICSharpCode.PackageManagement using (var updater = new EnsureNuGetPackageBuildImportsTargetUpdater ()) {
updater.RemoveImport (relativeTargetPath);
- project.DisposeProjectBuilder ();
project.Save ();
}
+
+ packageManagementEvents.OnImportRemoved (project, relativeTargetPath);
});
}
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ThreadSafePackageManagementEvents.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ThreadSafePackageManagementEvents.cs index 5fd0086856..d85e9f4457 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ThreadSafePackageManagementEvents.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ThreadSafePackageManagementEvents.cs @@ -319,5 +319,15 @@ namespace ICSharpCode.PackageManagement {
unsafeEvents.OnReferenceRemoving (reference);
}
+
+ public event EventHandler<DotNetProjectImportEventArgs> ImportRemoved {
+ add { unsafeEvents.ImportRemoved += value; }
+ remove { unsafeEvents.ImportRemoved -= value; }
+ }
+
+ public void OnImportRemoved (IDotNetProject project, string import)
+ {
+ unsafeEvents.OnImportRemoved (project, import);
+ }
}
}
|