-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Huge changes, too many for one commit... but here we go!
- Loading branch information
1 parent
2e559bc
commit 63cb709
Showing
46 changed files
with
749 additions
and
588 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -19,4 +19,4 @@ class FakeItemRepo @Inject constructor( | |
return Response.Failure() | ||
} | ||
} | ||
} | ||
} |
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
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
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,18 @@ | ||
plugins { | ||
kotlin("jvm") | ||
alias(libs.plugins.vanniktech.maven.publish) | ||
alias(libs.plugins.dokka) | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
} | ||
|
||
dependencies { | ||
compileOnly(gradleApi()) | ||
|
||
implementation(project(":invert-models")) | ||
implementation(project(":invert-gradle-plugin")) | ||
|
||
testImplementation(libs.kotlin.test) | ||
} |
63 changes: 63 additions & 0 deletions
63
...tors/src/main/kotlin/com/squareup/invert/collectors/contains/LineContainsStatCollector.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,63 @@ | ||
package com.squareup.invert.collectors.contains | ||
|
||
import com.squareup.invert.CollectedStat | ||
import com.squareup.invert.InvertProjectData | ||
import com.squareup.invert.StatCollector | ||
import com.squareup.invert.collectors.internal.wrapCodeForMarkdown | ||
import com.squareup.invert.models.Stat | ||
import com.squareup.invert.models.StatDataType | ||
import com.squareup.invert.models.StatMetadata | ||
import java.io.File | ||
|
||
open class LineContainsStatCollector( | ||
private val statKey: String, | ||
private val statDescription: String, | ||
private val linePredicate: (String) -> Boolean, | ||
private val filePredicate: (File) -> Boolean = { true }, | ||
) : StatCollector { | ||
override fun collect( | ||
invertProjectData: InvertProjectData, | ||
): List<CollectedStat>? { | ||
val codeReferences = mutableListOf<Stat.CodeReferencesStat.CodeReference>() | ||
invertProjectData.projectDir | ||
.walkTopDown() | ||
.filter { it.isFile && it.length() > 0 } | ||
.filter { filePredicate(it) } | ||
.forEach { sourceFile -> | ||
val relativeFilePath = sourceFile.relativeTo(invertProjectData.rootProjectDir).path | ||
sourceFile.readLines() | ||
.map { it.trim() } | ||
.forEachIndexed { index, line -> | ||
if (linePredicate(line)) { | ||
codeReferences.add( | ||
Stat.CodeReferencesStat.CodeReference( | ||
filePath = relativeFilePath, | ||
startLine = index + 1, | ||
endLine = index + 1, | ||
code = line.wrapCodeForMarkdown(), | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
return if (codeReferences.isNotEmpty()) { | ||
listOf( | ||
CollectedStat( | ||
metadata = StatMetadata( | ||
key = statKey, | ||
description = statDescription, | ||
dataType = StatDataType.CODE_REFERENCES, | ||
), | ||
stat = Stat.CodeReferencesStat(codeReferences) | ||
) | ||
) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun getName(): String { | ||
return this::class.java.name | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
invert-collectors/src/main/kotlin/com/squareup/invert/collectors/internal/FormattingUtils.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,7 @@ | ||
package com.squareup.invert.collectors.internal | ||
|
||
internal fun String.wrapCodeForMarkdown(language: String = "") = buildString { | ||
appendLine("```$language") | ||
appendLine(this@wrapCodeForMarkdown) | ||
appendLine("```") | ||
} |
78 changes: 78 additions & 0 deletions
78
...rs/src/main/kotlin/com/squareup/invert/collectors/linesofcode/LinesOfCodeStatCollector.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,78 @@ | ||
package com.squareup.invert.collectors.linesofcode | ||
|
||
import com.squareup.invert.CollectedStat | ||
import com.squareup.invert.InvertProjectData | ||
import com.squareup.invert.StatCollector | ||
import com.squareup.invert.models.Stat | ||
import com.squareup.invert.models.StatDataType | ||
import com.squareup.invert.models.StatMetadata | ||
import com.squareup.invert.projectSrcDir | ||
import java.io.File | ||
|
||
open class LinesOfCodeStatCollector( | ||
name: String, | ||
private val fileExtensions: List<String>, | ||
keySuffix: String = fileExtensions.joinToString(","), | ||
private val sourcesDirectory: (InvertProjectData) -> File = { | ||
it.projectSrcDir | ||
}, | ||
) : StatCollector { | ||
|
||
companion object { | ||
const val STAT_CATEGORY_LINES_OF_CODE = "Lines of Code" | ||
} | ||
|
||
private val fileCountStatMetadata: StatMetadata = StatMetadata( | ||
key = "file_count_$keySuffix", | ||
description = "File Count - $name", | ||
dataType = StatDataType.NUMERIC, | ||
category = STAT_CATEGORY_LINES_OF_CODE, | ||
) | ||
|
||
private val linesOfCodeStatMetadata: StatMetadata = StatMetadata( | ||
key = "lines_of_code_$keySuffix", | ||
description = "Lines of Code - $name", | ||
dataType = StatDataType.NUMERIC, | ||
category = STAT_CATEGORY_LINES_OF_CODE, | ||
) | ||
|
||
override fun collect( | ||
invertProjectData: InvertProjectData, | ||
): List<CollectedStat>? { | ||
val matchingSourceFiles = sourcesDirectory(invertProjectData) | ||
.walkTopDown() | ||
.filter { file -> file.isFile } | ||
.filter { fileExtensions.contains(it.extension) } | ||
.toList() | ||
|
||
return if (matchingSourceFiles.isNotEmpty()) { | ||
var totalLoc = 0 | ||
matchingSourceFiles | ||
.map { it.readLines().filter { line -> line.isNotBlank() } } | ||
.forEach { | ||
totalLoc += it.size | ||
} | ||
|
||
listOf( | ||
CollectedStat( | ||
metadata = fileCountStatMetadata, | ||
stat = Stat.NumericStat( | ||
value = matchingSourceFiles.size, | ||
) | ||
), | ||
CollectedStat( | ||
metadata = linesOfCodeStatMetadata, | ||
stat = Stat.NumericStat( | ||
value = totalLoc, | ||
) | ||
) | ||
) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
override fun getName(): String { | ||
return this::class.java.name | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.