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

Move the generated checkstyle config to root dir #66442

Merged
merged 1 commit into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ testfixtures_shared/

# These are generated from .ci/jobs.t
.ci/jobs/

# Generated
checkstyle_ide.xml
16 changes: 6 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,13 @@ it is removed due to a `./gradlew clean` or other action.
3. Check the "+" under "Configuration file"
4. Set "Description" to "Elasticsearch" (or whatever you want)
5. Select "Use a local Checkstyle file"
6. For the "File", navigate to `build/checkstyle_ide.xml`
6. For the "File", enter `checkstyle_ide.xml`
7. Tick "Store relative to project location"
8. Click "Next"
9. The Checkstyle config file contains the variable `config_loc`, and
IntelliJ will ask for a value. Fill in `buildSrc/src/main/resources`.
This allows the config file to reference the exclusions file in that directory.
10. Click "Next", then "Finish".
11. Click the box next to the new configuration to make it "Active". Without doing this,
you'll have to explicitly choose the "Elasticsearch" configuration in the Checkstyle
tool window and run the check manually. You can still do this with an active config.
12. Click "OK" to apply the new preferences
8. Click "Next", then "Finish".
9. Click the box next to the new configuration to make it "Active". Without doing this,
you'll have to explicitly choose the "Elasticsearch" configuration in the Checkstyle
tool window and run the check manually. You can still do this with an active config.
10. Click "OK" to apply the new preferences

#### Formatting

Expand Down
12 changes: 9 additions & 3 deletions gradle/ide.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tasks.register('configureIdeCheckstyle') {
description = 'Generated a suitable checkstyle config for IDEs'

String checkstyleConfig = 'buildSrc/src/main/resources/checkstyle.xml'
String checkstyleIdeConfig = "${buildDir}/checkstyle_ide.xml"
String checkstyleIdeConfig = "$rootDir/checkstyle_ide.xml"

inputs.files(file(checkstyleConfig))
outputs.files(file(checkstyleIdeConfig))
Expand All @@ -43,7 +43,7 @@ tasks.register('configureIdeCheckstyle') {
)
// Edit the copy so that IntelliJ can copy with it
modifyXml(checkstyleIdeConfig, { xml ->
// This module since it is implemented with custom code
// Remove this module since it is implemented with custom code
xml.module.findAll { it.'@name' == 'org.elasticsearch.gradle.checkstyle.SnippetLengthCheck' }.each { it.parent().remove(it) }

// Move the line length check because the IDE thinks it can't belong under a TreeWalker. Moving the
Expand All @@ -52,11 +52,17 @@ tasks.register('configureIdeCheckstyle') {
Node lineLength = treeWalker.module.find { it.'@name' == 'LineLength' }
treeWalker.remove(lineLength)
xml.append(lineLength)

// Change the checkstyle config to inline the path to the
// suppressions config. This removes a configuration step when using
// the checkstyle config in an IDE.
Node suppressions = xml.module.find { it.'@name' == 'SuppressionFilter' }
suppressions.property.findAll { it.'@name' == 'file' }.each { it.'@value' = "buildSrc/src/main/resources/checkstyle_suppressions.xml" }
},
"<!DOCTYPE module PUBLIC\n" +
" \"-//Puppy Crawl//DTD Check Configuration 1.3//EN\"\n" +
" \"http://www.puppycrawl.com/dtds/configuration_1_3.dtd\">\n" +
"<!-- Generated automatically from ./checkstyle.xml - do not edit this file directly. -->\n"
"<!-- Generated automatically from ${checkstyleConfig} - do not edit this file directly. -->\n"
)
}
}
Expand Down