-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
--debug
flag to enable debug mode #577
- Loading branch information
Showing
6 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 35 additions & 3 deletions
38
autograder-core/src/main/java/de/firemage/autograder/core/integrated/CoreUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,48 @@ | ||
package de.firemage.autograder.core.integrated; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
// TODO: rename? | ||
/** | ||
* Utility class for functionality that does not fit in any other utility class. | ||
*/ | ||
public final class CoreUtil { | ||
private static Optional<Boolean> AUTOGRADER_DEBUG_ENVIRONMENT = parseOptionalFlag(System.getenv("AUTOGRADER_DEBUG")); | ||
private static final boolean IS_IN_JUNIT_TEST = Arrays.stream(Thread.currentThread().getStackTrace()) | ||
.anyMatch(element -> element.getClassName().startsWith("org.junit.")); | ||
|
||
private CoreUtil() { | ||
} | ||
|
||
public static boolean isInJunitTest() { | ||
return IS_IN_JUNIT_TEST; | ||
private static Optional<Boolean> parseOptionalFlag(String flag) { | ||
if (flag == null) { | ||
return Optional.empty(); | ||
} | ||
|
||
try { | ||
return Optional.of(Integer.parseInt(flag) != 0); | ||
} catch (NumberFormatException exception) { | ||
return Optional.of(Boolean.parseBoolean(flag)); | ||
} | ||
} | ||
|
||
/** | ||
* Enables debug mode for the autograder. | ||
* <br> | ||
* Note that this slows down the execution by a lot and should therefore only be used for debugging purposes. | ||
*/ | ||
public static void setDebugMode() { | ||
AUTOGRADER_DEBUG_ENVIRONMENT = Optional.of(true); | ||
} | ||
|
||
/** | ||
* Checks if the code is currently running in debug mode. | ||
* <br> | ||
* This is the case if the code is executed in a junit test or if the debug mode is explicitly enabled. | ||
* | ||
* @return {@code true} if the code is currently running in debug mode | ||
*/ | ||
public static boolean isInDebugMode() { | ||
return IS_IN_JUNIT_TEST || AUTOGRADER_DEBUG_ENVIRONMENT.orElse(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters