Skip to content

Commit a198728

Browse files
committed
Apply code formatting with Spotless and palantir format
1 parent 4661c19 commit a198728

46 files changed

Lines changed: 1264 additions & 1027 deletions

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
2-
id 'com.github.johnrengelman.shadow' version '7.1.2'
32
id 'java'
3+
id 'com.diffplug.spotless' version '6.25.0'
4+
id 'com.github.johnrengelman.shadow' version '7.1.2'
45
}
56

67

@@ -23,4 +24,4 @@ allprojects {
2324

2425
task createAllJars (type: GradleBuild) {
2526
tasks = [":client:shadowJar",":server:shadowJar",":ice-adapter:shadowJar"]
26-
}
27+
}

ice-adapter/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ apply plugin: 'idea'
99
apply plugin: 'java'
1010
apply plugin: 'java-library'
1111
apply plugin: 'com.github.johnrengelman.shadow'
12+
apply plugin: 'com.diffplug.spotless'
1213

1314
group 'com.faforever'
1415

@@ -67,3 +68,14 @@ shadowJar {
6768
attributes 'Main-Class': 'com.faforever.iceadapter.IceAdapter'
6869
}
6970
}
71+
72+
tasks.named("check") {
73+
dependsOn("spotlessCheck")
74+
}
75+
76+
spotless {
77+
java {
78+
cleanthat()
79+
palantirJavaFormat()
80+
}
81+
}

ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
package com.faforever.iceadapter;
22

3+
import static com.faforever.iceadapter.debug.Debug.debug;
4+
35
import com.faforever.iceadapter.debug.Debug;
46
import com.faforever.iceadapter.gpgnet.GPGNetServer;
57
import com.faforever.iceadapter.gpgnet.GameState;
68
import com.faforever.iceadapter.ice.GameSession;
79
import com.faforever.iceadapter.rpc.RPCService;
810
import com.faforever.iceadapter.util.Executor;
911
import com.faforever.iceadapter.util.TrayIcon;
12+
import java.util.concurrent.Callable;
1013
import lombok.extern.slf4j.Slf4j;
1114
import picocli.CommandLine;
1215

