/*
 * Copyright 2018 Google LLC. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.cloud.tools.jib.http;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;

/** Simple local web server for testing. */
class TestWebServer implements Closeable {

  private final ServerSocket serverSocket;
  private final ExecutorService executorService = Executors.newSingleThreadExecutor();
  private final Semaphore threadStarted = new Semaphore(0);

  TestWebServer() throws IOException, InterruptedException {
    serverSocket = new ServerSocket(0);
    executorService.submit(this::serve200);
    threadStarted.acquire();
  }

  String getEndpoint() {
    String host = serverSocket.getInetAddress().getHostAddress();
    return "http://" + host + ":" + serverSocket.getLocalPort();
  }

  @Override
  public void close() throws IOException {
    serverSocket.close();
    executorService.shutdown();
  }

  private Void serve200() throws IOException {
    threadStarted.release();
    try (Socket socket = serverSocket.accept()) {
      String response = "HTTP/1.1 200 OK\nContent-Length:12\n\nHello World!";
      socket.getOutputStream().write(response.getBytes(StandardCharsets.UTF_8));
      socket.getOutputStream().flush();

      InputStream in = socket.getInputStream();
      for (int ch = in.read(); ch != -1; ch = in.read()) ;
    }
    return null;
  }
}

@@ -915,16 +915,52 @@
 cutors;%0A
+import java.util.concurrent.Future;%0A
 import j
@@ -1371,24 +1371,37 @@
 ket(0);%0A    
+ignoreReturn(
 executorServ
@@ -1426,16 +1426,17 @@
 erve200)
+)
 ;%0A    th
@@ -2201,11 +2201,112 @@
 ull;%0A  %7D
+%0A%0A  private void ignoreReturn(Future%3CVoid%3E future) %7B%0A    // do nothing; to make Error Prone happy%0A  %7D
 %0A%7D%0A

Make Error Prone happy (#707)