Skip to content

Commit

Permalink
Stop versioning Checkstyle IDE config (elastic#87285)
Browse files Browse the repository at this point in the history
Closes elastic#86945.

The IntelliJ Checkstyle plugin likes to modify its configuration file
unecessarily, which creates friction for developers because they have
the revert these changes.

Instead, stop versioning the config file and instead update the
`configureIdeCheckstyle` task to copy the required content into place.
  • Loading branch information
pugnascotia authored Jun 2, 2022
1 parent a71ad6e commit d72f3e4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ build-idea/
out/

# include shared intellij config
!.idea/checkstyle-idea.xml
!.idea/eclipseCodeFormatter.xml
!.idea/externalDependencies.xml
!.idea/inspectionProfiles/Project_Default.xml
Expand Down
34 changes: 27 additions & 7 deletions build-tools-internal/src/main/groovy/elasticsearch.ide.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,35 @@ tasks.register('configureIdeCheckstyle') {
group = 'ide'
description = 'Generated a suitable checkstyle config for IDEs'

String checkstyleConfig = 'build-tools-internal/src/main/resources/checkstyle.xml'
String checkstyleSuppressions = 'build-tools-internal/src/main/resources/checkstyle_suppressions.xml'
String checkstyleIdeFragment = 'build-tools-internal/src/main/resources/checkstyle_ide_fragment.xml'
String checkstyleIdeConfig = "$rootDir/checkstyle_ide.xml"

inputs.files(file(checkstyleConfig), file(checkstyleIdeFragment))
outputs.files(file(checkstyleIdeConfig))
String resources = 'build-tools-internal/src/main/resources'
String checkstyleConfig = "${resources}/checkstyle.xml"
String checkstyleSuppressions = "${resources}/checkstyle_suppressions.xml"
String checkstyleIdeFragment = "${resources}/checkstyle_ide_fragment.xml"
String checkstyleIdeConfig = "${rootDir}/checkstyle_ide.xml"

String checkstylePluginConfigTemplate = "${resources}/checkstyle-idea.xml"
String checkstylePluginConfig = "${rootDir}/.idea/checkstyle-idea.xml"

inputs.files(
file(checkstyleConfig),
file(checkstyleIdeFragment),
file(checkstylePluginConfigTemplate)
)
outputs.files(
file(checkstyleIdeConfig),
file(checkstylePluginConfig)
)

doLast {
// Configure the IntelliJ Checkstyle plugin by copying a standard file. We don't simply commit
// the result to version control, because the plugin has a habit of modifying the file and
// replacing the `$PROJECT_DIR$` placeholders, which developers must then revert.
Files.copy(
Paths.get(file(checkstylePluginConfigTemplate).getPath()),
Paths.get(file(checkstylePluginConfig).getPath()),
StandardCopyOption.REPLACE_EXISTING
)

// Create an IDE-specific checkstyle config by first copying the standard config
Files.copy(
Paths.get(file(checkstyleConfig).getPath()),
Expand Down
File renamed without changes.

0 comments on commit d72f3e4

Please sign in to comment.