diff options
author | Matt Ward <matt.ward@xamarin.com> | 2015-08-04 19:17:39 +0300 |
---|---|---|
committer | Matt Ward <matt.ward@xamarin.com> | 2015-08-04 19:17:39 +0300 |
commit | c094207be6ba1660a623e462eea1991c40708d44 (patch) | |
tree | b890d4adb3c265434b3d4faf9d4ae938af37f53b /main/src/addins/MonoDevelop.PackageManagement | |
parent | 554c78679a93f36bb1693d32bdf9a16787f4552a (diff) | |
parent | 108cada2653b6e26e0604080473211e5914763fc (diff) |
Merge branch 'nuget-packages-config-file-named-after-project'
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
7 files changed, 325 insertions, 9 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/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/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/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/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);
}
}
}
|