You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/05/17 12:35:14 UTC

[commons-rng] 01/02: Update examples stress to expose a single public application class.

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 9f434e9d0dd3170f5493bb9e721b9834fd2ddfef
Author: aherbert <ah...@apache.org>
AuthorDate: Fri May 17 13:33:27 2019 +0100

    Update examples stress to expose a single public application class.
    
    This fixes the javadoc plugin as all other classes are package-private.
---
 commons-rng-examples/examples-stress/pom.xml       |  2 +-
 ...Command.java => ExamplesStressApplication.java} | 47 +++++----------
 .../rng/examples/stress/ExamplesStressCommand.java | 70 +---------------------
 3 files changed, 18 insertions(+), 101 deletions(-)

diff --git a/commons-rng-examples/examples-stress/pom.xml b/commons-rng-examples/examples-stress/pom.xml
index f471600..d652bab 100644
--- a/commons-rng-examples/examples-stress/pom.xml
+++ b/commons-rng-examples/examples-stress/pom.xml
@@ -48,7 +48,7 @@
     <rng.parent.dir>${basedir}/../..</rng.parent.dir>
 
     <uberjar.name>examples-stress</uberjar.name>
-    <project.mainClass>org.apache.commons.rng.examples.stress.ExamplesStressCommand</project.mainClass>
+    <project.mainClass>org.apache.commons.rng.examples.stress.ExamplesStressApplication</project.mainClass>
 
     <rng.picocli.version>3.9.5</rng.picocli.version>
   </properties>
diff --git a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressApplication.java
similarity index 78%
copy from commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java
copy to commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressApplication.java
index 6b54d91..0a8f1c4 100644
--- a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java
+++ b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressApplication.java
@@ -19,54 +19,44 @@ package org.apache.commons.rng.examples.stress;
 import org.apache.commons.rng.UniformRandomProvider;
 
 import picocli.CommandLine;
-import picocli.CommandLine.Command;
-import picocli.CommandLine.Mixin;
-import picocli.CommandLine.Model.CommandSpec;
 import picocli.CommandLine.RunLast;
-import picocli.CommandLine.Spec;
-
-import java.util.concurrent.Callable;
 
 /**
- * Class containing utilities for the random number generators in the Commons
- * RNG library.
+ * Executes testing utilities for the random number generators in the Commons RNG library.
  *
  * <p>The principle action is testing a generator by piping the values
  * returned by its {@link UniformRandomProvider#nextInt()} method to a
  * program that reads {@code int} values from its standard input and
  * writes an analysis report to standard output.
  * The <a href="http://www.phy.duke.edu/~rgb/General/dieharder.php">
- * "dieharder"</a> test suite is such a software.</p>
+ * "Dieharder"</a> test suite is such a software.</p>
  *
  * <p>Example of command line, assuming that "examples-stress.jar" specifies this
- * class as the "main" class (see {@link #main(String[]) main} method):
+ * class as the "main" class (see {@link #main(String[]) main} method):</p>
+ *
  * <pre>{@code $ java -jar examples-stress.jar stress /usr/bin/dieharder -a -g 200 -Y 1 -k 2}</pre>
- * </p>
  *
  * <p>Other functionality includes:</p>
  *
  * <ul>
- *   <li>Listing all the generators
- *   <li>...
+ *   <li>Listing all the available generators
+ *   <li>Collating results from known stress test applications
+ *   <li>Outputting data from a random generator
+ *   <li>Showing the platform native byte order
+ *   <li>Testing data transfer to an application sub-process via its standard input
  * </ul>
  */
