这是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
2 changes: 1 addition & 1 deletion MLS.Agent.Tests/ApiContracts/ApiOutputContractTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public async Task The_signature_help_contract_has_not_been_broken()
this.Assent(result.FormatJson(), configuration);
}

[Fact]
[Fact(Skip = "Needs moved onto Package2")]
public async Task The_instrumentation_contract_has_not_been_broken()
{
var requestJson = new WorkspaceRequest(
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 @@ -68,7 +68,7 @@ public async Task Pack_project_blazor_contents()

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

var tool = new WorkspaceServer.WorkspaceFeatures.PackageTool(packageName, asset.Directory);
var tool = new WorkspaceServer.WorkspaceFeatures.PackageTool(packageName, new FileSystemDirectoryAccessor(asset.Directory));

await tool.Prepare();

Expand Down
11 changes: 7 additions & 4 deletions MLS.Agent.Tests/LocalToolPackageDiscoveryStrategyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Xunit;
using Xunit.Abstractions;
using WorkspaceServer;
using System.IO;
using System.Linq;

namespace MLS.Agent.Tests
{
Expand All @@ -29,14 +31,15 @@ public async Task Discover_tool_from_directory()
{
var console = new TestConsole();
var temp = directory.Directory;
var asset = (await Create.ConsoleWorkspaceCopy()).Directory;
await PackCommand.Do(new PackOptions(asset, outputDirectory: temp, enableWasm: false), console);
var result = await Tools.CommandLine.Execute("dotnet", $"tool install --add-source {temp.FullName} console --tool-path {temp.FullName}");
var package = await Create.ConsoleWorkspaceCopy();
File.Move(package.Directory.GetFiles("*.csproj").First().FullName, Path.Combine(package.Directory.FullName, "not-console.csproj"));
await PackCommand.Do(new PackOptions(package.Directory, outputDirectory: temp, enableWasm: false), console);
var result = await Tools.CommandLine.Execute("dotnet", $"tool install --add-source {temp.FullName} not-console --tool-path {temp.FullName}");
output.WriteLine(string.Join("\n", result.Error));
result.ExitCode.Should().Be(0);

var strategy = new LocalToolInstallingPackageDiscoveryStrategy(temp);
var tool = await strategy.Locate(new PackageDescriptor("console"));
var tool = await strategy.Locate(new PackageDescriptor("not-console"));
tool.Should().NotBeNull();
}
}
Expand Down
2 changes: 1 addition & 1 deletion MLS.Agent/CommandLine/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static async Task Do(InstallOptions options, IConsole console)
options.Location,
options.AddSource)).ThrowOnFailure();

