Refactor SolutionAbpVersionFinder (Renamed to SolutionPackageVersionFinder)

pull/10363/head
Yunus Emre Kalkan 4 years ago
parent f02ea9a464
commit 7c450d764a

@ -18,7 +18,7 @@ namespace Volo.Abp.Cli.Commands
public ILogger<AddModuleCommand> Logger { get; set; }
protected SolutionModuleAdder SolutionModuleAdder { get; }
public SolutionAbpVersionFinder SolutionAbpVersionFinder { get; }
public SolutionPackageVersionFinder SolutionPackageVersionFinder { get; }
public AddModuleInfoOutput LastAddedModuleInfo
{
@ -33,10 +33,10 @@ namespace Volo.Abp.Cli.Commands
}
}
public AddModuleCommand(SolutionModuleAdder solutionModuleAdder, SolutionAbpVersionFinder solutionAbpVersionFinder)
public AddModuleCommand(SolutionModuleAdder solutionModuleAdder, SolutionPackageVersionFinder solutionPackageVersionFinder)
{
SolutionModuleAdder = solutionModuleAdder;
SolutionAbpVersionFinder = solutionAbpVersionFinder;
SolutionPackageVersionFinder = solutionPackageVersionFinder;
Logger = NullLogger<AddModuleCommand>.Instance;
}
@ -62,7 +62,7 @@ namespace Volo.Abp.Cli.Commands
var version = commandLineArgs.Options.GetOrNull(Options.Version.Short, Options.Version.Long);
if (version == null)
{
version = SolutionAbpVersionFinder.Find(solutionFile);
version = SolutionPackageVersionFinder.Find(solutionFile);
}
var moduleInfo = await SolutionModuleAdder.AddAsync(

@ -7,15 +7,15 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.ProjectModification
{
public class SolutionAbpVersionFinder : ITransientDependency
public class SolutionPackageVersionFinder : ITransientDependency
{
public string Find(string solutionFile)
public string Find(string solutionFile, string packagePrefix = "Volo.Abp")
{
var projectFilesUnderSrc = GetProjectFilesOfSolution(solutionFile);
foreach (var projectFile in projectFilesUnderSrc)
{
var content = File.ReadAllText(projectFile);
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s))
if (TryParseVersionFromCsprojViaXmlDocument(content, out var s, packagePrefix))
{
return s;
}
@ -24,13 +24,13 @@ namespace Volo.Abp.Cli.ProjectModification
return null;
}
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version)
private static bool TryParseVersionFromCsprojViaXmlDocument(string content, out string version, string packagePrefix)
{
var doc = new XmlDocument() { PreserveWhitespace = true };
using (var stream = StreamHelper.GenerateStreamFromString(content))
{
doc.Load(stream);
var nodes = doc.SelectNodes("/Project/ItemGroup/PackageReference[starts-with(@Include, 'Volo.Abp')]");
var nodes = doc.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packagePrefix}')]");
var value = nodes?[0]?.Attributes?["Version"]?.Value;
if (value == null)
{
@ -43,12 +43,12 @@ namespace Volo.Abp.Cli.ProjectModification
}
}
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version)
public static bool TryParseVersionFromCsprojFile(string csprojContent, out string version, string packagePrefix = "Volo.Abp")
{
try
{
var matches = Regex.Matches(csprojContent,
@"PackageReference\s*Include\s*=\s*\""Volo.Abp(.*?)\""\s*Version\s*=\s*\""(.*?)\""",
@"PackageReference\s*Include\s*=\s*\""" + packagePrefix + @"(.*?)\""\s*Version\s*=\s*\""(.*?)\""",
RegexOptions.IgnoreCase |
RegexOptions.IgnorePatternWhitespace |
RegexOptions.Singleline | RegexOptions.Multiline);
@ -72,11 +72,11 @@ namespace Volo.Abp.Cli.ProjectModification
}
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version)
public static bool TryParseSemanticVersionFromCsprojFile(string csprojContent, out SemanticVersion version, string packagePrefix = "Volo.Abp")
{
try
{
if (TryParseVersionFromCsprojFile(csprojContent, out var versionText))
if (TryParseVersionFromCsprojFile(csprojContent, out var versionText, packagePrefix))
{
return SemanticVersion.TryParse(versionText, out version);
}
@ -90,13 +90,13 @@ namespace Volo.Abp.Cli.ProjectModification
return false;
}
public static bool TryFind(string solutionFile, out string version)
public static bool TryFind(string solutionFile, out string version, string packagePrefix = "Volo.Abp")
{
var projectFiles = GetProjectFilesOfSolution(solutionFile);
foreach (var projectFile in projectFiles)
{
var csprojContent = File.ReadAllText(projectFile);
if (TryParseVersionFromCsprojFile(csprojContent, out var parsedVersion))
if (TryParseVersionFromCsprojFile(csprojContent, out var parsedVersion, packagePrefix))
{
version = parsedVersion;
return true;
@ -107,13 +107,13 @@ namespace Volo.Abp.Cli.ProjectModification
return false;
}
public static bool TryFindSemanticVersion(string solutionFile, out SemanticVersion version)
public static bool TryFindSemanticVersion(string solutionFile, out SemanticVersion version, string packagePrefix = "Volo.Abp")
{
var projectFiles = GetProjectFilesOfSolution(solutionFile);
foreach (var projectFile in projectFiles)
{
var csprojContent = File.ReadAllText(projectFile);
if (TryParseSemanticVersionFromCsprojFile(csprojContent, out var parsedVersion))
if (TryParseSemanticVersionFromCsprojFile(csprojContent, out var parsedVersion, packagePrefix))
{
version = parsedVersion;
return true;

@ -36,7 +36,7 @@ namespace Volo.Abp.Cli
"</ItemGroup>" +
"</Project>";
var success = SolutionAbpVersionFinder.TryParseVersionFromCsprojFile(csprojContent, out var version);
var success = SolutionPackageVersionFinder.TryParseVersionFromCsprojFile(csprojContent, out var version);
success.ShouldBe(true);
version.ShouldBe("4.4.0-rc.1");
}
@ -58,7 +58,7 @@ namespace Volo.Abp.Cli
"</ItemGroup>" +
"</Project>";
var success = SolutionAbpVersionFinder.TryParseSemanticVersionFromCsprojFile(csprojContent, out var version);
var success = SolutionPackageVersionFinder.TryParseSemanticVersionFromCsprojFile(csprojContent, out var version);
success.ShouldBe(true);
version.Major.ShouldBe(12);
version.Minor.ShouldBe(8);

Loading…
Cancel
Save