13-
import java.util.concurrent.Callable;
14-
15-
import static com.faforever.iceadapter.debug.Debug.debug;
16-
@CommandLine.Command(name = "faf-ice-adapter", mixinStandardHelpOptions = true, usageHelpAutoWidth = true,
16+
@CommandLine.Command(
17+
name = "faf-ice-adapter",
18+
mixinStandardHelpOptions = true,
19+
usageHelpAutoWidth = true,
1720
description = "An ice (RFC 5245) based network bridge between FAF client and ForgedAlliance.exe")
1821
@Slf4j
1922
public class IceAdapter implements Callable<Integer> {
@@ -43,9 +46,7 @@ public class IceAdapter implements Callable<Integer> {
4346
public static volatile GameSession gameSession;
4447

4548
public static void main(String[] args) {
46-
new CommandLine(new IceAdapter())
47-
.setUnmatchedArgumentsAllowed(true)
48-
.execute(args);
49+
new CommandLine(new IceAdapter()).setUnmatchedArgumentsAllowed(true).execute(args);
4950
}
5051

5152
@Override
@@ -61,14 +62,15 @@ public static void start(IceOptions iceOptions) {
6162

6263
TrayIcon.create();
6364

64-
//Configure file appender
65-
// RollingFileAppender fileAppender = (ch.qos.logback.core.rolling.RollingFileAppender)((ch.qos.logback.classic.Logger)log).getAppender("FILE");
66-
// if (logDirectory != null) {
67-
// Util.mkdir(Paths.get(logDirectory).toFile());
68-
// //TODO: set log dir
69-
// } else {
70-
//// fileAppender.stop();
71-
// }
65+
// Configure file appender
66+
// RollingFileAppender fileAppender =
67+
// (ch.qos.logback.core.rolling.RollingFileAppender)((ch.qos.logback.classic.Logger)log).getAppender("FILE");
68+
// if (logDirectory != null) {
69+
// Util.mkdir(Paths.get(logDirectory).toFile());
70+
// //TODO: set log dir
71+
// } else {
72+
//// fileAppender.stop();
73+
// }
7274

7375
log.info("Version: {}", VERSION);
7476

@@ -102,7 +104,10 @@ public static void onJoinGame(String remotePlayerLogin, int remotePlayerId) {
102104
}
103105

104106
public static void onConnectToPeer(String remotePlayerLogin, int remotePlayerId, boolean offer) {
105-
if(GPGNetServer.isConnected() && GPGNetServer.getGameState().isPresent() && (GPGNetServer.getGameState().get() == GameState.LAUNCHING || GPGNetServer.getGameState().get() == GameState.ENDED)) {
107+
if (GPGNetServer.isConnected()
108+
&& GPGNetServer.getGameState().isPresent()
109+
&& (GPGNetServer.getGameState().get() == GameState.LAUNCHING
110+
|| GPGNetServer.getGameState().get() == GameState.ENDED)) {
106111
log.warn("Game ended or in progress, ABORTING connectToPeer");
107112
return;
108113
}
@@ -128,7 +133,7 @@ public static void onDisconnectFromPeer(int remotePlayerId) {
128133
});
129134
}
130135

131-
private synchronized static void createGameSession() {
136+
private static synchronized void createGameSession() {
132137
if (gameSession != null) {
133138
gameSession.close();
134139
gameSession = null;
@@ -141,12 +146,12 @@ private synchronized static void createGameSession() {
141146
* Triggered by losing gpgnet connection to FA.
142147
* Closes the active Game/ICE session
143148
*/
144-
public synchronized static void onFAShutdown() {
145-
if(gameSession != null) {
149+
public static synchronized void onFAShutdown() {
150+
if (gameSession != null) {
146151
log.info("FA SHUTDOWN, closing everything");
147152
gameSession.close();
148153
gameSession = null;
149-
//Do not put code outside of this if clause, else it will be executed multiple times
154+
// Do not put code outside of this if clause, else it will be executed multiple times
150155
}
151156
}
152157

@@ -158,15 +163,14 @@ public static void close() {
158163

159164
Executor.executeDelayed(500, () -> System.exit(0));
160165

161-
onFAShutdown();//will close gameSession aswell
166+
onFAShutdown(); // will close gameSession aswell
162167
GPGNetServer.close();
163168
RPCService.close();
164169
TrayIcon.close();
165170

166171
System.exit(0);
167172
}
168173

169-
170174
/**
171175
* Read command line arguments and set global, constant values
172176
* @param iceOptions The arguments to be read
@@ -180,7 +184,7 @@ public static void loadOptions(IceOptions iceOptions) {
180184
GPGNET_PORT = iceOptions.getGpgnetPort();
181185
LOBBY_PORT = iceOptions.getLobbyPort();
182186

183-
if(iceOptions.isForceRelay()) {
187+
if (iceOptions.isForceRelay()) {
184188
ALLOW_HOST = false;
185189
ALLOW_REFLEXIVE = false;
186190
ALLOW_RELAY = true;
@@ -197,7 +201,7 @@ public static void loadOptions(IceOptions iceOptions) {
197201

198202
private static void determineVersion() {
199203
String versionFromGradle = IceAdapter.class.getPackage().getImplementationVersion();
200-
if(versionFromGradle != null) {
204+
if (versionFromGradle != null) {
201205
VERSION = versionFromGradle;
202206
}
203207
}

ice-adapter/src/main/java/com/faforever/iceadapter/IceOptions.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ public class IceOptions {
2424
@Option(names = "--gpgnet-port", defaultValue = "0", description = "set the port of internal GPGNet server")
2525
private int gpgnetPort;
2626

27-
@Option(names = "--lobby-port", defaultValue = "0", description = "set the port the game lobby should use for incoming UDP packets from the PeerRelay")
27+
@Option(
28+
names = "--lobby-port",
29+
defaultValue = "0",
30+
description = "set the port the game lobby should use for incoming UDP packets from the PeerRelay")
2831
private int lobbyPort;
2932

3033
@Option(names = "--force-relay", description = "force the usage of relay candidates only")
@@ -36,15 +39,27 @@ public class IceOptions {
3639
@Option(names = "--info-window", description = "activate the info window")
3740
private boolean infoWindow;
3841

39-
@Option(names = "--delay-ui", defaultValue = "0", description = "delays the launch of the info and debug window (in ms)")
42+
@Option(
43+
names = "--delay-ui",
44+
defaultValue = "0",
45+
description = "delays the launch of the info and debug window (in ms)")
4046
private int delayUi;
4147

42-
@Option(names = "--ping-count", defaultValue = "1", description = "number of times to ping each turn server to determine latency")
48+
@Option(
49+
names = "--ping-count",
50+
defaultValue = "1",
51+
description = "number of times to ping each turn server to determine latency")
4352
private int pingCount;
4453

45-
@Option(names = "--acceptable-latency", defaultValue = "250.0", description = "number of times to ping each turn server to determine latency")
54+
@Option(
55+
names = "--acceptable-latency",
56+
defaultValue = "250.0",
57+
description = "number of times to ping each turn server to determine latency")
4658
private double acceptableLatency;
4759

48-
@Option(names = "--telemetry-server", defaultValue = "wss://ice-telemetry.faforever.com", description = "Telemetry server to connect to")
60+
@Option(
61+
names = "--telemetry-server",
62+
defaultValue = "wss://ice-telemetry.faforever.com",
63+
description = "Telemetry server to connect to")
4964
private String telemetryServer;
5065
}
Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,71 @@
11
package com.faforever.iceadapter.debug;
22

33
import com.faforever.iceadapter.IceAdapter;
4-
import lombok.extern.slf4j.Slf4j;
5-
64
import java.lang.reflect.InvocationTargetException;
7-
import java.util.concurrent.CompletableFuture;
8-
import java.util.concurrent.ExecutionException;
5+
import lombok.extern.slf4j.Slf4j;
96

107
@Slf4j
118
public class Debug {
12-
//TODO
13-
public static boolean ENABLE_DEBUG_WINDOW_LOG_TEXT_AREA = false; // disabled as this causes high memory and cpu load, should be replaced by limiting the number of lines in the text area
14-
15-
public static boolean ENABLE_DEBUG_WINDOW = false;
16-
public static boolean ENABLE_INFO_WINDOW = false;
17-
public static int DELAY_UI_MS = 0;//delays the launch of the user interface by X ms
9+
// TODO
10+
public static boolean ENABLE_DEBUG_WINDOW_LOG_TEXT_AREA =
11+
false; // disabled as this causes high memory and cpu load, should be replaced by limiting the number of
12+
// lines in the text area
1813

19-
private final static DebugFacade debugFacade = new DebugFacade();
14+
public static boolean ENABLE_DEBUG_WINDOW = false;
15+
public static boolean ENABLE_INFO_WINDOW = false;
16+
public static int DELAY_UI_MS = 0; // delays the launch of the user interface by X ms
2017

21-
public static void register(Debugger debugger) {
22-
debugFacade.add(debugger);
23-
}
18+
private static final DebugFacade debugFacade = new DebugFacade();
2419

25-
public static void remove(Debugger debugger) {
26-
debugFacade.remove(debugger);
27-
}
20+
public static void register(Debugger debugger) {
21+
debugFacade.add(debugger);
22+
}
2823

29-
public static void init() {
30-
new TelemetryDebugger(IceAdapter.TELEMETRY_SERVER, IceAdapter.gameId, IceAdapter.id);
24+
public static void remove(Debugger debugger) {
25+
debugFacade.remove(debugger);
26+
}
3127

32-
// Debugger window is started and set to debugFuture when either window is requested as the info window can be used to open the debug window
33-
// This is not used anymore as the debug window is started and hidden in case it is requested via the tray icon
34-
if(! ENABLE_DEBUG_WINDOW && ! ENABLE_INFO_WINDOW) {
35-
return;
36-
}
28+
public static void init() {
29+
new TelemetryDebugger(IceAdapter.TELEMETRY_SERVER, IceAdapter.gameId, IceAdapter.id);
3730

38-
if(isJavaFxSupported()) {
39-
new Thread(() -> {
40-
try {
41-
Class.forName("com.faforever.iceadapter.debug.DebugWindow").getMethod("launchApplication").invoke(null);
42-
} catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
43-
e.printStackTrace();
44-
log.error("Could not create DebugWindow. Running without debug window.");
45-
}
46-
}).start(); //Completes future once application started
47-
} else {
48-
log.info("No JavaFX support detected. Running without debug window.");
49-
}
50-
}
31+
// Debugger window is started and set to debugFuture when either window is requested as the info window can be
32+
// used to open the debug window
33+
// This is not used anymore as the debug window is started and hidden in case it is requested via the tray icon
34+
if (!ENABLE_DEBUG_WINDOW && !ENABLE_INFO_WINDOW) {
35+
return;
36+
}
5137

38+
if (isJavaFxSupported()) {
39+
new Thread(() -> {
40+
try {
41+
Class.forName("com.faforever.iceadapter.debug.DebugWindow")
42+
.getMethod("launchApplication")
43+
.invoke(null);
44+
} catch (IllegalAccessException
45+
| ClassNotFoundException
46+
| NoSuchMethodException
47+
| InvocationTargetException e) {
48+
e.printStackTrace();
49+
log.error("Could not create DebugWindow. Running without debug window.");
50+
}
51+
})
52+
.start(); // Completes future once application started
53+
} else {
54+
log.info("No JavaFX support detected. Running without debug window.");
55+
}
56+
}
5257

53-
public static Debugger debug() {
54-
return debugFacade;
55-
}
58+
public static Debugger debug() {
59+
return debugFacade;
60+
}
5661

57-
public static boolean isJavaFxSupported() {
58-
try {
59-
Debug.class.getClassLoader().loadClass("javafx.application.Application");
60-
return true;
61-
} catch(ClassNotFoundException e) {
62-
log.warn("Could not create debug window, no JavaFX found.");
63-
return false;
64-
}
65-
}
62+
public static boolean isJavaFxSupported() {
63+
try {
64+
Debug.class.getClassLoader().loadClass("javafx.application.Application");
65+
return true;
66+
} catch (ClassNotFoundException e) {
67+
log.warn("Could not create debug window, no JavaFX found.");
68+
return false;
69+
}
70+
}
6671
}

ice-adapter/src/main/java/com/faforever/iceadapter/debug/DebugFacade.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.faforever.iceadapter.ice.Peer;
44
import com.faforever.iceadapter.telemetry.CoturnServer;
55
import com.nbarraille.jjsonrpc.JJsonPeer;
6-
76
import java.util.Collection;
87
import java.util.List;
98
import java.util.concurrent.CompletableFuture;

0 commit comments

Comments
 (0)