Browse Source

Template IntelliJ Checkstyle plugin configuration

Mark Vieira 3 years ago
parent
commit
2bfdeffd24

+ 6 - 5
build-tools-internal/src/main/groovy/elasticsearch.ide.gradle

@@ -33,6 +33,7 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
     description = 'Generated a suitable checkstyle config for IDEs'
 
     String resources = "${elasticsearchProject.left()}/build-tools-internal/src/main/resources"
+    String buildConventionsJar = "${elasticsearchProject.left()}/build-conventions/build/libs/build-conventions.jar"
     String checkstyleConfig = "${resources}/checkstyle.xml"
     String checkstyleSuppressions = "${resources}/checkstyle_suppressions.xml"
     String checkstyleIdeFragment = "${resources}/checkstyle_ide_fragment.xml"
@@ -55,11 +56,11 @@ if (providers.systemProperty('idea.active').getOrNull() == 'true') {
       // 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
-      )
+      project.copy {
+        from(checkstylePluginConfigTemplate)
+        into("${rootDir}/.idea")
+        expand(jarLocation: buildConventionsJar, configLocation: checkstyleIdeConfig)
+      }
 
       // Create an IDE-specific checkstyle config by first copying the standard config
       Files.copy(

+ 2 - 2
build-tools-internal/src/main/resources/checkstyle-idea.xml

@@ -4,7 +4,7 @@
         <checkstyleVersion>10.3.1</checkstyleVersion>
         <scanScope>JavaOnlyWithTests</scanScope>
         <option name="thirdPartyClasspath">
-            <option value="$PROJECT_DIR$/build-conventions/build/libs/build-conventions.jar" />
+            <option value="${jarLocation}" />
         </option>
         <option name="activeLocationIds">
             <option value="dfb90780-ced3-4152-a4df-3cc9be08e3d8" />
@@ -13,7 +13,7 @@
             <list>
                 <ConfigurationLocation id="bundled-sun-checks" type="BUNDLED" scope="All" description="Sun Checks">(bundled)</ConfigurationLocation>
                 <ConfigurationLocation id="bundled-google-checks" type="BUNDLED" scope="All" description="Google Checks">(bundled)</ConfigurationLocation>
-                <ConfigurationLocation id="dfb90780-ced3-4152-a4df-3cc9be08e3d8" type="PROJECT_RELATIVE" scope="All" description="Elasticsearch">$PROJECT_DIR$/checkstyle_ide.xml</ConfigurationLocation>
+                <ConfigurationLocation id="dfb90780-ced3-4152-a4df-3cc9be08e3d8" type="PROJECT_RELATIVE" scope="All" description="Elasticsearch">${configLocation}</ConfigurationLocation>
             </list>
         </option>
     </component>