-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add missing lint plugin * Fix broken test * Introduce module metadata * Introduce module metadata * Introduce back lint * Disable lint unless ran explicitly * Add basic LintReport plugin with printing stuff * Try to add Lint to CI * Proper name to Lint job * Add proper analytics reporting * Add Lint report to scheduled job * Add Lint report to scheduled job * Add Lint report to check job to test End to End * Fix caching, remove lint report from pipeline and add reporting message
- Loading branch information
Showing
22 changed files
with
561 additions
and
43 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
apply plugin: 'java-library' | ||
apply plugin: 'com.android.lint' | ||
apply plugin: 'kotlin' | ||
|
||
dependencies { | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
apply plugin: 'java-library' | ||
apply plugin: 'com.android.lint' | ||
apply plugin: 'kotlin' | ||
|
||
dependencies { | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
apply plugin: 'java-library' | ||
apply plugin: 'com.android.lint' | ||
apply plugin: 'kotlin' | ||
|
||
dependencies { | ||
|
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
77 changes: 77 additions & 0 deletions
77
plugins/src/main/java/com/jraska/lint/LintAnalyticsReporter.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,77 @@ | ||
package com.jraska.lint | ||
|
||
import com.jraska.analytics.AnalyticsEvent | ||
import com.jraska.analytics.AnalyticsReporter | ||
|
||
class LintAnalyticsReporter( | ||
private val analyticsReporter: AnalyticsReporter | ||
) { | ||
fun report(projectResult: LintProjectResult) { | ||
val allEvents = mutableListOf(convertProjectResult(projectResult)) | ||
|
||
allEvents.addAll( | ||
projectResult.moduleResults | ||
.flatMap { convertModule(it) } | ||
) | ||
|
||
analyticsReporter.report(*allEvents.toTypedArray()) | ||
|
||
println("$GRAPH_ICON Lint results reported $GRAPH_ICON") | ||
} | ||
|
||
private fun convertModule(moduleResult: LintModuleResult): List<AnalyticsEvent> { | ||
val moduleEvents = moduleResult.issues.map { convertIssue(it) }.toMutableList() | ||
|
||
moduleEvents.add( | ||
AnalyticsEvent( | ||
"Lint Module Result", | ||
mapOf( | ||
"totalIssues" to moduleResult.issuesCount, | ||
"totalWarnings" to moduleResult.warningsCount, | ||
"totalInfo" to moduleResult.infoCount, | ||
"totalErrors" to moduleResult.errorsCount, | ||
"totalIgnored" to moduleResult.ignoredCount, | ||
"moduleName" to moduleResult.metadata.moduleName, | ||
"moduleType" to moduleResult.metadata.type.name | ||
) | ||
) | ||
) | ||
|
||
return moduleEvents | ||
} | ||
|
||
private fun convertIssue(issue: LintIssue): AnalyticsEvent { | ||
return AnalyticsEvent( | ||
"Lint Issue Result", | ||
mapOf( | ||
"category" to issue.category, | ||
"errorLine" to issue.errorLine, | ||
"issueId" to issue.id, | ||
"location" to issue.location, | ||
"message" to issue.message, | ||
"moduleName" to issue.metadata.moduleName, | ||
"moduleType" to issue.metadata.type.name, | ||
"priority" to issue.priority, | ||
"severity" to issue.severity.name, | ||
"summary" to issue.summary, | ||
) | ||
) | ||
} | ||
|
||
private fun convertProjectResult(projectResult: LintProjectResult): AnalyticsEvent { | ||
return AnalyticsEvent( | ||
"Lint Project Result", | ||
mapOf( | ||
"totalIssues" to projectResult.issuesCount, | ||
"totalWarnings" to projectResult.warningsCount, | ||
"totalInfo" to projectResult.infoCount, | ||
"totalErrors" to projectResult.errorsCount, | ||
"totalIgnored" to projectResult.ignoredCount, | ||
) | ||
) | ||
} | ||
|
||
companion object { | ||
private val GRAPH_ICON = "\uD83D\uDCC9" | ||
} | ||
} |
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,42 @@ | ||
package com.jraska.lint | ||
|
||
import com.jraska.module.ModuleMetadata | ||
|
||
data class LintIssue( | ||
val metadata: ModuleMetadata, | ||
val id: String, | ||
val message: String, | ||
val severity: Severity, | ||
val category: String, | ||
val priority: Int, | ||
val summary: String, | ||
val errorLine: String?, | ||
val location: String? | ||
) | ||
|
||
data class LintModuleResult( | ||
val metadata: ModuleMetadata, | ||
val issues: List<LintIssue>, | ||
val issuesCount: Int, | ||
val errorsCount: Int, | ||
val warningsCount: Int, | ||
val infoCount: Int, | ||
val ignoredCount: Int | ||
) | ||
|
||
data class LintProjectResult( | ||
val issuesCount: Int, | ||
val errorsCount: Int, | ||
val warningsCount: Int, | ||
val infoCount: Int, | ||
val ignoredCount: Int, | ||
val moduleResults: List<LintModuleResult> | ||
) | ||
|
||
enum class Severity { | ||
Error, | ||
Warning, | ||
Info, | ||
Fatal, | ||
Ignore | ||
} |
55 changes: 55 additions & 0 deletions
55
plugins/src/main/java/com/jraska/lint/LintProjectExtractor.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,55 @@ | ||
package com.jraska.lint | ||
|
||
import com.jraska.module.extract.StatisticsGradleExtractor.Companion.moduleMetadata | ||
import org.gradle.api.Project | ||
import java.io.File | ||
|
||
class LintProjectExtractor { | ||
fun extract(project: Project): LintProjectResult { | ||
val moduleStats = project.rootProject | ||
.subprojects | ||
.filter { it.childProjects.isEmpty() } | ||
.map { extractFromModule(it) } | ||
|
||
return LintProjectResult( | ||
moduleResults = moduleStats, | ||
issuesCount = moduleStats.map { it.issuesCount }.sum(), | ||
warningsCount = moduleStats.map { it.warningsCount }.sum(), | ||
infoCount = moduleStats.map { it.infoCount }.sum(), | ||
errorsCount = moduleStats.map { it.errorsCount }.sum(), | ||
ignoredCount = moduleStats.map { it.ignoredCount }.sum() | ||
) | ||
} | ||
|
||
private fun extractFromModule(module: Project): LintModuleResult { | ||
val moduleMetadata = module.moduleMetadata() | ||
|
||
val xml = locateLintFile(module).readText() | ||
val issues = LintXmlParser(moduleMetadata).parse(xml) | ||
|
||
return LintModuleResult( | ||
metadata = moduleMetadata, | ||
issues = issues, | ||
issuesCount = issues.size, | ||
warningsCount = issues.count { it.severity == Severity.Warning }, | ||
errorsCount = issues.count { it.severity == Severity.Error || it.severity == Severity.Fatal }, | ||
ignoredCount = issues.count { it.severity == Severity.Ignore }, | ||
infoCount = issues.count { it.severity == Severity.Info } | ||
) | ||
} | ||
|
||
private fun locateLintFile(project: Project): File { | ||
val buildDir = project.buildDir | ||
val androidModuleCase = File(buildDir, "reports/lint-results.xml") | ||
if (androidModuleCase.exists()) { | ||
return androidModuleCase | ||
} | ||
|
||
val jvmModuleCase = File(buildDir, "test-results/lint-results.xml") | ||
if (jvmModuleCase.exists()) { | ||
return jvmModuleCase | ||
} | ||
|
||
throw IllegalStateException("Lint results didn't found in paths: [$androidModuleCase, $jvmModuleCase]") | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
plugins/src/main/java/com/jraska/lint/LintReportProcess.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,23 @@ | ||
package com.jraska.lint | ||
|
||
import com.jraska.analytics.AnalyticsReporter | ||
import org.gradle.api.Project | ||
|
||
class LintReportProcess( | ||
private val lintProjectExtractor: LintProjectExtractor, | ||
private val lintAnalyticsReporter: LintAnalyticsReporter | ||
) { | ||
fun executeReport(project: Project) { | ||
val report = lintProjectExtractor.extract(project) | ||
lintAnalyticsReporter.report(report) | ||
} | ||
|
||
companion object { | ||
fun create(): LintReportProcess { | ||
return LintReportProcess( | ||
LintProjectExtractor(), | ||
LintAnalyticsReporter(AnalyticsReporter.create("Lint Reporter")) | ||
) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
plugins/src/main/java/com/jraska/lint/LintReporterPlugin.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,22 @@ | ||
package com.jraska.lint | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class LintReporterPlugin : Plugin<Project> { | ||
override fun apply(project: Project) { | ||
project.afterEvaluate { | ||
it.tasks.register("lintStatisticsReport") { lintReportTask -> | ||
lintReportTask.doLast { | ||
LintReportProcess.create().executeReport(lintReportTask.project) | ||
} | ||
|
||
project.rootProject.subprojects | ||
.filter { it.childProjects.isEmpty() } | ||
.forEach { | ||
lintReportTask.dependsOn(it.tasks.named("lint")) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.