Skip to content

Commit 4c05d5f

Browse files
nickcmaynardwing328
authored andcommitted
Allow Java source formatting mvn formatter:format (#4214)
Uses Eclipse formatting tools with a configuration matching Google's style guide (plus our customisations).
1 parent ba194ba commit 4c05d5f

File tree

6 files changed

+406
-0
lines changed

6 files changed

+406
-0
lines changed

eclipse-formatter.xml

+341
Large diffs are not rendered by default.

modules/swagger-codegen-cli/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
</execution>
6262
</executions>
6363
</plugin>
64+
<plugin>
65+
<groupId>net.revelc.code</groupId>
66+
<artifactId>formatter-maven-plugin</artifactId>
67+
<configuration>
68+
<!-- Point at the eclipse-formatter.xml in the swagger-codegen parent project directory -->
69+
<configFile>${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml</configFile>
70+
</configuration>
71+
</plugin>
6472
</plugins>
6573
</build>
6674

modules/swagger-codegen-maven-plugin/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,15 @@
8383
</plugin>
8484
</plugins>
8585
</pluginManagement>
86+
<plugins>
87+
<plugin>
88+
<groupId>net.revelc.code</groupId>
89+
<artifactId>formatter-maven-plugin</artifactId>
90+
<configuration>
91+
<!-- Point at the eclipse-formatter.xml in the swagger-codegen parent project directory -->
92+
<configFile>${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml</configFile>
93+
</configuration>
94+
</plugin>
95+
</plugins>
8696
</build>
8797
</project>

modules/swagger-codegen/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@
110110
<artifactId>maven-release-plugin</artifactId>
111111
<version>2.5.3</version>
112112
</plugin>
113+
<plugin>
114+
<groupId>net.revelc.code</groupId>
115+
<artifactId>formatter-maven-plugin</artifactId>
116+
<configuration>
117+
<!-- Point at the eclipse-formatter.xml in the swagger-codegen parent project directory -->
118+
<configFile>${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml</configFile>
119+
</configuration>
120+
</plugin>
113121
</plugins>
114122
</build>
115123
<profiles>

modules/swagger-generator/pom.xml

+8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@
119119
</execution>
120120
</executions>
121121
</plugin>
122+
<plugin>
123+
<groupId>net.revelc.code</groupId>
124+
<artifactId>formatter-maven-plugin</artifactId>
125+
<configuration>
126+
<!-- Point at the eclipse-formatter.xml in the swagger-codegen parent project directory -->
127+
<configFile>${project.basedir}${file.separator}${project.parent.relativePath}${file.separator}eclipse-formatter.xml</configFile>
128+
</configuration>
129+
</plugin>
122130
</plugins>
123131
</build>
124132
<dependencies>

pom.xml

+31
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@
6767
<directory>target</directory>
6868
<finalName>${project.artifactId}-${project.version}</finalName>
6969
<plugins>
70+
<plugin>
71+
<groupId>net.revelc.code</groupId>
72+
<artifactId>formatter-maven-plugin</artifactId>
73+
<!-- Uncomment this to format before checkstyle -->
74+
<!-- <executions>
75+
<execution>
76+
<id>format</id>
77+
<phase>validate</phase>
78+
<goals>
79+
<goal>format</goal>
80+
</goals>
81+
</execution>
82+
</executions> -->
83+
<configuration>
84+
<compilerSource>1.7</compilerSource>
85+
<compilerCompliance>1.7</compilerCompliance>
86+
<compilerTargetPlatform>1.7</compilerTargetPlatform>
87+
<lineEnding>LF</lineEnding>
88+
</configuration>
89+
</plugin>
7090
<plugin>
7191
<groupId>org.apache.maven.plugins</groupId>
7292
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -77,6 +97,8 @@
7797
<phase>validate</phase>
7898
<configuration>
7999
<configLocation>google_checkstyle.xml</configLocation>
100+
<!-- Don't include generated sources a la http://stackoverflow.com/a/30406454 -->
101+
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
80102
<encoding>UTF-8</encoding>
81103
<consoleOutput>true</consoleOutput>
82104
<failsOnError>true</failsOnError>
@@ -201,6 +223,15 @@
201223
</executions>
202224
</plugin>
203225
</plugins>
226+
<pluginManagement>
227+
<plugins>
228+
<plugin>
229+
<groupId>net.revelc.code</groupId>
230+
<artifactId>formatter-maven-plugin</artifactId>
231+
<version>0.5.2</version>
232+
</plugin>
233+
</plugins>
234+
</pluginManagement>
204235
</build>
205236
<profiles>
206237
<profile>

0 commit comments

Comments
 (0)