Browse Source

Move custom checkstyle rule implementations to build-conventions project (#74017)

Mark Vieira 4 years ago
parent
commit
1f1c8b0019

+ 1 - 0
.gitignore

@@ -12,6 +12,7 @@ out/
 !.idea/scopes/x_pack.xml
 !.idea/inspectionProfiles/Project_Default.xml
 !.idea/runConfigurations/Debug_Elasticsearch.xml
+!.idea/checkstyle-idea.xml
 
 # These files are generated in the main tree by IntelliJ
 benchmarks/src/main/generated/*

+ 19 - 0
.idea/checkstyle-idea.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CheckStyle-IDEA">
+    <option name="configuration">
+      <map>
+        <entry key="active-configuration" value="PROJECT_RELATIVE:$PROJECT_DIR$/checkstyle_ide.xml:Elasticsearch" />
+        <entry key="checkstyle-version" value="8.42" />
+        <entry key="copy-libs" value="false" />
+        <entry key="location-0" value="BUNDLED:(bundled):Sun Checks" />
+        <entry key="location-1" value="BUNDLED:(bundled):Google Checks" />
+        <entry key="location-2" value="PROJECT_RELATIVE:$PROJECT_DIR$/checkstyle_ide.xml:Elasticsearch" />
+        <entry key="scan-before-checkin" value="false" />
+        <entry key="scanscope" value="JavaOnlyWithTests" />
+        <entry key="suppress-errors" value="false" />
+        <entry key="thirdparty-classpath" value="$PROJECT_DIR$/build-conventions/build/libs/build-conventions.jar" />
+      </map>
+    </option>
+  </component>
+</project>

+ 3 - 21
CONTRIBUTING.md

@@ -174,27 +174,9 @@ file is generated automatically after IntelliJ finishes syncing. You can
 manually generate the file with `./gradlew configureIdeCheckstyle` in case
 it is removed due to a `./gradlew clean` or other action.
 
-   1. Open **Preferences > Tools > Checkstyle**
-   2. We have some custom Checkstyle rules, and the Checkstyle plugin needs
-      to know where to find them. Under the "Third-Party Checks" section,
-      click the "+" button.
-   3. Select `build-tools-internal/build/distributions/build-tools-internal-$VERSION.jar` where
-      `$VERSION` is something like `7.0.0-SNAPSHOT`. This jar file will
-      always exist if you imported the project into IntelliJ before
-      configuring Checkstyle.
-   4. Make sure that "Checkstyle version" is set to the highest available version
-   5. Change the "Scan Scope" to "Only Java sources (including tests)"
-   6. Click the "+" under "Configuration file"
-   7. Set "Description" to "Elasticsearch"
-   8. Select "Use a local Checkstyle file"
-   9. For the "File", enter `checkstyle_ide.xml`
-   10. Tick "Store relative to project location"
-   11. Click "Next", then "Finish".
-   12. 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.
-   13. Click "OK" to apply the new preferences
+IntelliJ should be automatically configured to use the generated rules after
+import via the `.idea/checkstyle-idea.xml` configuration file. No further
+action is required.
 
 #### Formatting
 

+ 2 - 1
build-conventions/build.gradle

@@ -6,7 +6,7 @@
  * Side Public License, v 1.
  */
 
-import org.gradle.plugins.ide.eclipse.model.SourceFolder;
+import org.gradle.plugins.ide.eclipse.model.SourceFolder
 
 plugins {
     id 'java-gradle-plugin'
@@ -57,6 +57,7 @@ dependencies {
     api 'org.apache.maven:maven-model:3.6.2'
     api 'gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0'
     api 'org.apache.rat:apache-rat:0.11'
+    compileOnly "com.puppycrawl.tools:checkstyle:8.42"
 }
 
 project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> {

+ 0 - 0
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java → build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java


+ 0 - 0
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java → build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java


+ 3 - 2
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java

@@ -11,7 +11,6 @@ package org.elasticsearch.gradle.internal.precommit;
 import org.elasticsearch.gradle.VersionProperties;
 import org.elasticsearch.gradle.internal.InternalPlugin;
 import org.elasticsearch.gradle.internal.conventions.precommit.PrecommitPlugin;
-import org.elasticsearch.gradle.internal.conventions.util.Util;
 import org.gradle.api.Action;
 import org.gradle.api.GradleException;
 import org.gradle.api.Project;
@@ -19,6 +18,7 @@ import org.gradle.api.Task;
 import org.gradle.api.artifacts.dsl.DependencyHandler;
 import org.gradle.api.plugins.quality.Checkstyle;
 import org.gradle.api.plugins.quality.CheckstyleExtension;
+import org.gradle.api.provider.Provider;
 import org.gradle.api.tasks.TaskProvider;
 
 import java.io.File;
@@ -88,8 +88,9 @@ public class CheckstylePrecommitPlugin extends PrecommitPlugin implements Intern
 
         DependencyHandler dependencies = project.getDependencies();
         String checkstyleVersion = VersionProperties.getVersions().get("checkstyle");
+        Provider<String> dependencyProvider = project.provider(() -> "org.elasticsearch:build-conventions:" + project.getVersion());
         dependencies.add("checkstyle", "com.puppycrawl.tools:checkstyle:" + checkstyleVersion);
-        dependencies.add("checkstyle", project.files(getBuildSrcCodeSource()));
+        dependencies.addProvider("checkstyle", dependencyProvider, dep -> dep.setTransitive(false));
 
         project.getTasks().withType(Checkstyle.class).configureEach(t -> {
             t.dependsOn(copyCheckstyleConf);

+ 2 - 0
build-tools-internal/src/testKit/elasticsearch.build/build.gradle

@@ -66,3 +66,5 @@ tasks.register("hello") {
     println "build plugin can be applied"
   }
 }
+// requires further classpath
+tasks.named("checkstyleMain").configure {enabled = false }