11/*
2- * Copyright (c) 2017, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2017, 2020 , 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
2121 * questions.
2222 */
2323
24- import jdk .test .lib .Platform ;
25- import jdk .test .lib .Utils ;
26-
2724import java .io .File ;
2825import java .io .IOException ;
2926import java .io .InputStream ;
3027import java .io .OutputStream ;
3128import java .nio .file .Path ;
3229import java .nio .file .Paths ;
30+ import java .util .ArrayList ;
3331import java .util .Arrays ;
32+ import java .util .Collections ;
33+ import java .util .List ;
3434
3535/**
3636 * Starts a new process to execute a command.
4848 * {@code --java}, i.e. 0 or 95 means pass.
4949 */
5050public class ExecDriver {
51+ // copied from jdk.test.lib.Utils.TEST_CLASS_PATH
52+ private static final String TEST_CLASS_PATH = System .getProperty ("test.class.path" , "." );
53+ // copied from jdk.test.lib.Utils.TEST_CLASS_PATH
54+ private static final String TEST_JDK = System .getProperty ("test.jdk" );
5155 public static void main (String [] args ) throws IOException , InterruptedException {
5256 boolean java = false ;
5357 boolean launcher = false ;
@@ -68,7 +72,7 @@ public static void main(String[] args) throws IOException, InterruptedException
6872 }
6973 args [0 ] = javaBin ();
7074 args [1 ] = "-cp" ;
71- args [2 ] = Utils . TEST_CLASS_PATH ;
75+ args [2 ] = TEST_CLASS_PATH ;
7276 System .arraycopy (oldArgs , 1 , args , count , oldArgs .length - 1 );
7377 java = true ;
7478 break ;
@@ -84,7 +88,7 @@ public static void main(String[] args) throws IOException, InterruptedException
8488 // adding 'test.vm.opts' and 'test.java.opts'
8589 if (java ) {
8690 String [] oldArgs = args ;
87- String [] testJavaOpts = Utils . getTestJavaOpts ();
91+ String [] testJavaOpts = getTestJavaOpts ();
8892 if (testJavaOpts .length > 0 ) {
8993 args = new String [args .length + testJavaOpts .length ];
9094 // bin/java goes before options
@@ -101,10 +105,11 @@ public static void main(String[] args) throws IOException, InterruptedException
101105 ProcessBuilder pb = new ProcessBuilder (args );
102106 // adding jvm.so to library path
103107 if (launcher ) {
104- Path dir = Paths .get (Utils . TEST_JDK );
108+ Path dir = Paths .get (TEST_JDK );
105109 String value ;
106- String name = Platform .sharedLibraryPathVariableName ();
107- if (Platform .isWindows ()) {
110+ String name = sharedLibraryPathVariableName ();
111+ // if (jdk.test.lib.Platform.isWindows()) {
112+ if (System .getProperty ("os.name" ).toLowerCase ().startsWith ("win" )) {
108113 value = dir .resolve ("bin" )
109114 .resolve (variant ())
110115 .toAbsolutePath ()
@@ -125,7 +130,7 @@ public static void main(String[] args) throws IOException, InterruptedException
125130 .merge (name , value , (x , y ) -> y + File .pathSeparator + x ));
126131 System .out .println (" with CLASSPATH = " +
127132 pb .environment ()
128- .put ("CLASSPATH" , Utils . TEST_CLASS_PATH ));
133+ .put ("CLASSPATH" , TEST_CLASS_PATH ));
129134 }
130135 Process p = pb .start ();
131136 // inheritIO does not work as expected for @run driver
@@ -138,19 +143,52 @@ public static void main(String[] args) throws IOException, InterruptedException
138143 }
139144 }
140145
146+ // copied from jdk.test.lib.Platform::sharedLibraryPathVariableName
147+ private static String sharedLibraryPathVariableName () {
148+ String osName = System .getProperty ("os.name" ).toLowerCase ();
149+ if (osName .startsWith ("win" )) {
150+ return "PATH" ;
151+ } else if (osName .startsWith ("mac" )) {
152+ return "DYLD_LIBRARY_PATH" ;
153+ } else if (osName .startsWith ("aix" )) {
154+ return "LIBPATH" ;
155+ } else {
156+ return "LD_LIBRARY_PATH" ;
157+ }
158+ }
159+
160+ // copied from jdk.test.lib.Utils::getTestJavaOpts()
161+ private static String [] getTestJavaOpts () {
162+ List <String > opts = new ArrayList <String >();
163+ {
164+ String v = System .getProperty ("test.vm.opts" , "" ).trim ();
165+ if (!v .isEmpty ()) {
166+ Collections .addAll (opts , v .split ("\\ s+" ));
167+ }
168+ }
169+ {
170+ String v = System .getProperty ("test.java.opts" , "" ).trim ();
171+ if (!v .isEmpty ()) {
172+ Collections .addAll (opts , v .split ("\\ s+" ));
173+ }
174+ }
175+ return opts .toArray (new String [0 ]);
176+ }
177+
178+ // copied jdk.test.lib.Platform::variant
141179 private static String variant () {
142- if (Platform .isServer ()) {
180+ String vmName = System .getProperty ("java.vm.name" );
181+ if (vmName .endsWith (" Server VM" )) {
143182 return "server" ;
144- } else if (Platform . isClient ( )) {
183+ } else if (vmName . endsWith ( " Client VM" )) {
145184 return "client" ;
146- } else if (Platform . isMinimal ( )) {
185+ } else if (vmName . endsWith ( " Minimal VM" )) {
147186 return "minimal" ;
148187 } else {
149188 throw new Error ("TESTBUG: unsuppported vm variant" );
150189 }
151190 }
152191
153-
154192 private static void copy (InputStream is , OutputStream os ) {
155193 byte [] buffer = new byte [1024 ];
156194 int n ;
@@ -165,7 +203,7 @@ private static void copy(InputStream is, OutputStream os) {
165203 }
166204
167205 private static String javaBin () {
168- return Paths .get (Utils . TEST_JDK )
206+ return Paths .get (TEST_JDK )
169207 .resolve ("bin" )
170208 .resolve ("java" )
171209 .toAbsolutePath ()
0 commit comments