Skip to content

Commit

Permalink
VCI-772: Net 8 (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro authored Feb 22, 2024
1 parent 23b6827 commit 118c7b1
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Copyright>Copyright © VirtoCommerce 2011-2022</Copyright>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>3.22.0</VersionPrefix>
<VersionPrefix>3.800.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
</PropertyGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/VirtoCommerce.Build.Tests/PackageManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Extensions;
using Nuke.Common.IO;
using PlatformTools;
using VirtoCommerce.Build.PlatformTools;

Expand Down Expand Up @@ -76,7 +78,7 @@ public void ToFile_SavesManifestToFile()
var path = "./test-vc-package.json";

// Act
PackageManager.ToFile(manifest, path);
PackageManager.ToFile(manifest, path.ToAbsolutePath());

// Assert
Assert.True(File.Exists(path));
Expand All @@ -91,7 +93,7 @@ public void FromFile_LoadsManifestFromFile()
// Arrange
var manifest = PackageManager.CreatePackageManifest("1.0.0");
var path = "./test-vc-package.json";
PackageManager.ToFile(manifest, path);
PackageManager.ToFile(manifest, path.ToAbsolutePath());

// Act
var loadedManifest = PackageManager.FromFile(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
67 changes: 34 additions & 33 deletions src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text.Json;
using System.Threading.Tasks;
using System.Xml;
using Extensions;
using Microsoft.Build.Locator;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -45,9 +46,9 @@ internal partial class Build : NukeBuild
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
private static readonly string[] _moduleContentFolders = { "dist", "Localizations", "Scripts", "Content" };
private static readonly string[] _moduleContentFolders = ["dist", "Localizations", "Scripts", "Content"];

private static readonly string[] _sonarLongLiveBranches = { "master", "develop", "dev", "main" };
private static readonly string[] _sonarLongLiveBranches = ["master", "develop", "dev", "main"];
private static readonly HttpClient _httpClient = new();
private static int? _exitCode;

Expand All @@ -67,9 +68,9 @@ public static Solution Solution
get
{
var solutions = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly);
if (solutions.Any())
if (solutions.Length > 0)
{
return ProjectModelTasks.ParseSolution(solutions[0]);
return SolutionModelTasks.ParseSolution(solutions[0]);
}

Log.Warning("No solution files found in the current directory");
Expand Down Expand Up @@ -233,12 +234,13 @@ public static Solution Solution

protected static bool IsModule => ModuleManifestFile.FileExists();

private static readonly string[] cleanSearchPattern = new[] { "**/bin", "**/obj" };

public Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
var searchPattern = new[] { "**/bin", "**/obj" };
CleanSolution(searchPattern);
CleanSolution(cleanSearchPattern);
});

