Skip to content

Commit

Permalink
Feature/1066/attribute descriptors for svn tokeii raw (#3176)
Browse files Browse the repository at this point in the history
* Add attribute descriptors to svn log parser

* Refactor svn tests to backtick naming scheme and format to junit5

* Add attribute descriptors to tokei

* Remove unused code

* Refactor metric gardener tests to use junit5

* Add upper bound to V to fix warning https://youtrack.jetbrains.com/issue/KT-36770

* Refactor remove unused code and deprecated test methods

* Remove junit4 dependencies

* Refactor name parameter in project build call

* Reverse test case for fileMetrics to equal check

* Refactor AttributeDescriptors to directly return a map
  • Loading branch information
phanlezz authored Jan 11, 2023
1 parent 5ea25b2 commit 680f8cb
Show file tree
Hide file tree
Showing 55 changed files with 397 additions and 352 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

### Added 🚀

- Add an option to hide floor lables under the Area Metric Options. This recalculates the map. [#3175](https://github.com/MaibornWolff/codecharta/pull/3175)
- Add an option to hide floor labels under the Area Metric Options. This recalculates the map. [#3175](https://github.com/MaibornWolff/codecharta/pull/3175)

### Chore 👨‍💻 👩‍💻

- Add attribute descriptors (metric descriptions) to TokeiImporter and SVNlogParser [#3176](https://github.com/MaibornWolff/codecharta/pull/3176)

### Fixed 🐞

Expand Down
1 change: 0 additions & 1 deletion analysis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ buildscript {
assertj_version = '3.23.1'
hamcrest_version = '1.4-atlassian-1'
hamkrest_version = '1.8.0.1'
junit4_version = '4.13.2'
junit5_version = '5.9.1'
junit_platform_version = '1.9.1'
jsonassert_version = '1.5.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class NodeRemover(private val project: Project) {
copyAttributeTypes(),
copyAttributeDescriptors(),
removeBlacklistItems(paths)
).build(true)
).build(cleanAttributeDescriptors = true)
}

private fun filterNodes(path: List<String>, node: MutableNode): MutableNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SubProjectExtractor(private val project: Project) {
copyAttributeTypes(),
copyAttributeDescriptors(),
copyBlacklist()
).build(true)
).build(cleanAttributeDescriptors = true)
}

