diff --git a/.gitignore b/.gitignore index ff9e964289f3..024e3224397a 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,6 @@ testfixtures_shared/ # These are generated from .ci/jobs.t .ci/jobs/ + +# Generated +checkstyle_ide.xml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb92204b97fe..1dd03be3a04d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -164,17 +164,13 @@ file is generated automatically after IntelliJ finishes syncing. 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 diff --git a/gradle/ide.gradle b/gradle/ide.gradle index d1bbf46d8f67..720375bdffab 100644 --- a/gradle/ide.gradle +++ b/gradle/ide.gradle @@ -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)) @@ -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 @@ -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" } }, "\n" + - "\n" + "\n" ) } }