Skip to content

Commit 7891752

Browse files
committed
removed support for older .net frameworks, improved flubu entry point
1 parent b5f940c commit 7891752

20 files changed

Lines changed: 283 additions & 369 deletions

src/BuildScript/BuildScript.cs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public class BuildScript : DefaultBuildScript
2727
"FlubuCore.WebApi.Model",
2828
"FlubuCore.WebApi.Client",
2929
"FlubuCore",
30-
"dotnet-flubu",
3130
"FlubuCore.Tool",
3231
"FlubuCore.Analyzers",
3332
};
@@ -50,7 +49,7 @@ protected override void ConfigureTargets(ITaskContext context)
5049
var compile = context
5150
.CreateTarget("compile")
5251
.SetDescription("Compiles the VS solution")
53-
.AddCoreTask(x => x.UpdateNetCoreVersionTask("FlubuCore/FlubuCore.csproj", "dotnet-flubu/dotnet-flubu.csproj", "FlubuCore.Tests/FlubuCore.Tests.csproj", "FlubuCore.WebApi.Model/FlubuCore.WebApi.Model.csproj", "FlubuCore.WebApi.Client/FlubuCore.WebApi.Client.csproj", "FlubuCore.WebApi/FlubuCore.WebApi.csproj", "FlubuCore.Tool/FlubuCore.Tool.csproj"))
52+
.AddCoreTask(x => x.UpdateNetCoreVersionTask("FlubuCore/FlubuCore.csproj", "FlubuCore.Tests/FlubuCore.Tests.csproj", "FlubuCore.WebApi.Model/FlubuCore.WebApi.Model.csproj", "FlubuCore.WebApi.Client/FlubuCore.WebApi.Client.csproj", "FlubuCore.WebApi/FlubuCore.WebApi.csproj", "FlubuCore.Tool/FlubuCore.Tool.csproj"))
5453
.AddCoreTask(x => x.Build())
5554
.DependsOn(buildVersion);
5655

@@ -94,28 +93,23 @@ protected override void ConfigureTargets(ITaskContext context)
9493
DependsOn(buildVersion);
9594

9695
var packageFlubuRunner = context.CreateTarget("package.FlubuRunner")
97-
.SetDescription("Packages .net 4.62 FlubuCore runner into zip.")
96+
.SetDescription("Packages FlubuCore runner into zip.")
9897
.Do(TargetPackageFlubuRunner);
9998

100-
var packageDotnetFlubu = context.CreateTarget("package.DotnetFlubu")
101-
.SetDescription("Packages dotnet-flubu tool into zip.")
102-
.Do(TargetPackageDotnetFlubu);
103-
10499
context.CreateTarget("rebuild")
105100
.SetDescription("Rebuilds the solution")
106101
.SetAsDefault()
107102
.DependsOn(compile, flubuTests);
108103

109104
var branch = context.BuildServers().AppVeyor().BranchName;
110-
105+
111106
context.CreateTarget("rebuild.server")
112107
.SetDescription("Rebuilds the solution and publishes nuget packages.")
113108
.SequentialLogging(true)
114109
.DependsOn(compile, flubuTests)
115110
.DependsOn(pack, publishWebApi)
116111
.DependsOnAsync(flubuRunnerMerge)
117112
.DependsOn(packageFlubuRunner)
118-
.DependsOn(packageDotnetFlubu)
119113
.DependsOn(packageWebApi)
120114
.DependsOn(nugetPublish).When((c) =>
121115
c.BuildServers().RunningOn == BuildServerType.AppVeyor && branch != null && branch.Contains("stable", StringComparison.OrdinalIgnoreCase));
@@ -124,7 +118,7 @@ protected override void ConfigureTargets(ITaskContext context)
124118
var compileLinux = context
125119
.CreateTarget("compile.linux")
126120
.SetDescription("Compiles the VS solution")
127-
.AddCoreTask(x => x.UpdateNetCoreVersionTask("FlubuCore/FlubuCore.csproj", "dotnet-flubu/dotnet-flubu.csproj", "FlubuCore.Tests/FlubuCore.Tests.csproj", "FlubuCore.GlobalTool/FlubuCore.GlobalTool.csproj"))
121+
.AddCoreTask(x => x.UpdateNetCoreVersionTask("FlubuCore/FlubuCore.csproj", "FlubuCore.Tests/FlubuCore.Tests.csproj", "FlubuCore.Tool/FlubuCore.Tool.csproj"))
128122
.AddCoreTask(x => x.Restore())
129123
.DependsOn(buildVersion);
130124

