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 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>(); var moduleFilePaths = new List<string>();
@ -20,7 +20,7 @@ namespace Volo.Abp.Cli.ProjectModification
foreach (var csFile in csFiles) foreach (var csFile in csFiles)
{ {
if (IsDerivedFromAbpModule(csFile)) if (IsDerivedFromAbpModule(csFile, baseClass))
{ {
moduleFilePaths.Add(csFile); moduleFilePaths.Add(csFile);
} }
@ -29,14 +29,14 @@ namespace Volo.Abp.Cli.ProjectModification
return moduleFilePaths; return moduleFilePaths;
} }
private bool IsDerivedFromAbpModule(string csFile) protected bool IsDerivedFromAbpModule(string csFile, string baseClass)
{ {
var root = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile)).GetRoot(); var root = CSharpSyntaxTree.ParseText(File.ReadAllText(csFile)).GetRoot();
var namespaceSyntax = root.DescendantNodes().OfType<NamespaceDeclarationSyntax>().First(); var namespaceSyntax = root.DescendantNodes().OfType<NamespaceDeclarationSyntax>().First();
var classDeclaration = (namespaceSyntax.DescendantNodes().OfType<ClassDeclarationSyntax>()).First(); var classDeclaration = (namespaceSyntax.DescendantNodes().OfType<ClassDeclarationSyntax>()).First();
return classDeclaration.BaseList?.Types 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 IJsonSerializer JsonSerializer { get; }
protected ProjectNpmPackageAdder NpmPackageAdder { get; } protected ProjectNpmPackageAdder NpmPackageAdder { get; }
protected AbpModuleClassFinder ModuleClassFinder { get; } protected DerivedClassFinder ModuleClassFinder { get; }
protected ModuleClassDependcyAdder ModuleClassDependcyAdder { get; } protected ModuleClassDependcyAdder ModuleClassDependcyAdder { get; }
public ProjectNugetPackageAdder( public ProjectNugetPackageAdder(
IJsonSerializer jsonSerializer, IJsonSerializer jsonSerializer,
ProjectNpmPackageAdder npmPackageAdder, ProjectNpmPackageAdder npmPackageAdder,
AbpModuleClassFinder moduleClassFinder, DerivedClassFinder moduleClassFinder,
ModuleClassDependcyAdder moduleClassDependcyAdder) ModuleClassDependcyAdder moduleClassDependcyAdder)
{ {
JsonSerializer = jsonSerializer; JsonSerializer = jsonSerializer;
@ -52,7 +52,7 @@ namespace Volo.Abp.Cli.ProjectModification
CmdHelper.Run("dotnet", "add package " + package.Name); CmdHelper.Run("dotnet", "add package " + package.Name);
var moduleFiles = ModuleClassFinder.Find(projectFile); var moduleFiles = ModuleClassFinder.Find(projectFile, "AbpModule");
if (moduleFiles.Count == 0) if (moduleFiles.Count == 0)
{ {
throw new CliUsageException($"Could not find a class derived from AbpModule in the project {projectFile}"); throw new CliUsageException($"Could not find a class derived from AbpModule in the project {projectFile}");

Loading…
Cancel
Save