-@Command(name = "examples-stress",
-         description = "Apache Commons RNG Examples Stress Utilities.")
-class ExamplesStressCommand implements Callable<Void> {
-    /** The command specification. Used to print the usage built by Picocli. */
-    @Spec
-    private CommandSpec spec;
-
-    /** The standard options. */
-    @Mixin
-    private StandardOptions reusableOptions;
+public class ExamplesStressApplication {
+    /** No public constructor. */
+    private ExamplesStressApplication() {}
 
     /**
-     * Run the RNG Utilities command line application.
+     * Run the RNG examples stress command line application.
      *
      * @param args Application's arguments.
      */
-    public static void main(String[] args) {
+    public static void main(String[] args)
+    {
         // Build the command line manually so we can configure options.
         final CommandLine cmd = new CommandLine(new ExamplesStressCommand())
                 .addSubcommand("bridge",  new CommandLine(new BridgeTestCommand())
@@ -104,11 +94,4 @@ class ExamplesStressCommand implements Callable<Void> {
             throw ex;
         }
     }
-
-    @Override
-    public Void call() {
-        // All work is done in sub-commands so just print the usage
-        spec.commandLine().usage(System.out);
-        return null;
-    }
 }
diff --git a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java
index 6b54d91..ac9e186 100644
--- a/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java
+++ b/commons-rng-examples/examples-stress/src/main/java/org/apache/commons/rng/examples/stress/ExamplesStressCommand.java
@@ -16,39 +16,17 @@
  */
 package org.apache.commons.rng.examples.stress;
 
-import org.apache.commons.rng.UniformRandomProvider;
-
-import picocli.CommandLine;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Model.CommandSpec;
-import picocli.CommandLine.RunLast;
 import picocli.CommandLine.Spec;
 
 import java.util.concurrent.Callable;
 
 /**
- * Class containing utilities for the random number generators in the Commons
- * RNG library.
- *
- * <p>The principle action is testing a generator by piping the values
- * returned by its {@link UniformRandomProvider#nextInt()} method to a
- * program that reads {@code int} values from its standard input and
- * writes an analysis report to standard output.
- * The <a href="http://www.phy.duke.edu/~rgb/General/dieharder.php">
- * "dieharder"</a> test suite is such a software.</p>
- *
- * <p>Example of command line, assuming that "examples-stress.jar" specifies this
- * class as the "main" class (see {@link #main(String[]) main} method):
- * <pre>{@code $ java -jar examples-stress.jar stress /usr/bin/dieharder -a -g 200 -Y 1 -k 2}</pre>
- * </p>
- *
- * <p>Other functionality includes:</p>
+ * Specification for the top-level command in the examples stress application.
  *
- * <ul>
- *   <li>Listing all the generators
- *   <li>...
- * </ul>
+ * <p>This command is will print the top-level help message.</p>
  */
 @Command(name = "examples-stress",
          description = "Apache Commons RNG Examples Stress Utilities.")
@@ -61,50 +39,6 @@ class ExamplesStressCommand implements Callable<Void> {
     @Mixin
     private StandardOptions reusableOptions;
 
-    /**
-     * Run the RNG Utilities command line application.
-     *
-     * @param args Application's arguments.
-     */
-    public static void main(String[] args) {
-        // Build the command line manually so we can configure options.
-        final CommandLine cmd = new CommandLine(new ExamplesStressCommand())
-                .addSubcommand("bridge",  new CommandLine(new BridgeTestCommand())
-                                                          .setStopAtPositional(true))
-                .addSubcommand("endian",  new EndianessCommand())
-                .addSubcommand("list",    new ListCommand())
-                .addSubcommand("output",  new CommandLine(new OutputCommand())
-                                                          // Allow the input seed using hex (0x, 0X, #)
-                                                          // or octal (starting with 0)
-                                                          .registerConverter(Long.class, Long::decode))
-                .addSubcommand("results", new ResultsCommand())
-                .addSubcommand("stress",  new CommandLine(new StressTestCommand())
-                                                          .setStopAtPositional(true))
-                // Call last to apply to all sub-commands
-                .setCaseInsensitiveEnumValuesAllowed(true);
-
-        try {
-            // Parse the command line and invokes the Callable program (RNGUtilities)
-            cmd.parseWithHandler(new RunLast(), args);
-        } catch (final picocli.CommandLine.ExecutionException ex) {
-            final Throwable cause = ex.getCause();
-            if (cause != null) {
-                // If this was an exception generated by the application then the full
-                // stack trace is not needed depending on log level. This limits stack
-                // trace output to unexpected errors in the common use case.
-                if (cause instanceof ApplicationException &&
-                        !LogUtils.isLoggable(LogUtils.LogLevel.DEBUG)) {
-                    LogUtils.error(cause.getMessage());
-                } else {
-                    LogUtils.error(cause, cause.getMessage());
-                }
-                System.exit(1);
-            }
-            // No cause so re-throw. This may be a Picocli parsing error.
-            throw ex;
-        }
-    }
-
     @Override
     public Void call() {
         // All work is done in sub-commands so just print the usage