Skip to content

Commit

Permalink
Move exit codes to class defined in core module
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Oct 19, 2024
1 parent 36506ca commit 76869c2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
11 changes: 8 additions & 3 deletions recaf-core/src/main/java/software/coley/recaf/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ public static Recaf get() {
long then = System.currentTimeMillis();

// Create the Recaf container
SeContainer container = createContainer();
instance = new Recaf(container);
logger.info("Recaf CDI container created in {}ms", System.currentTimeMillis() - then);
try {
SeContainer container = createContainer();
instance = new Recaf(container);
logger.info("Recaf CDI container created in {}ms", System.currentTimeMillis() - then);
} catch (Throwable t) {
logger.error("Failed to create Recaf CDI container", t);
System.exit(ExitCodes.ERR_CDI_INIT_FAILURE);
}
}
return instance;
}
Expand Down
20 changes: 20 additions & 0 deletions recaf-core/src/main/java/software/coley/recaf/ExitCodes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package software.coley.recaf;

/**
* Exit codes for Recaf calling {@link System#exit(int)}.
*
* @author Matt Coley
*/
public class ExitCodes {
public static final int SUCCESS = 0;
public static final int ERR_UNKNOWN = 100;
public static final int ERR_CLASS_NOT_FOUND = 101;
public static final int ERR_NO_SUCH_METHOD = 102;
public static final int ERR_INVOKE_TARGET = 103;
public static final int ERR_ACCESS_TARGET = 104;
public static final int ERR_OLD_JFX_VERSION = 105;
public static final int ERR_UNKNOWN_JFX_VERSION = 106;
public static final int ERR_CDI_INIT_FAILURE = 107;
public static final int INTELLIJ_TERMINATION = 130;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.slf4j.Logger;
import regexodus.Matcher;
import software.coley.recaf.ExitCodes;
import software.coley.recaf.analytics.logging.Logging;

import java.lang.reflect.InaccessibleObjectException;
Expand All @@ -14,14 +15,6 @@
*/
public class JFXValidation {
public static final int MIN_JFX_VERSION = 19;
public static final int SUCCESS = 0;
public static final int ERR_UNKNOWN = 100;
public static final int ERR_CLASS_NOT_FOUND = 101;
public static final int ERR_NO_SUCH_METHOD = 102;
public static final int ERR_INVOKE_TARGET = 103;
public static final int ERR_ACCESS_TARGET = 104;
public static final int ERR_OLD_JFX_VERSION = 105;
public static final int ERR_UNKNOWN_JFX_VERSION = 106;
private static final Logger logger = Logging.get(JFXValidation.class);

/**
Expand All @@ -40,30 +33,30 @@ public static int validateJFX() {
int majorVersion = Integer.parseInt(versionMatcher.group());
if (majorVersion < MIN_JFX_VERSION) {
logger.error("JavaFX version {} is present, but Recaf requires {}+", majorVersion, MIN_JFX_VERSION);
return ERR_OLD_JFX_VERSION;
return ExitCodes.ERR_OLD_JFX_VERSION;
}
} else {
logger.error("JavaFX version {} does not declare a major release version, cannot validate compatibility", versionProperty);
return ERR_UNKNOWN_JFX_VERSION;
return ExitCodes.ERR_UNKNOWN_JFX_VERSION;
}

logger.info("JavaFX successfully initialized: {}", versionProperty);
return SUCCESS;
return ExitCodes.SUCCESS;
} catch (ClassNotFoundException ex) {
logger.error("JFX validation failed, could not find 'VersionInfo' class", ex);
return ERR_CLASS_NOT_FOUND;
return ExitCodes.ERR_CLASS_NOT_FOUND;
} catch (NoSuchMethodException ex) {
logger.error("JFX validation failed, could not find 'setupSystemProperties' in 'VersionInfo'", ex);
return ERR_NO_SUCH_METHOD;
return ExitCodes.ERR_NO_SUCH_METHOD;
} catch (InvocationTargetException ex) {
logger.error("JFX validation failed, failed to invoke 'setupSystemProperties'", ex);
return ERR_INVOKE_TARGET;
return ExitCodes.ERR_INVOKE_TARGET;
} catch (IllegalAccessException | InaccessibleObjectException ex) {
logger.error("JFX validation failed, failed to invoke 'setupSystemProperties'", ex);
return ERR_ACCESS_TARGET;
return ExitCodes.ERR_ACCESS_TARGET;
} catch (Exception ex) {
logger.error("JFX validation failed due to unhandled exception", ex);
return ERR_UNKNOWN;
return ExitCodes.ERR_UNKNOWN;
}
}
}

0 comments on commit 76869c2

Please sign in to comment.