Skip to content

Commit 447bf20

Browse files
committed
Use Cake for managing paths
1 parent 8360f93 commit 447bf20

11 files changed

Lines changed: 55 additions & 71 deletions

Build/Context.cs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ namespace DotNetNuke.Build
55
{
66
using System;
77
using System.Globalization;
8-
using System.IO;
98

109
using Cake.Common;
1110
using Cake.Common.Build;
@@ -19,8 +18,6 @@ namespace DotNetNuke.Build
1918
using Cake.Frosting;
2019
using Cake.Json;
2120

22-
using Path = System.IO.Path;
23-
2421
/// <inheritdoc />
2522
public class Context : FrostingContext
2623
{
@@ -45,30 +42,26 @@ public Context(ICakeContext context)
4542
//////////////////////////////////////////////////////////////////////
4643

4744
// Define directories.
48-
this.RootFolder = "./";
49-
this.RootDir = context.MakeAbsolute(context.Directory(this.RootFolder));
45+
this.RootDir = context.MakeAbsolute(context.Directory("./"));
5046
context.Verbose($"RootDir: {this.RootDir}");
5147

52-
this.TempFolder = "./Temp/";
53-
this.TempDir = context.Directory(this.TempFolder);
48+
this.TempDir = context.Directory("./Temp/");
5449
context.Information($"TempDir: {this.TempDir}");
5550

56-
this.ArtifactsFolder = "./Artifacts/";
57-
this.ArtifactsDir = context.Directory(this.ArtifactsFolder);
51+
this.ArtifactsDir = context.Directory("./Artifacts/");
5852
context.Information($"ArtifactsDir: {this.ArtifactsDir}");
5953

60-
this.WebsiteFolder = "./Website/";
61-
this.WebsiteDir = context.Directory(this.WebsiteFolder);
54+
this.WebsiteDir = context.Directory("./Website/");
6255
context.Information($"WebsiteDir: {this.WebsiteDir}");
6356

6457
// Global information variables
6558
this.IsRunningInCI = false;
6659

67-
this.DnnSolutionPath = "./DNN_Platform.sln";
60+
this.DnnSolutionPath = context.File("./DNN_Platform.sln");
6861

6962
this.SqlDataProviderExists = false;
7063

71-
const string settingsFile = "./settings.local.json";
64+
var settingsFile = context.File("./settings.local.json");
7265
this.Settings = LoadSettings(context, settingsFile);
7366
this.WriteSettings(context, settingsFile);
7467

@@ -101,35 +94,23 @@ public Context(ICakeContext context)
10194
public bool SqlDataProviderExists { get; set; }
10295

10396
/// <summary>Gets or sets the path to the DNN solution.</summary>
104-
public string DnnSolutionPath { get; set; }
97+
public FilePath DnnSolutionPath { get; set; }
10598

10699
/// <summary>Gets or sets a value indicating whether this build is running in a CI environment.</summary>
107100
public bool IsRunningInCI { get; set; }
108101

109102
/// <summary>Gets or sets the path to the root of the repository.</summary>
110103
public DirectoryPath RootDir { get; set; }
111104

112-
/// <summary>Gets or sets the relative path to the root of the repository.</summary>
113-
public string RootFolder { get; set; }
114-
115105
/// <summary>Gets or sets the path to the website directory.</summary>
116106
public ConvertableDirectoryPath WebsiteDir { get; set; }
117107

118-
/// <summary>Gets or sets the relative path to the website directory.</summary>
119-
public string WebsiteFolder { get; set; }
120-
121108
/// <summary>Gets or sets the path to the artifacts directory.</summary>
122109
public ConvertableDirectoryPath ArtifactsDir { get; set; }
123110

124-
/// <summary>Gets or sets the relative path to the artifacts directory.</summary>
125-
public string ArtifactsFolder { get; set; }
126-
127111
/// <summary>Gets or sets the path to the temp directory.</summary>
128112
public ConvertableDirectoryPath TempDir { get; set; }
129113

130-
/// <summary>Gets or sets the relative path to the temp directory.</summary>
131-
public string TempFolder { get; set; }
132-
133114
/// <summary>Gets or sets the build configuration, e.g. Debug or Release.</summary>
134115
public string BuildConfiguration { get; set; }
135116

@@ -176,22 +157,22 @@ public string GetProductVersion()
176157
return this.ProductVersion;
177158
}
178159

179-
private static LocalSettings LoadSettings(ICakeContext context, string settingsFile)
160+
private static LocalSettings LoadSettings(ICakeContext context, FilePath settingsFile)
180161
{
181-
if (File.Exists(settingsFile))
162+
if (context.FileExists(settingsFile))
182163
{
183-
context.Information((FormattableLogActionEntry log) => log($"Loading settings from {Path.GetFullPath(settingsFile)}"));
164+
context.Information((FormattableLogActionEntry log) => log($"Loading settings from {settingsFile.FullPath}"));
184165
return context.DeserializeJsonFromFile<LocalSettings>(settingsFile);
185166
}
186167

187-
context.Information((FormattableLogActionEntry log) => log($"Did not find settings file {Path.GetFullPath(settingsFile)}"));
168+
context.Information((FormattableLogActionEntry log) => log($"Did not find settings file {settingsFile.FullPath}"));
188169
return new LocalSettings();
189170
}
190171

191-
private void WriteSettings(ICakeContext context, string settingsFile)
172+
private void WriteSettings(ICakeContext context, FilePath settingsFile)
192173
{
193174
context.SerializeJsonToPrettyFile(settingsFile, this.Settings);
194-
context.Information((FormattableLogActionEntry log) => log($"Saved settings to {Path.GetFullPath(settingsFile)}"));
175+
context.Information((FormattableLogActionEntry log) => log($"Saved settings to {settingsFile.FullPath}"));
195176
context.Debug(log => log("{0}", $"Settings: {context.SerializeJson(this.Settings)}"));
196177
}
197178
}

