changeset 1238:3378c82927e0

7901448: Profiler help should not yield an ERROR message
author shade
date Thu, 11 Jun 2015 17:56:42 +0300
parents 15cd0bde0cee
children ec073422d692
files jmh-core/src/main/java/org/openjdk/jmh/Main.java jmh-core/src/main/java/org/openjdk/jmh/runner/ProfilersFailedException.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 3 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Wed Jun 10 22:28:27 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/Main.java	Thu Jun 11 17:56:42 2015 +0300
@@ -24,10 +24,7 @@
  */
 package org.openjdk.jmh;
 
-import org.openjdk.jmh.runner.Defaults;
-import org.openjdk.jmh.runner.NoBenchmarksException;
-import org.openjdk.jmh.runner.Runner;
-import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.*;
 import org.openjdk.jmh.runner.options.CommandLineOptionException;
 import org.openjdk.jmh.runner.options.CommandLineOptions;
 import org.openjdk.jmh.runner.options.VerboseMode;
@@ -76,6 +73,10 @@
                     runner.list();
                 }
                 System.exit(1);
+            } catch (ProfilersFailedException e) {
+                // This is not exactly an error, set non-zero exit code
+                System.err.print(e.getMessage());
+                System.exit(1);
             } catch (RunnerException e) {
                 System.err.print("ERROR: ");
                 e.printStackTrace(System.err);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/ProfilersFailedException.java	Thu Jun 11 17:56:42 2015 +0300
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.runner;
+
+public class ProfilersFailedException extends RunnerException {
+    private static final long serialVersionUID = 1446854343206595167L;
+
+    public String getMessage() {
+        return "Profilers failed to initialize.";
+    }
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Jun 10 22:28:27 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Thu Jun 11 17:56:42 2015 +0300
@@ -206,7 +206,7 @@
                 someProfilersFail = true;
             }
             if (someProfilersFail) {
-                throw new RunnerException("Some profilers have failed to initialize");
+                throw new ProfilersFailedException();
             }
         }