/*
 * Copyright 2015 the original author or authors.
 *
 * 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 org.gradle.api.internal.changedetection.state;

import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.internal.cache.StringInterner;
import org.gradle.api.internal.file.DefaultFileVisitDetails;
import org.gradle.api.internal.file.FileResolver;
import org.gradle.cache.CacheAccess;
import org.gradle.internal.nativeplatform.filesystem.FileSystem;
import org.gradle.internal.serialize.SerializerRegistry;

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

/**
 * A minimal file set snapshotter is different from the default file collection snapshotter in that it creates a snapshot for every file
 * in the input FileCollection without visiting the files on disk.  This allows files that do not exist yet to be considered part of the
 * FileCollectionSnapshot without that information being lost.
 */
public class MinimalFileSetSnapshotter extends AbstractFileCollectionSnapshotter {
    private final FileSystem fileSystem;

    public MinimalFileSetSnapshotter(FileSnapshotter snapshotter, CacheAccess cacheAccess, StringInterner stringInterner, FileResolver fileResolver, FileSystem fileSystem) {
        super(snapshotter, cacheAccess, stringInterner, fileResolver);
        this.fileSystem = fileSystem;
    }

    @Override
    protected void visitFiles(FileCollection input, List<FileTreeElement> fileTreeElements, List<FileTreeElement> missingFiles) {
        for (File file : input.getFiles()) {
            if (file.exists()) {
                fileTreeElements.add(new DefaultFileVisitDetails(file, fileSystem, fileSystem));
            } else {
                missingFiles.add(new DefaultFileVisitDetails(file, fileSystem, fileSystem));
            }
        }
    }

    @Override
    public void registerSerializers(SerializerRegistry registry) {

    }
}

@@ -666,16 +666,60 @@
 state;%0A%0A
+import org.gradle.api.UncheckedIOException;%0A
 import o
@@ -797,16 +797,102 @@
 lement;%0A
+import org.gradle.api.file.FileVisitDetails;%0Aimport org.gradle.api.file.RelativePath;%0A
 import o
@@ -1228,16 +1228,111 @@
 o.File;%0A
+import java.io.FileNotFoundException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0A
 import j
@@ -2476,39 +2476,39 @@
 ngFiles.add(new 
-Default
+Missing
 FileVisitDetails
@@ -2516,32 +2516,8 @@
 file
-, fileSystem, fileSystem
 ));%0A
@@ -2628,16 +2628,1683 @@
 stry) %7B%0A
+    %7D%0A%0A    private static class MissingFileVisitDetails implements FileVisitDetails %7B%0A        private final File file;%0A        private final RelativePath relativePath;%0A%0A        public MissingFileVisitDetails(File file) %7B%0A            this.file = file;%0A            this.relativePath = new RelativePath(true, file.getName());%0A        %7D%0A%0A        @Override%0A        public File getFile() %7B%0A            return file;%0A        %7D%0A%0A        @Override%0A        public boolean isDirectory() %7B%0A            return false;%0A        %7D%0A%0A        @Override%0A        public String getName() %7B%0A            return file.getName();%0A        %7D%0A%0A        @Override%0A        public String getPath() %7B%0A            return file.getName();%0A        %7D%0A%0A        @Override%0A        public RelativePath getRelativePath() %7B%0A            return relativePath;%0A        %7D%0A%0A        @Override%0A        public int getMode() %7B%0A            return 0;%0A        %7D%0A%0A        @Override%0A        public long getLastModified() %7B%0A            return 0L;%0A        %7D%0A%0A        @Override%0A        public long getSize() %7B%0A            return 0L;%0A        %7D%0A%0A        @Override%0A        public InputStream open() %7B%0A            throw new UncheckedIOException(new FileNotFoundException(file.getAbsolutePath()));%0A        %7D%0A%0A        @Override%0A        public void copyTo(OutputStream output) %7B%0A            throw new UncheckedIOException(new FileNotFoundException(file.getAbsolutePath()));%0A        %7D%0A%0A        @Override%0A        public boolean copyTo(File target) %7B%0A            throw new UncheckedIOException(new FileNotFoundException(file.getAbsolutePath()));%0A        %7D%0A%0A        @Override%0A        public void stopVisiting() %7B%0A            // Ignore%0A        %7D
 %0A    %7D%0A%7D

Create special details for missing files