Build/Tasks/CopyToDevSite.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public sealed class CopyToDevSite : FrostingTask<Context>
2121
public override void Run(Context context)
2222
{
2323
context.CleanDirectory(context.Settings.WebsitePath);
24-
var files = context.GetFilesByPatterns(context.WebsiteFolder, IncludeAll, context.PackagingPatterns.InstallExclude);
25-
files.Add(context.GetFilesByPatterns(context.WebsiteFolder, context.PackagingPatterns.InstallInclude));
24+
var files = context.GetFilesByPatterns(context.WebsiteDir, IncludeAll, context.PackagingPatterns.InstallExclude);
25+
files.Add(context.GetFilesByPatterns(context.WebsiteDir, context.PackagingPatterns.InstallInclude));
2626
context.Information("Copying {0} files to {1}", files.Count, context.Settings.WebsitePath);
2727
context.CopyFiles(files, context.Settings.WebsitePath, true);
2828
}

Build/Tasks/CopyWebsite.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public sealed class CopyWebsite : FrostingTask<Context>
1717
/// <inheritdoc />
1818
public override void Run(Context context)
1919
{
20-
context.CopyFiles(context.GetFiles("./DNN Platform/Website/**/*"), context.WebsiteFolder, true);
20+
context.CopyFiles(context.GetFiles("./DNN Platform/Website/**/*"), context.WebsiteDir, true);
2121
}
2222
}
2323
}

Build/Tasks/CopyWebsiteBinFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public override void Run(Context context)
1717
{
1818
context.CopyFiles(
1919
context.GetFiles("./DNN Platform/Website/bin/**/*"),
20-
context.WebsiteFolder + "bin/",
20+
context.WebsiteDir + context.Directory("bin/"),
2121
true);
2222
}
2323
}

