@@ -134,13 +134,8 @@ private static Path installedGcdPath() {
134134 }
135135
136136 private static String installedGcdVersion () throws IOException , InterruptedException {
137- CommandWrapper gcloudCommand ;
138- if (isWindows ()) {
139- gcloudCommand = CommandWrapper .cmd ();
140- } else {
141- gcloudCommand = CommandWrapper .bash ();
142- }
143- Process process = gcloudCommand .command ("gcloud" , "version" ).redirectErrorStream ().start ();
137+ Process process =
138+ CommandWrapper .create ().command ("gcloud" , "version" ).redirectErrorStream ().start ();
144139 process .waitFor ();
145140 try (BufferedReader reader =
146141 new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
@@ -225,6 +220,14 @@ private static class CommandWrapper {
225220
226221 private CommandWrapper () {
227222 this .prefix = new ArrayList <>();
223+ if (isWindows ()) {
224+ this .prefix .add ("cmd" );
225+ this .prefix .add ("/C" );
226+ this .nullFilename = "NUL:" ;
227+ } else {
228+ this .prefix .add ("bash" );
229+ this .nullFilename = "/dev/null" ;
230+ }
228231 }
229232
230233 public CommandWrapper command (String ... command ) {
@@ -275,19 +278,8 @@ public Process start() throws IOException {
275278 return builder ().start ();
276279 }
277280
278- public static CommandWrapper cmd () {
279- CommandWrapper wrapper = new CommandWrapper ();
280- wrapper .prefix .add ("cmd" );
281- wrapper .prefix .add ("/C" );
282- wrapper .nullFilename = "NUL:" ;
283- return wrapper ;
284- }
285-
286- public static CommandWrapper bash () {
287- CommandWrapper wrapper = new CommandWrapper ();
288- wrapper .prefix .add ("bash" );
289- wrapper .nullFilename = "/dev/null" ;
290- return wrapper ;
281+ public static CommandWrapper create () {
282+ return new CommandWrapper ();
291283 }
292284 }
293285
@@ -362,17 +354,11 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
362354 File datasetFolder = new File (gcdPath .toFile (), projectId );
363355 deleteRecurse (datasetFolder .toPath ());
364356
365- // create command wrappers
366- CommandWrapper gcdCreateCommand ;
367- CommandWrapper gcdStartCommand ;
357+ // Get path to cmd executable
368358 Path gcdAbsolutePath ;
369359 if (isWindows ()) {
370- gcdCreateCommand = CommandWrapper .cmd ();
371- gcdStartCommand = CommandWrapper .cmd ();
372360 gcdAbsolutePath = executablePath .toAbsolutePath ().resolve ("gcd.cmd" );
373361 } else {
374- gcdCreateCommand = CommandWrapper .bash ();
375- gcdStartCommand = CommandWrapper .bash ();
376362 gcdAbsolutePath = executablePath .toAbsolutePath ().resolve ("gcd.sh" );
377363 }
378364
@@ -381,7 +367,8 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
381367 log .log (Level .FINE , "Creating datastore for the project: {0}" , projectId );
382368 }
383369 Process createProcess =
384- gcdCreateCommand .command (gcdAbsolutePath .toString (), "create" , "-p" , projectId , projectId )
370+ CommandWrapper .create ()
371+ .command (gcdAbsolutePath .toString (), "create" , "-p" , projectId , projectId )
385372 .redirectErrorInherit ()
386373 .directory (gcdPath )
387374 .redirectOutputToNull ()
@@ -393,7 +380,7 @@ private void startGcd(Path executablePath) throws IOException, InterruptedExcept
393380 log .log (Level .FINE , "Starting datastore emulator for the project: {0}" , projectId );
394381 }
395382 Process startProcess =
396- gcdStartCommand
383+ CommandWrapper . create ()
397384 .command (gcdAbsolutePath .toString (), "start" , "--testing" , "--allow_remote_shutdown" ,
398385 projectId )
399386 .directory (gcdPath )
0 commit comments