Skip to content

Commit

Permalink
Move custom checkstyle rule implementations to build-conventions proj…
Browse files Browse the repository at this point in the history
…ect (#74017) (#74033)
  • Loading branch information
mark-vieira authored Jun 10, 2021
1 parent c05fedb commit c8fae49
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
19 changes: 19 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 3 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `buildSrc/build-bootstrap/libs/buildSrc-$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

Expand Down
3 changes: 2 additions & 1 deletion build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -56,6 +56,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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
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;
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;
Expand Down Expand Up @@ -88,8 +88,9 @@ public void execute(Task task) {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ tasks.register("hello") {
println "build plugin can be applied"
}
}
// requires further classpath
tasks.named("checkstyleMain").configure {enabled = false }

0 comments on commit c8fae49

Please sign in to comment.