@@ -115,12 +115,15 @@ public static void main(String[] args) {
115115 exit (2 );
116116 }
117117 }
118+
119+ // TODO also try neighboring files, currently only pwd
118120
119121 boolean noTimeout = (boolean ) parser .getOptionValue (noTimeoutOption , false );
120122 for (int i = 0 ; i < 2 ; i ++) {
121123 players [i ].canTimeout = !(noTimeout || (boolean ) parser .getOptionValue (noTimeoutOptions [i ], false ));
122124 players [i ].name = (String ) parser .getOptionValue (nameOptions [i ], "player" + (i + 1 ));
123- players [i ].executable = new File ((String ) parser .getOptionValue (execOptions [i ], "defaultplayer.jar" ));
125+ String playerFile = (String ) parser .getOptionValue (execOptions [i ], null );
126+ players [i ].executable = playerFile == null ? findInClasspath (new File ("defaultplayer.jar" )) : new File (playerFile );
124127 players [i ].isJar = Util .isJar (players [i ].executable );
125128 }
126129 if (players [0 ].name .equals (players [1 ].name )) {
@@ -129,21 +132,29 @@ public static void main(String[] args) {
129132 players [1 ].name = players [1 ].name + "-2" ;
130133 }
131134 logger .info ("Players: " + Arrays .toString (players ));
132-
135+
136+ File stdout = new File (logDir , "server_port" + port + ".log" );
137+ File stderr = new File (logDir , "server_port" + port + "-err.log" );
133138 try {
134139 if (startServer ) {
135- File serverLocation = findInClasspath ((File ) parser .getOptionValue (serverLocationOption , new File ("server.jar" )));
140+ String serverFile = (String ) parser .getOptionValue (serverLocationOption , null );
141+ File serverLocation = serverFile == null ? findInClasspath (new File ("server.jar" )) : new File (serverFile );
136142 logger .info ("Starting server from {}" , serverLocation );
137- ProcessBuilder builder = new ProcessBuilder ("java" , "-classpath" , classpath , "-Dfile.encoding=UTF-8" , "-jar" , serverLocation .getPath (), "--port" , String .valueOf (port ));
143+ ProcessBuilder builder = new ProcessBuilder ("java" , "-classpath" , classpath , "-Dfile.encoding=UTF-8" , "-jar" , serverLocation .getName (), "--port" , String .valueOf (port ));
138144 logDir .mkdirs ();
139- File stdout = new File ( logDir , "server_port" + port + ".log" );
145+ builder . directory ( serverLocation . getParentFile () );
140146 builder .redirectOutput (stdout );
141- builder .redirectError (new File ( logDir , "server_port" + port + "-err.log" ) );
147+ builder .redirectError (stderr );
142148 Process server = builder .start ();
143149 Runtime .getRuntime ().addShutdownHook (new Thread (server ::destroyForcibly ));
144150 int i = 0 ;
145- while (Files .size (stdout .toPath ()) < 1000 && i ++ < 50 )
151+ while (server . isAlive () && Files .size (stdout .toPath ()) < 1000 && i ++ < 50 )
146152 Thread .sleep (300 );
153+ if (!server .isAlive ()) {
154+ System .out .println ("Server stderr:" );
155+ System .out .print (new String (Files .readAllBytes (stderr .toPath ())));
156+ throw new IOException ("Server did not start: Exit Code " + server .exitValue ());
157+ }
147158 Thread .sleep (300 );
148159 }
149160 testclient = new TestClient (host , port , numberOfTests );
0 commit comments