private fun extractNodes(extractionPattern: List<String>, node: MutableNode): MutableList<MutableNode> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ParserDialogTest {
val outputFileName = "sampleOutputFile"
val printLevels = BigDecimal(0)
val setRoot = ""
val moveTo = ""
val moveFrom = ""
val remove = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SourceMonitorImporter(
val csvProjectBuilder =
CSVProjectBuilder(pathSeparator, csvDelimiter, "File Name", sourceMonitorReplacement, getAttributeDescriptors())
files.map { it.inputStream() }.forEach<InputStream> { csvProjectBuilder.parseCSVStream(it) }
val project = csvProjectBuilder.build(true)
val project = csvProjectBuilder.build(cleanAttributeDescriptors = true)

ProjectSerializer.serializeToFileOrStream(project, outputFile, output, compress)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ package de.maibornwolff.codecharta.importer.codemaat
import de.maibornwolff.codecharta.model.AttributeDescriptor

fun getAttributeDescriptors(): Map<String, AttributeDescriptor> {
val descriptors: MutableMap<String, AttributeDescriptor> = mutableMapOf()
descriptors["pairingRate"] = AttributeDescriptor(
"Pairing Rate",
"Pairing rate gives a percentage value of the chance that given files are committed together",
"Indicates that the given file is not often committed together with the other file",
"Indicates the the given files are often committed together",
"https://github.com/adamtornhill/code-maat#mining-logical-coupling"
return mapOf(
"pairingRate" to AttributeDescriptor(
"Pairing Rate",
"Pairing rate gives a percentage value of the chance that given files are committed together",
"Indicates that the given file is not often committed together with the other file",
"Indicates the the given files are often committed together",
"https://github.com/adamtornhill/code-maat#mining-logical-coupling"
),
"avgCommits" to AttributeDescriptor(
"Average Commits",
"Average amount of commits in which the given files were included",
"Indicates that a file is not committed often",
"Indicates that a file is committed often",
"https://github.com/adamtornhill/code-maat#mining-logical-coupling"
)
)
descriptors["avgCommits"] = AttributeDescriptor(
"Average Commits",
"Average amount of commits in which the given files were included",
"Indicates that a file is not committed often",
"Indicates that a file is committed often",
"https://github.com/adamtornhill/code-maat#mining-logical-coupling"
)
return descriptors.toMap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package de.maibornwolff.codecharta.importer.gitlogparser
import de.maibornwolff.codecharta.model.AttributeDescriptor

fun getAttributeDescriptors(): Map<String, AttributeDescriptor> {
val descriptors = mutableMapOf<String, AttributeDescriptor>()
val ghLink = "https://maibornwolff.github.io/codecharta/docs/git-log-parser"
descriptors["number_of_authors"] = AttributeDescriptor(title = "Number of Authors", description = "Number of authors", link = ghLink)
descriptors["number_of_commits"] = AttributeDescriptor(title = "Number of Commits", description = "Number of commits", link = ghLink)
descriptors["range_of_weeks_with_commits"] = AttributeDescriptor(title = "Week Range of Commits", description = "Average number of weeks between commits", link = ghLink)
descriptors["weeks_with_commits"] = AttributeDescriptor(title = "Weeks with Commits", description = "Number of weeks in which commits occurred", link = ghLink)
descriptors["highly_coupled_files"] = AttributeDescriptor(title = "Highly Coupled Files", description = "Number of highly coupled files (>=35% of times modified the same time) with this file", link = ghLink)
descriptors["median_coupled_files"] = AttributeDescriptor(title = "Median Coupled Files", description = "Median of number of other files that where committed with this file", link = ghLink)
descriptors["number_of_renames"] = AttributeDescriptor(title = "Number of Renames", description = "Number of file renames", link = ghLink)
descriptors["age_in_weeks"] = AttributeDescriptor(title = "Age in Weeks", description = "File age in weeks", link = ghLink)

return descriptors.toMap()
return mapOf(
"number_of_authors" to AttributeDescriptor(title = "Number of Authors", description = "Number of authors", link = ghLink),
"number_of_commits" to AttributeDescriptor(title = "Number of Commits", description = "Number of commits", link = ghLink),
"range_of_weeks_with_commits" to AttributeDescriptor(title = "Week Range of Commits", description = "Average number of weeks between commits", link = ghLink),
"weeks_with_commits" to AttributeDescriptor(title = "Weeks with Commits", description = "Number of weeks in which commits occurred", link = ghLink),
"highly_coupled_files" to AttributeDescriptor(title = "Highly Coupled Files", description = "Number of highly coupled files (>=35% of times modified the same time) with this file", link = ghLink),
"median_coupled_files" to AttributeDescriptor(title = "Median Coupled Files", description = "Median of number of other files that where committed with this file", link = ghLink),
"number_of_renames" to AttributeDescriptor(title = "Number of Renames", description = "Number of file renames", link = ghLink),
"age_in_weeks" to AttributeDescriptor(title = "Age in Weeks", description = "File age in weeks", link = ghLink)
)
}
7 changes: 1 addition & 6 deletions analysis/import/MetricGardenerImporter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@ dependencies {
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-xml', version: jackson_version
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-kotlin', version: jackson_version

implementation group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version
implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: jersey_version
implementation group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'

implementation group: 'com.lordcodes.turtle', name: 'turtle', version: '0.8.0'

testImplementation group: 'junit', name: 'junit', version: junit4_version
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: junit5_version
testImplementation group: 'org.assertj', name: 'assertj-core', version: assertj_version
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version: hamcrest_version
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: hamcrest_version
testImplementation group: 'io.mockk', name: 'mockk', version: mockk_version
testImplementation group: 'com.github.tomakehurst', name: 'wiremock', version: wiremock_version

testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junit5_version
}

test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package de.maibornwolff.codecharta.importer.metricgardenerimporter
import de.maibornwolff.codecharta.model.AttributeDescriptor

fun getAttributeDescriptors(): Map<String, AttributeDescriptor> {
val descriptors = mutableMapOf<String, AttributeDescriptor>()
val npmLink = "https://www.npmjs.com/package/metric-gardener"

descriptors["mcc"] = AttributeDescriptor(title = "Maximum Cyclic Complexity", description = "Maximum cyclic complexity based on paths through the code by McCabe", link = npmLink)
descriptors["functions"] = AttributeDescriptor(title = "Number of Functions", description = "Number of functions", link = npmLink)
descriptors["classes"] = AttributeDescriptor(title = "Number of Classes", description = "Number of classes", link = npmLink)
descriptors["lines_of_code"] = AttributeDescriptor(title = "Lines of Code", description = "Lines of code including empty lines and comments", link = npmLink)
descriptors["comment_lines"] = AttributeDescriptor(title = "Comment Lines", description = "Number of lines containing either a comment or commented-out code", link = npmLink)
descriptors["real_lines_of_code"] = AttributeDescriptor(title = "Real Lines of Code", description = "Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment", link = npmLink)

return descriptors.toMap()
return mapOf(
"mcc" to AttributeDescriptor(title = "Maximum Cyclic Complexity", description = "Maximum cyclic complexity based on paths through the code by McCabe", link = npmLink),
"functions" to AttributeDescriptor(title = "Number of Functions", description = "Number of functions", link = npmLink),
"classes" to AttributeDescriptor(title = "Number of Classes", description = "Number of classes", link = npmLink),
"lines_of_code" to AttributeDescriptor(title = "Lines of Code", description = "Lines of code including empty lines and comments", link = npmLink),
"comment_lines" to AttributeDescriptor(title = "Comment Lines", description = "Number of lines containing either a comment or commented-out code", link = npmLink),
"real_lines_of_code" to AttributeDescriptor(title = "Real Lines of Code", description = "Number of physical lines that contain at least one character which is neither a whitespace nor a tabulation nor part of a comment", link = npmLink)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import de.maibornwolff.codecharta.importer.metricgardenerimporter.model.MetricGa
import de.maibornwolff.codecharta.importer.metricgardenerimporter.model.MetricGardenerNodes
import de.maibornwolff.codecharta.model.MutableNode
import de.maibornwolff.codecharta.model.NodeType
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class MetricGardenerProjectBuilderTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package de.maibornwolff.codecharta.importer.metricgardenerimporter.model

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import de.maibornwolff.codecharta.model.Path
import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test

internal class MetricGardenerNodeTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.maibornwolff.codecharta.importer.metricgardenerimporter.model

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.junit.Assert.assertNotEquals
import org.junit.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotEquals
import org.junit.jupiter.api.Test

internal class MetricGardenerNodesTest {

Expand Down
4 changes: 1 addition & 3 deletions analysis/import/SVNLogParser/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ dependencies {
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version
implementation group: 'com.googlecode.juniversalchardet', name: 'juniversalchardet', version: juniversalchardet_version

implementation group: 'org.slf4j', name: 'slf4j-simple', version: slf4j_version
implementation group: 'com.github.kotlin-inquirer', name: 'kotlin-inquirer', version: kotlin_inquirer_version

testImplementation group: 'junit', name: 'junit', version: junit4_version
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: junit5_version
testImplementation group: 'org.assertj', name: 'assertj-core', version: assertj_version
testImplementation group: 'io.mockk', name: 'mockk', version: mockk_version
testImplementation project(path: ':model', configuration: 'testOutput')

testRuntimeOnly group: 'org.junit.vintage', name: 'junit-vintage-engine', version: junit5_version
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.maibornwolff.codecharta.importer.svnlogparser

import de.maibornwolff.codecharta.model.AttributeDescriptor

fun getAttributeDescriptors(): Map<String, AttributeDescriptor> {
val ghLink = "https://github.com/MaibornWolff/codecharta/blob/main/analysis/import/SVNLogParser/README.md"
return mapOf(
"age_in_weeks" to AttributeDescriptor(title = "Age in Weeks", description = "File age in weeks", link = ghLink),
"number_of_commits" to AttributeDescriptor(title = "Number of Commits", description = "Number of commits", link = ghLink),
"highly_coupled_files" to AttributeDescriptor(title = "Highly Coupled Files", description = "Number of highly coupled files (>=35% of times modified the same time) with this file", link = ghLink),
"median_coupled_files" to AttributeDescriptor(title = "Median Coupled Files", description = "Median of number of other files that where committed with this file", link = ghLink),
"number_of_renames" to AttributeDescriptor(title = "Number of Renames", description = "Number of file renames", link = ghLink),
"weeks_with_commits" to AttributeDescriptor(title = "Weeks with Commits", description = "Number of weeks in which commits occurred", link = ghLink),
"number_of_authors" to AttributeDescriptor(title = "Number of Authors", description = "Number of authors", link = ghLink),
"temporal_coupling" to AttributeDescriptor(title = "Temporal Coupling", description = "The degree of temporal coupling between two files (>=35%)", link = ghLink),
"successive_weeks_with_commits" to AttributeDescriptor(title = "Successive Weeks with Commits", description = "Number of successive weeks in which the file was included in a commit", link = ghLink),
"range_of_weeks_with_commits" to AttributeDescriptor(title = "Week Range of Commits", description = "Average number of weeks between commits", link = ghLink)
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.maibornwolff.codecharta.importer.svnlogparser.converter

import de.maibornwolff.codecharta.importer.svnlogparser.getAttributeDescriptors
import de.maibornwolff.codecharta.importer.svnlogparser.input.VersionControlledFile
import de.maibornwolff.codecharta.importer.svnlogparser.input.metrics.MetricsFactory
import de.maibornwolff.codecharta.model.Edge
Expand Down Expand Up @@ -54,8 +55,9 @@ class ProjectConverter(private val containsAuthors: Boolean) {
val metrics = metricsFactory.createMetrics()
projectBuilder.addAttributeTypes(AttributeTypesFactory.createNodeAttributeTypes(metrics))
projectBuilder.addAttributeTypes(AttributeTypesFactory.createEdgeAttributeTypes(metrics))
projectBuilder.addAttributeDescriptions(getAttributeDescriptors())

return projectBuilder.build()
return projectBuilder.build(cleanAttributeDescriptors = true)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,29 @@ package de.maibornwolff.codecharta.importer.svnlogparser

import de.maibornwolff.codecharta.importer.svnlogparser.converter.ProjectConverter
import de.maibornwolff.codecharta.importer.svnlogparser.input.metrics.MetricsFactory
import de.maibornwolff.codecharta.importer.svnlogparser.parser.LogParserStrategy
import de.maibornwolff.codecharta.importer.svnlogparser.parser.svn.SVNLogParserStrategy
import de.maibornwolff.codecharta.model.Project
import de.maibornwolff.codecharta.serialization.ProjectDeserializer
import de.maibornwolff.codecharta.serialization.ProjectSerializer
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.nio.file.Files
import java.nio.file.Paths
import java.util.Arrays

@RunWith(Parameterized::class)
class SVNLogProjectCreatorGoldenTest(
val svn: String,
private val strategy: LogParserStrategy,
private val containsAuthors: Boolean,
private val logFilename: String,
private val expectedProjectFilename: String
) {

companion object {
@JvmStatic
@Parameterized.Parameters(name = "{index}: {0}")
fun data(): Collection<Array<Any>> {
return Arrays.asList(
arrayOf("svn", SVNLogParserStrategy(), true, "example_svn.log", "expected_svn.json"),
)
}
}
class SVNLogProjectCreatorGoldenTest {
private val svn = "svn"
private val strategy = SVNLogParserStrategy()
private val containsAuthors = true
private val logFilename = "example_svn.log"
private val expectedProjectFilename = "expected_svn.json"

private val metricsFactory = MetricsFactory(
Arrays.asList(
listOf(
"number_of_authors",
"number_of_commits",
"weeks_with_commits",
Expand All @@ -51,7 +35,7 @@ class SVNLogProjectCreatorGoldenTest(

@Test
@Throws(Exception::class)
fun logParserGoldenTest() {
fun `log parser golden test`() {
// given
val projectConverter = ProjectConverter(containsAuthors)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package de.maibornwolff.codecharta.importer.svnlogparser.converter
import de.maibornwolff.codecharta.importer.svnlogparser.input.metrics.MetricsFactory
import de.maibornwolff.codecharta.model.AttributeType
import org.assertj.core.api.Assertions
import org.junit.Test
import org.junit.jupiter.api.Test

class AttributeTypesFactoryTest {

Expand Down
Loading

0 comments on commit 680f8cb

Please sign in to comment.