public Target Restore => _ => _
Expand Down Expand Up @@ -271,7 +273,7 @@ public static Solution Solution
.DependsOn(Compile)
.Executes(() =>
{
var testProjects = Solution.GetProjects("*.Test|*.Tests|*.Testing");
var testProjects = Solution.GetAllProjects("*.Test|*.Tests|*.Testing");
var outPath = RootDirectory / ".tmp";

foreach (var testProjectPath in testProjects.Select(p=> p.Path).ToArray())
Expand All @@ -294,7 +296,7 @@ public static Solution Solution

if (coberturaReports.Count > 0)
{
var reportGenerator = ToolResolver.GetPackageTool("dotnet-reportgenerator-globaltool",
var reportGenerator = ToolResolver.GetNuGetTool("dotnet-reportgenerator-globaltool",
"ReportGenerator.dll", "4.8.8", "netcoreapp3.0");
reportGenerator.Invoke(
$"-reports:{outPath / "**/coverage.cobertura.xml"} -targetdir:{outPath} -reporttypes:SonarQube");
Expand Down Expand Up @@ -532,7 +534,7 @@ private static void WebPackBuildMethod(Project webProject)

var modulesJsonFilePath = ModulesLocalDirectory / ModulesJsonName;
var externalManifests =
JsonConvert.DeserializeObject<List<ExternalModuleManifest>>(TextTasks.ReadAllText(modulesJsonFilePath));
JsonConvert.DeserializeObject<List<ExternalModuleManifest>>(modulesJsonFilePath.ReadAllText());
var externalManifest = externalManifests?.Find(x => x.Id == manifest.Id);

if (externalManifest != null)
Expand Down Expand Up @@ -582,8 +584,7 @@ private static void WebPackBuildMethod(Project webProject)
externalManifests?.Add(ExternalModuleManifest.FromManifest(manifest));
}

TextTasks.WriteAllText(modulesJsonFilePath,
JsonConvert.SerializeObject(externalManifests, Formatting.Indented));
modulesJsonFilePath.WriteAllText(JsonConvert.SerializeObject(externalManifests, Formatting.Indented));
});

public Target PublishManifestGit => _ => _
Expand All @@ -603,7 +604,7 @@ private static void WebPackBuildMethod(Project webProject)
.Requires(() => !IsModule)
.Executes(async () =>
{
var swashbuckle = ToolResolver.GetPackageTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll",
var swashbuckle = ToolResolver.GetNuGetTool("Swashbuckle.AspNetCore.Cli", "dotnet-swagger.dll",
framework: "netcoreapp3.0");
var projectPublishPath = ArtifactsDirectory / "publish" / $"{WebProject.Name}.dll";
var swaggerJsonPath = ArtifactsDirectory / "swagger.json";
Expand Down Expand Up @@ -715,14 +716,14 @@ private static void WebPackBuildMethod(Project webProject)
if (OperatingSystem.IsLinux())
{
const string sonarScript = "sonar-scanner";
var sonarScannerShPath = ToolPathResolver.GetPackageExecutable("dotnet-sonarscanner",
var sonarScannerShPath = NuGetToolPathResolver.GetPackageExecutable("dotnet-sonarscanner",
sonarScript, framework: framework)
.Replace("netcoreapp2.0", "net5.0")
.Replace("netcoreapp3.0", "net5.0");
var sonarScannerShRightPath = Directory.GetParent(sonarScannerShPath)?.Parent?.FullName ?? string.Empty;
var tmpFile = TemporaryDirectory / sonarScript;
FileSystemTasks.MoveFile(sonarScannerShPath, tmpFile);
FileSystemTasks.DeleteDirectory(sonarScannerShRightPath);
sonarScannerShRightPath.ToAbsolutePath().DeleteDirectory();
var sonarScriptDestinationPath = Path.Combine(sonarScannerShRightPath, sonarScript);
FileSystemTasks.MoveFile(tmpFile, sonarScriptDestinationPath);
Log.Information($"{sonarScript} path: {sonarScriptDestinationPath}");
Expand All @@ -748,7 +749,7 @@ private static void WebPackBuildMethod(Project webProject)
foreach (var moduleDirectory in Directory.GetDirectories(ModulesFolderPath))
{
var isGitRepository =
FileSystemTasks.FindParentDirectory(moduleDirectory, x => x.GetDirectories(".git").Any()) !=
moduleDirectory.ToAbsolutePath().FindParentOrSelf(x => x.GetDirectories(".git").Any()) !=
null;

if (isGitRepository)
Expand Down Expand Up @@ -831,7 +832,7 @@ private static void ClearTempOnExit()
{
if (ClearTempBeforeExit)
{
FileSystemTasks.DeleteDirectory(TemporaryDirectory);
TemporaryDirectory.DeleteDirectory();
}
}

Expand All @@ -841,7 +842,7 @@ private static void CreateNukeDirectory()

var nukeFiles = Directory.GetFiles(currentDirectory, ".nuke");

if (!nukeFiles.Any() && !Directory.Exists(Path.Join(currentDirectory, ".nuke")))
if (nukeFiles.Length == 0 && !Directory.Exists(Path.Join(currentDirectory, ".nuke")))
{
Console.WriteLine("No .nuke file found!");
var solutions = Directory.GetFiles(currentDirectory, "*.sln");
Expand All @@ -857,7 +858,7 @@ private static void CreateNukeDirectory()
CreateDotNuke(currentDirectory);
}
}
else if (nukeFiles.Any())
else if (nukeFiles.Length > 0)
{
var nukeFile = nukeFiles[0];
ConvertDotNukeFile(nukeFile);
Expand Down Expand Up @@ -893,21 +894,21 @@ private static void RegisterMSBuildLocator()
}
}

private static void ConvertDotNukeFile(string path)
private static void ConvertDotNukeFile(AbsolutePath path)
{
var directory = Path.GetDirectoryName(path);
var solutionPath = File.ReadLines(path).FirstOrDefault();
FileSystemTasks.DeleteFile(path);
path.DeleteFile();
CreateDotNuke(directory, solutionPath);
}

private static void CreateDotNuke(string path, string solutionPath = "")
{
var dotnukeDir = Path.Join(path, ".nuke");
var paramsFilePath = Path.Join(dotnukeDir, "parameters.json");
FileSystemTasks.EnsureExistingDirectory(dotnukeDir);
dotnukeDir.ToAbsolutePath().CreateDirectory();
var parameters = new NukeParameters { Solution = solutionPath };
SerializationTasks.JsonSerializeToFile(parameters, paramsFilePath);
JsonExtensions.WriteJson(paramsFilePath, parameters);
}

public static void CustomDotnetLogger(OutputType type, string text)
Expand All @@ -925,9 +926,9 @@ public static void ChangeProjectVersion(string versionPrefix = null, string vers
//theme
if (IsTheme)
{
var jObject = SerializationTasks.JsonDeserializeFromFile<JObject>(PackageJsonPath);
var jObject = JsonExtensions.ReadJson<JObject>(PackageJsonPath);
jObject["version"] = versionPrefix;
SerializationTasks.JsonSerializeToFile(jObject, Path.GetFullPath(PackageJsonPath));
JsonExtensions.WriteJson(Path.GetFullPath(PackageJsonPath), jObject);
return;
}

Expand Down Expand Up @@ -1172,15 +1173,15 @@ private void CompressExecuteMethod()

if (ModuleIgnoreFile.FileExists())
{
ignoredFiles = ignoredFiles.Concat(TextTasks.ReadAllLines(ModuleIgnoreFile)).ToArray();
ignoredFiles = ignoredFiles.Concat(ModuleIgnoreFile.ReadAllLines()).ToArray();
}

ignoredFiles = ignoredFiles.Select(x => x.Trim()).Distinct().ToArray();

var keepFiles = Array.Empty<string>();
if (ModuleKeepFile.FileExists())
{
keepFiles = TextTasks.ReadAllLines(ModuleKeepFile).ToArray();
keepFiles = ModuleKeepFile.ReadAllLines().ToArray();
}

ArtifactPacker.CompressModule(options => options.WithSourceDirectory(ModuleOutputDirectory)
Expand All @@ -1202,33 +1203,33 @@ private static void CleanSolution(string[] searchPattern, AbsolutePath[] ignoreP
{
if (SourceDirectory.DirectoryExists())
{
if (ignorePaths?.Any() == true)
if (ignorePaths?.Length > 0)
{
SourceDirectory
.GlobDirectories(searchPattern)
.Where(directory => !ignorePaths.Any(p => p.Contains(directory)))
.ForEach(FileSystemTasks.DeleteDirectory);
.ForEach(p => p.DeleteDirectory());
}
else
{
SourceDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory);
SourceDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory());
}

if (TestsDirectory.DirectoryExists())
{
TestsDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory);
TestsDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory());
}

if (SamplesDirectory.DirectoryExists())
{
SamplesDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory);
SamplesDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory());
}
}
else
{
RootDirectory.GlobDirectories(searchPattern).ForEach(FileSystemTasks.DeleteDirectory);
RootDirectory.GlobDirectories(searchPattern).ForEach(p => p.DeleteDirectory());
}

FileSystemTasks.EnsureCleanDirectory(ArtifactsDirectory);
ArtifactsDirectory.CreateOrCleanDirectory();
}
}
10 changes: 5 additions & 5 deletions src/VirtoCommerce.Build/Cloud/Build.SaaS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private async Task PrepareDockerContextMethod()
var modulesPath = platformDirectory / "modules";
var dockerfilePath = dockerBuildContext / "Dockerfile";

