Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply code formatting with Spotless and palantir format #62

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'java'
id 'com.diffplug.spotless' version '6.25.0'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}


Expand All @@ -23,4 +24,4 @@ allprojects {

task createAllJars (type: GradleBuild) {
tasks = [":client:shadowJar",":server:shadowJar",":ice-adapter:shadowJar"]
}
}
12 changes: 12 additions & 0 deletions ice-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.diffplug.spotless'

group 'com.faforever'

Expand Down Expand Up @@ -67,3 +68,14 @@ shadowJar {
attributes 'Main-Class': 'com.faforever.iceadapter.IceAdapter'
}
}

tasks.named("check") {
dependsOn("spotlessCheck")
}

spotless {
java {
cleanthat()
palantirJavaFormat()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add

tasks.named('shadowJar') {
    dependsOn 'spotlessCheck'
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it to check instead =)

52 changes: 28 additions & 24 deletions ice-adapter/src/main/java/com/faforever/iceadapter/IceAdapter.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package com.faforever.iceadapter;

import static com.faforever.iceadapter.debug.Debug.debug;

import com.faforever.iceadapter.debug.Debug;
import com.faforever.iceadapter.gpgnet.GPGNetServer;
import com.faforever.iceadapter.gpgnet.GameState;
import com.faforever.iceadapter.ice.GameSession;
import com.faforever.iceadapter.rpc.RPCService;
import com.faforever.iceadapter.util.Executor;
import com.faforever.iceadapter.util.TrayIcon;
import java.util.concurrent.Callable;
import lombok.extern.slf4j.Slf4j;
import picocli.CommandLine;

import java.util.concurrent.Callable;

import static com.faforever.iceadapter.debug.Debug.debug;
@CommandLine.Command(name = "faf-ice-adapter", mixinStandardHelpOptions = true, usageHelpAutoWidth = true,
@CommandLine.Command(
name = "faf-ice-adapter",
mixinStandardHelpOptions = true,
usageHelpAutoWidth = true,
description = "An ice (RFC 5245) based network bridge between FAF client and ForgedAlliance.exe")
@Slf4j
public class IceAdapter implements Callable<Integer> {
Expand Down Expand Up @@ -43,9 +46,7 @@ public class IceAdapter implements Callable<Integer> {
public static volatile GameSession gameSession;

public static void main(String[] args) {
new CommandLine(new IceAdapter())
.setUnmatchedArgumentsAllowed(true)
.execute(args);
new CommandLine(new IceAdapter()).setUnmatchedArgumentsAllowed(true).execute(args);
}

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

TrayIcon.create();

//Configure file appender
// RollingFileAppender fileAppender = (ch.qos.logback.core.rolling.RollingFileAppender)((ch.qos.logback.classic.Logger)log).getAppender("FILE");
// if (logDirectory != null) {
// Util.mkdir(Paths.get(logDirectory).toFile());
// //TODO: set log dir
// } else {
//// fileAppender.stop();
// }
// Configure file appender
// RollingFileAppender fileAppender =
// (ch.qos.logback.core.rolling.RollingFileAppender)((ch.qos.logback.classic.Logger)log).getAppender("FILE");
// if (logDirectory != null) {
// Util.mkdir(Paths.get(logDirectory).toFile());
// //TODO: set log dir
// } else {
//// fileAppender.stop();
// }

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

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

public static void onConnectToPeer(String remotePlayerLogin, int remotePlayerId, boolean offer) {
if(GPGNetServer.isConnected() && GPGNetServer.getGameState().isPresent() && (GPGNetServer.getGameState().get() == GameState.LAUNCHING || GPGNetServer.getGameState().get() == GameState.ENDED)) {
if (GPGNetServer.isConnected()
&& GPGNetServer.getGameState().isPresent()
&& (GPGNetServer.getGameState().get() == GameState.LAUNCHING
|| GPGNetServer.getGameState().get() == GameState.ENDED)) {
log.warn("Game ended or in progress, ABORTING connectToPeer");
return;
}
Expand All @@ -128,7 +133,7 @@ public static void onDisconnectFromPeer(int remotePlayerId) {
});
}

private synchronized static void createGameSession() {
private static synchronized void createGameSession() {
if (gameSession != null) {
gameSession.close();
gameSession = null;
Expand All @@ -141,12 +146,12 @@ private synchronized static void createGameSession() {
* Triggered by losing gpgnet connection to FA.
* Closes the active Game/ICE session
*/
public synchronized static void onFAShutdown() {
if(gameSession != null) {
public static synchronized void onFAShutdown() {
if (gameSession != null) {
log.info("FA SHUTDOWN, closing everything");
gameSession.close();
gameSession = null;
//Do not put code outside of this if clause, else it will be executed multiple times
// Do not put code outside of this if clause, else it will be executed multiple times
}
}

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

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

onFAShutdown();//will close gameSession aswell
onFAShutdown(); // will close gameSession aswell
GPGNetServer.close();
RPCService.close();
TrayIcon.close();

System.exit(0);
}


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

if(iceOptions.isForceRelay()) {
if (iceOptions.isForceRelay()) {
ALLOW_HOST = false;
ALLOW_REFLEXIVE = false;
ALLOW_RELAY = true;
Expand All @@ -197,7 +201,7 @@ public static void loadOptions(IceOptions iceOptions) {

private static void determineVersion() {
String versionFromGradle = IceAdapter.class.getPackage().getImplementationVersion();
if(versionFromGradle != null) {
if (versionFromGradle != null) {
VERSION = versionFromGradle;
}
}
Expand Down
25 changes: 20 additions & 5 deletions ice-adapter/src/main/java/com/faforever/iceadapter/IceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ public class IceOptions {
@Option(names = "--gpgnet-port", defaultValue = "0", description = "set the port of internal GPGNet server")
private int gpgnetPort;

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

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

@Option(names = "--delay-ui", defaultValue = "0", description = "delays the launch of the info and debug window (in ms)")
@Option(
names = "--delay-ui",
defaultValue = "0",
description = "delays the launch of the info and debug window (in ms)")
private int delayUi;

@Option(names = "--ping-count", defaultValue = "1", description = "number of times to ping each turn server to determine latency")
@Option(
names = "--ping-count",
defaultValue = "1",
description = "number of times to ping each turn server to determine latency")
private int pingCount;

@Option(names = "--acceptable-latency", defaultValue = "250.0", description = "number of times to ping each turn server to determine latency")
@Option(
names = "--acceptable-latency",
defaultValue = "250.0",
description = "number of times to ping each turn server to determine latency")
private double acceptableLatency;

@Option(names = "--telemetry-server", defaultValue = "wss://ice-telemetry.faforever.com", description = "Telemetry server to connect to")
@Option(
names = "--telemetry-server",
defaultValue = "wss://ice-telemetry.faforever.com",
description = "Telemetry server to connect to")
private String telemetryServer;
}
103 changes: 54 additions & 49 deletions ice-adapter/src/main/java/com/faforever/iceadapter/debug/Debug.java
Original file line number Diff line number Diff line change
@@ -1,66 +1,71 @@
package com.faforever.iceadapter.debug;

import com.faforever.iceadapter.IceAdapter;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Debug {
//TODO
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

public static boolean ENABLE_DEBUG_WINDOW = false;
public static boolean ENABLE_INFO_WINDOW = false;
public static int DELAY_UI_MS = 0;//delays the launch of the user interface by X ms
// TODO
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

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

public static void register(Debugger debugger) {
debugFacade.add(debugger);
}
private static final DebugFacade debugFacade = new DebugFacade();

public static void remove(Debugger debugger) {
debugFacade.remove(debugger);
}
public static void register(Debugger debugger) {
debugFacade.add(debugger);
}

public static void init() {
new TelemetryDebugger(IceAdapter.TELEMETRY_SERVER, IceAdapter.gameId, IceAdapter.id);
public static void remove(Debugger debugger) {
debugFacade.remove(debugger);
}

// 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
// This is not used anymore as the debug window is started and hidden in case it is requested via the tray icon
if(! ENABLE_DEBUG_WINDOW && ! ENABLE_INFO_WINDOW) {
return;
}
public static void init() {
new TelemetryDebugger(IceAdapter.TELEMETRY_SERVER, IceAdapter.gameId, IceAdapter.id);

if(isJavaFxSupported()) {
new Thread(() -> {
try {
Class.forName("com.faforever.iceadapter.debug.DebugWindow").getMethod("launchApplication").invoke(null);
} catch (IllegalAccessException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace();
log.error("Could not create DebugWindow. Running without debug window.");
}
}).start(); //Completes future once application started
} else {
log.info("No JavaFX support detected. Running without debug window.");
}
}
// 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
// This is not used anymore as the debug window is started and hidden in case it is requested via the tray icon
if (!ENABLE_DEBUG_WINDOW && !ENABLE_INFO_WINDOW) {
return;
}

if (isJavaFxSupported()) {
new Thread(() -> {
try {
Class.forName("com.faforever.iceadapter.debug.DebugWindow")
.getMethod("launchApplication")
.invoke(null);
} catch (IllegalAccessException
| ClassNotFoundException
| NoSuchMethodException
| InvocationTargetException e) {
e.printStackTrace();
log.error("Could not create DebugWindow. Running without debug window.");
}
})
.start(); // Completes future once application started
} else {
log.info("No JavaFX support detected. Running without debug window.");
}
}

public static Debugger debug() {
return debugFacade;
}
public static Debugger debug() {
return debugFacade;
}

public static boolean isJavaFxSupported() {
try {
Debug.class.getClassLoader().loadClass("javafx.application.Application");
return true;
} catch(ClassNotFoundException e) {
log.warn("Could not create debug window, no JavaFX found.");
return false;
}
}
public static boolean isJavaFxSupported() {
try {
Debug.class.getClassLoader().loadClass("javafx.application.Application");
return true;
} catch (ClassNotFoundException e) {
log.warn("Could not create debug window, no JavaFX found.");
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.faforever.iceadapter.ice.Peer;
import com.faforever.iceadapter.telemetry.CoturnServer;
import com.nbarraille.jjsonrpc.JJsonPeer;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down
Loading
Loading