@@ -135,7 +129,7 @@ protected override void ConfigureTargets(ITaskContext context)
135129

136130
context.CreateTarget("rebuild.linux")
137131
.SetDescription("Rebuilds the solution.")
138-
.DependsOn(compileLinux, flubuTestsLinux, packageDotnetFlubu);
132+
.DependsOn(compileLinux, flubuTestsLinux);
139133
}
140134

141135
private void TargetPackageFlubuRunner(ITaskContext context)
@@ -148,20 +142,6 @@ private void TargetPackageFlubuRunner(ITaskContext context)
148142
.Execute(context);
149143
}
150144

151-
private void TargetPackageDotnetFlubu(ITaskContext context)
152-
{
153-
context.CoreTasks().Publish("dotnet-flubu").Framework("netcoreapp3.1").Execute(context);
154-
if (!Directory.Exists(Output.CombineWith("dotnet-flubu")))
155-
{
156-
Directory.CreateDirectory(@"output/dotnet-flubu");
157-
}
158-
159-
context.Tasks().PackageTask(Output.CombineWith("dotnet-flubu"))
160-
.AddDirectoryToPackage(@"dotnet-flubu/bin/Release/netcoreapp3.1/publish", "", true)
161-
.ZipPackage("dotnet-flubu", true)
162-
.Execute(context);
163-
}
164-
165145
private void PublishNuGetPackage(ITaskContext context)
166146
{
167147
var version = context.Properties.GetBuildVersion();
@@ -188,11 +168,6 @@ private void PublishNuGetPackage(ITaskContext context)
188168
.ServerUrl("https://www.nuget.org/api/v2/package")
189169
.ApiKey(NugetApiKey).Execute(context);
190170

191-
context.CoreTasks().NugetPush(Output.CombineWith($"dotnet-flubu.{nugetVersion}.nupkg"))
192-
.DoNotFailOnError(e => { Console.WriteLine($"Failed to publish dotnet-flubu. exception: {e.Message}"); })
193-
.ServerUrl("https://www.nuget.org/api/v2/package")
194-
.ApiKey(NugetApiKey).Execute(context);
195-
196171
context.CoreTasks().NugetPush(Output.CombineWith($"FlubuCore.Tool.{nugetVersion}.nupkg"))
197172
.DoNotFailOnError(e => { Console.WriteLine($"Failed to publish FlubuCore.Tool. exception: {e.Message}"); })
198173
.ServerUrl("https://www.nuget.org/api/v2/package")
@@ -222,7 +197,7 @@ private void TargetMerge(ITaskContext context)
222197
.WithArguments("--exclude", "FlubuCore.dll")
223198
.WithArguments("--move")
224199
.Execute(context);
225-
200+
226201
progTask = context.Tasks().RunProgramTask(@"tools\LibZ.Tool\1.2.0\tools\libz.exe");
227202

228203
progTask

src/FlubuCore.Tests/FlubuCore.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
</Content>
7878
</ItemGroup>
7979
<ItemGroup>
80-
<ProjectReference Include="..\dotnet-flubu\dotnet-flubu.csproj" />
8180
<ProjectReference Include="..\FlubuCore\FlubuCore.csproj" />
8281
</ItemGroup>
8382
<ItemGroup>

src/FlubuCore.Tests/FlubuTestBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.IO;
33
using System.Runtime.InteropServices;
4-
using DotNet.Cli.Flubu.Infrastructure;
54
using FlubuCore.Context;
65
using FlubuCore.Context.FluentInterface;
76
using FlubuCore.Infrastructure;

src/FlubuCore.Tests/InfrastructureTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using DotNet.Cli.Flubu.Infrastructure;
32
using FlubuCore.Commanding;
43
using FlubuCore.Infrastructure;
54
using FlubuCore.Scripting;

src/FlubuCore.Tests/Integration/IntegrationTestFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using DotNet.Cli.Flubu.Infrastructure;
32
using FlubuCore.Infrastructure;
43
using FlubuCore.Scripting;
54
using Microsoft.Extensions.DependencyInjection;

src/FlubuCore.Tests/Integration/TargetTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
5-
using DotNet.Cli.Flubu.Infrastructure;
65
using FlubuCore.Context;
76
using FlubuCore.Infrastructure;
87
using FlubuCore.IO.Wrappers;

src/FlubuCore.Tool/FlubuCore.Tool.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
</PropertyGroup>
3131

3232
<ItemGroup>
33-
<ProjectReference Include="..\dotnet-flubu\dotnet-flubu.csproj" />
33+
<ProjectReference Include="..\FlubuCore\FlubuCore.csproj" />
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
38+
<PrivateAssets>All</PrivateAssets>
39+
</PackageReference>
3440
</ItemGroup>
3541
</Project>

src/FlubuCore.Tool/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22

33
namespace FlubuCore.Tool
44
{
55
public class Program
66
{
77
public static async Task<int> Main(string[] args)
88
{
9-
return await DotNet.Cli.Flubu.Program.Main(args);
9+
return await FlubuEntryPoint.MainAsync(args);
1010
}
1111
}
1212
}

src/FlubuCore/Commanding/ShellCompletionProvider.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ private static List<string> TokenizeCommandLine(string commandLine)
160160
// Strip leading "flubu" or "flubu.exe" command name
161161
if (tokens.Count > 0 &&
162162
(tokens[0].Equals("flubu", StringComparison.OrdinalIgnoreCase) ||
163-
tokens[0].Equals("flubu.exe", StringComparison.OrdinalIgnoreCase) ||
164-
tokens[0].EndsWith("dotnet-flubu", StringComparison.OrdinalIgnoreCase) ||
165-
tokens[0].EndsWith("dotnet-flubu.exe", StringComparison.OrdinalIgnoreCase)))
163+
tokens[0].Equals("flubu.exe", StringComparison.OrdinalIgnoreCase)))
166164
{
167165
tokens.RemoveAt(0);
168166
}

