diff --git a/jmh-core/src/main/java/org/openjdk/jmh/Main.java b/jmh-core/src/main/java/org/openjdk/jmh/Main.java index 58a30dc7..d9ec0729 100644 --- a/jmh-core/src/main/java/org/openjdk/jmh/Main.java +++ b/jmh-core/src/main/java/org/openjdk/jmh/Main.java @@ -37,67 +37,78 @@ public class Main { public static void main(String[] argv) throws IOException { - try { - CommandLineOptions cmdOptions = new CommandLineOptions(argv); + Main main = new Main(); - Runner runner = new Runner(cmdOptions); + CommandLineOptions cmdOptions = main.createCommandLineOptions(argv); - if (cmdOptions.shouldHelp()) { - cmdOptions.showHelp(); - return; - } + Runner runner = new Runner(cmdOptions); - if (cmdOptions.shouldList()) { - runner.list(); - return; - } + main.run(cmdOptions, runner); + } - if (cmdOptions.shouldListWithParams()) { - runner.listWithParams(cmdOptions); - return; - } + protected CommandLineOptions createCommandLineOptions(String[] argv) + { + try { + return new CommandLineOptions(argv); + } catch (CommandLineOptionException e) { + System.err.println("Error parsing command line:"); + System.err.println(" " + e.getMessage()); + System.exit(1); + return null; + } + } - if (cmdOptions.shouldListProfilers()) { - cmdOptions.listProfilers(); - return; - } + protected void run(CommandLineOptions cmdOptions, Runner runner) throws IOException { + if (cmdOptions.shouldHelp()) { + cmdOptions.showHelp(); + return; + } - if (cmdOptions.shouldListResultFormats()) { - cmdOptions.listResultFormats(); - return; - } + if (cmdOptions.shouldList()) { + runner.list(); + return; + } - try { - runner.run(); - } catch (NoBenchmarksException e) { - System.err.println("No matching benchmarks. Miss-spelled regexp?"); + if (cmdOptions.shouldListWithParams()) { + runner.listWithParams(cmdOptions); + return; + } - if (cmdOptions.verbosity().orElse(Defaults.VERBOSITY) != VerboseMode.EXTRA) { - System.err.println("Use " + VerboseMode.EXTRA + " verbose mode to debug the pattern matching."); - } else { - runner.list(); - } - System.exit(1); - } catch (ProfilersFailedException e) { - // This is not exactly an error, print all messages and set the non-zero exit code. - Throwable ex = e; - while (ex != null) { - System.err.println(ex.getMessage()); - for (Throwable supp : ex.getSuppressed()) { - System.err.println(supp.getMessage()); - } - ex = ex.getCause(); + if (cmdOptions.shouldListProfilers()) { + cmdOptions.listProfilers(); + return; + } + + if (cmdOptions.shouldListResultFormats()) { + cmdOptions.listResultFormats(); + return; + } + + try { + runner.run(); + } catch (NoBenchmarksException e) { + System.err.println("No matching benchmarks. Miss-spelled regexp?"); + + if (cmdOptions.verbosity().orElse(Defaults.VERBOSITY) != VerboseMode.EXTRA) { + System.err.println("Use " + VerboseMode.EXTRA + " verbose mode to debug the pattern matching."); + } else { + runner.list(); + } + System.exit(1); + } catch (ProfilersFailedException e) { + // This is not exactly an error, print all messages and set the non-zero exit code. + Throwable ex = e; + while (ex != null) { + System.err.println(ex.getMessage()); + for (Throwable supp : ex.getSuppressed()) { + System.err.println(supp.getMessage()); } - System.exit(1); - } catch (RunnerException e) { - System.err.print("ERROR: "); - e.printStackTrace(System.err); - System.exit(1); + ex = ex.getCause(); } - - } catch (CommandLineOptionException e) { - System.err.println("Error parsing command line:"); - System.err.println(" " + e.getMessage()); + System.exit(1); + } catch (RunnerException e) { + System.err.print("ERROR: "); + e.printStackTrace(System.err); System.exit(1); } }