changeset 947:0234208765da

runners: produce the result file if either -rf/result() or -rrf/resultFormat() is supplied.
author shade
date Wed, 13 Aug 2014 23:20:26 +0400
parents bdfb6ec5251c
children 32d412b1693a
files jmh-core/src/main/java/org/openjdk/jmh/results/format/NoneResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatFactory.java jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatType.java jmh-core/src/main/java/org/openjdk/jmh/runner/Defaults.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java
diffstat 5 files changed, 8 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/NoneResultFormat.java	Wed Aug 13 22:59:50 2014 +0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2005, 2013, 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.results.format;
-
-import org.openjdk.jmh.results.RunResult;
-
-import java.util.Collection;
-
-class NoneResultFormat implements ResultFormat {
-    @Override
-    public void writeOut(Collection<RunResult> results) {
-        // do nothing
-    }
-}
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatFactory.java	Wed Aug 13 22:59:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatFactory.java	Wed Aug 13 23:20:26 2014 +0400
@@ -41,9 +41,6 @@
      * @return result format
      */
     public static ResultFormat getInstance(final ResultFormatType type, final String file) {
-        if (type == ResultFormatType.NONE) {
-            return new NoneResultFormat();
-        }
         return new ResultFormat() {
             @Override
             public void writeOut(Collection<RunResult> results) {
@@ -70,8 +67,6 @@
      */
     public static ResultFormat getInstance(ResultFormatType type, PrintWriter writer) {
         switch (type) {
-            case NONE:
-                throw new IllegalStateException(ResultFormatType.NONE + " should be handled already");
             case TEXT:
                 return new TextResultFormat(writer);
             case CSV:
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatType.java	Wed Aug 13 22:59:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/format/ResultFormatType.java	Wed Aug 13 23:20:26 2014 +0400
@@ -26,7 +26,6 @@
 
 public enum ResultFormatType {
 
-    NONE,
     TEXT,
     CSV,
     SCSV,
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Defaults.java	Wed Aug 13 22:59:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Defaults.java	Wed Aug 13 23:20:26 2014 +0400
@@ -110,7 +110,7 @@
     /**
      * The default {@link org.openjdk.jmh.results.format.ResultFormatType} to use.
      */
-    public static final ResultFormatType RESULT_FORMAT = ResultFormatType.NONE;
+    public static final ResultFormatType RESULT_FORMAT = ResultFormatType.CSV;
 
     /**
      * Default location of result file.
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Aug 13 22:59:50 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Wed Aug 13 23:20:26 2014 +0400
@@ -34,9 +34,7 @@
 import org.openjdk.jmh.results.BenchmarkResult;
 import org.openjdk.jmh.results.Result;
 import org.openjdk.jmh.results.RunResult;
-import org.openjdk.jmh.results.format.ResultFormat;
 import org.openjdk.jmh.results.format.ResultFormatFactory;
-import org.openjdk.jmh.results.format.ResultFormatType;
 import org.openjdk.jmh.runner.format.OutputFormat;
 import org.openjdk.jmh.runner.format.OutputFormatFactory;
 import org.openjdk.jmh.runner.link.BinaryLinkServer;
@@ -234,10 +232,13 @@
         out.flush();
         out.close();
 
-        ResultFormatType resultFormatType = options.getResultFormat().orElse(Defaults.RESULT_FORMAT);
-        String resultFormatFile = options.getResult().orElse(Defaults.RESULT_FILE);
-        ResultFormat resultFormat = ResultFormatFactory.getInstance(resultFormatType, resultFormatFile);
-        resultFormat.writeOut(results);
+        // If user requested the result file in one way or the other, write it out.
+        if (options.getResult().hasValue() || options.getResultFormat().hasValue()) {
+            ResultFormatFactory.getInstance(
+                        options.getResultFormat().orElse(Defaults.RESULT_FORMAT),
+                        options.getResult().orElse(Defaults.RESULT_FILE)
+            ).writeOut(results);
+        }
 
         return results;
     }