-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
### What's done: - supported reporters to configure reporters in maven - supported a default location for all reporters It closes #1818
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Utilities for diktat maven plugin | ||
*/ | ||
|
||
package com.saveourtool.diktat.plugin.maven | ||
|
||
import com.saveourtool.diktat.api.DiktatReporterType | ||
import org.apache.maven.project.MavenProject | ||
import java.io.File | ||
|
||
/** | ||
* @param reporterType | ||
* @return default location of report with provided [reporterType] | ||
*/ | ||
internal fun MavenProject.defaultReportLocation( | ||
reporterType: DiktatReporterType, | ||
): File = basedir | ||
.resolve(build.directory) | ||
.resolve("reports") | ||
.resolve("diktat") | ||
.resolve("diktat.${reporterType.extension}") | ||
Check warning on line 21 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/Utils.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/Utils.kt#L17-L21
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* All default reporters | ||
*/ | ||
|
||
package com.saveourtool.diktat.plugin.maven.reporters | ||
|
||
import com.saveourtool.diktat.api.DiktatReporterCreationArguments | ||
import com.saveourtool.diktat.api.DiktatReporterType | ||
import com.saveourtool.diktat.plugin.maven.defaultReportLocation | ||
import org.apache.maven.plugins.annotations.Parameter | ||
import org.apache.maven.project.MavenProject | ||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
/** | ||
* A base interface for a default reporter | ||
* | ||
* @property type type of reporter | ||
*/ | ||
abstract class DefaultReporter( | ||
Check warning Code scanning / detekt An abstract class is unnecessary. May be refactored to an interface or to a concrete class. Warning
An abstract class without an abstract member can be refactored to a concrete class.
|
||
private val type: DiktatReporterType, | ||
Check failure Code scanning / ktlint [KDOC_NO_CONSTRUCTOR_PROPERTY] all properties from the primary constructor should be documented in a @Property tag in KDoc: change @property tag to @param tag for to KDoc Error
[KDOC_NO_CONSTRUCTOR_PROPERTY] all properties from the primary constructor should be documented in a @property tag in KDoc: change @property tag to @param tag for to KDoc
Check warning on line 21 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L20-L21
|
||
) : Reporter { | ||
/** | ||
* Location for output | ||
*/ | ||
@Parameter | ||
var output: File? = null | ||
Check warning on line 27 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L27
|
||
|
||
override fun getOutput(project: MavenProject): File? = output ?: project.defaultReportLocation(type) | ||
|
||
override fun toCreationArguments( | ||
project: MavenProject, | ||
sourceRootDir: Path, | ||
): DiktatReporterCreationArguments = DiktatReporterCreationArguments( | ||
reporterType = type, | ||
outputStream = getOutputStream(project), | ||
Check warning on line 36 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L34-L36
|
||
sourceRootDir = sourceRootDir.takeIf { type == DiktatReporterType.SARIF }, | ||
) | ||
Check warning on line 38 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L38
|
||
} | ||
|
||
/** | ||
* Plain reporter | ||
*/ | ||
class PlainReporter : DefaultReporter( | ||
type = DiktatReporterType.PLAIN, | ||
Check warning on line 45 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L44-L45
|
||
) { | ||
/** | ||
* Plain reporter prints to stdout by default | ||
*/ | ||
override fun getOutput(project: MavenProject): File? = output | ||
Check warning on line 50 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L50
|
||
} | ||
|
||
/** | ||
* JSON reporter | ||
*/ | ||
class JsonReporter : DefaultReporter( | ||
type = DiktatReporterType.JSON, | ||
Check warning on line 57 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L56-L57
|
||
) | ||
|
||
/** | ||
* SARIF reporter | ||
*/ | ||
class SarifReporter : DefaultReporter( | ||
type = DiktatReporterType.SARIF, | ||
Check warning on line 64 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L63-L64
|
||
) | ||
|
||
/** | ||
* Checkstyle reporter | ||
*/ | ||
class CheckstyleReporter : DefaultReporter( | ||
type = DiktatReporterType.CHECKSTYLE, | ||
Check warning on line 71 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L70-L71
|
||
) | ||
|
||
/** | ||
* HTML reporter | ||
*/ | ||
class HtmlReporter : DefaultReporter( | ||
type = DiktatReporterType.HTML, | ||
Check warning on line 78 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.kt#L77-L78
|
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.saveourtool.diktat.plugin.maven.reporters | ||
|
||
import com.saveourtool.diktat.api.DiktatReporterCreationArguments | ||
import com.saveourtool.diktat.api.DiktatReporterType | ||
import com.saveourtool.diktat.plugin.maven.defaultReportLocation | ||
import org.apache.maven.project.MavenProject | ||
import java.io.File | ||
import java.nio.file.Path | ||
|
||
/** | ||
* GitHub actions reporter | ||
*/ | ||
class GitHubActionsReporter : Reporter { | ||
override fun getOutput(project: MavenProject): File = project.defaultReportLocation(DiktatReporterType.SARIF) | ||
Check warning on line 14 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/GitHubActionsReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/GitHubActionsReporter.kt#L13-L14
|
||
override fun toCreationArguments(project: MavenProject, sourceRootDir: Path): DiktatReporterCreationArguments = | ||
DiktatReporterCreationArguments( | ||
reporterType = DiktatReporterType.SARIF, | ||
outputStream = getOutputStream(project), | ||
sourceRootDir = sourceRootDir, | ||
) | ||
Check warning on line 20 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/GitHubActionsReporter.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/GitHubActionsReporter.kt#L16-L20
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.saveourtool.diktat.plugin.maven.reporters | ||
|
||
import com.saveourtool.diktat.api.DiktatReporterCreationArguments | ||
import org.apache.maven.project.MavenProject | ||
import java.io.File | ||
import java.io.OutputStream | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
/** | ||
* A base interface for reporter | ||
*/ | ||
interface Reporter { | ||
/** | ||
* @param project | ||
* @return location as a [File] for output or default value resolved by [project] | ||
*/ | ||
fun getOutput(project: MavenProject): File? | ||
|
||
/** | ||
* @param project | ||
* @return location as an [OutputStream] for output or default value resolved by [project] | ||
*/ | ||
fun getOutputStream(project: MavenProject): OutputStream? = getOutput(project)?.also { Files.createDirectories(it.parentFile.toPath()) }?.outputStream() | ||
|
||
/** | ||
* @param project | ||
* @param sourceRootDir | ||
* @return [DiktatReporterCreationArguments] to create this reporter | ||
*/ | ||
fun toCreationArguments(project: MavenProject, sourceRootDir: Path): DiktatReporterCreationArguments | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.saveourtool.diktat.plugin.maven.reporters | ||
|
||
import org.apache.maven.plugins.annotations.Parameter | ||
|
||
/** | ||
Check failure Code scanning / ktlint [USE_DATA_CLASS] this class can be converted to a data class: Reporters (cannot be auto-corrected) Error
[USE_DATA_CLASS] this class can be converted to a data class: Reporters (cannot be auto-corrected)
|
||
* Configuration for reporters | ||
*/ | ||
class Reporters { | ||
Check warning on line 8 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L8
|
||
/** | ||
* Configure *plain* reporter | ||
*/ | ||
@Parameter | ||
var plain: PlainReporter? = null | ||
Check warning on line 13 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L13
|
||
|
||
/** | ||
* Configure *json* reporter | ||
*/ | ||
@Parameter | ||
var json: JsonReporter? = null | ||
Check warning on line 19 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L19
|
||
|
||
/** | ||
* Configure *sarif* reporter | ||
*/ | ||
@Parameter | ||
var sarif: SarifReporter? = null | ||
Check warning on line 25 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L25
|
||
|
||
/** | ||
* Configure *sarif* reporter for GitHub actions | ||
*/ | ||
@Parameter | ||
var gitHubActions: GitHubActionsReporter? = null | ||
Check warning on line 31 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L31
|
||
|
||
/** | ||
* Configure *checkstyle* reporter | ||
*/ | ||
@Parameter | ||
var checkstyle: CheckstyleReporter? = null | ||
Check warning on line 37 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L37
|
||
|
||
/** | ||
* Configure *html* reporter | ||
*/ | ||
@Parameter | ||
var html: HtmlReporter? = null | ||
Check warning on line 43 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L43
|
||
|
||
/** | ||
* @return all configured reporters | ||
*/ | ||
val all: List<Reporter> | ||
get() = listOfNotNull( | ||
Check failure Code scanning / ktlint [CUSTOM_GETTERS_SETTERS] custom getters and setters are not recommended, use class methods instead: get (cannot be auto-corrected) Error
[CUSTOM_GETTERS_SETTERS] custom getters and setters are not recommended, use class methods instead: get (cannot be auto-corrected)
|
||
plain, | ||
json, | ||
sarif, | ||
gitHubActions, | ||
checkstyle, | ||
html, | ||
) | ||
Check warning on line 56 in diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt Codecov / codecov/patchdiktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.kt#L49-L56
|
||
} |