Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 8 additions & 34 deletions cmf-cli/Commands/upgrade/UpgradeBaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,20 @@ public override void Configure(Command cmd)
};
cmd.Add(baseVersionArgument);

var iotVersionOption = new Option<string>("--iotVersion", "-iot")
var manifestOption = new Option<string>("--manifest", "-m")
{
Description = "New MES version for the IoT workflows & masterdatas."
Description = "The manifest file to use for the upgrade."
};
cmd.Add(iotVersionOption);

var iotPackagesToIgnoreOption = new Option<List<string>>("--iotPackagesToIgnore", "-ignore")
{
Description = "IoT packages to ignore when updating the MES version of the tasks in IoT workflows",
AllowMultipleArgumentsPerToken = true
};
cmd.Add(iotPackagesToIgnoreOption);
cmd.Add(manifestOption);

// Add the handler
cmd.SetAction((parseResult, cancellationToken) =>
{
var packagePath = parseResult.GetValue(packagePathArgument);
var baseVersion = parseResult.GetValue(baseVersionArgument);
var iotVersion = parseResult.GetValue(iotVersionOption);
var iotPackagesToIgnore = parseResult.GetValue(iotPackagesToIgnoreOption);
var manifest = parseResult.GetValue(manifestOption);

Execute(packagePath, baseVersion, iotVersion, iotPackagesToIgnore);
Execute(packagePath, baseVersion, manifest);
return Task.FromResult(0);
});
}
Expand All @@ -88,10 +80,8 @@ public override void Configure(Command cmd)
/// </summary>
/// <param name="packagePath">The package path.</param>
/// <param name="baseVersion">The new Base version.</param>
/// <param name="iotVersion">New MES version for the IoT workflows & masterdata</param>
/// <param name="iotPackagesToIgnore">IoT packages to ignore when updating the MES version of the tasks in IoT workflows</param>
/// <exception cref="CliException"></exception>
public void Execute(IDirectoryInfo packagePath, string baseVersion, string iotVersion, List<string> iotPackagesToIgnore)
/// <param name="manifest">The manifest file to use for the upgrade.</param>
public void Execute(IDirectoryInfo packagePath, string baseVersion, string manifest = null)
{
using var activity = ExecutionContext.ServiceProvider?.GetService<ITelemetryService>()?.StartExtendedActivity(this.GetType().Name);

Expand All @@ -100,29 +90,13 @@ public void Execute(IDirectoryInfo packagePath, string baseVersion, string iotVe
foreach (IFileInfo path in cmfPackagePaths)
{
Log.Debug($"Processing {path.FullName}");
Execute(CmfPackage.Load(path), baseVersion, iotVersion, iotPackagesToIgnore);
new UpgradeCommand(this.fileSystem).Execute(path.Directory, baseVersion, manifest);
}

UpdateProjectConfig(packagePath, baseVersion);
Log.Warning("Don't forget to update pipeline files");
}

/// <summary>
/// Executes the specified CMF package.
/// </summary>
/// <param name="cmfPackage">The CMF package.</param>
/// <param name="version">The version.</param>
/// <param name="iotVersion">New MES version for the IoT workflows & masterdata</param>
/// <param name="iotPackagesToIgnore">IoT packages to ignore when updating the MES version of the tasks in IoT workflows</param>
/// <exception cref="CliException"></exception>
public void Execute(CmfPackage cmfPackage, string version, string iotVersion, List<string> iotPackagesToIgnore)
{
IDirectoryInfo packageDirectory = cmfPackage.GetFileInfo().Directory;
IPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfPackage);

packageTypeHandler.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
}

#region Utilities

/// <summary>
Expand Down
84 changes: 84 additions & 0 deletions cmf-cli/Commands/upgrade/UpgradeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Cmf.CLI.Constants;
using Cmf.CLI.Core.Attributes;
using Cmf.CLI.Core.Interfaces;
using Cmf.CLI.Factories;
using System.CommandLine;
using System.IO.Abstractions;
using System.Threading.Tasks;

