This repository has been archived by the owner on Dec 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
fix #1113 by adding 'dnu feeds list' command #2121
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/Microsoft.Framework.PackageManager/ConsoleCommands/ListSourcesConsoleCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Framework.Runtime.Common.CommandLine; | ||
|
||
namespace Microsoft.Framework.PackageManager | ||
{ | ||
internal static class FeedsConsoleCommand | ||
{ | ||
public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory) | ||
{ | ||
cmdApp.Command("feeds", c => | ||
{ | ||
c.Description = "Commands related to managing package feeds currently in use"; | ||
c.HelpOption("-?|-h|--help"); | ||
c.OnExecute(() => | ||
{ | ||
c.ShowHelp(); | ||
return 2; | ||
}); | ||
|
||
RegisterListCommand(c, reportsFactory); | ||
}); | ||
} | ||
|
||
public static void RegisterListCommand(CommandLineApplication cmdApp, ReportsFactory reportsFactory) | ||
{ | ||
cmdApp.Command("list", c => | ||
{ | ||
c.Description = "Displays a list of package sources in effect for a project"; | ||
var argRoot = c.Argument("[root]", | ||
"The path of the project to calculate effective package sources for (defaults to the current directory)"); | ||
|
||
c.OnExecute(() => | ||
{ | ||
var command = new ListSourcesCommand( | ||
reportsFactory.CreateReports(quiet: false), | ||
string.IsNullOrEmpty(argRoot.Value) ? "." : argRoot.Value); | ||
|
||
return command.Execute(); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NuGet; | ||
|
||
namespace Microsoft.Framework.PackageManager | ||
{ | ||
/// <summary> | ||
/// Manages the NuGet.config hierarchy | ||
/// </summary> | ||
public class NuGetConfig | ||
{ | ||
public NuGetConfig(ISettings settings, PackageSourceProvider sources) | ||
{ | ||
Settings = settings; | ||
Sources = sources; | ||
} | ||
|
||
public ISettings Settings { get; } | ||
|
||
public IPackageSourceProvider Sources { get; } | ||
|
||
public static NuGetConfig ForSolution(string solutionDirectory) | ||
{ | ||
return ForSolution(solutionDirectory, new PhysicalFileSystem(Directory.GetCurrentDirectory())); | ||
} | ||
|
||
public static NuGetConfig ForSolution(string solutionDirectory, IFileSystem fileSystem) | ||
{ | ||
var settings = SettingsUtils.ReadSettings( | ||
solutionDirectory, | ||
nugetConfigFile: null, | ||
fileSystem: fileSystem, | ||
machineWideSettings: new CommandLineMachineWideSettings()); | ||
|
||
// Recreate the source provider | ||
var sources = PackageSourceBuilder.CreateSourceProvider(settings); | ||
|
||
return new NuGetConfig(settings, sources); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ public RestoreCommand(FrameworkName fallbackFramework) | |
{ | ||
FallbackFramework = fallbackFramework; | ||
FileSystem = new PhysicalFileSystem(Directory.GetCurrentDirectory()); | ||
MachineWideSettings = new CommandLineMachineWideSettings(); | ||
ScriptExecutor = new ScriptExecutor(); | ||
ErrorMessages = new Dictionary<string, List<string>>(StringComparer.Ordinal); | ||
InformationMessages = new Dictionary<string, List<string>>(StringComparer.Ordinal); | ||
|
@@ -58,15 +57,13 @@ public RestoreCommand(FrameworkName fallbackFramework) | |
public FeedOptions FeedOptions { get; set; } | ||
|
||
public List<string> RestoreDirectories { get; } = new List<string>(); | ||
public string NuGetConfigFile { get; set; } | ||
public bool Lock { get; set; } | ||
public bool Unlock { get; set; } | ||
|
||
public ScriptExecutor ScriptExecutor { get; private set; } | ||
|
||
public List<FrameworkName> TargetFrameworks { get; set; } = new List<FrameworkName>(); | ||
public FrameworkName FallbackFramework { get; set; } | ||
public IMachineWideSettings MachineWideSettings { get; set; } | ||
public IFileSystem FileSystem { get; set; } | ||
public Reports Reports { get; set; } | ||
public bool CheckHashFile { get; set; } = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nobody ever changes this value... |
||
|
@@ -77,8 +74,7 @@ public RestoreCommand(FrameworkName fallbackFramework) | |
private Dictionary<string, List<string>> ErrorMessages { get; set; } | ||
private Dictionary<string, List<string>> InformationMessages { get; set; } | ||
|
||
protected internal ISettings Settings { get; set; } | ||
protected internal IPackageSourceProvider SourceProvider { get; set; } | ||
protected internal NuGetConfig Config { get; set; } | ||
|
||
public async Task<bool> Execute() | ||
{ | ||
|
@@ -104,7 +100,7 @@ public async Task<bool> Execute() | |
} | ||
} | ||
|
||
var settings = Settings as Settings; | ||
var settings = Config.Settings as Settings; | ||
if (settings != null) | ||
{ | ||
var configFiles = settings.GetConfigFiles(); | ||
|
@@ -310,7 +306,7 @@ private async Task<bool> RestoreForProject(string projectJsonPath, string rootDi | |
new NuGetDependencyResolver(packageRepository))); | ||
|
||
var effectiveSources = PackageSourceUtils.GetEffectivePackageSources( | ||
SourceProvider, | ||
Config.Sources, | ||
FeedOptions.Sources, | ||
FeedOptions.FallbackSources); | ||
|
||
|
@@ -955,12 +951,7 @@ void Display(string indent, IEnumerable<GraphNode> graphs) | |
|
||
private void ReadSettings(string solutionDirectory) | ||
{ | ||
Settings = SettingsUtils.ReadSettings(solutionDirectory, NuGetConfigFile, FileSystem, MachineWideSettings); | ||
|
||
// Recreate the source provider and credential provider | ||
SourceProvider = PackageSourceBuilder.CreateSourceProvider(Settings); | ||
//HttpClient.DefaultCredentialProvider = new SettingsCredentialProvider(new ConsoleCredentialProvider(Console), SourceProvider, Console); | ||
|
||
Config = NuGetConfig.ForSolution(solutionDirectory, FileSystem); | ||
} | ||
|
||
private IFileSystem CreateFileSystem(string path) | ||
|
48 changes: 48 additions & 0 deletions
48
src/Microsoft.Framework.PackageManager/Sources/ListSourcesCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Linq; | ||
|
||
namespace Microsoft.Framework.PackageManager | ||
{ | ||
internal class ListSourcesCommand | ||
{ | ||
public Reports Reports { get; } | ||
public string TargetDirectory { get; } | ||
|
||
public ListSourcesCommand(Reports reports, string targetDirectory) | ||
{ | ||
Reports = reports; | ||
TargetDirectory = targetDirectory; | ||
} | ||
|
||
public int Execute() | ||
{ | ||
// Most of this code is from NuGet, just some refactoring for our system. | ||
// Collect config | ||
var config = NuGetConfig.ForSolution(TargetDirectory); | ||
|
||
var sources = config.Sources.LoadPackageSources(); | ||
if (!sources.Any()) | ||
{ | ||
Reports.Information.WriteLine("No sources found."); | ||
} | ||
else | ||
{ | ||
Reports.Information.WriteLine("Registered Sources:"); | ||
|
||
// Iterate over the sources and report them | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: add empty line before comment |
||
int index = 1; // This is an index for display so it should be 1-based | ||
foreach (var source in sources) | ||
{ | ||
var enabledString = source.IsEnabled ? "" : " [Disabled]"; | ||
var line = $"{index.ToString("0\\.").PadRight(3)} {source.Name} {source.Source}{enabledString.Yellow().Bold()}"; | ||
Reports.Information.WriteLine(line); | ||
|
||
index++; | ||
} | ||
} | ||
return 0; | ||
} | ||
} | ||
} |
154 changes: 154 additions & 0 deletions
154
test/Microsoft.Framework.PackageManager.FunctionalTests/DnuFeedsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.Framework.CommonTestUtils; | ||
using Microsoft.Framework.PackageManager.FunctionalTests; | ||
using Xunit; | ||
|
||
namespace Microsoft.Framework.PackageManager | ||
{ | ||
[Collection(nameof(PackageManagerFunctionalTestCollection))] | ||
public class DnuFeedsTests | ||
{ | ||
private readonly PackageManagerFunctionalTestFixture _fixture; | ||
|
||
public DnuFeedsTests(PackageManagerFunctionalTestFixture fixture) | ||
{ | ||
_fixture = fixture; | ||
} | ||
|
||
public static IEnumerable<object[]> RuntimeComponents | ||
{ | ||
get | ||
{ | ||
return TestUtils.GetRuntimeComponentsCombinations(); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(RuntimeComponents))] | ||
public void DnuFeeds_NoSources(string flavor, string os, string architecture) | ||
{ | ||
var environment = new Dictionary<string, string> | ||
{ | ||
{ "DNX_TRACE", "0" }, | ||
}; | ||
|
||
var rootConfig = | ||
@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> <!-- Remove the effects of any machine-level config --> | ||
</packageSources> | ||
</configuration>"; | ||
|
||
var projectStructure = | ||
@"{ | ||
'root': { | ||
'NuGet.Config': """", | ||
} | ||
}"; | ||
|
||
var expectedContent = @"Registered Sources: | ||
1. https://www.nuget.org/api/v2/ https://www.nuget.org/api/v2/ | ||
"; | ||
var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); | ||
using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) | ||
{ | ||
var projectPath = testEnv.ProjectPath; | ||
DirTree.CreateFromJson(projectStructure) | ||
.WithFileContents("root/NuGet.Config", rootConfig) | ||
.WriteTo(projectPath); | ||
|
||
string output; | ||
string error; | ||
var exitCode = DnuTestUtils.ExecDnu( | ||
runtimeHomePath, | ||
subcommand: "feeds", | ||
arguments: "list root", | ||
stdOut: out output, | ||
stdErr: out error, | ||
environment: environment, | ||
workingDir: projectPath); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Empty(error); | ||
Assert.Equal(expectedContent, output); | ||
} | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(RuntimeComponents))] | ||
public void DnuFeeds_ListsAllSources(string flavor, string os, string architecture) | ||
{ | ||
var environment = new Dictionary<string, string> | ||
{ | ||
{ "DNX_TRACE", "0" }, | ||
}; | ||
|
||
var rootConfig = | ||
@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<configuration> | ||
<packageSources> | ||
<clear /> <!-- Remove the effects of any machine-level config --> | ||
<add key=""Source1"" value=""https://source1"" /> | ||
<add key=""Source2"" value=""https://source2"" /> | ||
</packageSources> | ||
</configuration>"; | ||
|
||
var subConfig = | ||
@"<?xml version=""1.0"" encoding=""utf-8""?> | ||
<configuration> | ||
<packageSources> | ||
<add key=""Source3"" value=""https://source3"" /> | ||
</packageSources> | ||
<disabledPackageSources> | ||
<add key=""Source1"" value=""https://source1"" /> | ||
</disabledPackageSources> | ||
</configuration>"; | ||
|
||
var projectStructure = | ||
@"{ | ||
'root': { | ||
'NuGet.Config': """", | ||
'sub': { | ||
'NuGet.Config': """" | ||
} | ||
} | ||
}"; | ||
|
||
var expectedContent = @"Registered Sources: | ||
1. Source1 https://source1 [Disabled] | ||
2. Source2 https://source2 | ||
3. Source3 https://source3 | ||
4. https://www.nuget.org/api/v2/ https://www.nuget.org/api/v2/ [Disabled] | ||
"; | ||
var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); | ||
using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) | ||
{ | ||
var projectPath = testEnv.ProjectPath; | ||
DirTree.CreateFromJson(projectStructure) | ||
.WithFileContents("root/NuGet.Config", rootConfig) | ||
.WithFileContents("root/sub/NuGet.Config", subConfig) | ||
.WriteTo(projectPath); | ||
|
||
string output; | ||
string error; | ||
var exitCode = DnuTestUtils.ExecDnu( | ||
runtimeHomePath, | ||
subcommand: "feeds", | ||
arguments: "list root/sub", | ||
stdOut: out output, | ||
stdErr: out error, | ||
environment: environment, | ||
workingDir: projectPath); | ||
|
||
Assert.Equal(0, exitCode); | ||
Assert.Empty(error); | ||
Assert.Equal(expectedContent, output); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a new line to separate the properties.