Skip to content
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

Export Config with --generate-config #54

Merged
merged 8 commits into from May 29, 2017
Merged

Conversation

lummax
Copy link
Contributor

@lummax lummax commented May 29, 2017

Fixes #48.

--generate-config is marked as help=True to prevent the required option exception. But the jcommander.Parameter class only cares for the existence of at least one of those and there is no further special treatment.

@arturbosch arturbosch self-requested a review May 29, 2017 07:16
@arturbosch
Copy link
Member

The review fixes and I'm gladly merging this PR. Thx!

@@ -157,7 +157,7 @@ allprojects {
}

detekt {
config = "$project.projectDir/default-detekt-config.yml"
config = "$project.projectDir/detekt-cli/src/main/resources/default-detekt-config.yml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats wrong. The config parameter should be used to locate your default-config from any path on your filesystem. If you have the default-config inside your resources (maven multi-module support), you should use the configResource field eg. configResource = "default-detekt-config.yml" which will be extracted from the resources

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the local build.gradle. From what I undernstand this is the local configuration of the gradle detekt plugin? Within this context, this path will always contain the configuration. Using configResource does not work here, as the default-detekt-config.yml only gets bundled into the detekt-cli jar?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, your right. I somehow thought this was the README and the users would get confused. :)

class ConfigExporter(val main: Main) {

fun execute() {
val defaultConfig = ClassLoader.getSystemClassLoader().getResourceAsStream("default-detekt-config.yml")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use javaClass.getResourceAsStream() and explicitly throw an InvalidStateException if the inputstream is null

@@ -64,6 +68,9 @@ class Main {
if (main.debug) {
Debugger(main).execute()
return
} else if (main.generateConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's time to introduce an Executable interface :) Something like:

val executable = when {
    main.debug -> Debugger(main) 
    main.generateConfig -> ConfigExporter(main)
    else -> Runner(main)
}
executable.execute()

@arturbosch arturbosch added this to the M11 milestone May 29, 2017
@arturbosch arturbosch merged commit e791c6b into detekt:master May 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants