Skip to content

Commit

Permalink
VCI-772: Fix codesmells
Browse files Browse the repository at this point in the history
  • Loading branch information
krankenbro committed Feb 22, 2024
1 parent a5a50f7 commit a41421f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/VirtoCommerce.Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,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
13 changes: 7 additions & 6 deletions src/VirtoCommerce.Build/PlatformTools/Build.MatchVerisons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace VirtoCommerce.Build
{
internal partial class Build
{
private Regex _moduleNameRegEx = new Regex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled);
[GeneratedRegex(@"(VirtoCommerce.+)Module", RegexOptions.Compiled)]
private static partial Regex ModuleNameRegEx();

public Target MatchVersions => _ => _
.Executes(() =>
Expand All @@ -38,7 +39,7 @@ internal partial class Build
var missedDependenciesErrors = ValidateForMissedDependencies(allPackages);
errors.AddRange(missedDependenciesErrors);

if (errors.Any())
if (errors.Count != 0)
{
Assert.Fail(errors.Join(Environment.NewLine));
}
Expand All @@ -54,7 +55,7 @@ private IEnumerable<PackageItem> GetProjectPackages(Project project)
// find all VirtoCommerce references
return msBuildProject.Items
.Where(x => x.ItemType == "PackageReference"
&& (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || _moduleNameRegEx.IsMatch(x.EvaluatedInclude)))
&& (x.EvaluatedInclude.StartsWith("VirtoCommerce.Platform.") || ModuleNameRegEx().IsMatch(x.EvaluatedInclude)))
.Select(x =>
{
var versionMetadata = x.Metadata.FirstOrDefault(x => x.Name == "Version");
Expand Down Expand Up @@ -90,7 +91,7 @@ private IEnumerable<string> ValdatePlatformVersion(IEnumerable<PackageItem> pack
/// <summary>
/// Check dependencies for module packages versions mismatch
/// </summary>
private IEnumerable<string> ValidateModuleDependenciesVersions(IEnumerable<PackageItem> packages)
private List<string> ValidateModuleDependenciesVersions(IEnumerable<PackageItem> packages)
{
var result = new List<string>();

Expand All @@ -117,7 +118,7 @@ private IEnumerable<string> ValidateModuleDependenciesVersions(IEnumerable<Packa
/// <summary>
/// Check project packages for missed dependency in manifest
/// </summary>
private IEnumerable<string> ValidateForMissedDependencies(IEnumerable<PackageItem> packages)
private List<string> ValidateForMissedDependencies(IEnumerable<PackageItem> packages)
{
var result = new List<string>();

Expand All @@ -139,7 +140,7 @@ private IEnumerable<string> ValidateForMissedDependencies(IEnumerable<PackageIte

private bool HasNameMatch(string packageName, string dependencyName)
{
var match = _moduleNameRegEx.Match(packageName);
var match = ModuleNameRegEx().Match(packageName);
return match.Groups.Values.Any(x => x.Value == dependencyName);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/VirtoCommerce.Build/PlatformTools/Build.PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal partial class Build
{
UpdateModules(Module, externalModuleCatalog, modules);
}
else if (!PlatformParameter && !modules.Any() && !File.Exists(Path.GetFullPath(PackageManifestPath)))
else if (!PlatformParameter && modules.IsEmpty() && !File.Exists(Path.GetFullPath(PackageManifestPath)))
{
AddCommerceModules(externalModuleCatalog, modules);
}
Expand Down Expand Up @@ -162,7 +162,7 @@ private static IEnumerable<ModuleItem> ParseModuleParameter(string[] moduleStrin
if (parts.Length > 1)
{
moduleId = parts[0];
moduleVersion = parts[parts.Count() - 1];
moduleVersion = parts[parts.Length - 1];
}
else if (moduleStrings.Length == 1 && !string.IsNullOrEmpty(VersionToInstall))
{
Expand Down Expand Up @@ -209,7 +209,7 @@ private static bool PlatformVersionChanged()
public Target Rollback => _ => _
.DependsOn(Backup)
.After(Backup, Install, Update, InstallPlatform, InstallModules)
.OnlyWhenDynamic(() => FailedTargets.Any() && SucceededTargets.Contains(Backup))
.OnlyWhenDynamic(() => FailedTargets.Count > 0 && SucceededTargets.Contains(Backup))
.AssuredAfterFailure()
.Executes(() => CompressionExtensions.UnTarGZipTo(BackupFile, RootDirectory));

Expand Down
7 changes: 5 additions & 2 deletions src/VirtoCommerce.Build/Utils/ArtifactPacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Utils
{
public static class ArtifactPacker
public static partial class ArtifactPacker
{
public static void CompressPlatform(AbsolutePath sourceDirectory, AbsolutePath outputZipPath)
{
Expand All @@ -26,7 +26,7 @@ public static void CompressModule(Action<ModuleCompressionOptionsBuilder> option
FileExistsPolicy.Overwrite);

//Exclude all ignored files and *module files not related to compressed module
var ignoreModuleFilesRegex = new Regex(@".+Module\..*", RegexOptions.IgnoreCase);
var ignoreModuleFilesRegex = IgnoreModuleFilesRegex();
var includeModuleFilesRegex =
new Regex(@$".*{options.ModuleId}(Module)?\..*", RegexOptions.IgnoreCase);

Expand Down Expand Up @@ -73,5 +73,8 @@ public static bool KeepFileByRegex(string name, Regex keepRegex)
{
return keepRegex.IsMatch(name);
}

[GeneratedRegex(@".+Module\..*", RegexOptions.IgnoreCase)]
private static partial Regex IgnoreModuleFilesRegex();
}
}

0 comments on commit a41421f

Please sign in to comment.