-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: should return too many repository dependencies issue when anays…
…is java service that depends on more then 5 repositories
- Loading branch information
Jia Liu
committed
Jan 9, 2024
1 parent
f76cc78
commit f50ceff
Showing
6 changed files
with
109 additions
and
74 deletions.
There are no files selected for viewing
22 changes: 18 additions & 4 deletions
22
code-quality/src/main/kotlin/cc/unitmesh/quality/extension/JavaServiceAnalyser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
code-quality/src/main/kotlin/cc/unitmesh/quality/extension/rule/ServiceRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package cc.unitmesh.quality.extension.rule | ||
|
||
import chapi.domain.core.CodeDataStruct | ||
import org.archguard.rule.core.IssueEmit | ||
import org.archguard.rule.core.Rule | ||
|
||
open class ServiceRule : Rule() { | ||
open fun visitRoot(rootNode: List<CodeDataStruct>, callback: IssueEmit) {} | ||
} |
30 changes: 30 additions & 0 deletions
30
...y/src/main/kotlin/cc/unitmesh/quality/extension/rule/TooManyRepositoryDependenciesRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cc.unitmesh.quality.extension.rule | ||
|
||
import chapi.domain.core.CodeDataStruct | ||
import org.archguard.rule.core.IssueEmit | ||
import org.archguard.rule.core.IssuePosition | ||
import org.archguard.rule.core.Severity | ||
|
||
/** | ||
* Service should not dependent more than 5 repositories. | ||
*/ | ||
const val LIMIT = 5 | ||
|
||
class TooManyRepositoryDependenciesRule : ServiceRule() { | ||
init { | ||
this.id = "too-many-repository-dependencies" | ||
this.name = "TooManyRepositoryDependencies" | ||
this.key = this.javaClass.name | ||
this.severity = Severity.WARN | ||
this.description = "Service should not dependent more than 5 repositories." | ||
} | ||
|
||
override fun visitRoot(rootNodes: List<CodeDataStruct>, callback: IssueEmit) { | ||
rootNodes.forEach { | ||
val repositoryCount = it.Fields.filter { it.TypeType.contains("Repository", true) }.count() | ||
if (repositoryCount > LIMIT) { | ||
callback(this, IssuePosition()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
code-quality/src/test/resources/java/ServiceWithSixRepositories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.afs.restapi.service; | ||
|
||
import com.afs.restapi.repository.CompanyRepository; | ||
import com.afs.restapi.repository.EmployeeRepository; | ||
import com.afs.restapi.repository.DepartmentRepository; | ||
import com.afs.restapi.repository.TeamRepository; | ||
import com.afs.restapi.repository.GroupRepository; | ||
import com.afs.restapi.repository.CommunitRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class Example { | ||
private CompanyRepository companyRepository; | ||
private EmployeeRepository employeeRepository; | ||
private DepartmentRepository departmentRepository; | ||
private TeamRepository teamRepository; | ||
private GroupRepository groupRepository; | ||
private CommunitRepository communitRepository; | ||
|
||
public Example(CompanyRepository companyRepository, EmployeeRepository employeeRepository, | ||
DepartmentRepository departmentRepository, TeamRepository teamRepository, | ||
GroupRepository groupRepository, CommunitRepository communitRepository) { | ||
this.companyRepository = companyRepository; | ||
this.employeeRepository = employeeRepository; | ||
this.departmentRepository = departmentRepository; | ||
this.teamRepository = teamRepository; | ||
this.groupRepository = groupRepository; | ||
this.communitRepository = communitRepository; | ||
} | ||
} |
70 changes: 0 additions & 70 deletions
70
code-quality/src/test/resources/java/structs_HelloService.json
This file was deleted.
Oops, something went wrong.