Skip to content

Commit 44ec576

Browse files
authored
add google code formatter (#175)
1 parent d27ea79 commit 44ec576

File tree

83 files changed

+1385
-1341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1385
-1341
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ jobs:
2323
with:
2424
java-version: 21
2525
distribution: 'temurin'
26-
- name: Build
26+
- name: Format check
27+
run: mvn spotless:check && mvn checkstyle:check
28+
- name: Build & Test
2729
run: mvn --batch-mode --update-snapshots --no-transfer-progress verify

README.md

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<p align='center'>
22
<a href="https://github.com/eclipse-xpanse/terraform-boot/actions/workflows/ci.yml" target="_blank">
3-
<img src="https://github.com/eclipse-xpanse/terraform-boot/actions/workflows/ci.yml/badge.svg" alt="build">
3+
<img src="https://github.com/eclipse-xpanse/terraform-boot/actions/workflows/ci.yml/badge.svg" alt="build">
44
</a>
55
<a href="https://opensource.org/licenses/Apache-2.0" target="_blank">
6-
<img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="coverage">
7-
</a>
6+
<img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="coverage">
7+
</a>
88
</p>
99

1010
# terraform-boot
1111

12-
A spring-boot-based project which aims to provide a RESTful API for Terraform CLI. It provides three different modes of
12+
A spring-boot-based project which aims to provide a RESTful API for Terraform CLI. It provides three different modes of
1313
execution
1414

1515
1. Scripts in a directory
@@ -42,8 +42,8 @@ the files and return terraform execution result.
4242

4343
### Scripts in GIT Repo
4444

45-
If the scripts are present in a GIT repo, then we can directly pass the details of the GIT repo. Terraform-boot will
46-
clone the repo and execute the scripts and then return the result.
45+
If the scripts are present in a GIT repo, then we can directly pass the details of the GIT repo. Terraform-boot will
46+
clone the repo and execute the scripts and then return the result.
4747

4848
> [!NOTE]
4949
> Currently supports only repos that can be cloned without authentication and also with HTTP(S) only.
@@ -124,15 +124,15 @@ $ java -jar target/terraform-boot-*.jar
124124

125125
1.Start with oauth
126126

127-
1.Set values for the authorization related variables in the application-oauth-properties configuration file,
128-
and specify the configuration file for loading oauth in the application-properties configuration file,
129-
start the main application.
130-
2.Or the oauth related variables configuration can be added to IDE and the main application can be executed directly
131-
to launch the application.
127+
1.Set values for the authorization related variables in the application-oauth-properties configuration file,
128+
and specify the configuration file for loading oauth in the application-properties configuration file,
129+
start the main application.
130+
2.Or the oauth related variables configuration can be added to IDE and the main application can be executed directly
131+
to launch the application.
132132

133133
2.Start without oauth
134134

135-
Simply start the main application.
135+
Simply start the main application.
136136

137137
API can be accessed using the following URLs
138138

@@ -167,4 +167,20 @@ value of `otel.exporter.otlp.endpoint` configuration property.
167167

168168
## Dependencies File
169169

170-
All third-party related content is listed in the [DEPENDENCIES](DEPENDENCIES) file.
170+
All third-party related content is listed in the [DEPENDENCIES](DEPENDENCIES) file.
171+
172+
## Code Formatter
173+
174+
The project follows [google-code-format](https://github.com/google/google-java-format).
175+
We use the [spotless plugin](https://github.com/diffplug/spotless/tree/main/plugin-maven#google-java-format) to format code and to validate code format.
176+
We can automatically format the code using the command below.
177+
178+
```shell
179+
mvn spotless:apply
180+
```
181+
182+
To validate errors we can run the command below.
183+
184+
```shell
185+
mvn spotless:check && mvn checkstyle:check
186+
```

checkstyle.xml

+2-42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!--
33
~ SPDX-License-Identifier: Apache-2.0
44
~ SPDX-FileCopyrightText: Huawei Inc.
5+
~
56
-->
67

78
<!DOCTYPE module PUBLIC
@@ -30,12 +31,6 @@
3031
<property name="eachLine" value="true"/>
3132
</module>
3233

33-
<module name="LineLength">
34-
<property name="fileExtensions" value="java"/>
35-
<property name="max" value="100"/>
36-
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
37-
</module>
38-
3934
<module name="SuppressWithPlainTextCommentFilter">
4035
<property name="offCommentFormat" value="CHECKSTYLE OFF\: ([\w\|]+)"/>
4136
<property name="onCommentFormat" value="CHECKSTYLE ON\: ([\w\|]+)"/>
@@ -99,27 +94,6 @@
9994
or preceding-sibling::*[last()][self::LCURLY]]"/>
10095
</module>
10196
<module name="WhitespaceAfter"/>
102-
<module name="WhitespaceAround">
103-
<property name="allowEmptyConstructors" value="true"/>
104-
<property name="allowEmptyLambdas" value="true"/>
105-
<property name="allowEmptyMethods" value="true"/>
106-
<property name="allowEmptyTypes" value="true"/>
107-
<property name="allowEmptyLoops" value="true"/>
108-
<property name="ignoreEnhancedForColon" value="false"/>
109-
<property name="tokens"
110-
value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR,
111-
BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN, DO_WHILE, EQUAL, GE, GT, LAMBDA, LAND,
112-
LCURLY, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
113-
LITERAL_FOR, LITERAL_IF, LITERAL_RETURN, LITERAL_SWITCH, LITERAL_SYNCHRONIZED,
114-
LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN,
115-
NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR,
116-
SR_ASSIGN, STAR, STAR_ASSIGN, LITERAL_ASSERT, TYPE_EXTENSION_AND"/>
117-
<message key="ws.notFollowed"
118-
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks
119-
may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
120-
<message key="ws.notPreceded"
121-
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
122-
</module>
12397
<module name="OneStatementPerLine"/>
12498
<module name="MultipleVariableDeclarations"/>
12599
<module name="ArrayTypeStyle"/>
@@ -223,7 +197,7 @@
223197
value="Method type name ''{0}'' must match pattern ''{1}''."/>
224198
</module>
225199
<module name="InterfaceTypeParameterName">
226-
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
200+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[a-zA-Z]$)"/>
227201
<message key="name.invalidPattern"
228202
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
229203
</module>
@@ -257,12 +231,6 @@
257231
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
258232
<module name="OverloadMethodsDeclarationOrder"/>
259233
<module name="VariableDeclarationUsageDistance"/>
260-
<module name="CustomImportOrder">
261-
<property name="sortImportsInGroupAlphabetically" value="true"/>
262-
<property name="separateLineBetweenGroups" value="true"/>
263-
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
264-
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>
265-
</module>
266234
<module name="MethodParamPad">
267235
<property name="tokens"
268236
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
@@ -282,13 +250,6 @@
282250
METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL, LAMBDA,
283251
RECORD_DEF"/>
284252
</module>
285-
<module name="OperatorWrap">
286-
<property name="option" value="NL"/>
287-
<property name="tokens"
288-
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,
289-
LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF,
290-
TYPE_EXTENSION_AND "/>
291-
</module>
292253
<module name="AnnotationLocation">
293254
<property name="id" value="AnnotationLocationMostCases"/>
294255
<property name="tokens"
@@ -397,7 +358,6 @@
397358
<module name="MethodParamPad"/>
398359
<module name="NoWhitespaceBefore"/>
399360
<module name="NoWhitespaceAfter"/>
400-
<module name="OperatorWrap"/>
401361
<module name="ParenPad"/>
402362
<module name="TypecastParenPad"/>
403363
<module name="WhitespaceAfter">

pom.xml

+46
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<maven.complier.plugin.version>3.13.0</maven.complier.plugin.version>
3535
<maven.surefire.plugin.version>3.5.2</maven.surefire.plugin.version>
3636
<maven.enforcer.plugin.version>3.5.0</maven.enforcer.plugin.version>
37+
<spotless.version>2.43.0</spotless.version>
3738
</properties>
3839
<dependencyManagement>
3940
<dependencies>
@@ -181,6 +182,51 @@
181182
</execution>
182183
</executions>
183184
</plugin>
185+
<plugin>
186+
<groupId>com.diffplug.spotless</groupId>
187+
<artifactId>spotless-maven-plugin</artifactId>
188+
<version>${spotless.version}</version>
189+
<configuration>
190+
<formats>
191+
<format>
192+
<includes>
193+
<include>*.md</include>
194+
<include>.gitignore</include>
195+
</includes>
196+
<trimTrailingWhitespace/>
197+
<endWithNewline/>
198+
<indent>
199+
<tabs>true</tabs>
200+
<spacesPerTab>4</spacesPerTab>
201+
</indent>
202+
</format>
203+
</formats>
204+
<java>
205+
<importOrder />
206+
<removeUnusedImports />
207+
<googleJavaFormat>
208+
<style>AOSP</style>
209+
<reflowLongStrings>true</reflowLongStrings>
210+
</googleJavaFormat>
211+
</java>
212+
</configuration>
213+
<executions>
214+
<execution>
215+
<id>apply-spotless</id>
216+
<goals>
217+
<goal>apply</goal>
218+
</goals>
219+
<phase>validate</phase>
220+
</execution>
221+
<execution>
222+
<id>check-spotless</id>
223+
<goals>
224+
<goal>check</goal>
225+
</goals>
226+
<phase>verify</phase>
227+
</execution>
228+
</executions>
229+
</plugin>
184230
<plugin>
185231
<groupId>org.apache.maven.plugins</groupId>
186232
<artifactId>maven-enforcer-plugin</artifactId>

src/main/java/org/eclipse/xpanse/terraform/boot/TerraformBootApplication.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import org.springframework.scheduling.annotation.EnableAsync;
1414
import org.springframework.scheduling.annotation.EnableScheduling;
1515

16-
/**
17-
* Main entry class to terraform-boot. This class can be directly executed to start the server.
18-
*/
16+
/** Main entry class to terraform-boot. This class can be directly executed to start the server. */
1917
@EnableRetry
2018
@EnableAsync
2119
@EnableCaching
@@ -26,5 +24,4 @@ public class TerraformBootApplication {
2624
public static void main(String[] args) {
2725
SpringApplication.run(TerraformBootApplication.class, args);
2826
}
29-
3027
}

src/main/java/org/eclipse/xpanse/terraform/boot/api/config/SpringDocOpenApiConfig.java

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@
1111
import org.springframework.context.annotation.Bean;
1212
import org.springframework.context.annotation.Configuration;
1313

14-
15-
/**
16-
* Configuration springdoc openAPI.
17-
*/
14+
/** Configuration springdoc openAPI. */
1815
@Configuration
1916
public class SpringDocOpenApiConfig {
2017

2118
@Value("${app.version:1.0.0}")
2219
private String version;
2320

24-
/**
25-
* Configuration openAPI.
26-
*/
21+
/** Configuration openAPI. */
2722
@Bean
2823
public OpenAPI configOpenApi() {
29-
return new OpenAPI().info(new Info().title("Terraform-Boot API")
30-
.description("RESTful Services to interact with terraform CLI")
31-
.version(version));
24+
return new OpenAPI()
25+
.info(
26+
new Info()
27+
.title("Terraform-Boot API")
28+
.description("RESTful Services to interact with terraform CLI")
29+
.version(version));
3230
}
3331
}

src/main/java/org/eclipse/xpanse/terraform/boot/api/controllers/TerraformBootAdminApi.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import org.springframework.web.bind.annotation.ResponseStatus;
2121
import org.springframework.web.bind.annotation.RestController;
2222

23-
/**
24-
* REST controller for admin services of terraform-boot.
25-
*/
23+
/** REST controller for admin services of terraform-boot. */
2624
@Slf4j
2725
@CrossOrigin
2826
@RestController
@@ -34,7 +32,7 @@ public class TerraformBootAdminApi {
3432
@Autowired
3533
public TerraformBootAdminApi(
3634
@Qualifier("terraformDirectoryService")
37-
TerraformDirectoryService terraformDirectoryService) {
35+
TerraformDirectoryService terraformDirectoryService) {
3836
this.terraformDirectoryService = terraformDirectoryService;
3937
}
4038

@@ -43,13 +41,11 @@ public TerraformBootAdminApi(
4341
*
4442
* @return Returns the current state of the system.
4543
*/
46-
@Tag(name = "Admin", description =
47-
"Admin services for managing the application.")
44+
@Tag(name = "Admin", description = "Admin services for managing the application.")
4845
@Operation(description = "Check health of Terraform Boot API service")
4946
@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
5047
@ResponseStatus(HttpStatus.OK)
5148
public TerraformBootSystemStatus healthCheck() {
5249
return terraformDirectoryService.tfHealthCheck();
5350
}
54-
5551
}

0 commit comments

Comments
 (0)