From 1f1c8b0019d48bc6e38c979336450173ef26cb66 Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Thu, 10 Jun 2021 16:06:44 -0700 Subject: [PATCH] Move custom checkstyle rule implementations to build-conventions project (#74017) --- .gitignore | 1 + .idea/checkstyle-idea.xml | 19 +++++++++++++++ CONTRIBUTING.md | 24 +++---------------- build-conventions/build.gradle | 3 ++- .../checkstyle/MissingJavadocTypeCheck.java | 0 .../checkstyle/SnippetLengthCheck.java | 0 .../precommit/CheckstylePrecommitPlugin.java | 5 ++-- .../testKit/elasticsearch.build/build.gradle | 2 ++ 8 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 .idea/checkstyle-idea.xml rename {build-tools-internal => build-conventions}/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java (100%) rename {build-tools-internal => build-conventions}/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java (100%) diff --git a/.gitignore b/.gitignore index fd6449f1c7c4c..0163712c89559 100644 --- a/.gitignore +++ b/.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/* diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml new file mode 100644 index 0000000000000..75cca1a8171f4 --- /dev/null +++ b/.idea/checkstyle-idea.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cb1e8b73dbfa7..3c0f8a22203cc 100644 --- a/CONTRIBUTING.md +++ b/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 diff --git a/build-conventions/build.gradle b/build-conventions/build.gradle index d5b1a71fa673c..2d0989fc77d99 100644 --- a/build-conventions/build.gradle +++ b/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 -> { diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java similarity index 100% rename from build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java rename to build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/MissingJavadocTypeCheck.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java b/build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java similarity index 100% rename from build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java rename to build-conventions/src/main/java/org/elasticsearch/gradle/internal/checkstyle/SnippetLengthCheck.java diff --git a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java index d2baacc114451..582fb2e4e0df5 100644 --- a/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java +++ b/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/CheckstylePrecommitPlugin.java @@ -11,7 +11,6 @@ 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.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 void execute(Task task) { DependencyHandler dependencies = project.getDependencies(); String checkstyleVersion = VersionProperties.getVersions().get("checkstyle"); + Provider 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); diff --git a/build-tools-internal/src/testKit/elasticsearch.build/build.gradle b/build-tools-internal/src/testKit/elasticsearch.build/build.gradle index 93c9bd273a8ff..0f379b6127b36 100644 --- a/build-tools-internal/src/testKit/elasticsearch.build/build.gradle +++ b/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 }