这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MLS.Agent.Tests/CommandLine/CommandLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using FluentAssertions;
using MLS.Agent.CommandLine;
using WorkspaceServer;
using WorkspaceServer.Tests.TestUtility;
using Xunit;
using Xunit.Abstractions;
Expand All @@ -23,7 +24,7 @@ public class CommandLineParserTests : IDisposable
private TryGitHubOptions _tryGitHubOptions;
private PackOptions _packOptions;
private InstallOptions _installOptions;
private DirectoryInfo _install_packageSource;
private PackageSource _install_packageSource;
private VerifyOptions _verifyOptions;
private DemoOptions _demoOptions;
private JupyterOptions _jupyter_Options;
Expand Down Expand Up @@ -305,7 +306,7 @@ public async Task Install_parses_source_option()
await _parser.InvokeAsync($"install --add-source {expectedPackageSource} the-package", console);

_installOptions.PackageName.Should().Be("the-package");
_install_packageSource.FullName.Should().Be(expectedPackageSource);
_install_packageSource.ToString().Should().Be(expectedPackageSource);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion MLS.Agent.Tests/CommandLine/PackCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Pack_project_blazor_contents()

var dotnet = new Dotnet(asset.Directory);

var result = await dotnet.ToolInstall(packageName, asset.Directory, asset.Directory);
var result = await dotnet.ToolInstall(packageName, asset.Directory, new PackageSource(asset.Directory.FullName));

var exe = Path.Combine(asset.Directory.FullName, packageName);

Expand Down
3 changes: 2 additions & 1 deletion MLS.Agent.Tests/LocalToolPackageDiscoveryStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using WorkspaceServer.Tests;
using Xunit;
using Xunit.Abstractions;
using WorkspaceServer;

namespace MLS.Agent.Tests
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public async Task Installs_tool_from_package_source_when_requested()
var console = new TestConsole();
var asset = await LocalToolHelpers.CreateTool(console);

var strategy = new LocalToolInstallingPackageDiscoveryStrategy(asset, asset);
var strategy = new LocalToolInstallingPackageDiscoveryStrategy(asset, new PackageSource(asset.FullName));
var package = await strategy.Locate(new PackageDescriptor("blazor-console"));
package.Should().NotBeNull();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CodeBlockAnnotationExtensionTests()
var console = new TestConsole();
_package = new AsyncLazy<(PackageRegistry, string)>( async () => {
var dir = await LocalToolHelpers.CreateTool(console);
var strategy = new LocalToolInstallingPackageDiscoveryStrategy(dir, dir);
var strategy = new LocalToolInstallingPackageDiscoveryStrategy(dir, new PackageSource(dir.FullName));
return (new PackageRegistry(true, null, additionalStrategies: strategy), "console");
}
);
Expand Down
3 changes: 2 additions & 1 deletion MLS.Agent.Tests/WorkspaceDiscoveryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Xunit.Abstractions;
using Buffer = Microsoft.DotNet.Try.Protocol.Buffer;
using File = Microsoft.DotNet.Try.Protocol.File;
using WorkspaceServer;

namespace MLS.Agent.Tests
{
Expand All @@ -34,7 +35,7 @@ public async Task Local_tool_workspace_can_be_discovered()
var output = Guid.NewGuid().ToString();
var requestJson = Create.SimpleWorkspaceRequestAsJson(output, packageName);

var response = await CallRun(requestJson, options: new StartupOptions(addPackageSource: packageLocation, dir: new DirectoryInfo(Directory.GetCurrentDirectory())));
var response = await CallRun(requestJson, options: new StartupOptions(addPackageSource: new PackageSource(packageLocation.FullName), dir: new DirectoryInfo(Directory.GetCurrentDirectory())));
var result = await response
.EnsureSuccess()
.DeserializeAs<RunResult>();
Expand Down
6 changes: 3 additions & 3 deletions MLS.Agent/CommandLine/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ RootCommand StartInTryMode()
command.AddOption(new Option(
"--add-package-source",
"Specify an additional NuGet package source",
new Argument<DirectoryInfo>(new DirectoryInfo(Directory.GetCurrentDirectory()))
new Argument<PackageSource>(new PackageSource(Directory.GetCurrentDirectory()))
{
Name = "NuGet source"
}.ExistingOnly()));
}));

