Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable OmniSharp.Cake tests for .NET 6 #2307

Merged
merged 3 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 .github/workflows/tests-net6.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
matrix:
os: [ubuntu-18.04, windows-2019, macos-10.15]
testProjects:
- OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests
- OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests
- OmniSharp.DotNetTest.Tests
name: 'Test'
steps:
Expand Down
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"OmniSharp.Stdio.Tests",
"OmniSharp.DotNetTest.Tests",
"OmniSharp.Tests",
"OmniSharp.Cake.Tests",
"OmniSharp.Script.Tests",
"OmniSharp.Lsp.Tests"
],
Expand Down
2 changes: 1 addition & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Update="Cake.Scripting.Transport" Version="0.8.1" />
<PackageReference Update="Cake.Scripting.Transport" Version="0.9.0" />

<PackageReference Update="Dotnet.Script.DependencyModel" Version="1.1.0" />
<PackageReference Update="Dotnet.Script.DependencyModel.NuGet" Version="1.1.0" />
Expand Down
11 changes: 8 additions & 3 deletions src/OmniSharp.Cake/Services/CakeScriptService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ public bool Initialize(CakeOptions options)
{
_logger.LogInformation($"Using Cake.Bakery at {serverExecutablePath}");

_generationService = PlatformHelper.IsMono ?
new ScriptGenerationClient(new MonoScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory) :
new ScriptGenerationClient(serverExecutablePath, _environment.TargetDirectory, _loggerFactory);
_generationService =
#if NET472_OR_GREATER
PlatformHelper.IsMono ?
new ScriptGenerationClient(new MonoScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory) :
new ScriptGenerationClient(serverExecutablePath, _environment.TargetDirectory, _loggerFactory);
#else
new ScriptGenerationClient(new DotnetScriptGenerationProcess(serverExecutablePath, _environment, _loggerFactory), _environment.TargetDirectory, _loggerFactory);
#endif
}
else if (!string.IsNullOrEmpty(serverExecutablePath))
{
Expand Down
74 changes: 74 additions & 0 deletions src/OmniSharp.Cake/Services/DotnetScriptGenerationProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#if NET6_0_OR_GREATER
using System;
using System.Diagnostics;
using System.IO;
using Cake.Scripting.Transport.Tcp.Client;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace OmniSharp.Cake.Services
{
internal sealed class DotnetScriptGenerationProcess : IScriptGenerationProcess
{
private readonly ILogger _logger;
private readonly IOmniSharpEnvironment _environment;
private Process _process;

public DotnetScriptGenerationProcess(string serverExecutablePath, IOmniSharpEnvironment environment, ILoggerFactory loggerFactory)
{
_logger = loggerFactory?.CreateLogger(typeof(DotnetScriptGenerationProcess)) ?? NullLogger.Instance;
_environment = environment ?? throw new ArgumentNullException(nameof(environment));
ServerExecutablePath = serverExecutablePath;
}

public void Dispose()
{
_process?.Kill();
_process?.WaitForExit();
_process?.Dispose();
}

public void Start(int port, string workingDirectory)
{
var fileName = "dotnet";
var arguments = $"\"{Path.ChangeExtension(ServerExecutablePath, ".dll")}\"";
arguments += $" --port={port}";
if (_logger.IsEnabled(LogLevel.Debug))
{
arguments += " --verbose";
}

var startInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
WorkingDirectory = workingDirectory,
};

_logger.LogDebug("Starting \"{fileName}\" with arguments \"{arguments}\"", startInfo.FileName, startInfo.Arguments);
_process = Process.Start(startInfo);
_process.ErrorDataReceived += (s, e) =>
{
if (e.Data != null)
{
_logger.LogError(e.Data);
}
};
_process.BeginErrorReadLine();
_process.OutputDataReceived += (s, e) =>
{
if (e.Data != null)
{
_logger.LogDebug(e.Data);
}
};
_process.BeginOutputReadLine();
}

public string ServerExecutablePath { get; set; }
}
}
#endif
4 changes: 3 additions & 1 deletion src/OmniSharp.Cake/Services/MonoScriptGenerationProcess.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NET472_OR_GREATER
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -108,3 +109,4 @@ public void Start(int port, string workingDirectory)
public string ServerExecutablePath { get; set; }
}
}
#endif
3 changes: 1 addition & 2 deletions test-assets/test-projects/CakeProject/tools/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<packages>
<package id="Cake" version="1.3.0" />
<package id="Cake.Bakery" version="0.8.1" />
<package id="Cake.Bakery" version="0.9.0" />
</packages>
2 changes: 0 additions & 2 deletions tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public class OmniSharpTestHost : DisposableObject
typeof(ScriptProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Script
typeof(OmniSharpWorkspace).GetTypeInfo().Assembly, // OmniSharp.Roslyn
typeof(RoslynFeaturesHostServicesProvider).GetTypeInfo().Assembly, // OmniSharp.Roslyn.CSharp
#if !NETCOREAPP
typeof(OmniSharp.Cake.CakeProjectSystem).GetTypeInfo().Assembly, // OmniSharp.Cake
#endif
typeof(LanguageServerHost).Assembly, // OmniSharp.LanguageServerProtocol
});

Expand Down
2 changes: 1 addition & 1 deletion tests/TestUtility/TestUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ProjectReference Include="..\..\src\OmniSharp.MSBuild\OmniSharp.MSBuild.csproj" />
<ProjectReference Include="..\..\src\OmniSharp.Roslyn.CSharp\OmniSharp.Roslyn.CSharp.csproj" />
<ProjectReference Include="..\..\src\OmniSharp.Script\OmniSharp.Script.csproj" />
<ProjectReference Condition="'$(TargetFramework)' == 'net472'" Include="..\..\src\OmniSharp.Cake\OmniSharp.Cake.csproj" />
<ProjectReference Include="..\..\src\OmniSharp.Cake\OmniSharp.Cake.csproj" />
<ProjectReference Include="..\..\src\OmniSharp.Shared\OmniSharp.Shared.csproj" />
</ItemGroup>

Expand Down