Skip to content

Commit

Permalink
refactor: formatter check uses spotless-maven-plugin (#3)
Browse files Browse the repository at this point in the history
- Fixed eclipse.importorder to make it similar to current
- Removed redundant module `ide-config` containing formatter config files
- Used Spotless Maven Plugin for both import order and formatting
- Removed no longer needed spotless plugin definition from java-generator
- Corrected CI to use Spotless ratchetFrom features instead of git diffing
- Updated documentation accordingly

Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa committed Mar 4, 2022
1 parent acd6ef1 commit a476c10
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 131 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,4 @@ jobs:
- name: Build Project
run: mvn ${MAVEN_ARGS} clean install
- name: Check Format (only on touched files)
run: |
set -euxo pipefail
git --no-pager diff --name-only | \
sed 's|^.*/main/java/||g' | \
sed 's|^.*/test/java/||g' | \
xargs -I {} mvn formatter:validate -Dformatter.includes={}
git --no-pager diff --name-only | \
sed 's|^.*/main/java/||g' | \
sed 's|^.*/test/java/||g' | \
xargs -I {} mvn impsort:check -Dimpsort.includes={}
run: mvn spotless:check
7 changes: 2 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ To run regression test
mvn clean install -P itests
```
#### * Format the files that you touched
```
git --no-pager diff --name-only | \
sed 's|^.*/main/java/||g' | \
sed 's|^.*/test/java/||g' | \
xargs -I {} mvn formatter:format impsort:sort -Dimpsort.includes={} -Dformatter.includes={}
```shell
mvn spotless:apply
```
#### * Push the changes to your fork
```
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions ide-config/eclipse.importorder
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Organize Import Order
0=
1=java
2=javax
3=\#
32 changes: 0 additions & 32 deletions ide-config/pom.xml

This file was deleted.

6 changes: 0 additions & 6 deletions ide-config/src/main/resources/eclipse.importorder

This file was deleted.

42 changes: 0 additions & 42 deletions java-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,4 @@
<module>it</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<formats>
<format>
<includes>
<include>*.md</include>
<include>.gitignore</include>
</includes>

<trimTrailingWhitespace />

<endWithNewline />

<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
<java>
<importOrder />
<googleJavaFormat>
<version>1.13.0</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
54 changes: 18 additions & 36 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
<sonar-maven-plugin.version>3.9.1.2184</sonar-maven-plugin.version>
<nexus-staging-maven-plugin>1.6.12</nexus-staging-maven-plugin>
<formatter-maven-plugin.version>2.17.1</formatter-maven-plugin.version>
<impsort-maven-plugin.version>1.6.2</impsort-maven-plugin.version>
<spotless-maven-plugin.version>2.21.0</spotless-maven-plugin.version>

<!-- Other options -->
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -199,7 +198,6 @@
<module>crd-generator</module>
<module>java-generator</module>
<module>httpclient-okhttp</module>
<module>ide-config</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -765,7 +763,7 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
Expand Down Expand Up @@ -1000,6 +998,22 @@
</configuration>
</plugin>

<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
<configuration>
<ratchetFrom>origin/master</ratchetFrom>
<java>
<eclipse>
<file>ide-config/eclipse-format.xml</file>
</eclipse>
<importOrder>
<file>ide-config/eclipse.importorder</file>
</importOrder>
</java>
</configuration>
</plugin>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand Down Expand Up @@ -1149,38 +1163,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-maven-plugin.version}</version>
<dependencies>
<dependency>
<artifactId>ide-config</artifactId>
<groupId>io.fabric8</groupId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<configFile>eclipse-format.xml</configFile>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${impsort-maven-plugin.version}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache</cachedir>
<groups>java.,javax.,org.,com.</groups>
<staticGroups>*</staticGroups>
<skip>${format.skip}</skip>
<removeUnused>true</removeUnused>
</configuration>
</plugin>
</plugins>
</build>

Expand Down

0 comments on commit a476c10

Please sign in to comment.