Browse Source
Install NuGet packages in project templates from the NuGet repositories configured and used by the Manage Packages dialog.pull/374/merge
12 changed files with 10 additions and 505 deletions
@ -1,89 +0,0 @@
@@ -1,89 +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 System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
/// <summary>
|
||||
/// Supports a configurable set of package repositories for project templates that can be
|
||||
/// different to the registered package repositories used with the Add Package Reference dialog.
|
||||
/// </summary>
|
||||
public class ProjectTemplatePackageRepositoryCache : IPackageRepositoryCache |
||||
{ |
||||
IPackageRepositoryCache packageRepositoryCache; |
||||
RegisteredProjectTemplatePackageSources registeredPackageSources; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the ProjectTemplatePackageRepositoryCache.
|
||||
/// </summary>
|
||||
/// <param name="packageRepositoryCache">The main package repository cache used
|
||||
/// with the Add Package Reference dialog.</param>
|
||||
public ProjectTemplatePackageRepositoryCache( |
||||
IPackageRepositoryCache packageRepositoryCache, |
||||
RegisteredProjectTemplatePackageSources registeredPackageSources) |
||||
{ |
||||
this.packageRepositoryCache = packageRepositoryCache; |
||||
this.registeredPackageSources = registeredPackageSources; |
||||
} |
||||
|
||||
public IRecentPackageRepository RecentPackageRepository { |
||||
get { throw new NotImplementedException(); } |
||||
} |
||||
|
||||
public IPackageRepository CreateAggregateRepository() |
||||
{ |
||||
IEnumerable<IPackageRepository> repositories = GetRegisteredPackageRepositories(); |
||||
return CreateAggregateRepository(repositories); |
||||
} |
||||
|
||||
IEnumerable<IPackageRepository> GetRegisteredPackageRepositories() |
||||
{ |
||||
foreach (PackageSource packageSource in GetEnabledPackageSources()) { |
||||
yield return CreateRepository(packageSource.Source); |
||||
} |
||||
} |
||||
|
||||
public IEnumerable<PackageSource> GetEnabledPackageSources() |
||||
{ |
||||
return registeredPackageSources.PackageSources.GetEnabledPackageSources(); |
||||
} |
||||
|
||||
public ISharedPackageRepository CreateSharedRepository(IPackagePathResolver pathResolver, IFileSystem fileSystem, IFileSystem configSettingsFileSystem) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IRecentPackageRepository CreateRecentPackageRepository(IList<RecentPackageInfo> recentPackages, IPackageRepository aggregateRepository) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public IPackageRepository CreateAggregateRepository(IEnumerable<IPackageRepository> repositories) |
||||
{ |
||||
return packageRepositoryCache.CreateAggregateRepository(repositories); |
||||
} |
||||
|
||||
public IPackageRepository CreateRepository(string packageSource) |
||||
{ |
||||
return packageRepositoryCache.CreateRepository(packageSource); |
||||
} |
||||
} |
||||
} |
||||
@ -1,64 +0,0 @@
@@ -1,64 +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 System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class RegisteredProjectTemplatePackageSources |
||||
{ |
||||
RegisteredPackageSourceSettings registeredPackageSourceSettings; |
||||
|
||||
public RegisteredProjectTemplatePackageSources() |
||||
: this(new PackageManagementPropertyService(), new SettingsFactory()) |
||||
{ |
||||
} |
||||
|
||||
public RegisteredProjectTemplatePackageSources( |
||||
IPropertyService propertyService, |
||||
ISettingsFactory settingsFactory) |
||||
{ |
||||
GetRegisteredPackageSources(propertyService, settingsFactory); |
||||
} |
||||
|
||||
void GetRegisteredPackageSources(IPropertyService propertyService, ISettingsFactory settingsFactory) |
||||
{ |
||||
ISettings settings = CreateSettings(propertyService, settingsFactory); |
||||
PackageSource defaultPackageSource = CreateDefaultPackageSource(propertyService); |
||||
registeredPackageSourceSettings = new RegisteredPackageSourceSettings(settings, defaultPackageSource); |
||||
} |
||||
|
||||
ISettings CreateSettings(IPropertyService propertyService, ISettingsFactory settingsFactory) |
||||
{ |
||||
var settingsFileName = new ProjectTemplatePackagesSettingsFileName(propertyService); |
||||
return settingsFactory.CreateSettings(settingsFileName.Directory); |
||||
} |
||||
|
||||
PackageSource CreateDefaultPackageSource(IPropertyService propertyService) |
||||
{ |
||||
var defaultPackageSource = new DefaultProjectTemplatePackageSource(propertyService); |
||||
return defaultPackageSource.PackageSource; |
||||
} |
||||
|
||||
public RegisteredPackageSources PackageSources { |
||||
get { return registeredPackageSourceSettings.PackageSources; } |
||||
} |
||||
} |
||||
} |
||||
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
<gui:OptionPanel |
||||
x:Class="ICSharpCode.PackageManagement.RegisteredProjectTemplatePackageSourcesView" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop" |
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
xmlns:pm="clr-namespace:ICSharpCode.PackageManagement" |
||||
xmlns:pmd="clr-namespace:ICSharpCode.PackageManagement.Design" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
mc:Ignorable="d" |
||||
d:DesignHeight="300" |
||||
d:DesignWidth="300" |
||||
Height="300"> |
||||
|
||||
<Grid x:Name="MainGrid"> |
||||
<Grid.Resources> |
||||
<pm:PackageManagementViewModels x:Key="ViewModels"/> |
||||
</Grid.Resources> |
||||
|
||||
<Grid.DataContext> |
||||
<Binding Source="{StaticResource ViewModels}" Path="RegisteredProjectTemplatePackageSourcesViewModel"/> |
||||
</Grid.DataContext> |
||||
|
||||
<pm:RegisteredPackageSourcesUserControl/> |
||||
</Grid> |
||||
</gui:OptionPanel> |
||||
@ -1,53 +0,0 @@
@@ -1,53 +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.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public partial class RegisteredProjectTemplatePackageSourcesView : OptionPanel |
||||
{ |
||||
RegisteredPackageSourcesViewModel viewModel; |
||||
|
||||
public RegisteredProjectTemplatePackageSourcesView() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
|
||||
RegisteredPackageSourcesViewModel ViewModel { |
||||
get { |
||||
if (viewModel == null) { |
||||
viewModel = MainGrid.DataContext as RegisteredPackageSourcesViewModel; |
||||
} |
||||
return viewModel; |
||||
} |
||||
} |
||||
|
||||
public override void LoadOptions() |
||||
{ |
||||
ViewModel.Load(); |
||||
} |
||||
|
||||
public override bool SaveOptions() |
||||
{ |
||||
ViewModel.Save(); |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
@ -1,120 +0,0 @@
@@ -1,120 +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 System.Collections.Generic; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ProjectTemplatePackageRepositoryCacheTests |
||||
{ |
||||
ProjectTemplatePackageRepositoryCache cache; |
||||
FakePackageRepositoryFactory fakeMainCache; |
||||
RegisteredProjectTemplatePackageSources registeredPackageSources; |
||||
FakeSettingsFactory fakeSettingsFactory; |
||||
|
||||
void CreateCache() |
||||
{ |
||||
fakeMainCache = new FakePackageRepositoryFactory(); |
||||
var propertyService = new FakePropertyService(); |
||||
fakeSettingsFactory = new FakeSettingsFactory(); |
||||
registeredPackageSources = new RegisteredProjectTemplatePackageSources(propertyService, fakeSettingsFactory); |
||||
cache = new ProjectTemplatePackageRepositoryCache(fakeMainCache, registeredPackageSources); |
||||
} |
||||
|
||||
void ClearRegisteredPackageSources() |
||||
{ |
||||
registeredPackageSources.PackageSources.Clear(); |
||||
} |
||||
|
||||
void AddRegisteredPackageSource(PackageSource packageSource) |
||||
{ |
||||
registeredPackageSources.PackageSources.Add(packageSource); |
||||
} |
||||
|
||||
void AddRegisteredPackageSource(string url, string name) |
||||
{ |
||||
var packageSource = new PackageSource(url, name); |
||||
AddRegisteredPackageSource(packageSource); |
||||
} |
||||
|
||||
FakePackageRepository AddRegisteredPackageRepository(string packageSourceUrl, string packageSourceName) |
||||
{ |
||||
var packageSource = new PackageSource(packageSourceUrl, packageSourceName); |
||||
AddRegisteredPackageSource(packageSource); |
||||
FakePackageRepository fakeRepository = new FakePackageRepository(); |
||||
fakeMainCache.FakePackageRepositories.Add(packageSource.Source, fakeRepository); |
||||
return fakeRepository; |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateAggregateRepository_OneRegisteredPackageSource_CreatesAggregrateRepositoryUsingMainCache() |
||||
{ |
||||
CreateCache(); |
||||
ClearRegisteredPackageSources(); |
||||
AddRegisteredPackageSource("http://sharpdevelop.com", "Test"); |
||||
|
||||
IPackageRepository repository = cache.CreateAggregateRepository(); |
||||
|
||||
IPackageRepository expectedRepository = fakeMainCache.FakeAggregateRepository; |
||||
Assert.AreEqual(expectedRepository, repository); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateAggregateRepository_TwoRegisteredPackageSources_CreatesRepositoriesForRegisteredPackageSources() |
||||
{ |
||||
CreateCache(); |
||||
ClearRegisteredPackageSources(); |
||||
FakePackageRepository fakeRepository1 = AddRegisteredPackageRepository("http://sharpdevelop.com", "Test"); |
||||
FakePackageRepository fakeRepository2 = AddRegisteredPackageRepository("http://test", "Test2"); |
||||
|
||||
IPackageRepository repository = cache.CreateAggregateRepository(); |
||||
|
||||
IEnumerable<IPackageRepository> repositories = fakeMainCache.RepositoriesPassedToCreateAggregateRepository; |
||||
var expectedRepositories = new List<IPackageRepository>(); |
||||
expectedRepositories.Add(fakeRepository1); |
||||
expectedRepositories.Add(fakeRepository2); |
||||
|
||||
Assert.AreEqual(expectedRepositories, repositories); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateAggregatePackageRepository_TwoRegisteredPackageSourcesButOneDisabled_ReturnsAggregateRepositoryCreatedWithOnlyEnabledPackageSource() |
||||
{ |
||||
CreateCache(); |
||||
ClearRegisteredPackageSources(); |
||||
FakePackageRepository fakeRepository1 = AddRegisteredPackageRepository("http://sharpdevelop.com", "Test"); |
||||
FakePackageRepository fakeRepository2 = AddRegisteredPackageRepository("http://test", "Test2"); |
||||
registeredPackageSources.PackageSources[0].IsEnabled = false; |
||||
|
||||
IPackageRepository repository = cache.CreateAggregateRepository(); |
||||
|
||||
IEnumerable<IPackageRepository> repositories = fakeMainCache.RepositoriesPassedToCreateAggregateRepository; |
||||
var expectedRepositories = new List<IPackageRepository>(); |
||||
expectedRepositories.Add(fakeRepository2); |
||||
|
||||
Assert.AreEqual(expectedRepositories, repositories); |
||||
} |
||||
} |
||||
} |
||||
@ -1,103 +0,0 @@
@@ -1,103 +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 System.Collections.Generic; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class RegisteredProjectTemplatePackageSourcesTests |
||||
{ |
||||
RegisteredProjectTemplatePackageSources registeredPackageSources; |
||||
FakeSettingsFactory fakeSettingsFactory; |
||||
|
||||
FakePropertyService CreatePropertyService() |
||||
{ |
||||
return new FakePropertyService(); |
||||
} |
||||
|
||||
void CreateRegisteredPackageSources(List<PackageSource> packageSources, FakePropertyService propertyService) |
||||
{ |
||||
fakeSettingsFactory = new FakeSettingsFactory(); |
||||
fakeSettingsFactory.FakeSettings.AddFakePackageSources(packageSources); |
||||
registeredPackageSources = |
||||
new RegisteredProjectTemplatePackageSources( |
||||
propertyService, |
||||
fakeSettingsFactory); |
||||
} |
||||
|
||||
[Test] |
||||
public void PackageSources_NoPredefinedPackageSources_DefaultPackageSourceCreated() |
||||
{ |
||||
FakePropertyService propertyService = CreatePropertyService(); |
||||
propertyService.DataDirectory = @"d:\sharpdevelop\data"; |
||||
|
||||
var packageSources = new List<PackageSource>(); |
||||
CreateRegisteredPackageSources(packageSources, propertyService); |
||||
|
||||
RegisteredPackageSources actualPackageSources = |
||||
registeredPackageSources.PackageSources; |
||||
|
||||
var expectedPackageSources = new PackageSource[] { |
||||
new PackageSource(@"d:\sharpdevelop\data\templates\packages", "Default") |
||||
}; |
||||
|
||||
PackageSourceCollectionAssert.AreEqual(expectedPackageSources, actualPackageSources); |
||||
} |
||||
|
||||
[Test] |
||||
public void PackageSources_OnePredefinedPackageSource_RegisteredPackageSourceIsPredefinedPackageSource() |
||||
{ |
||||
FakePropertyService propertyService = CreatePropertyService(); |
||||
propertyService.DataDirectory = @"d:\sharpdevelop\data"; |
||||
var expectedPackageSources = new List<PackageSource>(); |
||||
expectedPackageSources.Add(new PackageSource("http://sharpdevelop", "Test")); |
||||
CreateRegisteredPackageSources(expectedPackageSources, propertyService); |
||||
|
||||
RegisteredPackageSources actualPackageSources = |
||||
registeredPackageSources.PackageSources; |
||||
|
||||
PackageSourceCollectionAssert.AreEqual(expectedPackageSources, actualPackageSources); |
||||
} |
||||
|
||||
[Test] |
||||
public void PackageSources_NoPredefinedPackageSources_PackageSourceConfigLookedForInUserFolder() |
||||
{ |
||||
FakePropertyService propertyService = CreatePropertyService(); |
||||
propertyService.DataDirectory = @"d:\sharpdevelop\data"; |
||||
propertyService.ConfigDirectory = @"c:\Users\test\AppData\ICSharpCode\SharpDevelop4.1"; |
||||
|
||||
var packageSources = new List<PackageSource>(); |
||||
CreateRegisteredPackageSources(packageSources, propertyService); |
||||
|
||||
IEnumerable<PackageSource> actualPackageSources = |
||||
registeredPackageSources.PackageSources; |
||||
|
||||
string directory = fakeSettingsFactory.DirectoryPassedToCreateSettings; |
||||
string expectedDirectory = @"c:\Users\test\AppData\ICSharpCode\SharpDevelop4.1\templates"; |
||||
|
||||
Assert.AreEqual(expectedDirectory, directory); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue