-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML Report via a bit updated model, and tasks automatically added (#14)
* Describe mavenLocal() * Add new model and mapping * Move tasks to verification group * Add Violations HTML report supporting Lint for now * Allow violations task to be used from all modules, not just root
- Loading branch information
1 parent
213538f
commit 48df075
Showing
15 changed files
with
1,062 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ out/ | |
|
||
# IDEA Project files | ||
.idea/ | ||
!/.idea/misc.xml | ||
*.iml | ||
*.ipr | ||
*.iws | ||
|
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
76 changes: 60 additions & 16 deletions
76
quality/src/main/kotlin/net/twisterrob/gradle/quality/Violations.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 |
---|---|---|
@@ -1,25 +1,69 @@ | ||
package net.twisterrob.gradle.quality | ||
|
||
import se.bjurr.violations.lib.model.Violation | ||
import org.gradle.api.Project | ||
import java.io.File | ||
|
||
class Violations( | ||
@JvmField val parser: String, | ||
@JvmField val module: String, | ||
@JvmField val variant: String, | ||
/** | ||
* Parseable result. | ||
*/ | ||
@JvmField val result: File, | ||
/** | ||
* Human-consumable report. | ||
*/ | ||
@JvmField val report: File, | ||
/** | ||
* Report file missing, or error during read. | ||
*/ | ||
@JvmField val violations: List<Violation>? | ||
@JvmField val parser: String, | ||
@JvmField val module: String, | ||
@JvmField val variant: String, | ||
/** | ||
* Parseable result. | ||
*/ | ||
@JvmField val result: File, | ||
/** | ||
* Human-consumable report. | ||
*/ | ||
@JvmField val report: File, | ||
/** | ||
* Report file missing, or error during read. | ||
*/ | ||
@JvmField val violations: List<Violation>? | ||
) { | ||
|
||
override fun toString() = "${module}:${parser}@${variant} (${result}): ${violations}" | ||
} | ||
|
||
class Violation( | ||
val rule: String, | ||
val category: String?, | ||
val severity: Severity, | ||
val message: String, | ||
val specifics: Map<String, String> = emptyMap(), | ||
val location: Location, | ||
val source: Source | ||
) { | ||
|
||
override fun toString() = | ||
"Violation(rule='$rule', category=$category, severity=$severity, message='$message', specifics=$specifics, location=$location, source=$source)" | ||
|
||
enum class Severity { | ||
INFO, | ||
WARNING, | ||
ERROR | ||
} | ||
|
||
class Location( | ||
val module: Project, | ||
val variant: String, | ||
val file: File, | ||
val startLine: Int, | ||
val endLine: Int, | ||
val column: Int | ||
) { | ||
override fun toString() = | ||
"Location(module=$module, variant='$variant', file=$file, startLine=$startLine, endLine=$endLine, column=$column)" | ||
} | ||
|
||
class Source( | ||
val parser: String, | ||
val gatherer: String, | ||
val reporter: String, | ||
val source: String, | ||
val report: File, | ||
val humanReport: File? | ||
) { | ||
override fun toString() = | ||
"Source(parser='$parser', gatherer='$gatherer', reporter='$reporter', source='$source', report=$report, humanReport=$humanReport)" | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
quality/src/main/kotlin/net/twisterrob/gradle/quality/report/html/ViolationsCollapser.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,82 @@ | ||
package net.twisterrob.gradle.quality.report.html | ||
|
||
import net.twisterrob.gradle.quality.Violation | ||
import net.twisterrob.gradle.quality.Violation.Location | ||
|
||
/** | ||
* Assumes order by category then by rule then by file then by line then by column. | ||
*/ | ||
internal fun collapse(violations: List<Violation>): List<Violation> = | ||
violations | ||
.groupBy { it.rule } | ||
.mapValues { (_, list) -> collapseUniform(list) } | ||
.flatMap { it.value } | ||
|
||
internal fun collapseUniform(violations: List<Violation>): List<Violation> = | ||
violations | ||
.groupBy { it.location.file } | ||
.mapValues { (_, list) -> collapseFile(list) } | ||
.flatMap { it.value } | ||
|
||
internal fun collapseFile(violations: List<Violation>): List<Violation> { | ||
@Suppress("SimplifyBooleanWithConstants") | ||
fun verySimilarProblem(v1: Violation, v2: Violation): Boolean = | ||
true | ||
&& v1.rule == v2.rule | ||
&& v1.category == v2.category | ||
&& v1.severity == v2.severity | ||
&& v1.specifics == v2.specifics | ||
//&& v1.message == v2.message | ||
&& v1.location.module == v2.location.module | ||
&& v1.location.variant == v2.location.variant | ||
&& v1.location.file == v2.location.file | ||
//&& v1.location.startLine == v2.location.startLine | ||
//&& v1.location.endLine == v2.location.endLine | ||
//&& v1.location.column == v2.location.column | ||
&& v1.source.parser == v2.source.parser | ||
&& v1.source.gatherer == v2.source.gatherer | ||
&& v1.source.reporter == v2.source.reporter | ||
&& v1.source.source == v2.source.source | ||
&& v1.source.report == v2.source.report | ||
&& v1.source.humanReport == v2.source.humanReport | ||
|
||
fun merge(list: List<Violation>): Violation { | ||
val first = list.first() | ||
return Violation( | ||
first.rule, | ||
first.category, | ||
first.severity, | ||
list.joinToString { it.message }, | ||
first.specifics, | ||
Location( | ||
first.location.module, | ||
first.location.variant, | ||
first.location.file, | ||
first.location.startLine, | ||
list.last().location.endLine, | ||
first.location.column | ||
), | ||
first.source | ||
) | ||
} | ||
|
||
var continuation: MutableList<Violation> = mutableListOf(violations.first()) | ||
val mergeds = mutableListOf<Violation>() | ||
for (next in violations.asSequence().drop(1)) { | ||
if (verySimilarProblem(next, continuation.last())) { | ||
if (continuation.last().location.endLine + 1 == next.location.startLine) { | ||
// found a continuation, save and continue searching | ||
continuation.add(next) | ||
continue | ||
} | ||
} | ||
// if reached here, something is different and next is not part of the [first, last] group | ||
// continuation was already found, merge them (possible that continuation.size == 1, it still works | ||
mergeds.add(merge(continuation)) | ||
// continue searching from next one | ||
continuation = mutableListOf(next) | ||
} | ||
// merge remainder (i.e. last group); this could be a single input item as well | ||
mergeds.add(merge(continuation)) | ||
return mergeds | ||
} |
Oops, something went wrong.