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
Add support for 'console' output type of CodeNarc plugin (Fix 1481) #2170
Conversation
This fix gradle#1481 . Although it is documented that CodeNarc plugin supports 'console' output type, that type is never implemented. This commit add 'console' TaskGeneratedSingleFile to CodeNarcReportsImpl, and adjust the options with which Ant codenarc task is called. To redirect Ant output to Gradle standard output in 'console' type, the lifecycleLogLevel of AntLogAdapter is changed to INFO. Then, a unit test and an integration test are provided.
static void setLifecycleLogLevel(Object ant, String lifecycleLogLevel) { | ||
ant?.builder?.project?.buildListeners?.each { | ||
// We cannot use instanceof or getClass()==AntLoggingAdapter since they're in different class loaders | ||
if (it.class.simpleName == 'AntLoggingAdapter') { |
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.
Looks like there is no simpler way to do this.
We can improve it slightly, by replacing the check with
it.class.name == AntLoggingAdapter.name
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.
Yes, you're right.
option(name: 'outputFile', value: r.destination) | ||
// See http://codenarc.sourceforge.net/codenarc-TextReportWriter.html | ||
if (r.name == 'console') { | ||
setLifecycleLogLevel(ant,'INFO') |
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.
Following Gradle's code style rules, this should be (ant, 'INFO')
<- with a space
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.
Done. You're so careful.
option(name: 'writeToStandardOut', value: true) | ||
} | ||
} else { | ||
setLifecycleLogLevel(ant,null) |
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.
(ant, null)
@blindpirate PR looks good, thanks! Just some minor remarks. Could you address them? Then this can go into 4.1 I think this also deserves a short mentioning in the Release Notes. Could you add a |
As you say, I have improved it. Please let me know if there're any other questions. |
Thanks @blindpirate! The PR is merged and will be part of the 4.1 release. |
Thanks @jjohannes . |
@blindpirate did you consider implementing support for multiple reports? |
@vgaidarji Right now I don't think have enough bandwidth/priority to implement such a feature. However, I think this shouldn't be too difficult, maybe at most 100 lines change? We're glad if any contributions can be made. |
So just to confirm, multiple report format outputs aren't currently supported with this plugin? I have to choose either console, or HTML, or XML? |
Context
See #1481 and discussion in old forum.
Although it is documented that CodeNarc plugin supports 'console' output type, that type is never implemented. This commit add 'console' TaskGeneratedSingleFile to CodeNarcReportsImpl, and adjust the options with which Ant codenarc task is called. To redirect Ant output to Gradle standard output in 'console' type, the lifecycleLogLevel of AntLogAdapter is changed to INFO.
Then, a unit test and an integration test are provided.
Contributor Checklist
<subproject>/src/integTest
) to verify changes from a user perspective<subproject>/src/test
) to verify logic./gradlew quickCheck <impacted-subproject>:check