< prev index next >

test/lib/testlibrary/jdk/testlibrary/ProcessTools.java

Print this page




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.testlibrary;
  25 

  26 import java.io.IOException;
  27 import java.io.InputStream;
  28 import java.io.OutputStream;
  29 import java.io.PrintStream;

  30 import java.util.ArrayList;
  31 import java.util.Arrays;
  32 import java.util.Collections;
  33 import java.util.concurrent.CountDownLatch;

  34 import java.util.Map;
  35 import java.util.concurrent.ExecutionException;
  36 import java.util.concurrent.Future;
  37 import java.util.concurrent.TimeUnit;
  38 import java.util.concurrent.TimeoutException;
  39 import java.util.function.Predicate;
  40 import java.util.function.Consumer;
  41 import java.util.stream.Collectors;
  42 
  43 
  44 /**
  45  * @deprecated This class is deprecated. Use the one from
  46  *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
  47  */
  48 @Deprecated
  49 public final class ProcessTools {
  50     private static final class LineForwarder extends StreamPumper.LinePump {
  51         private final PrintStream ps;
  52         private final String prefix;
  53         LineForwarder(String prefix, PrintStream os) {


 322         // Reporting
 323         StringBuilder cmdLine = new StringBuilder();
 324         for (String cmd : args)
 325             cmdLine.append(cmd).append(' ');
 326         System.out.println("Command line: [" + cmdLine.toString() + "]");
 327 
 328         return new ProcessBuilder(args.toArray(new String[args.size()]));
 329     }
 330 
 331     private static void printStack(Thread t, StackTraceElement[] stack) {
 332         System.out.println("\t" +  t +
 333                            " stack: (length = " + stack.length + ")");
 334         if (t != null) {
 335             for (StackTraceElement stack1 : stack) {
 336                 System.out.println("\t" + stack1);
 337             }
 338             System.out.println();
 339         }
 340     }
 341 
































 342     /**
 343      * Executes a test java process, waits for it to finish and returns the process output.
 344      * The default options from jtreg, test.vm.opts and test.java.opts, are added.
 345      * The java from the test.jdk is used to execute the command.
 346      *
 347      * The command line will be like:
 348      * {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
 349      *
 350      * The java process will have exited before this method returns.
 351      *
 352      * @param cmds User specifed arguments.
 353      * @return The output from the process.
 354      */
 355     public static OutputAnalyzer executeTestJava(String... options) throws Exception {
 356         ProcessBuilder pb = createJavaProcessBuilder(Utils.addTestJavaOpts(options));
 357         return executeProcess(pb);
 358     }
 359 
 360     /**
 361      * @deprecated Use executeTestJava instead




   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package jdk.testlibrary;
  25 
  26 import java.io.File;
  27 import java.io.IOException;
  28 import java.io.InputStream;
  29 import java.io.OutputStream;
  30 import java.io.PrintStream;
  31 import java.nio.file.Path;
  32 import java.util.ArrayList;
  33 import java.util.Arrays;
  34 import java.util.Collections;
  35 import java.util.concurrent.CountDownLatch;
  36 import java.util.List;
  37 import java.util.Map;
  38 import java.util.concurrent.ExecutionException;
  39 import java.util.concurrent.Future;
  40 import java.util.concurrent.TimeUnit;
  41 import java.util.concurrent.TimeoutException;
  42 import java.util.function.Predicate;
  43 import java.util.function.Consumer;
  44 import java.util.stream.Collectors;
  45 
  46 
  47 /**
  48  * @deprecated This class is deprecated. Use the one from
  49  *             {@code <root>/test/lib/share/classes/jdk/test/lib/process}
  50  */
  51 @Deprecated
  52 public final class ProcessTools {
  53     private static final class LineForwarder extends StreamPumper.LinePump {
  54         private final PrintStream ps;
  55         private final String prefix;
  56         LineForwarder(String prefix, PrintStream os) {


 325         // Reporting
 326         StringBuilder cmdLine = new StringBuilder();
 327         for (String cmd : args)
 328             cmdLine.append(cmd).append(' ');
 329         System.out.println("Command line: [" + cmdLine.toString() + "]");
 330 
 331         return new ProcessBuilder(args.toArray(new String[args.size()]));
 332     }
 333 
 334     private static void printStack(Thread t, StackTraceElement[] stack) {
 335         System.out.println("\t" +  t +
 336                            " stack: (length = " + stack.length + ")");
 337         if (t != null) {
 338             for (StackTraceElement stack1 : stack) {
 339                 System.out.println("\t" + stack1);
 340             }
 341             System.out.println();
 342         }
 343     }
 344 
 345     public static OutputAnalyzer executeModularTest(String module, String mainClass,
 346         List<String> otherOptions,
 347         List<Path> classPath, List<Path> modulePath, List<String> addMods,
 348         String... arguments) throws Exception {
 349         List<String> args = new ArrayList<>();
 350         if (otherOptions != null && otherOptions.size() > 0) {
 351             args.addAll(otherOptions);
 352         }
 353         args.add("-mp");
 354         args.add(modulePath.stream()
 355             .map(Path::toString)
 356             .collect(Collectors.joining(File.pathSeparator)));
 357         if (classPath != null && classPath.size() > 0) {
 358             args.add("-cp");
 359             args.add(classPath.stream()
 360                 .map(Path::toString)
 361                 .collect(Collectors.joining(File.pathSeparator)));
 362         }
 363         if (addMods != null && addMods.size() > 0) {
 364             args.add("-addmods");
 365             args.add(String.join(",", addMods));
 366         }
 367         if (module != null) {
 368             args.add("-m"); args.add(module + ((mainClass != null) ? "/"+ mainClass : ""));
 369         } else {
 370             args.add(mainClass);
 371         }
 372         args.addAll(Arrays.asList(arguments));
 373         ProcessBuilder pb = createJavaProcessBuilder(args.toArray(new String[0]));
 374         return executeProcess(pb);
 375     }
 376 
 377     /**
 378      * Executes a test java process, waits for it to finish and returns the process output.
 379      * The default options from jtreg, test.vm.opts and test.java.opts, are added.
 380      * The java from the test.jdk is used to execute the command.
 381      *
 382      * The command line will be like:
 383      * {test.jdk}/bin/java {test.vm.opts} {test.java.opts} cmds
 384      *
 385      * The java process will have exited before this method returns.
 386      *
 387      * @param cmds User specifed arguments.
 388      * @return The output from the process.
 389      */
 390     public static OutputAnalyzer executeTestJava(String... options) throws Exception {
 391         ProcessBuilder pb = createJavaProcessBuilder(Utils.addTestJavaOpts(options));
 392         return executeProcess(pb);
 393     }
 394 
 395     /**
 396      * @deprecated Use executeTestJava instead


< prev index next >