Skip to content

Commit

Permalink
Need to build prior to setting up file provider for assembly loader
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Pekurny <mpekurny@paychex.com>
  • Loading branch information
mpekurny committed Dec 12, 2024
1 parent f90cfee commit 2f0fbbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/GaugeProjectBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ namespace Gauge.Dotnet;
public class GaugeProjectBuilder : IGaugeProjectBuilder
{
private readonly IConfiguration _config;
private readonly ILogger<GaugeProjectBuilder> _logger;

public GaugeProjectBuilder(IConfiguration config, ILogger<GaugeProjectBuilder> logger)
public GaugeProjectBuilder(IConfiguration config)
{
_config = config;
_logger = logger;
}

public bool BuildTargetGaugeProject()
Expand Down Expand Up @@ -65,14 +63,20 @@ public bool BuildTargetGaugeProject()
}
catch (NotAValidGaugeProjectException)
{
_logger.LogCritical("Cannot locate a Project File in {ProjectRoot}", _config.GetGaugeProjectRoot());
// Logger not available yet, so output log to console.
Console.WriteLine($$"""
{ "logLevel": "fatal", "message": "Cannot locate a Project File in {{_config.GetGaugeProjectRoot()}}"}
""");
throw;
}
catch (Exception ex)
{
if (!_config.IgnoreBuildFailures())
{
_logger.LogCritical("Unable to build Project in {ProjectRoot}\n{Message}\n{StackTrace}", _config.GetGaugeProjectRoot(), ex.Message, ex.StackTrace);
// Logger not available yet, so output log to console.
Console.WriteLine($$"""
{ "logLevel": "fatal", "message": "Unable to build Project in {{_config.GetGaugeProjectRoot()}}\n{{ex.Message}}\n{{ex.StackTrace}}"}
""");
throw;
}
return false;
Expand All @@ -88,8 +92,6 @@ private int RunDotnetCommand(string args)
Arguments = args
};
var buildProcess = new Process { EnableRaisingEvents = true, StartInfo = startInfo };
buildProcess.OutputDataReceived += (sender, e) => { _logger.LogDebug(e.Data); };
buildProcess.ErrorDataReceived += (sender, e) => { _logger.LogError(e.Data); };
buildProcess.Start();
buildProcess.WaitForExit();
return buildProcess.ExitCode;
Expand Down
7 changes: 4 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ private static async Task Main(string[] args)
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetupConfiguration();
builder.Logging.SetupLogging();

Environment.CurrentDirectory = builder.Configuration.GetGaugeProjectRoot();
var buildSucceeded = new GaugeProjectBuilder(builder.Configuration).BuildTargetGaugeProject();

builder.WebHost.ConfigureKestrel(opts =>
{
opts.Listen(IPAddress.Parse("127.0.0.1"), 0, (opt) => { opt.Protocols = HttpProtocols.Http2; });
Expand All @@ -50,8 +54,6 @@ private static async Task Main(string[] args)
var app = builder.Build();
_logger = app.Services.GetRequiredService<ILoggerFactory>().CreateLogger("Gauge");

Environment.CurrentDirectory = app.Configuration.GetGaugeProjectRoot();
var buildSucceeded = app.Services.GetRequiredService<IGaugeProjectBuilder>().BuildTargetGaugeProject();
if (!buildSucceeded && !app.Configuration.IgnoreBuildFailures())
{
return;
Expand Down Expand Up @@ -113,7 +115,6 @@ private static IServiceCollection ConfigureServices(this IServiceCollection serv
{
services.AddGrpc();
services.AddSingleton<IFileProvider>(new PhysicalFileProvider(config.GetGaugeBinDir()));
services.AddTransient<IGaugeProjectBuilder, GaugeProjectBuilder>();
services.AddSingleton<IAssemblyLocater, AssemblyLocater>();
services.AddSingleton<IReflectionWrapper, ReflectionWrapper>();
services.AddSingleton<IActivatorWrapper, ActivatorWrapper>();
Expand Down

0 comments on commit 2f0fbbe

Please sign in to comment.