Skip to content

Commit f008893

Browse files
committed
Backport d39b7bab27af5ba24ff0925037b8e5fb99680dc0
1 parent 8ea7310 commit f008893

File tree

4 files changed

+70
-119
lines changed

4 files changed

+70
-119
lines changed
Lines changed: 35 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,70 +30,48 @@
3030
* system property.
3131
* @author Luis-Miguel Alventosa
3232
*
33-
* @run clean ImplVersionTest ImplVersionCommand
33+
* @library /test/lib
3434
* @run build ImplVersionTest ImplVersionCommand ImplVersionReader
3535
* @run main ImplVersionTest
3636
*/
3737

38+
import jdk.test.lib.process.ProcessTools;
39+
3840
import java.io.File;
3941

4042
public class ImplVersionTest {
4143

42-
public static void main(String[] args) {
43-
try {
44-
// Get OS name
45-
//
46-
String osName = System.getProperty("os.name");
47-
System.out.println("osName = " + osName);
48-
if ("Windows 98".equals(osName)) {
49-
// Disable this test on Win98 due to parsing
50-
// errors (bad handling of white spaces) when
51-
// J2SE is installed under "Program Files".
52-
//
53-
System.out.println("This test is disabled on Windows 98.");
54-
System.out.println("Bye! Bye!");
55-
return;
56-
}
57-
// Get Java Home
58-
//
59-
String javaHome = System.getProperty("java.home");
60-
System.out.println("javaHome = " + javaHome);
61-
// Get test src
62-
//
63-
String testSrc = System.getProperty("test.src");
64-
System.out.println("testSrc = " + testSrc);
65-
// Get test classes
66-
//
67-
String testClasses = System.getProperty("test.classes");
68-
System.out.println("testClasses = " + testClasses);
69-
// Get boot class path
70-
//
71-
String command =
72-
javaHome + File.separator + "bin" + File.separator + "java " +
73-
" -classpath " + testClasses +
74-
" -Djava.security.manager -Djava.security.policy==" + testSrc +
75-
File.separator + "policy -Dtest.classes=" + testClasses +
76-
" ImplVersionCommand " +
77-
System.getProperty("java.runtime.version");
78-
System.out.println("ImplVersionCommand Exec Command = " +command);
79-
Process proc = Runtime.getRuntime().exec(command);
80-
new ImplVersionReader(proc, proc.getInputStream()).start();
81-
new ImplVersionReader(proc, proc.getErrorStream()).start();
82-
int exitValue = proc.waitFor();
83-
System.out.println("ImplVersionCommand Exit Value = " +
84-
exitValue);
85-
if (exitValue != 0) {
86-
System.out.println("TEST FAILED: Incorrect exit value " +
87-
"from ImplVersionCommand");
88-
System.exit(exitValue);
89-
}
90-
// Test OK!
91-
//
92-
System.out.println("Bye! Bye!");
93-
} catch (Exception e) {
94-
System.out.println("Unexpected exception caught = " + e);
95-
e.printStackTrace();
96-
System.exit(1);
44+
public static void main(String[] args) throws Exception {
45+
// Get test src
46+
//
47+
String testSrc = System.getProperty("test.src");
48+
System.out.println("testSrc = " + testSrc);
49+
// Get test classes
50+
//
51+
String testClasses = System.getProperty("test.classes");
52+
System.out.println("testClasses = " + testClasses);
53+
// Get boot class path
54+
//
55+
String[] command = new String[] {
56+
"-Djava.security.manager",
57+
"-Djava.security.policy==" + testSrc + File.separator + "policy",
58+
"-Dtest.classes=" + testClasses,
59+
"ImplVersionCommand",
60+
System.getProperty("java.runtime.version")
61+
};
62+
63+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(command);
64+
Process proc = pb.start();
65+
new ImplVersionReader(proc, proc.getInputStream()).start();
66+
new ImplVersionReader(proc, proc.getErrorStream()).start();
67+
int exitValue = proc.waitFor();
68+
System.out.println("ImplVersionCommand Exit Value = " + exitValue);
69+
if (exitValue != 0) {
70+
throw new RuntimeException("TEST FAILED: Incorrect exit value " +
71+
"from ImplVersionCommand " + exitValue);
9772
}
73+
// Test OK!
74+
//
75+
System.out.println("Bye! Bye!");
9876
}
9977
}

test/jdk/javax/management/remote/mandatory/connection/DefaultAgentFilterTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,9 @@ private static void testDefaultAgent(String propertyFile) throws Exception {
189189

190190
private static void testDefaultAgent(String propertyFile, int port) throws Exception {
191191
String propFile = System.getProperty("test.src") + File.separator + propertyFile;
192-
List<String> pbArgs = new ArrayList<>(Arrays.asList(
193-
"-cp",
194-
System.getProperty("test.class.path"),
195-
"-XX:+UsePerfData"
196-
));
192+
List<String> pbArgs = new ArrayList<>();
193+
pbArgs.add("-XX:+UsePerfData");
194+
197195
String[] args = new String[]{
198196
"-Dcom.sun.management.jmxremote.port=" + port,
199197
"-Dcom.sun.management.jmxremote.authenticate=false",
@@ -203,7 +201,7 @@ private static void testDefaultAgent(String propertyFile, int port) throws Excep
203201
pbArgs.addAll(Arrays.asList(args));
204202
pbArgs.add(TEST_APP_NAME);
205203

206-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
204+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
207205
pbArgs.toArray(new String[pbArgs.size()])
208206
);
209207

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,69 +30,48 @@
3030
* system property.
3131
* @author Luis-Miguel Alventosa, Joel Feraud
3232
*
33-
* @run clean ImplVersionTest ImplVersionCommand
33+
* @library /test/lib
3434
* @run build ImplVersionTest ImplVersionCommand ImplVersionReader
3535
* @run main ImplVersionTest
3636
*/
3737

38+
import jdk.test.lib.process.ProcessTools;
39+
3840
import java.io.File;
3941

4042
public class ImplVersionTest {
4143

42-
public static void main(String[] args) {
43-
try {
44-
// Get OS name
45-
//
46-
String osName = System.getProperty("os.name");
47-
System.out.println("osName = " + osName);
48-
if ("Windows 98".equals(osName)) {
49-
// Disable this test on Win98 due to parsing
50-
// errors (bad handling of white spaces) when
51-
// J2SE is installed under "Program Files".
52-
//
53-
System.out.println("This test is disabled on Windows 98.");
54-
System.out.println("Bye! Bye!");
55-
return;
56-
}
44+
public static void main(String[] args) throws Exception {
5745

58-
// Get Java Home
59-
String javaHome = System.getProperty("java.home");
46+
// Get test src
47+
//
48+
String testSrc = System.getProperty("test.src");
6049

61-
// Get test src
62-
//
63-
String testSrc = System.getProperty("test.src");
50+
// Get test classes
51+
String testClasses = System.getProperty("test.classes");
6452

65-
// Get test classes
66-
String testClasses = System.getProperty("test.classes");
53+
// Build command string
6754

68-
// Build command string
69-
String command =
70-
javaHome + File.separator + "bin" + File.separator + "java " +
71-
" -classpath " + testClasses +
72-
" -Djava.security.manager -Djava.security.policy==" + testSrc +
73-
File.separator + "policy -Dtest.classes=" + testClasses +
74-
" ImplVersionCommand " + System.getProperty("java.runtime.version");
75-
System.out.println("ImplVersionCommand Exec Command = " + command);
55+
String[] command = new String[] {
56+
"-Djava.security.manager",
57+
"-Djava.security.policy==" + testSrc + File.separator + "policy",
58+
"-Dtest.classes=" + testClasses,
59+
"ImplVersionCommand",
60+
System.getProperty("java.runtime.version")
61+
};
7662

77-
// Exec command
78-
Process proc = Runtime.getRuntime().exec(command);
79-
new ImplVersionReader(proc, proc.getInputStream()).start();
80-
new ImplVersionReader(proc, proc.getErrorStream()).start();
81-
int exitValue = proc.waitFor();
63+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(command);
64+
Process proc = pb.start();
65+
new ImplVersionReader(proc, proc.getInputStream()).start();
66+
new ImplVersionReader(proc, proc.getErrorStream()).start();
67+
int exitValue = proc.waitFor();
8268

83-
System.out.println("ImplVersionCommand Exit Value = " +
84-
exitValue);
85-
if (exitValue != 0) {
86-
System.out.println("TEST FAILED: Incorrect exit value " +
87-
"from ImplVersionCommand");
88-
System.exit(exitValue);
89-
}
90-
// Test OK!
91-
System.out.println("Bye! Bye!");
92-
} catch (Exception e) {
93-
System.out.println("Unexpected exception caught = " + e);
94-
e.printStackTrace();
95-
System.exit(1);
69+
System.out.println("ImplVersionCommand Exit Value = " + exitValue);
70+
if (exitValue != 0) {
71+
throw new RuntimeException("TEST FAILED: Incorrect exit value " +
72+
"from ImplVersionCommand " + exitValue);
9673
}
74+
// Test OK!
75+
System.out.println("Bye! Bye!");
9776
}
9877
}

test/jdk/javax/management/security/HashedPasswordFileTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -468,10 +468,6 @@ public void testDefaultAgentNoHash() throws Exception {
468468
perms.add(PosixFilePermission.OWNER_READ);
469469
perms.add(PosixFilePermission.OWNER_WRITE);
470470
Files.setPosixFilePermissions(file.toPath(), perms);
471-
472-
pbArgs.add("-cp");
473-
pbArgs.add(System.getProperty("test.class.path"));
474-
475471
pbArgs.add("-Dcom.sun.management.jmxremote.port=0");
476472
pbArgs.add("-Dcom.sun.management.jmxremote.authenticate=true");
477473
pbArgs.add("-Dcom.sun.management.jmxremote.password.file=" + file.getAbsolutePath());
@@ -481,7 +477,7 @@ public void testDefaultAgentNoHash() throws Exception {
481477
pbArgs.add("jdk.management.agent/jdk.internal.agent=ALL-UNNAMED");
482478
pbArgs.add(TestApp.class.getSimpleName());
483479

484-
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
480+
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
485481
pbArgs.toArray(new String[0]));
486482
Process process = ProcessTools.startProcess(
487483
TestApp.class.getSimpleName(),

0 commit comments

Comments
 (0)