src/FlubuCore/FlubuEntryPoint.cs

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using FlubuCore.Commanding;
6+
using FlubuCore.Context;
7+
using FlubuCore.Infrastructure;
8+
using FlubuCore.Scripting;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace FlubuCore
13+
{
14+
public static class FlubuEntryPoint
15+
{
16+
private static readonly IServiceCollection Services = new ServiceCollection();
17+
18+
private static IServiceProvider _provider;
19+
20+
private static ILogger<CommandExecutor> _logger;
21+
22+
private static bool _cleanUpPerformed = false;
23+
24+
private static volatile bool _wait = false;
25+
26+
public static async Task<int> MainAsync(string[] args)
27+
{
28+
if (args == null)
29+
{
30+
args = new string[0];
31+
}
32+
33+
// Handle --setup-completions before any DI/script loading
34+
var setupIdx = Array.FindIndex(args,
35+
a => a.Equals("--setup-completions", StringComparison.OrdinalIgnoreCase));
36+
if (setupIdx >= 0 && setupIdx + 1 < args.Length)
37+
{
38+
ShellCompletionProvider.WriteSetupScript(args[setupIdx + 1]);
39+
return 0;
40+
}
41+
42+
// Suppress all logging when generating completions
43+
if (Array.Exists(args, a => a.Equals("--completions", StringComparison.OrdinalIgnoreCase)))
44+
{
45+
FlubuConsoleLogger.SuppressAllLogging = true;
46+
}
47+
48+
var statusCode = await FlubuStartup(args);
49+
50+
if (statusCode != 0)
51+
{
52+
return statusCode;
53+
}
54+
55+
ICommandExecutor executor = _provider.GetRequiredService<ICommandExecutor>();
56+
57+
Console.CancelKeyPress += OnCancelKeyPress;
58+
var result = await executor.ExecuteAsync();
59+
60+
while (_wait)
61+
{
62+
Thread.Sleep(250);
63+
}
64+
65+
return result;
66+
}
67+
68+
private static async Task<int> FlubuStartup(string[] args)
69+
{
70+
IServiceCollection startUpServiceCollection = new ServiceCollection();
71+
72+
startUpServiceCollection.AddScriptAnalyzers()
73+
.AddCoreComponents()
74+
.AddCommandComponents(false)
75+
.AddParserComponents()
76+
.AddScriptAnalyzers();
77+
78+
Services.AddFlubuLogging(startUpServiceCollection);
79+
80+
var startupProvider = startUpServiceCollection.BuildServiceProvider();
81+
var parser = startupProvider.GetRequiredService<IFlubuCommandParser>();
82+
var commandArguments = parser.Parse(args);
83+
IScriptProvider scriptProvider = startupProvider.GetRequiredService<IScriptProvider>();
84+
IFlubuConfigurationBuilder flubuConfigurationBuilder = new FlubuConfigurationBuilder();
85+
ILoggerFactory loggerFactory = startupProvider.GetRequiredService<ILoggerFactory>();
86+
loggerFactory.AddProvider(new FlubuLoggerProvider());
87+
_logger = startupProvider.GetRequiredService<ILogger<CommandExecutor>>();
88+
var version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
89+
_logger.LogInformation($"Flubu v.{version}");
90+
91+
IBuildScript script = null;
92+
if (!commandArguments.IsInternalCommand())
93+
{
94+
try
95+
{
96+
script = await scriptProvider.GetBuildScriptAsync(commandArguments);
97+
}
98+
catch (BuildScriptLocatorException e)
99+
{
100+
if (!commandArguments.InteractiveMode && !commandArguments.IsCompletionMode)
101+
{
102+
var str = commandArguments.Debug ? e.ToString() : e.Message;
103+
_logger.Log(LogLevel.Error, 1, $"EXECUTION FAILED:\r\n{str}", null, (t, ex) => t);
104+
return StatusCodes.BuildScriptNotFound;
105+
}
106+
}
107+
}
108+
109+
Services
110+
.AddCoreComponents()
111+
.AddParserComponents()
112+
.AddCommandComponents(interactiveMode: commandArguments.InteractiveMode)
113+
.AddScriptAnalyzers()
114+
.AddTasks();
115+
116+
Services.AddSingleton(loggerFactory);
117+
Services.AddSingleton(commandArguments);
118+
119+
if (script != null)
120+
{
121+
script.ConfigureServices(Services);
122+
script.Configure(flubuConfigurationBuilder, loggerFactory);
123+
}
124+
125+
Services.AddSingleton(flubuConfigurationBuilder.Build());
126+
127+
_provider = Services.BuildServiceProvider();
128+
return 0;
129+
}
130+
131+
private static void OnCancelKeyPress(object sender, ConsoleCancelEventArgs eventArgs)
132+
{
133+
if (!_cleanUpPerformed && CleanUpStore.TaskCleanUpActions?.Count > 0)
134+
{
135+
_wait = true;
136+
_logger.LogInformation($"Performing clean up actions:");
137+
var taskSession = _provider.GetService<IFlubuSession>();
138+
foreach (var cleanUpAction in CleanUpStore.TaskCleanUpActions)
139+
{
140+
cleanUpAction.Invoke(taskSession);
141+
_logger.LogInformation($"Finished performing clean up actions.");
142+
}
143+
144+
_wait = false;
145+
}
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)