Browse Source

added DerivedClassFinder and removed AbpModuleClassFinder

pull/1126/head
Yunus Emre Kalkan 7 years ago
parent
commit
607ada4d44
  1. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DerivedClassFinder.cs
  2. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs

10
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/AbpModuleClassFinder.cs → framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/DerivedClassFinder.cs

@ -7,9 +7,9 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.ProjectModification
{
public class AbpModuleClassFinder : ITransientDependency
public class DerivedClassFinder : ITransientDependency
{
public virtual List<string> Find(string csprojFilePath)
public virtual List<string> Find(string csprojFilePath, string baseClass)
{
var moduleFilePaths = new List<string>();
@ -20,7 +20,7 @@ namespace Volo.Abp.Cli.ProjectModification
foreach (var csFile in csFiles)
{
if (IsDerivedFromAbpModule(csFile))
if (IsDerivedFromAbpModule(csFile, baseClass))
{
moduleFilePaths.Add(csFile);
}
@ -29,14 +29,14 @@ namespace Volo.Abp.Cli.ProjectModification
return moduleFilePaths;
}
private bool IsDerivedFromAbpModule(string csFile)
protected bool IsDerivedFromAbpModule(string csFile, string baseClass)
{
var root = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile)).GetRoot();
var namespaceSyntax = root.DescendantNodes().OfType<NamespaceDeclarationSyntax>().First();
var classDeclaration = (namespaceSyntax.DescendantNodes().OfType<ClassDeclarationSyntax>()).First();
return classDeclaration.BaseList?.Types
.Any(t => t.ToString().Contains("AbpModule")) ?? false;
.Any(t => t.ToString().Equals(baseClass)) ?? false;
}
}
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs

@ -20,13 +20,13 @@ namespace Volo.Abp.Cli.ProjectModification
protected IJsonSerializer JsonSerializer { get; }
protected ProjectNpmPackageAdder NpmPackageAdder { get; }
protected AbpModuleClassFinder ModuleClassFinder { get; }
protected DerivedClassFinder ModuleClassFinder { get; }
protected ModuleClassDependcyAdder ModuleClassDependcyAdder { get; }
public ProjectNugetPackageAdder(
IJsonSerializer jsonSerializer,
ProjectNpmPackageAdder npmPackageAdder,
AbpModuleClassFinder moduleClassFinder,
DerivedClassFinder moduleClassFinder,
ModuleClassDependcyAdder moduleClassDependcyAdder)
{
JsonSerializer = jsonSerializer;
@ -52,7 +52,7 @@ namespace Volo.Abp.Cli.ProjectModification
CmdHelper.Run("dotnet", "add package " + package.Name);
var moduleFiles = ModuleClassFinder.Find(projectFile);
var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule");
if (moduleFiles.Count == 0)
{
throw new CliUsageException($"Could not find a class derived from AbpModule in the project {projectFile}");

Loading…
Cancel
Save