forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract common component packaging task
Fixes dnnsoftware#5332 Fixes dnnsoftware#5997 Fixes dnnsoftware#6173
- Loading branch information
Showing
9 changed files
with
143 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
namespace DotNetNuke.Build.Tasks | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Xml; | ||
|
||
using Cake.Common.Diagnostics; | ||
using Cake.Common.IO; | ||
using Cake.Frosting; | ||
using Dnn.CakeUtils; | ||
namespace DotNetNuke.Build.Tasks; | ||
|
||
/// <summary>A cake task to generate the ASP.NET MVC package.</summary> | ||
public sealed class PackageAspNetMvc : FrostingTask<Context> | ||
/// <summary>A cake task to generate the ASP.NET MVC package.</summary> | ||
public sealed class PackageAspNetMvc : PackageComponentTask | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="PackageAspNetMvc"/> class.</summary> | ||
public PackageAspNetMvc() | ||
: base("AspNetMvc", "System.Web.Mvc.dll", "Microsoft.AspNetMvc") | ||
{ | ||
/// <inheritdoc/> | ||
public override void Run(Context context) | ||
{ | ||
var binDir = context.WebsiteDir.Path.Combine("bin"); | ||
var mainAssemblyPath = binDir.CombineWithFilePath("System.Web.Mvc.dll"); | ||
var packageVersion = context.GetAssemblyFileVersion(mainAssemblyPath); | ||
|
||
var packageZip = context.WebsiteDir.Path.CombineWithFilePath($"Install/Library/AspNetMvc_{packageVersion}_Install.zip"); | ||
var packageDir = context.Directory("DNN Platform/Components/Microsoft.AspNetMvc"); | ||
|
||
context.Information($"Creating {packageZip}"); | ||
context.Zip( | ||
packageDir.ToString(), | ||
packageZip, | ||
context.GetFilesByPatterns(packageDir, new[] { "*" }, new[] { "*.dnn" })); | ||
|
||
var manifestPath = context.GetFiles(packageDir.Path.CombineWithFilePath("*.dnn").ToString()).Single(); | ||
context.Information($"Reading manifest from {manifestPath}"); | ||
var manifest = new XmlDocument(); | ||
manifest.LoadXml(context.ReadFile(manifestPath)); | ||
var assemblies = | ||
from XmlNode assemblyNode in manifest.SelectNodes("//assembly") | ||
from XmlNode childNode in assemblyNode.ChildNodes | ||
where childNode.LocalName.Equals("name") | ||
select childNode; | ||
|
||
foreach (var assemblyNameNode in assemblies) | ||
{ | ||
var assemblyPath = binDir.CombineWithFilePath(assemblyNameNode.InnerText); | ||
context.Information($"Adding {assemblyPath} to {packageZip}"); | ||
context.AddFilesToZip( | ||
packageZip, | ||
context.MakeAbsolute(context.WebsiteDir.Path), | ||
context.GetFiles(assemblyPath.ToString()), | ||
append: true); | ||
|
||
var versionNode = assemblyNameNode.ParentNode.ChildNodes.Cast<XmlNode>() | ||
.SingleOrDefault(childNode => childNode.LocalName.Equals("version")); | ||
if (versionNode != null) | ||
{ | ||
versionNode.InnerText = context.GetAssemblyFileVersion(assemblyPath); | ||
context.Information($"Set {assemblyPath} version to {versionNode.InnerText}"); | ||
} | ||
} | ||
|
||
manifest.SelectSingleNode("//package[@version]").Attributes["version"].Value = packageVersion; | ||
|
||
context.AddXmlFileToZip(packageZip, manifest, manifestPath.GetFilename().ToString(), append: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
namespace DotNetNuke.Build.Tasks | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Xml; | ||
|
||
using Cake.Common.Diagnostics; | ||
using Cake.Common.IO; | ||
using Cake.Frosting; | ||
using Dnn.CakeUtils; | ||
namespace DotNetNuke.Build.Tasks; | ||
|
||
/// <summary>A cake task to generate the ASP.NET Web API package.</summary> | ||
public sealed class PackageAspNetWebApi : FrostingTask<Context> | ||
/// <summary>A cake task to generate the ASP.NET Web API package.</summary> | ||
public sealed class PackageAspNetWebApi : PackageComponentTask | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="PackageAspNetWebApi"/> class.</summary> | ||
public PackageAspNetWebApi() | ||
: base("AspNetWebApi", "System.Web.Http.dll", "Microsoft.AspNetWebApi") | ||
{ | ||
/// <inheritdoc/> | ||
public override void Run(Context context) | ||
{ | ||
var binDir = context.WebsiteDir.Path.Combine("bin"); | ||
var mainAssemblyPath = binDir.CombineWithFilePath("System.Web.Http.dll"); | ||
var packageVersion = context.GetAssemblyFileVersion(mainAssemblyPath); | ||
|
||
var packageZip = context.WebsiteDir.Path.CombineWithFilePath($"Install/Library/AspNetWebApi_{packageVersion}_Install.zip"); | ||
var packageDir = context.Directory("DNN Platform/Components/Microsoft.AspNetWebApi"); | ||
|
||
context.Information($"Creating {packageZip}"); | ||
context.Zip( | ||
packageDir.ToString(), | ||
packageZip, | ||
context.GetFilesByPatterns(packageDir, new[] { "*" }, new[] { "*.dnn" })); | ||
|
||
var manifestPath = context.GetFiles(packageDir.Path.CombineWithFilePath("*.dnn").ToString()).Single(); | ||
context.Information($"Reading manifest from {manifestPath}"); | ||
var manifest = new XmlDocument(); | ||
manifest.LoadXml(context.ReadFile(manifestPath)); | ||
var assemblies = | ||
from XmlNode assemblyNode in manifest.SelectNodes("//assembly") | ||
from XmlNode childNode in assemblyNode.ChildNodes | ||
where childNode.LocalName.Equals("name") | ||
select childNode; | ||
|
||
foreach (var assemblyNameNode in assemblies) | ||
{ | ||
var assemblyPath = binDir.CombineWithFilePath(assemblyNameNode.InnerText); | ||
context.Information($"Adding {assemblyPath} to {packageZip}"); | ||
context.AddFilesToZip( | ||
packageZip, | ||
context.MakeAbsolute(context.WebsiteDir.Path), | ||
context.GetFiles(assemblyPath.ToString()), | ||
append: true); | ||
|
||
var versionNode = assemblyNameNode.ParentNode.ChildNodes.Cast<XmlNode>() | ||
.SingleOrDefault(childNode => childNode.LocalName.Equals("version")); | ||
if (versionNode != null) | ||
{ | ||
versionNode.InnerText = context.GetAssemblyFileVersion(assemblyPath); | ||
context.Information($"Set {assemblyPath} version to {versionNode.InnerText}"); | ||
} | ||
} | ||
|
||
manifest.SelectSingleNode("//package[@version]").Attributes["version"].Value = packageVersion; | ||
|
||
context.AddXmlFileToZip(packageZip, manifest, manifestPath.GetFilename().ToString(), append: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
namespace DotNetNuke.Build.Tasks | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Xml; | ||
|
||
using Cake.Common.Diagnostics; | ||
using Cake.Common.IO; | ||
using Cake.Frosting; | ||
using Dnn.CakeUtils; | ||
namespace DotNetNuke.Build.Tasks; | ||
|
||
/// <summary>A cake task to generate the ASP.NET Web Pages package.</summary> | ||
public sealed class PackageAspNetWebPages : FrostingTask<Context> | ||
/// <summary>A cake task to generate the ASP.NET Web Pages package.</summary> | ||
public sealed class PackageAspNetWebPages : PackageComponentTask | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="PackageAspNetWebPages"/> class.</summary> | ||
public PackageAspNetWebPages() | ||
: base("AspNetWebPages", "System.Web.WebPages.dll", "Microsoft.AspNetWebPages") | ||
{ | ||
/// <inheritdoc/> | ||
public override void Run(Context context) | ||
{ | ||
var binDir = context.WebsiteDir.Path.Combine("bin"); | ||
var mainAssemblyPath = binDir.CombineWithFilePath("System.Web.WebPages.dll"); | ||
var packageVersion = context.GetAssemblyFileVersion(mainAssemblyPath); | ||
|
||
var packageZip = context.WebsiteDir.Path.CombineWithFilePath($"Install/Library/AspNetWebPages_{packageVersion}_Install.zip"); | ||
var packageDir = context.Directory("DNN Platform/Components/Microsoft.AspNetWebPages"); | ||
|
||
context.Information($"Creating {packageZip}"); | ||
context.Zip( | ||
packageDir.ToString(), | ||
packageZip, | ||
context.GetFilesByPatterns(packageDir, new[] { "*" }, new[] { "*.dnn" })); | ||
|
||
var manifestPath = context.GetFiles(packageDir.Path.CombineWithFilePath("*.dnn").ToString()).Single(); | ||
context.Information($"Reading manifest from {manifestPath}"); | ||
var manifest = new XmlDocument(); | ||
manifest.LoadXml(context.ReadFile(manifestPath)); | ||
var assemblies = | ||
from XmlNode assemblyNode in manifest.SelectNodes("//assembly") | ||
from XmlNode childNode in assemblyNode.ChildNodes | ||
where childNode.LocalName.Equals("name") | ||
select childNode; | ||
|
||
foreach (var assemblyNameNode in assemblies) | ||
{ | ||
var assemblyPath = binDir.CombineWithFilePath(assemblyNameNode.InnerText); | ||
context.Information($"Adding {assemblyPath} to {packageZip}"); | ||
context.AddFilesToZip( | ||
packageZip, | ||
context.MakeAbsolute(context.WebsiteDir.Path), | ||
context.GetFiles(assemblyPath.ToString()), | ||
append: true); | ||
|
||
var versionNode = assemblyNameNode.ParentNode.ChildNodes.Cast<XmlNode>() | ||
.SingleOrDefault(childNode => childNode.LocalName.Equals("version")); | ||
if (versionNode != null) | ||
{ | ||
versionNode.InnerText = context.GetAssemblyFileVersion(assemblyPath); | ||
context.Information($"Set {assemblyPath} version to {versionNode.InnerText}"); | ||
} | ||
} | ||
|
||
manifest.SelectSingleNode("//package[@version]").Attributes["version"].Value = packageVersion; | ||
|
||
context.AddXmlFileToZip(packageZip, manifest, manifestPath.GetFilename().ToString(), append: true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
|
||
namespace DotNetNuke.Build.Tasks; | ||
|
||
using System.Linq; | ||
using System.Xml; | ||
using Cake.Common.Diagnostics; | ||
using Cake.Common.IO; | ||
using Cake.Core.IO; | ||
using Cake.Frosting; | ||
using Dnn.CakeUtils; | ||
|
||
/// <summary>Provides the base functionality for packaging a folder inside Components.</summary> | ||
public abstract class PackageComponentTask : FrostingTask<Context> | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="PackageComponentTask"/> class.</summary> | ||
/// <param name="componentName">The name of the component.</param> | ||
/// <param name="primaryAssemblyName">The name of the primary assembly.</param> | ||
/// <param name="componentFolderName">The name of the folder in <c>DNN Platform/Components/</c>.</param> | ||
protected PackageComponentTask(string componentName, FilePath primaryAssemblyName = null, DirectoryPath componentFolderName = null) | ||
{ | ||
this.ComponentName = componentName; | ||
this.ComponentFolderName = componentFolderName ?? componentName; | ||
this.PrimaryAssemblyName = primaryAssemblyName ?? $"{componentName}.dll"; | ||
} | ||
|
||
/// <summary>Gets the name of the component.</summary> | ||
public string ComponentName { get; } | ||
|
||
/// <summary>Gets the name of the folder in <c>DNN Platform/Components/</c> where the component files are.</summary> | ||
public DirectoryPath ComponentFolderName { get; } | ||
|
||
/// <summary>Gets the name of the primary assembly.</summary> | ||
public FilePath PrimaryAssemblyName { get; } | ||
|
||
/// <inheritdoc /> | ||
public override void Run(Context context) | ||
{ | ||
var binDir = context.WebsiteDir.Path.Combine("bin"); | ||
var mainAssemblyPath = binDir.CombineWithFilePath(this.PrimaryAssemblyName); | ||
var packageVersion = context.GetAssemblyFileVersion(mainAssemblyPath); | ||
|
||
var packageZip = context.WebsiteDir.Path.CombineWithFilePath($"Install/Library/{this.ComponentName}_{packageVersion}_Install.zip"); | ||
var packageDir = context.Directory($"DNN Platform/Components/{this.ComponentFolderName}"); | ||
|
||
context.Information($"Creating {packageZip}"); | ||
context.Zip( | ||
packageDir.ToString(), | ||
packageZip, | ||
context.GetFilesByPatterns(packageDir, new[] { "*" }, new[] { "*.dnn" })); | ||
|
||
var manifestPath = context.GetFiles(packageDir.Path.CombineWithFilePath("*.dnn").ToString()).Single(); | ||
context.Information($"Reading manifest from {manifestPath}"); | ||
var manifest = new XmlDocument(); | ||
manifest.LoadXml(context.ReadFile(manifestPath)); | ||
var assemblies = | ||
from XmlNode assemblyNode in manifest.SelectNodes("//assembly") | ||
from XmlNode childNode in assemblyNode.ChildNodes | ||
where childNode.LocalName.Equals("name") | ||
select childNode; | ||
|
||
foreach (var assemblyNameNode in assemblies) | ||
{ | ||
var assemblyPath = binDir.CombineWithFilePath(assemblyNameNode.InnerText); | ||
context.Information($"Adding {assemblyPath} to {packageZip}"); | ||
context.AddFilesToZip( | ||
packageZip, | ||
context.MakeAbsolute(context.WebsiteDir.Path), | ||
context.GetFiles(assemblyPath.ToString()), | ||
append: true); | ||
|
||
var versionNode = assemblyNameNode.ParentNode?.ChildNodes.Cast<XmlNode>() | ||
.SingleOrDefault(childNode => childNode.LocalName.Equals("version")); | ||
if (versionNode != null) | ||
{ | ||
versionNode.InnerText = context.GetAssemblyFileVersion(assemblyPath); | ||
context.Information($"Set {assemblyPath} version to {versionNode.InnerText}"); | ||
} | ||
} | ||
|
||
manifest.SelectSingleNode("//package[@version]").Attributes["version"].Value = packageVersion; | ||
|
||
context.AddXmlFileToZip(packageZip, manifest, manifestPath.GetFilename().ToString(), append: true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,14 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information | ||
namespace DotNetNuke.Build.Tasks | ||
{ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Xml; | ||
|
||
using Cake.Common.Diagnostics; | ||
using Cake.Common.IO; | ||
using Cake.Frosting; | ||
using Dnn.CakeUtils; | ||
namespace DotNetNuke.Build.Tasks; | ||
|
||
/// <summary>A cake task to generate the MailKit package.</summary> | ||
public sealed class PackageMailKit : FrostingTask<Context> | ||
/// <summary>A cake task to generate the MailKit package.</summary> | ||
public sealed class PackageMailKit : PackageComponentTask | ||
{ | ||
/// <summary>Initializes a new instance of the <see cref="PackageMailKit"/> class.</summary> | ||
public PackageMailKit() | ||
: base("MailKit") | ||
{ | ||
/// <inheritdoc/> | ||
public override void Run(Context context) | ||
{ | ||
var binDir = context.WebsiteDir.Path.Combine("bin"); | ||
var mailKitPath = binDir.CombineWithFilePath("MailKit.dll"); | ||
var packageVersion = context.GetAssemblyFileVersion(mailKitPath); | ||
|
||
var packageZip = context.WebsiteDir.Path.CombineWithFilePath($"Install/Library/MailKit_{packageVersion}_Install.zip"); | ||
var packageDir = context.Directory("DNN Platform/Components/MailKit"); | ||
|
||
context.Information($"Creating {packageZip}"); | ||
context.Zip( | ||
packageDir.ToString(), | ||
packageZip, | ||
context.GetFilesByPatterns(packageDir, new[] { "*" }, new[] { "*.dnn" })); | ||
|
||
var manifestPath = context.GetFiles(packageDir.Path.CombineWithFilePath("*.dnn").ToString()).Single(); | ||
context.Information($"Reading manifest from {manifestPath}"); | ||
var manifest = new XmlDocument(); | ||
manifest.LoadXml(context.ReadFile(manifestPath)); | ||
var assemblies = | ||
from XmlNode assemblyNode in manifest.SelectNodes("//assembly") | ||
from XmlNode childNode in assemblyNode.ChildNodes | ||
where childNode.LocalName.Equals("name") | ||
select childNode; | ||
|
||
foreach (var assemblyNameNode in assemblies) | ||
{ | ||
var assemblyPath = binDir.CombineWithFilePath(assemblyNameNode.InnerText); | ||
context.Information($"Adding {assemblyPath} to {packageZip}"); | ||
context.AddFilesToZip( | ||
packageZip, | ||
context.MakeAbsolute(context.WebsiteDir.Path), | ||
context.GetFiles(assemblyPath.ToString()), | ||
append: true); | ||
|
||
var versionNode = assemblyNameNode.ParentNode.ChildNodes.Cast<XmlNode>() | ||
.SingleOrDefault(childNode => childNode.LocalName.Equals("version")); | ||
if (versionNode != null) | ||
{ | ||
versionNode.InnerText = context.GetAssemblyFileVersion(assemblyPath); | ||
context.Information($"Set {assemblyPath} version to {versionNode.InnerText}"); | ||
} | ||
} | ||
|
||
manifest.SelectSingleNode("//package[@version]").Attributes["version"].Value = packageVersion; | ||
|
||
context.AddXmlFileToZip(packageZip, manifest, manifestPath.GetFilename().ToString(), append: true); | ||
} | ||
} | ||
} |
Oops, something went wrong.