Skip to content

Commit cbff459

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Add google checkstyle (#1)
* google checkstyle * Formatted with Google Java Formatter Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 9dbb9b3 commit cbff459

File tree

16 files changed

+147
-150
lines changed

16 files changed

+147
-150
lines changed

.github/workflows/checkstyle.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Code Formatter
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
checkstyle:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-python@v2
11+
- name: Set up JDK 12
12+
uses: actions/setup-java@v1
13+
with:
14+
java-version: 12
15+
- run: wget https://github.com/google/google-java-format/releases/download/google-java-format-1.9/google-java-format-1.9-all-deps.jar -O formatter.jar
16+
- run: java -jar formatter.jar --replace --set-exit-if-changed $(find . -type f -name "*.java" | grep ".*/src/.*java")
17+
- name: Commit Format changes
18+
if: failure()
19+
run: |
20+
git config --global user.name github-actions
21+
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
22+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
23+
git commit -am "Formatted with Google Java Formatter"
24+
git push --force origin HEAD:$GITHUB_REF

consuming-rest/src/main/java/com/example/consumingrest/ConsumingRestApplication.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@
1212
@SpringBootApplication
1313
public class ConsumingRestApplication {
1414

15-
private static final Logger log = LoggerFactory.getLogger(ConsumingRestApplication.class);
15+
private static final Logger log = LoggerFactory.getLogger(ConsumingRestApplication.class);
1616

17-
public static void main(String[] args) {
18-
SpringApplication.run(ConsumingRestApplication.class, args);
19-
}
17+
public static void main(String[] args) {
18+
SpringApplication.run(ConsumingRestApplication.class, args);
19+
}
2020

21-
@Bean
22-
public RestTemplate restTemplate(RestTemplateBuilder builder) {
23-
return builder.build();
24-
}
21+
@Bean
22+
public RestTemplate restTemplate(RestTemplateBuilder builder) {
23+
return builder.build();
24+
}
2525

26-
@Bean
27-
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
28-
return args -> {
29-
Quote quote = restTemplate.getForObject(
30-
"https://gturnquist-quoters.cfapps.io/api/random", Quote.class);
31-
log.info(quote.toString());
32-
};
33-
}
26+
@Bean
27+
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
28+
return args -> {
29+
Quote quote =
30+
restTemplate.getForObject("https://gturnquist-quoters.cfapps.io/api/random", Quote.class);
31+
log.info(quote.toString());
32+
};
33+
}
3434
}

consuming-rest/src/main/java/com/example/consumingrest/Quote.java

+26-30
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,29 @@
55
@JsonIgnoreProperties(ignoreUnknown = true)
66
public class Quote {
77

8-
private String type;
9-
private Value value;
10-
11-
public Quote() {
12-
}
13-
14-
public String getType() {
15-
return type;
16-
}
17-
18-
public void setType(String type) {
19-
this.type = type;
20-
}
21-
22-
public Value getValue() {
23-
return value;
24-
}
25-
26-
public void setValue(Value value) {
27-
this.value = value;
28-
}
29-
30-
@Override
31-
public String toString() {
32-
return "Quote{" +
33-
"type='" + type + '\'' +
34-
", value=" + value +
35-
'}';
36-
}
37-
}
8+
private String type;
9+
private Value value;
10+
11+
public Quote() {}
12+
13+
public String getType() {
14+
return type;
15+
}
16+
17+
public void setType(String type) {
18+
this.type = type;
19+
}
20+
21+
public Value getValue() {
22+
return value;
23+
}
24+
25+
public void setValue(Value value) {
26+
this.value = value;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "Quote{" + "type='" + type + '\'' + ", value=" + value + '}';
32+
}
33+
}

consuming-rest/src/main/java/com/example/consumingrest/Value.java

+26-30
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,29 @@
55
@JsonIgnoreProperties(ignoreUnknown = true)
66
public class Value {
77

8-
private Long id;
9-
private String quote;
10-
11-
public Value() {
12-
}
13-
14-
public Long getId() {
15-
return this.id;
16-
}
17-
18-
public String getQuote() {
19-
return this.quote;
20-
}
21-
22-
public void setId(Long id) {
23-
this.id = id;
24-
}
25-
26-
public void setQuote(String quote) {
27-
this.quote = quote;
28-
}
29-
30-
@Override
31-
public String toString() {
32-
return "Value{" +
33-
"id=" + id +
34-
", quote='" + quote + '\'' +
35-
'}';
36-
}
37-
}
8+
private Long id;
9+
private String quote;
10+
11+
public Value() {}
12+
13+
public Long getId() {
14+
return this.id;
15+
}
16+
17+
public String getQuote() {
18+
return this.quote;
19+
}
20+
21+
public void setId(Long id) {
22+
this.id = id;
23+
}
24+
25+
public void setQuote(String quote) {
26+
this.quote = quote;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return "Value{" + "id=" + id + ", quote='" + quote + '\'' + '}';
32+
}
33+
}

consuming-rest/src/test/java/com/example/consumingrest/ConsumingRestApplicationTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
@SpringBootTest
77
class ConsumingRestApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
12-
9+
@Test
10+
void contextLoads() {}
1311
}

