-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supported multiple reporters in maven (#1824)
- supported reporters to configure reporters in maven - supported a default location for all reporters
- Loading branch information
Showing
9 changed files
with
245 additions
and
41 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
21 changes: 21 additions & 0 deletions
21
diktat-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/Utils.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,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}") |
79 changes: 79 additions & 0 deletions
79
...n-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/DefaultReporter.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,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 | ||
* | ||
* @param type type of reporter | ||
*/ | ||
open class DefaultReporter( | ||
private val type: DiktatReporterType, | ||
) : Reporter { | ||
/** | ||
* Location for output | ||
*/ | ||
@Parameter | ||
var output: File? = null | ||
|
||
override fun getOutput(project: MavenProject): File? = output ?: project.defaultReportLocation(type) | ||
|
||
override fun toCreationArguments( | ||
project: MavenProject, | ||
sourceRootDir: Path, | ||
): DiktatReporterCreationArguments = DiktatReporterCreationArguments( | ||
reporterType = type, | ||
outputStream = getOutputStream(project), | ||
sourceRootDir = sourceRootDir.takeIf { type == DiktatReporterType.SARIF }, | ||
) | ||
} | ||
|
||
/** | ||
* Plain reporter | ||
*/ | ||
class PlainReporter : DefaultReporter( | ||
type = DiktatReporterType.PLAIN, | ||
) { | ||
/** | ||
* Plain reporter prints to stdout by default | ||
*/ | ||
override fun getOutput(project: MavenProject): File? = output | ||
} | ||
|
||
/** | ||
* JSON reporter | ||
*/ | ||
class JsonReporter : DefaultReporter( | ||
type = DiktatReporterType.JSON, | ||
) | ||
|
||
/** | ||
* SARIF reporter | ||
*/ | ||
class SarifReporter : DefaultReporter( | ||
type = DiktatReporterType.SARIF, | ||
) | ||
|
||
/** | ||
* Checkstyle reporter | ||
*/ | ||
class CheckstyleReporter : DefaultReporter( | ||
type = DiktatReporterType.CHECKSTYLE, | ||
) | ||
|
||
/** | ||
* HTML reporter | ||
*/ | ||
class HtmlReporter : DefaultReporter( | ||
type = DiktatReporterType.HTML, | ||
) |
21 changes: 21 additions & 0 deletions
21
...in/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/GitHubActionsReporter.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,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) | ||
override fun toCreationArguments(project: MavenProject, sourceRootDir: Path): DiktatReporterCreationArguments = | ||
DiktatReporterCreationArguments( | ||
reporterType = DiktatReporterType.SARIF, | ||
outputStream = getOutputStream(project), | ||
sourceRootDir = sourceRootDir, | ||
) | ||
} |
32 changes: 32 additions & 0 deletions
32
...at-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporter.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,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 | ||
} |
56 changes: 56 additions & 0 deletions
56
...t-maven-plugin/src/main/kotlin/com/saveourtool/diktat/plugin/maven/reporters/Reporters.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,56 @@ | ||
package com.saveourtool.diktat.plugin.maven.reporters | ||
|
||
import org.apache.maven.plugins.annotations.Parameter | ||
|
||
/** | ||
* Configuration for reporters | ||
*/ | ||
class Reporters { | ||
/** | ||
* Configure *plain* reporter | ||
*/ | ||
@Parameter | ||
var plain: PlainReporter? = null | ||
|
||
/** | ||
* Configure *json* reporter | ||
*/ | ||
@Parameter | ||
var json: JsonReporter? = null | ||
|
||
/** | ||
* Configure *sarif* reporter | ||
*/ | ||
@Parameter | ||
var sarif: SarifReporter? = null | ||
|
||
/** | ||
* Configure *sarif* reporter for GitHub actions | ||
*/ | ||
@Parameter | ||
var gitHubActions: GitHubActionsReporter? = null | ||
|
||
/** | ||
* Configure *checkstyle* reporter | ||
*/ | ||
@Parameter | ||
var checkstyle: CheckstyleReporter? = null | ||
|
||
/** | ||
* Configure *html* reporter | ||
*/ | ||
@Parameter | ||
var html: HtmlReporter? = null | ||
|
||
/** | ||
* @return all configured reporters | ||
*/ | ||
fun getAll(): List<Reporter> = listOfNotNull( | ||
plain, | ||
json, | ||
sarif, | ||
gitHubActions, | ||
checkstyle, | ||
html, | ||
) | ||
} |