Skip to content

Commit

Permalink
Format build-tools and build-tools-internal (#78910)
Browse files Browse the repository at this point in the history
Our spotless configuration wasn't being applied to `build-tools`
and `build-tools-internal`. Move the Spotless configuration to a
Java plugin in `build-conventions`, and apply it everywhere.

This resulted in a lot more Java files being subject to formatting,
so I added more exclusions to the list.

Also remove the `paddedCell` stuff, we've never needed it.
  • Loading branch information
pugnascotia authored Oct 14, 2021
1 parent d29a8d3 commit 62d2df4
Show file tree
Hide file tree
Showing 126 changed files with 797 additions and 664 deletions.
4 changes: 2 additions & 2 deletions .idea/eclipseCodeFormatter.xml

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

20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ need them.
2. Click "Use the Eclipse Code Formatter"
3. Under "Eclipse formatter config", select "Eclipse workspace/project
folder or config file"
4. Click "Browse", and navigate to the file `build-tools-internal/formatterConfig.xml`
4. Click "Browse", and navigate to the file `build-conventions/formatterConfig.xml`
5. **IMPORTANT** - make sure "Optimize Imports" is **NOT** selected.
6. Click "OK"

Note that only some sub-projects in the Elasticsearch project are currently
fully-formatted. You can see a list of project that **are not**
automatically formatted in
[build-tools-internal/src/main/groovy/elasticsearch.formatting.gradle](build-tools-internal/src/main/groovy/elasticsearch.formatting.gradle).
[FormattingPrecommitPlugin.java](build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/precommit/FormattingPrecommitPlugin.java).

### Importing the project into Eclipse

Expand Down Expand Up @@ -234,15 +234,15 @@ Next you'll want to import our auto-formatter:
- Select **Window > Preferences**
- Select **Java > Code Style > Formatter**
- Click **Import**
- Import the file at **build-tools-internal/formatterConfig.xml**
- Import the file at **build-conventions/formatterConfig.xml**
- Make sure it is the **Active profile**

Finally, set up import order:

- Select **Window > Preferences**
- Select **Java > Code Style > Organize Imports**
- Click **Import...**
- Import the file at **build-tools-internal/elastic.importorder**
- Import the file at **build-conventions/elastic.importorder**
- Set the **Number of imports needed for `.*`** to ***9999***
- Set the **Number of static imports needed for `.*`** to ***9999*** as well
- Apply that
Expand Down Expand Up @@ -279,11 +279,12 @@ form.
Java files in the Elasticsearch codebase are automatically formatted using
the [Spotless Gradle] plugin. All new projects are automatically formatted,
while existing projects are gradually being opted-in. The formatting check
can be run explicitly with:
is run automatically via the `precommit` task, but it can be run explicitly with:

./gradlew spotlessJavaCheck

The code can be formatted with:
It is usually more useful, and just as fast, to just reformat the project. You
can do this with:

./gradlew spotlessApply

Expand All @@ -304,10 +305,9 @@ Please follow these formatting guidelines:
* Wildcard imports (`import foo.bar.baz.*`) are forbidden and will cause
the build to fail.
* If *absolutely* necessary, you can disable formatting for regions of code
with the `// tag::NAME` and `// end::NAME` directives, but note that
these are intended for use in documentation, so please make it clear what
you have done, and only do this where the benefit clearly outweighs the
decrease in consistency.
with the `// @formatter:off` and `// @formatter:on` directives, but
only do this where the benefit clearly outweighs the decrease in formatting
consistency.
* Note that Javadoc and block comments i.e. `/* ... */` are not formatted,
but line comments i.e `// ...` are.
* Negative boolean expressions must use the form `foo == false` instead of
Expand Down
7 changes: 7 additions & 0 deletions build-conventions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ gradlePlugin {
id = 'elasticsearch.versions'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.VersionPropertiesPlugin'
}
formatting {
id = 'elasticsearch.formatting'
implementationClass = 'org.elasticsearch.gradle.internal.conventions.precommit.FormattingPrecommitPlugin'
}
}
}

Expand All @@ -62,6 +66,9 @@ dependencies {
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"
api('com.diffplug.spotless:spotless-plugin-gradle:5.16.0') {
exclude module: "groovy-xml"
}
}

project.getPlugins().withType(JavaBasePlugin.class) {
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 62d2df4

Please sign in to comment.