customapplication/src/test/java/com/examplehub/customapplication/CustomapplicationApplicationTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
@SpringBootTest
77
class CustomapplicationApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
12-
9+
@Test
10+
void contextLoads() {}
1311
}

custombanner/src/main/java/com/examplehub/custombanner/CustombannerApplication.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
@SpringBootApplication
77
public class CustombannerApplication {
88

9-
public static void main(String[] args) {
10-
SpringApplication.run(CustombannerApplication.class, args);
11-
}
12-
9+
public static void main(String[] args) {
10+
SpringApplication.run(CustombannerApplication.class, args);
11+
}
1312
}

custombanner/src/test/java/com/examplehub/custombanner/CustombannerApplicationTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
@SpringBootTest
77
class CustombannerApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
12-
9+
@Test
10+
void contextLoads() {}
1311
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.examplehub.helloworld;
2+
23
import static org.hamcrest.Matchers.equalTo;
34
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
45
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
56

67
import org.junit.jupiter.api.Test;
7-
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
1010
import org.springframework.boot.test.context.SpringBootTest;
@@ -16,13 +16,12 @@
1616
@AutoConfigureMockMvc
1717
public class HomeControllerTests {
1818

19-
@Autowired
20-
private MockMvc mvc;
19+
@Autowired private MockMvc mvc;
2120

22-
@Test
23-
public void getHello() throws Exception {
24-
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
25-
.andExpect(status().isOk())
26-
.andExpect(content().string(equalTo("Hello World!")));
27-
}
21+
@Test
22+
public void getHello() throws Exception {
23+
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
24+
.andExpect(status().isOk())
25+
.andExpect(content().string(equalTo("Hello World!")));
26+
}
2827
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
package com.examplehub.lazyinitialization;
22

33
public class User {
4-
private String name;
5-
private int age;
4+
private String name;
5+
private int age;
66

7-
public User(String name, int age) {
8-
this.name = name;
9-
this.age = age;
7+
public User(String name, int age) {
8+
this.name = name;
9+
this.age = age;
1010
System.out.println(name + " initialized!");
11-
}
11+
}
1212

13-
public String getName() {
14-
return name;
15-
}
13+
public String getName() {
14+
return name;
15+
}
1616

17-
public void setName(String name) {
18-
this.name = name;
19-
}
17+
public void setName(String name) {
18+
this.name = name;
19+
}
2020

21-
public int getAge() {
22-
return age;
23-
}
21+
public int getAge() {
22+
return age;
23+
}
2424

25-
public void setAge(int age) {
26-
this.age = age;
27-
}
25+
public void setAge(int age) {
26+
this.age = age;
27+
}
2828

29-
@Override
30-
public String toString() {
31-
return "User{" +
32-
"name='" + name + '\'' +
33-
", age=" + age +
34-
'}';
35-
}
29+
@Override
30+
public String toString() {
31+
return "User{" + "name='" + name + '\'' + ", age=" + age + '}';
32+
}
3633
}

lazyinitialization/src/test/java/com/examplehub/lazyinitialization/LazyinitializationApplicationTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
@SpringBootTest
77
class LazyinitializationApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
12-
9+
@Test
10+
void contextLoads() {}
1311
}

rest-service/src/main/java/com/example/restservice/GreetingController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.example.restservice;
22

3+
import java.util.concurrent.atomic.AtomicLong;
34
import org.springframework.web.bind.annotation.RequestMapping;
45
import org.springframework.web.bind.annotation.RequestParam;
56
import org.springframework.web.bind.annotation.RestController;
67

7-
import java.util.concurrent.atomic.AtomicLong;
8-
98
@RestController
109
public class GreetingController {
1110
private final AtomicLong counter = new AtomicLong();

rest-service/src/main/java/com/example/restservice/RestServiceApplication.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@SpringBootApplication
77
public class RestServiceApplication {
88

9-
public static void main(String[] args) {
10-
SpringApplication.run(RestServiceApplication.class, args);
11-
}
9+
public static void main(String[] args) {
10+
SpringApplication.run(RestServiceApplication.class, args);
11+
}
1212
}

rest-service/src/test/java/com/example/restservice/RestServiceApplicationTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
@SpringBootTest
77
class RestServiceApplicationTests {
88

9-
@Test
10-
void contextLoads() {
11-
}
12-
9+
@Test
10+
void contextLoads() {}
1311
}

upload-files/src/main/java/com/examplehub/uploadfiles/UploadController.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.examplehub.uploadfiles;
22

3+
import java.io.File;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.nio.file.StandardCopyOption;
8+
import java.util.Objects;
39
import org.springframework.stereotype.Controller;
410
import org.springframework.util.StringUtils;
511
import org.springframework.web.bind.annotation.GetMapping;
@@ -8,13 +14,6 @@
814
import org.springframework.web.multipart.MultipartFile;
915
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
1016

11-
import java.io.File;
12-
import java.nio.file.Files;
13-
import java.nio.file.Path;
14-
import java.nio.file.Paths;
15-
import java.nio.file.StandardCopyOption;
16-
import java.util.Objects;
17-
1817
@Controller
1918
public class UploadController {
2019

0 commit comments

Comments
 (0)