FileSystemTasks.EnsureCleanDirectory(dockerBuildContext);
dockerBuildContext.CreateOrCleanDirectory();

await HttpTasks.HttpDownloadFileAsync(DockerfileUrl, dockerfilePath);

Expand Down Expand Up @@ -196,7 +196,7 @@ private static void CopyModules(AbsolutePath modulesPath, AbsolutePath modulesSo
var solutions = Directory.EnumerateFiles(solutionDir, "*.sln");
Assert.True(solutions.Count() == 1, $"Solutions found: {solutions.Count()}");
var solutionPath = solutions.FirstOrDefault();
var solution = ProjectModelTasks.ParseSolution(solutionPath);
var solution = SolutionModelTasks.ParseSolution(solutionPath);
var webProject = solution.AllProjects.First(p => p.Name.EndsWith(".Web"));

WebPackBuildMethod(webProject);
Expand Down Expand Up @@ -271,7 +271,6 @@ private static void CopyPlatformDirectory(AbsolutePath platformDirectory, Absolu
};
listener.Start();


Log.Information("Openning browser window");
var authUrl = $"{CloudUrl}/externalsignin?authenticationType={CloudAuthProvider}&returnUrl=/api/saas/token/{port}";
Process.Start(new ProcessStartInfo(authUrl) { UseShellExecute = true });
Expand Down Expand Up @@ -303,7 +302,8 @@ private async Task<string> GetCloudTokenAsync()

private void SaveCloudToken(string token)
{
FileSystemTasks.EnsureExistingDirectory(Path.GetDirectoryName(CloudTokenFile));
AbsolutePath cloudTokenDir = Path.GetDirectoryName(CloudTokenFile);
cloudTokenDir.CreateDirectory();
File.WriteAllText(CloudTokenFile, token);
}

Expand Down Expand Up @@ -378,7 +378,7 @@ private void SaveCloudToken(string token)
public Target CloudUp => _ => _
.DependsOn(CloudInit, CloudDeploy);

private static ISaaSDeploymentApi CreateVirtocloudClient(string url, string token)
private static SaaSDeploymentApi CreateVirtocloudClient(string url, string token)
{
var config = new VirtoCloud.Client.Client.Configuration();
config.BasePath = url;
Expand Down
5 changes: 3 additions & 2 deletions src/VirtoCommerce.Build/Cloud/Client/VirtoCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Cloud.Models;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Cloud.Client;

Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task<string> UpdateEnvironmentAsync(string manifest, string appProj

public async Task UpdateEnvironmentAsync(CloudEnvironment environment)
{
var jsonString = SerializationTasks.JsonSerialize(environment);
var jsonString = JsonExtensions.ToJson(environment);
var content = new StringContent(jsonString, Encoding.UTF8, "application/json");
var response = await _client.PutAsync(new Uri("api/saas/environments", UriKind.Relative), content);
if (!response.IsSuccessStatusCode)
Expand All @@ -65,7 +66,7 @@ public async Task<CloudEnvironment> GetEnvironment(string environmentName, strin
}

var responseContent = await response.Content.ReadAsStringAsync();
var env = SerializationTasks.JsonDeserialize<CloudEnvironment>(responseContent);
var env = JsonExtensions.GetJson<CloudEnvironment>(responseContent);
return env;
}
}
4 changes: 2 additions & 2 deletions src/VirtoCommerce.Build/Cloud/Models/HelmParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.ComponentModel;
using System.Globalization;
using Newtonsoft.Json;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Cloud.Models
{
Expand All @@ -17,7 +17,7 @@ public HelmParameter(bool? forceString = default, string name = default, string
public override string ToString()
{
var parameter = new V1alpha1HelmParameter(null, Name, Value);
return SerializationTasks.JsonSerialize(parameter);
return parameter.ToJson();
}

public class HelmJsonConverter : JsonConverter
Expand Down
23 changes: 23 additions & 0 deletions src/VirtoCommerce.Build/Extensions/PathExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nuke.Common.IO;
using System.IO;

namespace Extensions
{
public static class PathExtension
{
public static AbsolutePath ToAbsolutePath(this string path)
{
if(path == null)
{
return null;
}

return AbsolutePath.Create(Path.GetFullPath(path));
}
}
}
Loading

0 comments on commit 118c7b1

Please sign in to comment.