-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature. Enable confiuring of ktlint reporter in gradle plugin #724
Changes from 9 commits
0900ebb
1d374c0
68a5b0c
56c7621
7965ff1
918ebfd
5843f9a
d67ae58
caaaba7
0b42e86
4af0153
6eaa275
02cc214
4b8b601
cf1fb82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import org.cqfn.diktat.ruleset.rules.DIKTAT_CONF_PROPERTY | |
|
||
import generated.DIKTAT_VERSION | ||
import generated.KTLINT_VERSION | ||
import org.cqfn.diktat.ruleset.utils.log | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.Configuration | ||
import org.gradle.api.provider.Property | ||
|
@@ -17,6 +18,7 @@ import org.gradle.api.tasks.VerificationTask | |
import org.gradle.util.GradleVersion | ||
|
||
import java.io.File | ||
import java.io.PrintStream | ||
import javax.inject.Inject | ||
|
||
/** | ||
|
@@ -50,6 +52,10 @@ open class DiktatJavaExecTaskBase @Inject constructor( | |
} else { | ||
main = "com.pinterest.ktlint.Main" | ||
} | ||
// Plain, checkstyle and json reporter are provided out of the box in ktlint | ||
if (diktatExtension.reporterType == "html") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it needed? If yes, why onlu for html? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Others are already included in ktlint (plain, json, checkstyle) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, ok, that's strange. Leave a comment in code to explain this, pls. |
||
diktatConfiguration.dependencies.add(project.dependencies.create("com.pinterest.ktlint:ktlint-reporter-html:$KTLINT_VERSION")) | ||
} | ||
classpath = diktatConfiguration | ||
project.logger.debug("Setting diktatCheck classpath to ${diktatConfiguration.dependencies.toSet()}") | ||
if (diktatExtension.debug) { | ||
|
@@ -83,6 +89,8 @@ open class DiktatJavaExecTaskBase @Inject constructor( | |
diktatExtension.excludes.files.forEach { | ||
addPattern(it, negate = true) | ||
} | ||
|
||
add(createReporterFlag(diktatExtension)) | ||
} | ||
logger.debug("Setting JavaExec args to $args") | ||
} | ||
|
@@ -107,6 +115,38 @@ open class DiktatJavaExecTaskBase @Inject constructor( | |
@Suppress("FUNCTION_BOOLEAN_PREFIX") | ||
override fun getIgnoreFailures(): Boolean = ignoreFailuresProp.getOrElse(false) | ||
|
||
private fun createReporterFlag(diktatExtension: DiktatExtension): String { | ||
val flag: StringBuilder = StringBuilder() | ||
|
||
// Plain, checkstyle and json reporter are provided out of the box in ktlint | ||
when(diktatExtension.reporterType) { | ||
"json" -> flag.append("--reporter=json") | ||
"html" -> flag.append("--reporter=html") | ||
"checkstyle" -> flag.append("--reporter=checkstyle") | ||
else -> { | ||
if (diktatExtension.reporterType.startsWith("custom")) { | ||
val name = diktatExtension.reporterType.split(":")[1] | ||
val jarPath = diktatExtension.reporterType.split(":")[2] | ||
if (name.isEmpty() || jarPath.isEmpty()) { | ||
log.warn("Either name or path to jar is not specified. Falling to plain reporter") | ||
flag.append("--reporter=plain") | ||
} else { | ||
flag.append("--reporter=$name,artifact=$jarPath") | ||
} | ||
} else { | ||
flag.append("--reporter=plain") | ||
log.warn("Unknown reporter was specified. Falling back to plain reporter.") | ||
} | ||
} | ||
} | ||
|
||
if (diktatExtension.output.isNotEmpty()) { | ||
flag.append(",output=${diktatExtension.output}") | ||
petertrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return flag.toString() | ||
} | ||
|
||
@Suppress("MagicNumber") | ||
private fun isMainClassPropertySupported(gradleVersionString: String) = | ||
GradleVersion.version(gradleVersionString) >= GradleVersion.version("6.4") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this line needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't. Fixed