Skip to content

Commit

Permalink
feat(analysis): implement review notes (#3743)
Browse files Browse the repository at this point in the history
  • Loading branch information
phanlezz committed Dec 5, 2024
1 parent 98e081e commit 9920af9
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 12 deletions.
2 changes: 1 addition & 1 deletion analysis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

### Added 🚀

- Add a new `--large` flat to the MergeFilter that merges projects into one file each in its own subfolder depending on the input file's dot-prefix name [#3841](https://github.com/MaibornWolff/codecharta/pull/3841)
- Add a new `--large` flag to the MergeFilter that merges projects into one file each in its own subfolder depending on the input file's dot-prefix name [#3841](https://github.com/MaibornWolff/codecharta/pull/3841)
- Add the ability to the MergeFilter to specify the output file during `--mimo` operation [#3841](https://github.com/MaibornWolff/codecharta/pull/3841)

## [1.129.0] - 2024-11-29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import de.maibornwolff.codecharta.model.Project

class LargeMerge {
companion object {
fun packageProjectInto(project: Project, prefix: String): Project {
fun wrapProjectInFolder(project: Project, prefix: String): Project {
val modifiedProject = Project(
project.projectName,
moveNodesIntoFolder(project.rootNode, prefix),
Expand All @@ -22,32 +22,40 @@ class LargeMerge {
}

private fun moveNodesIntoFolder(root: Node, folderName: String): List<Node> {
val newRoot = Node(
val folderNode = Node(
name = folderName,
type = NodeType.Folder,
children = root.children
)
val mutableRoot = root.toMutableNode()
mutableRoot.children = mutableSetOf(newRoot.toMutableNode())
mutableRoot.children = mutableSetOf(folderNode.toMutableNode())
return listOf(mutableRoot.toNode())
}

private fun addFolderToEdgePaths(edges: List<Edge>, folderName: String): List<Edge> {
edges.forEach {
it.fromNodeName = insertFolderIntoPath(it.fromNodeName, folderName)
it.toNodeName = insertFolderIntoPath(it.toNodeName, folderName)
return edges.map { edge ->
Edge(
fromNodeName = insertFolderIntoPath(edge.fromNodeName, folderName),
toNodeName = insertFolderIntoPath(edge.toNodeName, folderName),
attributes = edge.attributes
)
}
return edges
}

private fun addFolderToBlackListPaths(blacklist: List<BlacklistItem>, folderName: String): List<BlacklistItem> {
blacklist.forEach {
it.path = insertFolderIntoPath(it.path, folderName)
return blacklist.map { item ->
BlacklistItem(
path = insertFolderIntoPath(item.path, folderName),
type = item.type
)
}
return blacklist
}

private fun insertFolderIntoPath(path: String, folderName: String): String {
val rootRegex = Regex("^/root/")
require(rootRegex.containsMatchIn(path)) {
"Input project structure doesn't have '/root/' as a base folder. If that's intended open an issue."
}
return path.replace(Regex("^/root/"), "/root/$folderName/")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class MergeFilter(

val packagedProjects: MutableList<Project> = mutableListOf()
projectsFileNamePairs.forEach {
packagedProjects.add(LargeMerge.packageProjectInto(it.second, it.first.substringBefore(".")))
packagedProjects.add(LargeMerge.wrapProjectInFolder(it.second, it.first.substringBefore(".")))
}

val mergedProject = ProjectMerger(packagedProjects, nodeMergerStrategy).merge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,5 +626,21 @@ class MergeFilterTest {
assertThat(outputProject2.children.toString()).isEqualTo(projectInput2.rootNode.children.toString())
outPutFile.deleteOnExit()
}

@Test
fun `should throw error if input project does not contain a strict root node`() {
val customRootProject = "$fatMergeTestFolder/duplicate/customRootFailure.cc.json"
System.setErr(PrintStream(errContent))
CommandLine(MergeFilter()).execute(
testFilePath1,
testFilePath2,
customRootProject,
"--large"
).toString()
System.setErr(originalErr)
assertThat(
errContent.toString()
).contains("Input project structure doesn't have '/root/' as a base folder. If that's intended open an issue.")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"projectName": "Sample Project 1",
"apiVersion": "1.0",
"nodes": [
{
"name": "customRoot",
"type": "Folder",
"attributes": {},
"children": [
{
"name": "file1",
"type": "File",
"attributes": {
"number_of_commits": 160.0,
"range_of_weeks_with_commits": 68.0,
"successive_weeks_with_commits": 10.0,
"weeks_with_commits": 51.0,
"highly_coupled_files": 0.0,
"median_coupled_files": 2.0,
"abs_coupled_churn": 33700.0,
"avg_code_churn": 3.0
},
"link": "",
"children": []
},
{
"name": "file4",
"type": "File",
"attributes": {
"number_of_authors": 22.0,
"number_of_commits": 130.0,
"range_of_weeks_with_commits": 18.0,
"successive_weeks_with_commits": 20.0,
"weeks_with_commits": 61.0,
"highly_coupled_files": 1.0,
"median_coupled_files": 4.0,
"abs_coupled_churn": 22000.0,
"avg_code_churn": 4.0
},
"link": "",
"children": []
},
{
"name": "visualization",
"type": "Folder",
"attributes": {},
"link": "",
"children": [
{
"name": "file2",
"type": "File",
"attributes": {
"number_of_authors": 12.0,
"number_of_commits": 120.0,
"range_of_weeks_with_commits": 30.0,
"successive_weeks_with_commits": 20.0,
"weeks_with_commits": 76.0,
"highly_coupled_files": 0.0,
"median_coupled_files": 2.0,
"abs_coupled_churn": 33700.0,
"avg_code_churn": 7.0
},
"link": "",
"children": []
},
{
"name": "file3",
"type": "File",
"attributes": {
"number_of_authors": 40.0,
"number_of_commits": 230.0,
"range_of_weeks_with_commits": 50.0,
"successive_weeks_with_commits": 80.0,
"weeks_with_commits": 10.0,
"highly_coupled_files": 5.0,
"median_coupled_files": 2.0,
"abs_coupled_churn": 44000.0,
"avg_code_churn": 4.0
},
"link": "",
"children": []
}
]
}
]
}
],
"edges": [
{
"fromNodeName": "/customRoot/file1",
"toNodeName": "/customRoot/visualization/file2",
"attributes": {
"pairingRate": 90,
"avgCommits": 5,
"anotherMetric": 25
}
},
{
"fromNodeName": "/customRoot/visualization/file2",
"toNodeName": "/customRoot/visualization/file3",
"attributes": {
"pairingRate": 80,
"avgCommits": 3
}
}
],
"attributeTypes": {
"nodes": {
"attributeA": "absolute",
"attributeB": "absolute",
"attributeZ": "absolute"
},
"edges": {
"attributeD": "absolute",
"attributeE": "relative"
}
},
"blacklist": [
{
"path": "/customRoot/file1",
"type": "hide"
},
{
"path": "/customRoot/visualization/file2",
"type": "exclude"
}
]
}

0 comments on commit 9920af9

Please sign in to comment.