/*
 * ForgeGradle
 * Copyright (C) 2018 Forge Development LLC
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package net.minecraftforge.gradle.common.tasks;

import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.MapProperty;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;

import com.google.common.collect.ImmutableMap;
import java.io.File;
import java.util.List;

public abstract class DynamicJarExec extends JarExec {
    public DynamicJarExec() {
        getOutput().convention(getProject().getLayout().getBuildDirectory().dir(getName()).map(d -> d.file("output.jar")));
    }

    @Override
    protected List<String> filterArgs(List<String> args) {
        ImmutableMap.Builder<String, Object> replace = ImmutableMap.builder();
        replace.put("{input}", getInput().get().getAsFile());
        replace.put("{output}", getOutput().get().getAsFile());
        getData().get().forEach((key, value) -> replace.put('{' + key + '}', value.getAbsolutePath()));

        return replaceArgs(args, replace.build(), null);
    }

    @InputFiles
    @Optional
    public abstract MapProperty<String, File> getData();

    @InputFile
    public abstract RegularFileProperty getInput();

    @OutputFile
    public abstract RegularFileProperty getOutput();
}

@@ -1016,24 +1016,58 @@
 tasks.In
-putFiles
+ternal;%0Aimport org.gradle.api.tasks.Nested
 ;%0Aimport
@@ -1203,24 +1203,50 @@
 va.io.File;%0A
+import java.util.HashMap;%0A
 import java.
@@ -1462,24 +1462,277 @@
 ut.jar%22)));%0A
+        // Dumb gradle...%0A        getDataGradle().putAll(getData().map(m -%3E %7B%0A            HashMap%3CString, FileWrapper%3E newMap = new HashMap%3C%3E();%0A            m.forEach((k, v) -%3E newMap.put(k, new FileWrapper(v)));%0A            return newMap;%0A        %7D));%0A
     %7D%0A%0A    @
@@ -2184,27 +2184,11 @@
  @In
-putFiles%0A    @Optio
+ter
 nal%0A
@@ -2253,139 +2253,650 @@
     
-@InputFile%0A    public abstract RegularFileProperty getInput();%0A%0A    @OutputFile%0A    public abstract RegularFileProperty getOutput();
+/**%0A     * @deprecated necessary until %3Ca href=%22https://github.com/gradle/gradle/issues/8646%22%3EGradle issue #8646%3C/a%3E is fixed%0A     */%0A    @Deprecated%0A    @Nested%0A    @Optional%0A    protected abstract MapProperty%3CString, FileWrapper%3E getDataGradle();%0A%0A    @InputFile%0A    public abstract RegularFileProperty getInput();%0A%0A    @OutputFile%0A    public abstract RegularFileProperty getOutput();%0A%0A    protected static class FileWrapper %7B%0A        private final File file;%0A%0A        protected FileWrapper(File file) %7B%0A            this.file = file;%0A        %7D%0A%0A        @InputFile%0A        public File getFile() %7B%0A            return this.file;%0A        %7D%0A    %7D
 %0A%7D%0A

Fix DynamicJarExec task