Improve CrashException handler, fix java encoding, updated junit dependencies, add private methods to javadoc, renamed Error to ErrorMessage

This commit is contained in:
Quentin Legot 2021-12-08 15:00:13 +01:00
parent 4305f8963b
commit 938eefe387
8 changed files with 40 additions and 24 deletions

11
build.gradle Normal file
View File

@ -0,0 +1,11 @@
subprojects {
apply plugin: 'java'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
javadoc {
options.memberLevel = JavadocMemberLevel.PRIVATE
}
compileJava {
// options.encoding = "UTF-8"
}
}

View File

@ -21,10 +21,6 @@ javafx {
modules = [ 'javafx.controls', 'javafx.graphics' ]
}
compileJava {
options.encoding = 'UTF-8'
}
application {
// Define the main class for the application.
mainClassName = 'fr.lnl.game.client.App'

View File

@ -24,19 +24,28 @@ public class App extends Application {
private static ViewManager viewManager;
public static void main(String[] args) {
argsList = new LinkedList<>(Arrays.asList(args));
argsList.removeIf(s -> s.startsWith("-D") || s.equals("fr.lnl.game.client.App")); // remove given parameters from gradle
Class<? extends AbstractView> clazz;
try {
clazz = parseView();
} catch (IllegalArgumentException e) {
throw new CrashException(e.getMessage(), e);
}
if(clazz.equals(Terminal.class)) {
launchTerminal();
} else {
launch();
}
try {
argsList = new LinkedList<>(Arrays.asList(args));
argsList.removeIf(s -> s.startsWith("-D") || s.equals("fr.lnl.game.client.App")); // remove given parameters from gradle
Class<? extends AbstractView> clazz;
try {
clazz = parseView();
} catch (IllegalArgumentException e) {
throw new CrashException(e.getMessage(), e);
}
if(clazz.equals(Terminal.class)) {
launchTerminal();
} else {
launch();
}
} catch(CrashException e) {
System.err.println("Une erreur est survenue et l'application a été obligé de fermer");
System.err.println(e.getCause().toString());
for (StackTraceElement element : e.getStackTrace()) {
System.err.println(" at " + element.toString());
}
System.exit(1);
}
}
public static void startGame(ViewLambda lambda) throws IllegalArgumentException, InvocationTargetException, NoSuchMethodException,

View File

@ -1 +1,2 @@
org.gradle.jvmargs='-Dfile.encoding=utf-8'
# org.gradle.jvmargs='-Dfile.encoding=UTF-8'
systemProp.file.encoding=UTF-8

View File

@ -8,8 +8,8 @@ plugins {
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
compileJava {

View File

@ -4,7 +4,6 @@ public class CrashException extends RuntimeException {
public CrashException(String message, Throwable cause) {
super(message, cause);
System.exit(1);
}

View File

@ -1,6 +1,6 @@
package fr.lnl.game.server.utils;
public class Error {
public class ErrorMessage {
public static final String Entry_Error_Message = "\033[0;31mErreur de saisie\033[0m : ";
}

View File

@ -6,7 +6,7 @@ public class Maths {
public static int testInteger(String entry, Scanner scanner, String error) {
while (!isNumeric(entry)) {
System.out.println(Error.Entry_Error_Message + error);
System.out.println(ErrorMessage.Entry_Error_Message + error);
entry = scanner.next();
}
return Integer.parseInt(entry);
@ -14,7 +14,7 @@ public class Maths {
public static float testFloat(String entry, Scanner scanner, String error) {
while (!isFloat(entry)) {
System.out.println(Error.Entry_Error_Message + error);
System.out.println(ErrorMessage.Entry_Error_Message + error);
entry = scanner.next();
}
return Integer.parseInt(entry);