Skip to content

Commit a16edb4

Browse files
committed
Code refactor and add more agressive style checks
1 parent b537202 commit a16edb4

74 files changed

Lines changed: 7174 additions & 5774 deletions

File tree

Some content is hidden

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

build.gradle

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
plugins {
2+
id 'com.diffplug.spotless' version '6.25.0' apply false
3+
}
4+
15
subprojects {
26
apply plugin: 'java'
7+
apply plugin: 'com.diffplug.spotless'
38

49
group = 'com.auction'
510
version = '1.0-SNAPSHOT'
@@ -25,4 +30,60 @@ subprojects {
2530
tasks.withType(Test).configureEach {
2631
useJUnitPlatform()
2732
}
33+
34+
spotless {
35+
java {
36+
target 'src/**/*.java'
37+
googleJavaFormat('1.35.0')
38+
removeUnusedImports()
39+
formatAnnotations()
40+
}
41+
}
42+
43+
tasks.register('checkGoogleJavaStyleHardRules') {
44+
def javaSources = fileTree(projectDir) {
45+
include 'src/**/*.java'
46+
exclude '**/build/**'
47+
}
48+
inputs.files(javaSources)
49+
50+
doLast {
51+
def violations = []
52+
javaSources.files.each { source ->
53+
if (!source.name.endsWith('.java')) {
54+
return
55+
}
56+
def hasPackage = false
57+
source.eachLine { line, number ->
58+
if (number <= 5 && line ==~ /\s*package\s+[^;]+;/) {
59+
hasPackage = true
60+
}
61+
if (line.contains('\t')) {
62+
violations << "${source}:${number}: tab characters are not allowed"
63+
}
64+
if (line ==~ /\s*import\s+(static\s+)?[^;]*\.\*;/) {
65+
violations << "${source}:${number}: wildcard imports are not allowed"
66+
}
67+
if (!(line ==~ /\s*(package|import)\s+.*/) && line.length() > 100) {
68+
violations << "${source}:${number}: line exceeds 100 columns"
69+
}
70+
if (line =~ /[âÃ�]/) {
71+
violations << "${source}:${number}: possible encoding-damaged text"
72+
}
73+
}
74+
if (!hasPackage) {
75+
violations << "${source}:1: missing package declaration"
76+
}
77+
}
78+
if (!violations.isEmpty()) {
79+
throw new GradleException(
80+
"Google Java Style hard-rule violations:\n" + violations.join('\n'))
81+
}
82+
}
83+
}
84+
85+
tasks.named('check') {
86+
dependsOn tasks.named('spotlessCheck')
87+
dependsOn tasks.named('checkGoogleJavaStyleHardRules')
88+
}
2889
}

client/src/main/java/com/auction/app/AppState.java

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,38 @@
1111
import com.auction.service.rest.RestUserService;
1212

1313
public class AppState {
14-
public final HttpClientService httpClient;
15-
public final UserRepository userRepository;
16-
public final ItemRepository itemRepository;
17-
public final UserService userService;
18-
public final ItemService itemService;
19-
public final BidService bidService;
20-
public final AuctionService auctionService;
21-
/**
22-
* Same instance as {@link #userService}, but typed concretely so the
23-
* UI can call REST-only helpers (addBalance / deductBalance) without
24-
* an instanceof check.
25-
*/
26-
public final RestUserService restUserService;
14+
public final HttpClientService httpClient;
15+
public final UserRepository userRepository;
16+
public final ItemRepository itemRepository;
17+
public final UserService userService;
18+
public final ItemService itemService;
19+
public final BidService bidService;
20+
public final AuctionService auctionService;
2721

28-
public User currentUser;
22+
/**
23+
* Same instance as {@link #userService}, but typed concretely so the UI can call REST-only
24+
* helpers (addBalance / deductBalance) without an instanceof check.
25+
*/
26+
public final RestUserService restUserService;
2927

30-
public AppState(HttpClientService httpClient,
31-
UserRepository userRepository, ItemRepository itemRepository,
32-
UserService userService, ItemService itemService,
33-
BidService bidService, AuctionService auctionService,
34-
RestUserService restUserService) {
35-
this.httpClient = httpClient;
36-
this.userRepository = userRepository;
37-
this.itemRepository = itemRepository;
38-
this.userService = userService;
39-
this.itemService = itemService;
40-
this.bidService = bidService;
41-
this.auctionService = auctionService;
42-
this.restUserService = restUserService;
43-
}
28+
public User currentUser;
29+
30+
public AppState(
31+
HttpClientService httpClient,
32+
UserRepository userRepository,
33+
ItemRepository itemRepository,
34+
UserService userService,
35+
ItemService itemService,
36+
BidService bidService,
37+
AuctionService auctionService,
38+
RestUserService restUserService) {
39+
this.httpClient = httpClient;
40+
this.userRepository = userRepository;
41+
this.itemRepository = itemRepository;
42+
this.userService = userService;
43+
this.itemService = itemService;
44+
this.bidService = bidService;
45+
this.auctionService = auctionService;
46+
this.restUserService = restUserService;
47+
}
4448
}

client/src/main/java/com/auction/app/MainApplication.java

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,66 +8,71 @@
88
import com.auction.service.AuctionService;
99
import com.auction.service.BidService;
1010
import com.auction.service.ItemService;
11-
import com.auction.service.UserService;
1211
import com.auction.service.http.HttpClientService;
1312
import com.auction.service.rest.RestAuctionService;
1413
import com.auction.service.rest.RestBidService;
1514
import com.auction.service.rest.RestItemService;
1615
import com.auction.service.rest.RestUserService;
16+
import java.io.IOException;
1717
import javafx.application.Application;
1818
import javafx.fxml.FXMLLoader;
1919
import javafx.scene.Scene;
2020
import javafx.stage.Stage;
2121

22-
import java.io.IOException;
23-
2422
public class MainApplication extends Application {
2523

26-
private AppState appState;
24+
private AppState appState;
2725

28-
@Override
29-
public void start(Stage primaryStage) throws IOException {
30-
appState = buildAppState();
26+
@Override
27+
public void start(Stage primaryStage) throws IOException {
28+
appState = buildAppState();
3129

32-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/login.fxml"));
33-
Scene scene = new Scene(loader.load(), 520, 440);
34-
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
30+
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/login.fxml"));
31+
Scene scene = new Scene(loader.load(), 520, 440);
32+
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
3533

36-
LoginController controller = loader.getController();
37-
controller.init(appState, primaryStage);
34+
LoginController controller = loader.getController();
35+
controller.init(appState, primaryStage);
3836

39-
primaryStage.setTitle("Auction Platform");
40-
primaryStage.setScene(scene);
41-
primaryStage.setResizable(false);
42-
primaryStage.show();
43-
}
37+
primaryStage.setTitle("Auction Platform");
38+
primaryStage.setScene(scene);
39+
primaryStage.setResizable(false);
40+
primaryStage.show();
41+
}
4442

45-
@Override
46-
public void stop() {
47-
if (appState != null) {
48-
appState.httpClient.disconnectEvents();
49-
appState.auctionService.shutdown();
50-
}
43+
@Override
44+
public void stop() {
45+
if (appState != null) {
46+
appState.httpClient.disconnectEvents();
47+
appState.auctionService.shutdown();
5148
}
49+
}
5250

53-
private AppState buildAppState() {
54-
// Single HTTP client shared across all REST-backed services so the
55-
// JWT bearer token captured at login flows to every other call.
56-
HttpClientService http = new HttpClientService();
51+
private AppState buildAppState() {
52+
// Single HTTP client shared across all REST-backed services so the
53+
// JWT bearer token captured at login flows to every other call.
54+
HttpClientService http = new HttpClientService();
5755

58-
UserRepository userRepo = new RestUserRepository(http);
59-
ItemRepository itemRepo = new RestItemRepository(http);
56+
UserRepository userRepo = new RestUserRepository(http);
57+
ItemRepository itemRepo = new RestItemRepository(http);
6058

61-
RestUserService userService = new RestUserService(userRepo, http);
62-
ItemService itemService = new RestItemService(itemRepo, http);
63-
BidService bidService = new RestBidService(http);
64-
AuctionService auctionService = new RestAuctionService(http);
59+
RestUserService userService = new RestUserService(userRepo, http);
60+
ItemService itemService = new RestItemService(itemRepo, http);
61+
BidService bidService = new RestBidService(http);
62+
AuctionService auctionService = new RestAuctionService(http);
6563

66-
return new AppState(http, userRepo, itemRepo, userService, itemService,
67-
bidService, auctionService, userService);
68-
}
64+
return new AppState(
65+
http,
66+
userRepo,
67+
itemRepo,
68+
userService,
69+
itemService,
70+
bidService,
71+
auctionService,
72+
userService);
73+
}
6974

70-
public static void main(String[] args) {
71-
launch(args);
72-
}
75+
public static void main(String[] args) {
76+
launch(args);
77+
}
7378
}

0 commit comments

Comments
 (0)