/*
 * Copyright 2016 Palantir Technologies, Inc. All rights reserved.
 *
 * THIS SOFTWARE CONTAINS PROPRIETARY AND CONFIDENTIAL INFORMATION OWNED BY PALANTIR TECHNOLOGIES INC.
 * UNAUTHORIZED DISCLOSURE TO ANY THIRD PARTY IS STRICTLY PROHIBITED
 *
 * For good and valuable consideration, the receipt and adequacy of which is acknowledged by Palantir and recipient
 * of this file ("Recipient"), the parties agree as follows:
 *
 * This file is being provided subject to the non-disclosure terms by and between Palantir and the Recipient.
 *
 * Palantir solely shall own and hereby retains all rights, title and interest in and to this software (including,
 * without limitation, all patent, copyright, trademark, trade secret and other intellectual property rights) and
 * all copies, modifications and derivative works thereof.  Recipient shall and hereby does irrevocably transfer and
 * assign to Palantir all right, title and interest it may have in the foregoing to Palantir and Palantir hereby
 * accepts such transfer. In using this software, Recipient acknowledges that no ownership rights are being conveyed
 * to Recipient.  This software shall only be used in conjunction with properly licensed Palantir products or
 * services.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.palantir.docker.compose.configuration;

import java.io.File;
import java.util.Collection;
import java.util.List;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;

public class DockerComposeFiles {

    private final List<File> dockerComposeFiles;

    public DockerComposeFiles(List<File> dockerComposeFiles) {
        this.dockerComposeFiles = dockerComposeFiles;
    }

    public static DockerComposeFiles from(String... dockerComposeFilenames) {
        List<File> dockerComposeFiles = newArrayList(dockerComposeFilenames).stream()
                .map(File::new)
                .collect(toList());
        validateComposeFilesExist(dockerComposeFiles);
        return new DockerComposeFiles(dockerComposeFiles);
    }

    public List<String> constructComposeFileCommand() {
        return dockerComposeFiles.stream()
                .map(File::getAbsolutePath)
                .map(f -> newArrayList("-f", f))
                .flatMap(Collection::stream)
                .collect(toList());
    }

    private static void validateComposeFilesExist(List<File> dockerComposeFiles) {
        List<File> missingFiles = dockerComposeFiles.stream()
                                                    .filter(f -> !f.exists())
                                                    .collect(toList());

        String errorMessage = missingFiles.stream()
                .map(File::getAbsolutePath)
                .collect(joining(", ", "The following docker-compose files: ", " do not exist."));
        checkState(missingFiles.isEmpty(), errorMessage);
    }

}

@@ -2142,16 +2142,82 @@
 .List;%0A%0A
+import static com.google.common.base.Preconditions.checkArgument;%0A
 import s
@@ -2271,16 +2271,16 @@
 kState;%0A
-
 import s
@@ -2870,24 +2870,92 @@
 (toList());%0A
+        validateAtLeastOneComposeFileSpecified(dockerComposeFiles);%0A
         vali
@@ -3300,16 +3300,16 @@
 stream)%0A
-
         
@@ -3339,24 +3339,225 @@
 ());%0A    %7D%0A%0A
+    private static void validateAtLeastOneComposeFileSpecified(List%3CFile%3E dockerComposeFiles) %7B%0A        checkArgument(!dockerComposeFiles.isEmpty(), %22A docker compose file must be specified.%22);%0A    %7D%0A%0A
     private 

Fix failing test for no docker compose file specified.