command.AddOption(new Option(
"--package",
Expand Down Expand Up @@ -339,7 +339,7 @@ Command Install()
installCommand.IsHidden = true;

var option = new Option("--add-source",
argument: new Argument<DirectoryInfo>().ExistingOnly());
argument: new Argument<PackageSource>());

installCommand.AddOption(option);

Expand Down
5 changes: 3 additions & 2 deletions MLS.Agent/CommandLine/InstallOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;
using WorkspaceServer;
using WorkspaceServer.Packaging;

namespace MLS.Agent.CommandLine
{
public class InstallOptions
{
public InstallOptions(DirectoryInfo addSource, string packageName, DirectoryInfo location = null)
public InstallOptions(PackageSource addSource, string packageName, DirectoryInfo location = null)
{
AddSource = addSource;
PackageName = packageName;
Location = location ?? Package.DefaultPackagesDirectory;
}

public DirectoryInfo AddSource { get; }
public PackageSource AddSource { get; }

public string PackageName { get; }
public DirectoryInfo Location { get; }
Expand Down
5 changes: 3 additions & 2 deletions MLS.Agent/CommandLine/StartupOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.CommandLine.Invocation;
using System.IO;
using Microsoft.DotNet.Try.Markdown;
using WorkspaceServer;

namespace MLS.Agent.CommandLine
{
Expand Down Expand Up @@ -34,7 +35,7 @@ public StartupOptions(
string id = null,
string regionId = null,
DirectoryInfo dir = null,
DirectoryInfo addPackageSource = null,
PackageSource addPackageSource = null,
Uri uri = null,
DirectoryInfo logPath = null,
bool verbose = false,
Expand Down Expand Up @@ -64,7 +65,7 @@ public StartupOptions(
public string Id { get; }
public string RegionId { get; }
public DirectoryInfo Dir { get; }
public DirectoryInfo AddPackageSource { get; }
public PackageSource AddPackageSource { get; }
public Uri Uri { get; set; }
public bool Production { get; }
public bool IsLanguageService { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer.Tests/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static async Task<IPackage> InstalledPackageWithBlazorEnabled([CallerMemb
{
var (packageName, addSource) = await NupkgWithBlazorEnabled(testName);
var destination = Package.DefaultPackagesDirectory;
await InstallCommand.Do(new InstallOptions(addSource, packageName, destination), new TestConsole());
await InstallCommand.Do(new InstallOptions(new PackageSource(addSource.FullName), packageName, destination), new TestConsole());

var strategy = new WebAssemblyAssetFinder(destination);
return await strategy.Find<IPackage>(packageName);
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer.Tests/PrebuiltBlazorPackageLocatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public PrebuiltBlazorPackageLocatorTests(ITestOutputHelper output)
public async Task Discovers_built_blazor_package()
{
var (packageName, addSource) = await Create.NupkgWithBlazorEnabled();
await InstallCommand.Do(new InstallOptions(addSource, packageName), new TestConsole());
await InstallCommand.Do(new InstallOptions(new PackageSource(addSource.FullName), packageName), new TestConsole());
var locator = new PrebuiltBlazorPackageLocator();

var asset = await locator.Locate(packageName);
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer/Dotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task<IEnumerable<string>> ToolList(DirectoryInfo directory, Budget
public Task<CommandLineResult> ToolInstall(
string packageName,
DirectoryInfo toolPath,
DirectoryInfo addSource = null,
PackageSource addSource = null,
Budget budget = null)
{
var args = $@"{packageName} --tool-path ""{toolPath.FullName}"" --version 1.0.0";
Expand Down
20 changes: 10 additions & 10 deletions WorkspaceServer/PackageRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,21 @@ public class PackageRegistry :

public PackageRegistry(
bool createRebuildablePackages = false,
DirectoryInfo addSource = null,
PackageSource addSource = null,
IEnumerable<IPackageFinder> packageFinders = null,
params IPackageDiscoveryStrategy[] additionalStrategies)
: this(addSource,
new IPackageDiscoveryStrategy[]
{
new ProjectFilePackageDiscoveryStrategy(createRebuildablePackages),
new DirectoryPackageDiscoveryStrategy(createRebuildablePackages)
}.Concat(additionalStrategies))
}.Concat(additionalStrategies),
packageFinders)
{
}

private PackageRegistry(
DirectoryInfo addSource,
PackageSource addSource,
IEnumerable<IPackageDiscoveryStrategy> strategies,
IEnumerable<IPackageFinder> packageFinders = null)
{
Expand All @@ -53,7 +54,7 @@ private PackageRegistry(
_strategies.Add(strategy);
}

_packageFinders = packageFinders?.ToList() ?? GetDefaultPackageFinders(addSource).ToList();
_packageFinders = packageFinders?.ToList() ?? GetDefaultPackageFinders().ToList();
}

public void Add(string name, Action<PackageBuilder> configure)
Expand Down Expand Up @@ -134,11 +135,13 @@ private Task<IPackage> GetPackageFromPackageBuilder<T>(string packageName, Budge
});
}

public static PackageRegistry CreateForTryMode(DirectoryInfo project, DirectoryInfo addSource = null)
public static PackageRegistry CreateForTryMode(DirectoryInfo project, PackageSource addSource = null)
{
var finders = GetDefaultPackageFinders().Append(new WebAssemblyAssetFinder(Package.DefaultPackagesDirectory, addSource));
var registry = new PackageRegistry(
true,
addSource,
finders,
additionalStrategies: new LocalToolInstallingPackageDiscoveryStrategy(Package.DefaultPackagesDirectory, addSource));

registry.Add(project.Name, builder =>
Expand All @@ -153,8 +156,7 @@ public static PackageRegistry CreateForTryMode(DirectoryInfo project, DirectoryI
public static PackageRegistry CreateForHostedMode()
{
var registry = new PackageRegistry(
false,
additionalStrategies: new LocalToolInstallingPackageDiscoveryStrategy(Package.DefaultPackagesDirectory));
false);

registry.Add("console",
packageBuilder =>
Expand Down Expand Up @@ -235,12 +237,10 @@ public IEnumerator<Task<PackageBuilder>> GetEnumerator() =>
IEnumerator IEnumerable.GetEnumerator() =>
GetEnumerator();

private static IEnumerable<IPackageFinder> GetDefaultPackageFinders(DirectoryInfo addSource)
private static IEnumerable<IPackageFinder> GetDefaultPackageFinders()
{
yield return new PackageNameIsFullyQualifiedPath();
yield return new FindPackageInDefaultLocation(new FileSystemDirectoryAccessor(Package.DefaultPackagesDirectory));
yield return new WebAssemblyAssetFinder(Package.DefaultPackagesDirectory, addSource);
//yield return new LocalToolInstallingPackageDiscoveryStrategy(Package.DefaultPackagesDirectory, addSource);
}

Task<T> IPackageFinder.Find<T>(PackageDescriptor descriptor)
Expand Down
40 changes: 40 additions & 0 deletions WorkspaceServer/PackageSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.IO;

namespace WorkspaceServer
{
public class PackageSource
{
DirectoryInfo _directory;
Uri _uri;

public PackageSource(string value)
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

// Uri.IsWellFormed will return false for path-like strings:
// (https://docs.microsoft.com/en-us/dotnet/api/system.uri.iswellformeduristring?view=netcore-2.2)
if (Uri.IsWellFormedUriString(value, UriKind.Absolute) &&
Uri.TryCreate(value, UriKind.Absolute, out var uri)
&& uri.Scheme != null)
{
_uri = uri;
}
else
{
_directory = new DirectoryInfo(value);
}
}

public override string ToString()
{
return _directory?.ToString() ?? _uri.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class LocalToolInstallingPackageDiscoveryStrategy : IPackageDiscoveryStra
{
private readonly DirectoryInfo _workingDirectory;
private readonly ToolPackageLocator _locator;
private readonly DirectoryInfo _addSource;
private readonly PackageSource _addSource;

public LocalToolInstallingPackageDiscoveryStrategy(DirectoryInfo workingDirectory, DirectoryInfo addSource = null)
public LocalToolInstallingPackageDiscoveryStrategy(DirectoryInfo workingDirectory, PackageSource addSource = null)
{
_workingDirectory = workingDirectory;
_locator = new ToolPackageLocator(workingDirectory);
Expand Down
4 changes: 2 additions & 2 deletions WorkspaceServer/Packaging/WebAssemblyAssetFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public class WebAssemblyAssetFinder : IPackageFinder
{
private readonly DirectoryInfo _workingDirectory;
private readonly ToolPackageLocator _locator;
private readonly DirectoryInfo _addSource;
private readonly PackageSource _addSource;

public WebAssemblyAssetFinder(DirectoryInfo workingDirectory, DirectoryInfo addSource = null)
public WebAssemblyAssetFinder(DirectoryInfo workingDirectory, PackageSource addSource = null)
{
_workingDirectory = workingDirectory;
_locator = new ToolPackageLocator(workingDirectory);
Expand Down