namespace Cmf.CLI.Commands
{
/// <summary>
/// Performs an upgrade of the current package
/// </summary>
/// <seealso cref="BaseCommand" />
[CmfCommand("upgrade", Id = "upgrade", Description = "Project upgrade utilities")]
public class UpgradeCommand : BaseCommand
{

/// <summary>
/// constructor for System.IO filesystem
/// </summary>
public UpgradeCommand() : base()
{
}

/// <summary>
/// constructor
/// </summary>
/// <param name="fileSystem"></param>
public UpgradeCommand(IFileSystem fileSystem) : base(fileSystem)
{
}

/// <summary>
/// Configure command
/// </summary>
/// <param name="cmd"></param>
public override void Configure(Command cmd)
{
var packagePathArgument = new Argument<IDirectoryInfo>("packagePath")
{
Description = "Package path",
CustomParser = argResult => Parse<IDirectoryInfo>(argResult, ".")
};
cmd.Add(packagePathArgument);

var baseVersionArgument = new Argument<string>("BaseVersion")
{
Description = "New framework/MES Version"
};
cmd.Add(baseVersionArgument);

var manifestOption = new Option<string>("--manifest", "-m")
{
Description = "The manifest file to use for the upgrade."
};
cmd.Add(manifestOption);

cmd.SetAction((parseResult) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not using the cmd.Handler = CommandHandler.Create<IDirectoryInfo, string, bool>(this.Execute); ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commands were updated to use this new format. Check this commit

{
var packagePath = parseResult.GetValue(packagePathArgument);
var baseVersion = parseResult.GetValue(baseVersionArgument);
var manifest = parseResult.GetValue(manifestOption);

Execute(packagePath, baseVersion, manifest);
return Task.FromResult(0);
});
}

/// <summary>
/// Executes the specified package path.
/// </summary>
/// <param name="packagePath">The package path.</param>
/// <param name="version">The new framework/MES version.</param>
/// <param name="manifest">The manifest file to use for the upgrade.</param>
public void Execute(IDirectoryInfo packagePath, string version, string manifest = null)
{
IFileInfo cmfpackageFile = this.fileSystem.FileInfo.New(this.fileSystem.Path.Combine(packagePath.FullName, CliConstants.CmfPackageFileName));

IPackageTypeHandler packageTypeHandler = PackageTypeFactory.GetPackageTypeHandler(cmfpackageFile);
packageTypeHandler.Upgrade(version, manifest);
}
}
}
9 changes: 3 additions & 6 deletions cmf-cli/Handlers/PackageType/BusinessPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,10 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateCSharpProject(this.fileSystem, this.CmfPackage, version, true);
}
}
Expand Down
24 changes: 8 additions & 16 deletions cmf-cli/Handlers/PackageType/DataPackageTypeHandlerV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Cmf.CLI.Handlers
public class DataPackageTypeHandlerV2 : PackageTypeHandler
{
/// <summary>
/// Initializes a new instance of the <see cref="DataPackageTypeHandler" /> class.
/// Initializes a new instance of the <see cref="DataPackageTypeHandlerV2" /> class.
/// </summary>
/// <param name="cmfPackage">The CMF package.</param>
public DataPackageTypeHandlerV2(CmfPackage cmfPackage) : base(cmfPackage)
Expand Down Expand Up @@ -52,8 +52,8 @@ public DataPackageTypeHandlerV2(CmfPackage cmfPackage) : base(cmfPackage)
}
});

BuildSteps = new IBuildCommand[]
{
BuildSteps =
[
new JSONValidatorCommand()
{
DisplayName = "JSON Validator Command",
Expand All @@ -64,7 +64,7 @@ public DataPackageTypeHandlerV2(CmfPackage cmfPackage) : base(cmfPackage)
DisplayName = "DEE Validator Command",
FilesToValidate = GetContentToPack(this.fileSystem.DirectoryInfo.New("."))
}
};
];

cmfPackage.DFPackageType = PackageType.Business; // necessary because we restart the host during installation

Expand All @@ -91,21 +91,13 @@ public override void Pack(IDirectoryInfo packageOutputDir, IDirectoryInfo output
base.Pack(packageOutputDir, outputDir, dryRun);
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateCSharpProject(this.fileSystem, this.CmfPackage, version, true);

if (iotVersion == null)
{
return;
}

UpgradeBaseUtilities.UpdateIoTMasterdatasAndWorkflows(this.fileSystem, this.CmfPackage, iotVersion, iotPackagesToIgnore);
UpgradeBaseUtilities.UpdateIoTMasterdataFiles(this.fileSystem, this.CmfPackage, version, manifest);
}

/// <summary>
Expand Down
9 changes: 3 additions & 6 deletions cmf-cli/Handlers/PackageType/HelpNgCliPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,10 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateNPMProject(this.fileSystem, this.CmfPackage, version);

// Update the version in the config.json file
Expand Down
9 changes: 3 additions & 6 deletions cmf-cli/Handlers/PackageType/HtmlNgCliPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,10 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateNPMProject(this.fileSystem, this.CmfPackage, version);

IFileInfo projectConfig = this.fileSystem.FileInfo.New(Path.Join(this.CmfPackage.GetFileInfo().DirectoryName, "src", "assets", "config.json"));
Expand Down
20 changes: 0 additions & 20 deletions cmf-cli/Handlers/PackageType/IoTDataPackageTypeHandlerV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
using Cmf.CLI.Core.Objects;
using Cmf.CLI.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text.RegularExpressions;

namespace Cmf.CLI.Handlers
{
Expand Down Expand Up @@ -90,23 +87,6 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
UpgradeBaseUtilities.UpdateCSharpProject(this.fileSystem, this.CmfPackage, version, true);

if (iotVersion == null)
{
return;
}

UpgradeBaseUtilities.UpdateIoTMasterdatasAndWorkflows(this.fileSystem, this.CmfPackage, iotVersion, iotPackagesToIgnore);
}

/// <summary>
/// Retrieves all custom iot package names
/// </summary>
Expand Down
9 changes: 3 additions & 6 deletions cmf-cli/Handlers/PackageType/IoTPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,10 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateNPMProject(this.fileSystem, this.CmfPackage, version);
}

Expand Down
8 changes: 3 additions & 5 deletions cmf-cli/Handlers/PackageType/PackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,9 @@ public virtual void Bump(string version, string versionSuffix, Dictionary<string
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public virtual void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore) {
/// <inheritdoc />
public virtual void Upgrade(string version, string manifest = null)
{
Log.Information($"Will bump {CmfPackage.PackageId}");

// Read and parse the JSON
Expand Down
9 changes: 3 additions & 6 deletions cmf-cli/Handlers/PackageType/TestPackageTypeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ public override void Bump(string version, string versionSuffix, Dictionary<strin
}
}

/// <summary>
/// Bumps the Base version of the package
/// </summary>
/// <param name="version">The new Base version.</param>
public override void UpgradeBase(string version, string iotVersion, List<string> iotPackagesToIgnore)
/// <inheritdoc/>
public override void Upgrade(string version, string manifest = null)
{
base.UpgradeBase(version, iotVersion, iotPackagesToIgnore);
base.Upgrade(version, manifest);
UpgradeBaseUtilities.UpdateCSharpProject(this.fileSystem, this.CmfPackage, version, false);
}

Expand Down
Loading