test/jdk/sun/tools/jcmd/TestProcessHelper.java
changeset 54460 6733a9176cce
parent 53707 67537bbafd7f
child 55386 2f4e214781a1
child 58678 9cf78a70fa4f
equal deleted inserted replaced
54459:e5713cefcf41 54460:6733a9176cce
   106                     }
   106                     }
   107                     cmd.add(TEST_PROCESS_MAIN_CLASS);
   107                     cmd.add(TEST_PROCESS_MAIN_CLASS);
   108                     for (String a : arg) {
   108                     for (String a : arg) {
   109                         cmd.add(a);
   109                         cmd.add(a);
   110                     }
   110                     }
   111                     testProcessHelper(cmd);
   111                     testProcessHelper(cmd, TEST_PROCESS_MAIN_CLASS);
   112                 }
   112                 }
   113             }
   113             }
   114         }
   114         }
   115     }
   115     }
   116 
   116 
   128                 cmd.add(JAR_OPTION);
   128                 cmd.add(JAR_OPTION);
   129                 cmd.add(jarFile.getAbsolutePath());
   129                 cmd.add(jarFile.getAbsolutePath());
   130                 for (String a : arg) {
   130                 for (String a : arg) {
   131                     cmd.add(a);
   131                     cmd.add(a);
   132                 }
   132                 }
   133                 testProcessHelper(cmd);
   133                 testProcessHelper(cmd, jarFile.getAbsolutePath());
   134             }
   134             }
   135         }
   135         }
   136 
   136 
   137     }
   137     }
   138 
   138 
   154                         cmd.add(m);
   154                         cmd.add(m);
   155                         cmd.add(MODULE_NAME + "/" + TEST_PROCESS_MAIN_CLASS);
   155                         cmd.add(MODULE_NAME + "/" + TEST_PROCESS_MAIN_CLASS);
   156                         for (String a : arg) {
   156                         for (String a : arg) {
   157                             cmd.add(a);
   157                             cmd.add(a);
   158                         }
   158                         }
   159                         testProcessHelper(cmd);
   159                         testProcessHelper(cmd, MODULE_NAME + "/" + TEST_PROCESS_MAIN_CLASS);
   160                     }
   160                     }
   161                 }
   161                 }
   162             }
   162             }
   163         }
   163         }
   164     }
   164     }
   169         if (!expectedMainClass.equals(mainClass)) {
   169         if (!expectedMainClass.equals(mainClass)) {
   170             throw new RuntimeException("Main class is wrong: " + mainClass);
   170             throw new RuntimeException("Main class is wrong: " + mainClass);
   171         }
   171         }
   172     }
   172     }
   173 
   173 
   174     private void testProcessHelper(List<String> args) throws Exception {
   174     private void testProcessHelper(List<String> args, String expectedValue) throws Exception {
   175         ProcessBuilder pb = new ProcessBuilder(args);
   175         ProcessBuilder pb = new ProcessBuilder(args);
   176         String cmd = pb.command().stream().collect(Collectors.joining(" "));
   176         String cmd = pb.command().stream().collect(Collectors.joining(" "));
   177         System.out.println("Starting the process:" + cmd);
   177         System.out.println("Starting the process:" + cmd);
   178         Process p = ProcessTools.startProcess("test", pb);
   178         Process p = ProcessTools.startProcess("test", pb);
   179         if (!p.isAlive()) {
   179         if (!p.isAlive()) {
   180             throw new RuntimeException("Cannot start the process: " + cmd);
   180             throw new RuntimeException("Cannot start the process: " + cmd);
   181         }
   181         }
   182         checkMainClass(p, TEST_PROCESS_MAIN_CLASS);
   182         checkMainClass(p, expectedValue);
   183     }
   183     }
   184 
   184 
   185     private File prepareJar() throws Exception {
   185     private File prepareJar() throws Exception {
   186         Path jarFile = USER_DIR.resolve("testprocess.jar");
   186         Path jarFile = USER_DIR.resolve("testprocess.jar");
   187         Manifest manifest = createManifest();
   187         Manifest manifest = createManifest();