Browse Source
If a solution has its own NuGet.Config file this will be read and any package sources defined in this file will be available in the list of package sources in the Manage Packages dialog.pull/480/head
14 changed files with 333 additions and 114 deletions
@ -1,28 +0,0 @@
@@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// 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 NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface ISettingsFactory |
||||
{ |
||||
ISettings CreateSettings(string directory); |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public interface ISettingsProvider |
||||
{ |
||||
event EventHandler SettingsChanged; |
||||
ISettings LoadSettings(); |
||||
} |
||||
} |
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// 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 NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class SettingsFactory : ISettingsFactory |
||||
{ |
||||
public ISettings CreateSettings(string directory) |
||||
{ |
||||
var fileSystem = new PhysicalFileSystem(directory); |
||||
return new Settings(fileSystem); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class SettingsProvider : ISettingsProvider |
||||
{ |
||||
public static Func<IFileSystem, string, IMachineWideSettings, ISettings> LoadDefaultSettings |
||||
= Settings.LoadDefaultSettings; |
||||
|
||||
IPackageManagementProjectService projectService; |
||||
|
||||
public SettingsProvider() |
||||
: this(PackageManagementServices.ProjectService) |
||||
{ |
||||
} |
||||
|
||||
public SettingsProvider(IPackageManagementProjectService projectService) |
||||
{ |
||||
this.projectService = projectService; |
||||
projectService.SolutionOpened += OnSettingsChanged; |
||||
projectService.SolutionClosed += OnSettingsChanged; |
||||
} |
||||
|
||||
public event EventHandler SettingsChanged; |
||||
|
||||
void OnSettingsChanged(object sender, SolutionEventArgs e) |
||||
{ |
||||
if (SettingsChanged != null) { |
||||
SettingsChanged(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
public ISettings LoadSettings() |
||||
{ |
||||
return LoadSettings(GetSolutionDirectory()); |
||||
} |
||||
|
||||
string GetSolutionDirectory() |
||||
{ |
||||
ISolution solution = projectService.OpenSolution; |
||||
if (solution != null) { |
||||
return solution.Directory; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
ISettings LoadSettings(string directory) |
||||
{ |
||||
if (directory == null) { |
||||
return LoadDefaultSettings(null, null, null); |
||||
} |
||||
|
||||
return LoadDefaultSettings(new PhysicalFileSystem(directory), null, null); |
||||
} |
||||
} |
||||
} |
@ -1,37 +0,0 @@
@@ -1,37 +0,0 @@
|
||||
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// 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; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakeSettingsFactory : ISettingsFactory |
||||
{ |
||||
public FakeSettings FakeSettings = new FakeSettings(); |
||||
public string DirectoryPassedToCreateSettings; |
||||
|
||||
public ISettings CreateSettings(string directory) |
||||
{ |
||||
DirectoryPassedToCreateSettings = directory; |
||||
return FakeSettings; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class SettingsProviderTests |
||||
{ |
||||
SettingsProvider settingsProvider; |
||||
FakeSettings fakeSettings; |
||||
FakePackageManagementProjectService projectService; |
||||
IFileSystem fileSystemUsedToLoadSettings; |
||||
string configFileUsedToLoadSettings; |
||||
IMachineWideSettings machinesettingsUsedToLoadSettings; |
||||
|
||||
[SetUp] |
||||
public void SetUp() |
||||
{ |
||||
fakeSettings = new FakeSettings(); |
||||
projectService = new FakePackageManagementProjectService(); |
||||
SettingsProvider.LoadDefaultSettings = LoadDefaultSettings; |
||||
settingsProvider = new SettingsProvider(projectService); |
||||
} |
||||
|
||||
ISettings LoadDefaultSettings(IFileSystem fileSystem, string configFile, IMachineWideSettings machineSettings) |
||||
{ |
||||
fileSystemUsedToLoadSettings = fileSystem; |
||||
configFileUsedToLoadSettings = configFile; |
||||
machinesettingsUsedToLoadSettings = machineSettings; |
||||
|
||||
return fakeSettings; |
||||
} |
||||
|
||||
void OpenSolution(string fileName) |
||||
{ |
||||
var helper = new SolutionHelper(fileName); |
||||
projectService.OpenSolution = helper.MSBuildSolution; |
||||
} |
||||
|
||||
[TearDown] |
||||
public void TearDown() |
||||
{ |
||||
// This resets SettingsProvider.LoadDefaultSettings.
|
||||
TestablePackageManagementOptions.CreateSettingsProvider(fakeSettings, projectService); |
||||
} |
||||
|
||||
[Test] |
||||
public void LoadSettings_NoSolutionOpen_NullFileSystemAndNullConfigFileAndNullMachineSettingsUsed() |
||||
{ |
||||
fileSystemUsedToLoadSettings = new FakeFileSystem(); |
||||
configFileUsedToLoadSettings = "configFile"; |
||||
|
||||
ISettings settings = settingsProvider.LoadSettings(); |
||||
|
||||
Assert.IsNull(fileSystemUsedToLoadSettings); |
||||
Assert.IsNull(configFileUsedToLoadSettings); |
||||
Assert.IsNull(machinesettingsUsedToLoadSettings); |
||||
Assert.AreEqual(fakeSettings, settings); |
||||
} |
||||
|
||||
[Test] |
||||
public void LoadSettings_SolutionOpen_FileSystemWithRootSetToSolutionDirectoryUsedToLoadSettings() |
||||
{ |
||||
string fileName = @"d:\projects\MyProject\MyProject.sln"; |
||||
OpenSolution(fileName); |
||||
|
||||
ISettings settings = settingsProvider.LoadSettings(); |
||||
|
||||
Assert.AreEqual(@"d:\projects\MyProject", fileSystemUsedToLoadSettings.Root); |
||||
Assert.AreEqual(fakeSettings, settings); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue