1616
1717package com .google .cloud .tools .jib .registry ;
1818
19+ import com .google .cloud .tools .jib .Command ;
1920import com .google .common .io .CharStreams ;
2021import java .io .IOException ;
2122import java .io .InputStreamReader ;
2223import java .nio .charset .StandardCharsets ;
23- import java .util .Arrays ;
2424import java .util .UUID ;
2525import org .junit .rules .ExternalResource ;
2626import org .junit .rules .TestRule ;
@@ -41,49 +41,43 @@ public LocalRegistry(int port) {
4141 @ Override
4242 protected void before () throws Throwable {
4343 // Runs the Docker registry.
44- runCommand (
45- "docker" ,
46- "run" ,
47- "-d" ,
48- "-p" ,
49- port + ":5000" ,
50- "--restart=always" ,
51- "--name" ,
52- containerName ,
53- "registry:2" );
44+ new Command (
45+ "docker" ,
46+ "run" ,
47+ "-d" ,
48+ "-p" ,
49+ port + ":5000" ,
50+ "--restart=always" ,
51+ "--name" ,
52+ containerName ,
53+ "registry:2" )
54+ .run ();
5455
5556 // Pulls 'busybox'.
56- runCommand ("docker" , "pull" , "busybox" );
57+ new Command ("docker" , "pull" , "busybox" ). run ( );
5758
5859 // Tags 'busybox' to push to our local registry.
59- runCommand ("docker" , "tag" , "busybox" , "localhost:" + port + "/busybox" );
60+ new Command ("docker" , "tag" , "busybox" , "localhost:" + port + "/busybox" ). run ( );
6061
6162 // Pushes 'busybox' to our local registry.
62- runCommand ("docker" , "push" , "localhost:" + port + "/busybox" );
63+ new Command ("docker" , "push" , "localhost:" + port + "/busybox" ). run ( );
6364 }
6465
6566 /** Stops the local registry. */
6667 @ Override
6768 protected void after () {
6869 try {
6970 // Stops the registry.
70- runCommand ("docker" , "stop" , containerName );
71+ new Command ("docker" , "stop" , containerName ). run ( );
7172
7273 // Removes the container.
73- runCommand ("docker" , "rm" , "-v" , containerName );
74+ new Command ("docker" , "rm" , "-v" , containerName ). run ( );
7475
7576 } catch (InterruptedException | IOException ex ) {
7677 throw new RuntimeException ("Could not stop local registry fully: " + containerName , ex );
7778 }
7879 }
7980
80- /** Runs a command with naive tokenization by whitespace. */
81- private void runCommand (String ... command ) throws IOException , InterruptedException {
82- if (new ProcessBuilder (Arrays .asList (command )).start ().waitFor () != 0 ) {
83- throw new IOException ("Command '" + String .join (" " , command ) + "' failed" );
84- }
85- }
86-
8781 private void printLogs () throws IOException , InterruptedException {
8882 Process process = Runtime .getRuntime ().exec ("docker logs " + containerName );
8983 try (InputStreamReader inputStreamReader =
0 commit comments