From 26de23c734fc22ed0c2b56c9a14e2086fc0de480 Mon Sep 17 00:00:00 2001 From: hinerm Date: Wed, 20 Nov 2024 13:43:16 -0600 Subject: [PATCH] ClassLauncher: indicate source of debug/error msgs --- .../org/scijava/launcher/ClassLauncher.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/scijava/launcher/ClassLauncher.java b/src/main/java/org/scijava/launcher/ClassLauncher.java index d125aa8..370212d 100644 --- a/src/main/java/org/scijava/launcher/ClassLauncher.java +++ b/src/main/java/org/scijava/launcher/ClassLauncher.java @@ -84,20 +84,20 @@ private static void run(String[] args) { switch (option) { // Note: No options for now, but might add some in the future. default: - Log.error("Unknown option: " + option + "!"); + error("Unknown option: " + option + "!"); System.exit(1); } } if (i >= args.length) { - Log.error("Missing argument: main class"); + error("Missing argument: main class"); System.exit(1); } String mainClass = args[i]; args = slice(args, i + 1); - Log.debug("Launching main class " + mainClass + " with parameters " + Arrays.toString(args)); + debug("Launching main class " + mainClass + " with parameters " + Arrays.toString(args)); try { launch(classLoader, mainClass, args); @@ -120,11 +120,19 @@ private static String[] slice(final String[] array, final int from, return result; } + private static void debug(String message) { + Log.debug("[ClassLauncher] " + message); + } + + private static void error(String message) { + Log.error("[ClassLauncher] " + message); + } + static void launch(ClassLoader classLoader, final String className, final String... args) { Class main = null; - Log.debug("Class loader = " + classLoader); + debug("Class loader = " + classLoader); try { main = ClassLoaders.loadClass(classLoader, className); } @@ -145,7 +153,7 @@ static void launch(ClassLoader classLoader, } catch (final NoSuchMethodException e) { Log.debug(e); - Log.error("Class '" + className + "' does not have a main method."); + error("Class '" + className + "' does not have a main method."); System.exit(1); } Integer result = 1; @@ -154,10 +162,10 @@ static void launch(ClassLoader classLoader, } catch (final IllegalAccessException e) { Log.debug(e); - Log.error("The main method of class '" + className + "' is not public."); + error("The main method of class '" + className + "' is not public."); } catch (final InvocationTargetException e) { - Log.error("Error while executing the main method of class '" + className + "':"); + error("Error while executing the main method of class '" + className + "':"); Log.error(e.getTargetException()); } if (result != null) System.exit(result);