Build/Tasks/CreateDeploy.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ public sealed class CreateDeploy : FrostingTask<Context>
2222
/// <inheritdoc />
2323
public override void Run(Context context)
2424
{
25-
context.CreateDirectory(context.ArtifactsFolder);
26-
var packageZip = $"{context.ArtifactsFolder}DNN_Platform_{context.GetBuildNumber()}_Deploy.zip";
25+
context.CreateDirectory(context.ArtifactsDir);
26+
var packageZip = context.ArtifactsDir + context.File($"DNN_Platform_{context.GetBuildNumber()}_Deploy.zip");
2727

28-
const string deployFolder = "./DotNetNuke/";
29-
var deployDir = context.Directory(deployFolder);
28+
var deployDir = context.Directory("./DotNetNuke/");
3029
Directory.Move(context.WebsiteDir.Path.FullPath, deployDir.Path.FullPath);
31-
var files = context.GetFilesByPatterns(deployFolder, IncludeAll, context.PackagingPatterns.InstallExclude);
32-
files.Add(context.GetFilesByPatterns(deployFolder, context.PackagingPatterns.InstallInclude));
30+
var files = context.GetFilesByPatterns(deployDir, IncludeAll, context.PackagingPatterns.InstallExclude);
31+
files.Add(context.GetFilesByPatterns(deployDir, context.PackagingPatterns.InstallInclude));
3332
context.Zip(string.Empty, packageZip, files);
3433
context.AddFilesToZip(packageZip, "./Build/Deploy", context.GetFiles("./Build/Deploy/*"), append: true);
3534
Directory.Move(deployDir.Path.FullPath, context.WebsiteDir.Path.FullPath);

Build/Tasks/CreateInstall.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public sealed class CreateInstall : FrostingTask<Context>
2222
/// <inheritdoc />
2323
public override void Run(Context context)
2424
{
25-
context.CreateDirectory(context.ArtifactsFolder);
26-
var files = context.GetFilesByPatterns(context.WebsiteFolder, IncludeAll, context.PackagingPatterns.InstallExclude);
27-
files.Add(context.GetFilesByPatterns(context.WebsiteFolder, context.PackagingPatterns.InstallInclude));
25+
context.CreateDirectory(context.ArtifactsDir);
26+
var files = context.GetFilesByPatterns(context.WebsiteDir, IncludeAll, context.PackagingPatterns.InstallExclude);
27+
files.Add(context.GetFilesByPatterns(context.WebsiteDir, context.PackagingPatterns.InstallInclude));
2828
context.Information("Zipping {0} files for Install zip", files.Count);
2929

30-
var packageZip = $"{context.ArtifactsFolder}DNN_Platform_{context.GetBuildNumber()}_Install.zip";
31-
context.Zip(context.WebsiteFolder, packageZip, files);
30+
var packageZip = context.ArtifactsDir + context.File($"DNN_Platform_{context.GetBuildNumber()}_Install.zip");
31+
context.Zip(context.WebsiteDir, packageZip, files);
3232
}
3333
}
3434
}

Build/Tasks/CreateSymbols.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public sealed class CreateSymbols : FrostingTask<Context>
1919
/// <inheritdoc />
2020
public override void Run(Context context)
2121
{
22-
context.CreateDirectory(context.ArtifactsFolder);
23-
var packageZip = $"{context.ArtifactsFolder}DNN_Platform_{context.GetBuildNumber()}_Symbols.zip";
22+
context.CreateDirectory(context.ArtifactsDir);
23+
var packageZip = context.ArtifactsDir + context.File($"DNN_Platform_{context.GetBuildNumber()}_Symbols.zip");
2424
context.Zip("./Build/Symbols/", packageZip, context.GetFiles("./Build/Symbols/*"));
2525

2626
// Fix for WebUtility symbols missing from bin folder
2727
context.CopyFiles(
2828
context.GetFiles("./DNN Platform/DotNetNuke.WebUtility/bin/DotNetNuke.WebUtility.*"),
29-
context.WebsiteFolder + "bin/");
29+
context.WebsiteDir + context.Directory("bin/"));
3030
var files = context.GetFilesByPatterns(
31-
context.WebsiteFolder,
31+
context.WebsiteDir,
3232
context.PackagingPatterns.SymbolsInclude,
3333
context.PackagingPatterns.SymbolsExclude);
34-
var resFile = context.ZipToBytes(context.WebsiteFolder.TrimEnd('/'), files);
34+
var resFile = context.ZipToBytes(context.WebsiteDir, files);
3535
context.AddBinaryFileToZip(packageZip, resFile, "Resources.zip", true);
3636
}
3737
}