var tool = new WorkspaceServer.WorkspaceFeatures.PackageTool(options.PackageName, options.Location);
var tool = new WorkspaceServer.WorkspaceFeatures.PackageTool(options.PackageName, new FileSystemDirectoryAccessor(options.Location));
await tool.Prepare();
}
}
Expand Down
2 changes: 1 addition & 1 deletion MLS.Agent/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"MLS.Agent": {
"commandName": "Project",
"commandLineArgs": "../docs",
"commandLineArgs": "hosted",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
4 changes: 2 additions & 2 deletions MLS.PackageTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MLS.PackageTool
{
public class PackageToolConstants
{
public const string LocateBuildAsset = "locate-build-asset";
public const string LocateProjectAsset = "locate-project-asset";
public const string LocateWasmAsset = "locate-wasm-asset";
public const string PreparePackage = "prepare-package";
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public static Parser Create(

Command LocateBuildAsset()
{
return new Command(PackageToolConstants.LocateBuildAsset)
return new Command(PackageToolConstants.LocateProjectAsset)
{
Handler = CommandHandler.Create(getBuildAsset)
};
Expand Down
6 changes: 3 additions & 3 deletions PackageTool.Tests/CommandLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public CommandLineParserTests(ITestOutputHelper output)
{
_output = output;
_parser = CommandLineParser.Create(
getBuildAsset: (_) => { _command = PackageToolConstants.LocateBuildAsset; },
getBuildAsset: (_) => { _command = PackageToolConstants.LocateProjectAsset; },
getWasmAsset: (_) => { _command = PackageToolConstants.LocateWasmAsset; },
prepare: (_) => {
_command = "prepare-package";
Expand All @@ -33,8 +33,8 @@ public CommandLineParserTests(ITestOutputHelper output)
[Fact]
public async Task Parse_locate_build_locates_build()
{
await _parser.InvokeAsync(PackageToolConstants.LocateBuildAsset, _console);
_command.Should().Be(PackageToolConstants.LocateBuildAsset);
await _parser.InvokeAsync(PackageToolConstants.LocateProjectAsset, _console);
_command.Should().Be(PackageToolConstants.LocateProjectAsset);
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer.Tests/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static async Task<IPackage> InstalledPackageWithBlazorEnabled([CallerMemb
var destination = Package.DefaultPackagesDirectory;
await InstallCommand.Do(new InstallOptions(new PackageSource(addSource.FullName), packageName, destination), new TestConsole());

var strategy = new WebAssemblyAssetFinder(destination);
var strategy = new WebAssemblyAssetFinder(new FileSystemDirectoryAccessor(destination));
return await strategy.Find<IPackage>(packageName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public async Task Syntax_Tree_Has_Parameters_When_Augmentation_Has_Parameters()
Assert.Contains("\\\"name\\\":\\\"args\\\"", treeString);
}

[Fact]
[Fact(Skip = "Needs moved onto Package2")]
public async void Syntax_Tree_Has_Same_Language_As_Package()
{
var package = await Create.ConsoleWorkspaceCopy();
Expand Down
Binary file modified WorkspaceServer.Tests/RoslynWorkspaceServerConsoleProjectTests.cs
Binary file not shown.
13 changes: 12 additions & 1 deletion WorkspaceServer/Dotnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ public async Task<IEnumerable<string>> ToolList(DirectoryInfo directory, Budget
.Select(s => s.Split(separator, StringSplitOptions.RemoveEmptyEntries)[2]);
}

private string RemoveTrailingSlash(string path)
{
// dotnet tool install doesn't like it if directory arguments end with "/"
if (path.EndsWith("\\"))
{
return path.Substring(0, path.Length - 1);
}

return path;
}

public Task<CommandLineResult> ToolInstall(
string packageName,
DirectoryInfo toolPath,
PackageSource addSource = null,
Budget budget = null)
{
var args = $@"{packageName} --tool-path ""{toolPath.FullName}"" --version 1.0.0";
var args = $@"{packageName} --tool-path ""{RemoveTrailingSlash(toolPath.FullName)}"" --version 1.0.0";
if (addSource != null)
{
args += $@" --add-source ""{addSource}""";
Expand Down
44 changes: 26 additions & 18 deletions WorkspaceServer/PackageRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,41 @@ public async Task<T> Get<T>(string packageName, Budget budget = null)
return (T)package;
}

private Task<IPackage> GetPackage2<T>(PackageDescriptor descriptor)
private async Task<IPackage> GetPackage2<T>(PackageDescriptor descriptor)
where T : class, IPackage
{
return _packages2.GetOrAdd(descriptor, async descriptor2 =>
var package = await ( _packages2.GetOrAdd(descriptor, async descriptor2 =>
{
foreach (var packageFinder in _packageFinders)
{
var package = await packageFinder.Find<IPackage>(descriptor);
if (package != null)
var package2 = await packageFinder.Find<Package2>(descriptor);
if (package2 != null)
{
if (package is Package2 package2)
{
var packageAsset = package2.Assets.OfType<T>().FirstOrDefault();
if (packageAsset != null)
{
return packageAsset;
}
}
return package2;
}
if (package is T pkg)
}

return default;
}));

if (package != null)
{
if (package is T pkg)
{
return pkg;
}

if (package is Package2 package2)
{
var packageAsset = package2.Assets.OfType<T>().FirstOrDefault();
if (packageAsset != null)
{
return pkg;
return packageAsset;
}
}
}

return default;
});
return null;
}

private Task<IPackage> GetPackageFromPackageBuilder(string packageName, Budget budget, PackageDescriptor descriptor)
Expand Down Expand Up @@ -151,7 +159,7 @@ private Task<IPackage> GetPackageFromPackageBuilder(string packageName, Budget b

public static PackageRegistry CreateForTryMode(DirectoryInfo project, PackageSource addSource = null)
{
var finders = GetDefaultPackageFinders().Append(new PackageInstallingWebAssemblyAssetFinder(Package.DefaultPackagesDirectory, addSource));
var finders = GetDefaultPackageFinders().Append(new PackageInstallingWebAssemblyAssetFinder(new FileSystemDirectoryAccessor(Package.DefaultPackagesDirectory), addSource));
var registry = new PackageRegistry(
true,
addSource,
Expand All @@ -169,7 +177,7 @@ public static PackageRegistry CreateForTryMode(DirectoryInfo project, PackageSou

public static PackageRegistry CreateForHostedMode()
{
var finders = GetDefaultPackageFinders().Append(new WebAssemblyAssetFinder(Package.DefaultPackagesDirectory));
var finders = GetDefaultPackageFinders().Append(new WebAssemblyAssetFinder(new FileSystemDirectoryAccessor(Package.DefaultPackagesDirectory)));
var registry = new PackageRegistry(
createRebuildablePackages: false,
packageFinders: finders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PackageInstallingWebAssemblyAssetFinder : WebAssemblyAssetFinder, I
{
private readonly PackageSource _addSource;

public PackageInstallingWebAssemblyAssetFinder(DirectoryInfo workingDirectory, PackageSource addSource = null)
public PackageInstallingWebAssemblyAssetFinder(IDirectoryAccessor workingDirectory, PackageSource addSource = null)
: base(workingDirectory)
{
_addSource = addSource;
Expand Down Expand Up @@ -42,7 +42,7 @@ private async Task<IPackage> TryInstallAndLocateTool(PackageDescriptor packageDe

var installationResult = await dotnet.ToolInstall(
packageDesciptor.Name,
_workingDirectory,
_workingDirectory.GetFullyQualifiedRoot(),
_addSource,
new Budget());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<IEnumerable<PackageAsset>> LoadAsync(Package2 package)

if (directory.FileExists(exeName))
{
var tool = new PackageTool(package.Name, directory.GetFullyQualifiedRoot());
var tool = new PackageTool(package.Name, directory);
var exePath = directory.GetFullyQualifiedFilePath(exeName);

var toolDirectory = await _toolPackageLocator.PrepareToolAndLocateAssetDirectory(tool);
Expand Down
4 changes: 2 additions & 2 deletions WorkspaceServer/Packaging/ToolPackageLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ToolPackageLocator(DirectoryInfo baseDirectory = null)

public async Task<Package> LocatePackageAsync(string name, Budget budget)
{
var candidateTool = new PackageTool(name, _baseDirectory);
var candidateTool = new PackageTool(name, new FileSystemDirectoryAccessor(_baseDirectory));
if (!candidateTool.Exists)
{
return null;
Expand All @@ -43,7 +43,7 @@ public async Task<Package> LocatePackageAsync(string name, Budget budget)
public async Task<DirectoryInfo> PrepareToolAndLocateAssetDirectory(PackageTool tool)
{
await tool.Prepare();
return await tool.LocateBuildAsset();
return (await tool.LocateProjectAsset()).DirectoryAccessor.GetFullyQualifiedRoot();
}
}
}
21 changes: 14 additions & 7 deletions WorkspaceServer/Packaging/WebAssemblyAssetFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 Microsoft.Build.Logging.StructuredLogger;
using System;
using System.IO;
using System.Threading.Tasks;
Expand All @@ -10,9 +11,9 @@ namespace WorkspaceServer.Packaging
{
public class WebAssemblyAssetFinder : IPackageFinder
{
protected readonly DirectoryInfo _workingDirectory;
protected readonly IDirectoryAccessor _workingDirectory;

public WebAssemblyAssetFinder(DirectoryInfo workingDirectory)
public WebAssemblyAssetFinder(IDirectoryAccessor workingDirectory)
{
_workingDirectory = workingDirectory;
}
Expand All @@ -37,12 +38,18 @@ async Task<TPackage> IPackageFinder.Find<TPackage>(PackageDescriptor descriptor)
protected async Task<IPackage> CreatePackage(PackageDescriptor descriptor, PackageTool tool)
{
await tool.Prepare();
var wasmAsset = await tool.LocateWasmAsset();
if (wasmAsset != null)
var projectAsset = await tool.LocateProjectAsset();
if (projectAsset != null)
{
var package = new Package2(descriptor.Name, new FileSystemDirectoryAccessor(wasmAsset.DirectoryAccessor.GetFullyQualifiedRoot().Parent));
package.Add(wasmAsset);
return package;
var package = new Package2(descriptor.Name, tool.DirectoryAccessor);
package.Add(projectAsset);

var wasmAsset = await tool.LocateWasmAsset();
if (wasmAsset != null)
{
package.Add(wasmAsset);
return package;
}
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer/PrebuiltBlazorPackageLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task<WebAssemblyAsset> Locate(string name)
if (toolNames.Contains(name))
{
operation.Info($"Checking tool {name}");
var tool = new PackageTool(name, _packagesDirectory);
var tool = new PackageTool(name, new FileSystemDirectoryAccessor(_packagesDirectory));
await tool.Prepare();
return await tool.LocateWasmAsset();
}
Expand Down
5 changes: 3 additions & 2 deletions WorkspaceServer/Servers/Roslyn/RoslynWorkspaceServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,10 @@ private async Task<CompileWorkerResult> CompileWorker(
BufferId activeBufferId,
Budget budget)
{
var package = await _packageFinder.Find<Package>(workspace.WorkspaceType);
var package = await _packageFinder.Find<ICreateWorkspace>(workspace.WorkspaceType);
workspace = await _transformer.TransformAsync(workspace);
var compilation = await package.Compile(workspace, budget, activeBufferId);
var sources = workspace.GetSourceFiles();
var (compilation, documents) = await package.GetCompilation(sources, SourceCodeKind.Regular, workspace.Usings, () => package.CreateRoslynWorkspaceAsync(budget), budget);
var (diagnosticsInActiveBuffer, allDiagnostics) = workspace.MapDiagnostics(activeBufferId, compilation.GetDiagnostics());

budget.RecordEntryAndThrowIfBudgetExceeded();
Expand Down
21 changes: 10 additions & 11 deletions WorkspaceServer/WorkspaceFeatures/PackageTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ namespace WorkspaceServer.WorkspaceFeatures
{
public class PackageTool
{
private readonly DirectoryInfo _workingDirectory;
private Lazy<FileInfo> _path { get; }

public PackageTool(string name, DirectoryInfo workingDirectory)
public PackageTool(string name, IDirectoryAccessor directoryAccessor)
{
this.Name = name;
this._workingDirectory = workingDirectory;
Name = name;
DirectoryAccessor = directoryAccessor;
_path = new Lazy<FileInfo>(() => FindTool());
}

public IDirectoryAccessor DirectoryAccessor { get; }
public bool Exists => _path.Value != null && _path.Value.Exists;

public string Name { get; }

public async Task<DirectoryInfo> LocateBuildAsset()
public async Task<ProjectAsset> LocateProjectAsset()
{
var result = await CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.LocateBuildAsset, _workingDirectory);
var result = await CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.LocateProjectAsset, DirectoryAccessor.GetFullyQualifiedRoot());
var projectDirectory = new DirectoryInfo(string.Join("", result.Output));
return projectDirectory;
return new ProjectAsset(new FileSystemDirectoryAccessor(projectDirectory));
}

public async Task<WebAssemblyAsset> LocateWasmAsset()
{
var result = await CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.LocateWasmAsset, _workingDirectory);
var result = await CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.LocateWasmAsset, DirectoryAccessor.GetFullyQualifiedRoot());
var projectDirectory = new DirectoryInfo(string.Join("", result.Output));

if (!projectDirectory.Exists)
Expand All @@ -50,13 +50,12 @@ public async Task<WebAssemblyAsset> LocateWasmAsset()

public Task Prepare()
{
return CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.PreparePackage, _workingDirectory);
return CommandLine.Execute(_path.Value, MLS.PackageTool.PackageToolConstants.PreparePackage, DirectoryAccessor.GetFullyQualifiedRoot());
}

FileInfo FindTool()
{
var exeName = Path.Combine(_workingDirectory.FullName, Name.ExecutableName());
var fileInfo = new FileInfo(exeName);
var fileInfo = DirectoryAccessor.GetFullyQualifiedFilePath(Name.ExecutableName());

if (!fileInfo.Exists)
{
Expand Down