Build/Tasks/CreateUpgrade.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ public sealed class CreateUpgrade : FrostingTask<Context>
2626
/// <inheritdoc />
2727
public override void Run(Context context)
2828
{
29-
context.CreateDirectory(context.ArtifactsFolder);
29+
context.CreateDirectory(context.ArtifactsDir);
3030
var excludes = new string[context.PackagingPatterns.InstallExclude.Length + context.PackagingPatterns.UpgradeExclude.Length];
3131
context.PackagingPatterns.InstallExclude.CopyTo(excludes, 0);
3232
context.PackagingPatterns.UpgradeExclude.CopyTo(excludes, context.PackagingPatterns.InstallExclude.Length);
33-
var files = context.GetFilesByPatterns(context.WebsiteFolder, IncludeAll, excludes);
34-
files.Add(context.GetFilesByPatterns(context.WebsiteFolder, context.PackagingPatterns.UpgradeInclude));
33+
var files = context.GetFilesByPatterns(context.WebsiteDir, IncludeAll, excludes);
34+
files.Add(context.GetFilesByPatterns(context.WebsiteDir, context.PackagingPatterns.UpgradeInclude));
3535
context.Information("Zipping {0} files for Upgrade zip", files.Count);
3636

37-
var packageZip = $"{context.ArtifactsFolder}DNN_Platform_{context.GetBuildNumber()}_Upgrade.zip";
38-
context.Zip(context.WebsiteFolder, packageZip, files);
37+
var packageZip = context.ArtifactsDir + context.File($"DNN_Platform_{context.GetBuildNumber()}_Upgrade.zip");
38+
context.Zip(context.WebsiteDir, packageZip, files);
3939
}
4040
}
4141
}

Build/Tasks/GeneratePackagesChecksums.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace DotNetNuke.Build.Tasks
1111
using System.Text;
1212

1313
using Cake.Common.Diagnostics;
14+
using Cake.Common.IO;
1415
using Cake.Core.IO;
16+
using Cake.FileHelpers;
1517
using Cake.Frosting;
1618

1719
using Dnn.CakeUtils;
@@ -41,7 +43,7 @@ public override void Run(Context context)
4143
|------------|----------|
4244
""");
4345

44-
var files = context.GetFilesByPatterns(context.ArtifactsFolder, ZipFiles);
46+
var files = context.GetFilesByPatterns(context.ArtifactsDir, ZipFiles);
4547
foreach (var file in files)
4648
{
4749
var fileName = file.GetFilename();
@@ -50,8 +52,8 @@ public override void Run(Context context)
5052
}
5153

5254
checksumsMarkdown.AppendLine();
53-
var filePath = Path.Combine(context.ArtifactsFolder, "checksums.md");
54-
File.WriteAllText(filePath, checksumsMarkdown.ToString());
55+
var filePath = context.ArtifactsDir + context.File("checksums.md");
56+
context.FileWriteText(filePath, checksumsMarkdown.ToString());
5557

5658
context.Information($"Saved checksums to {filePath}");
5759
}

Build/Tasks/OtherPackages.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ public override void Run(Context context)
4444

4545
private static void PackageOtherPackage(Context context, OtherPackage package)
4646
{
47-
var srcFolder = "./" + package.Folder;
47+
var srcFolder = context.RootDir + context.Directory(package.Folder);
4848
var files = package.Excludes.Length == 0
49-
? context.GetFiles(srcFolder + "**/*")
49+
? context.GetFiles($"{srcFolder}**/*")
5050
: context.GetFilesByPatterns(srcFolder, IncludeAll, package.Excludes);
5151
var version = "00.00.00";
52-
foreach (var dnn in context.GetFiles(srcFolder + "**/*.dnn"))
52+
foreach (var dnn in context.GetFiles($"{srcFolder}**/*.dnn"))
5353
{
5454
version = context.XmlPeek(dnn, "dotnetnuke/packages/package/@version");
5555
}
5656

5757
context.CreateDirectory(package.Destination);
5858

59-
var packageZip = $"{context.WebsiteFolder}{package.Destination}/{package.Name}_{version}_Install.{package.Extension}";
60-
context.Information("Packaging {0}", packageZip);
61-
context.Zip(srcFolder, packageZip, files);
59+
var destination = context.WebsiteDir + context.Directory(package.Destination);
60+
var packageZipName = context.File($"{package.Name}_{version}_Install.{package.Extension}");
61+
var packageZipPath = destination + packageZipName;
62+
context.Information("Packaging {0}", packageZipPath);
63+
context.Zip(srcFolder, packageZipPath, files);
6264
}
6365

6466
private sealed class OtherPackage
@@ -71,7 +73,7 @@ private sealed class OtherPackage
7173

7274
public string Extension { get; set; } = "zip";
7375

74-
public string[] Excludes { get; set; } = Array.Empty<string>();
76+
public string[] Excludes { get; set; } = [];
7577
}
7678
}
7779
}

0 commit comments

Comments
 (0)