package fi.evident.apina.gradle.tasks;

import fi.evident.apina.ApinaProcessor;
import fi.evident.apina.java.reader.Classpath;
import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;

import static java.util.Objects.requireNonNull;
import static org.gradle.util.GFileUtils.writeFile;

public class ApinaTask extends DefaultTask {

    private File target;

    private FileCollection classpath;

    private static final Logger log = LoggerFactory.getLogger(ApinaTask.class);

    public static final String GENERATE_API_CLIENT_TASK_NAME = "apina";

    @TaskAction
    public void generateTypeScript() throws IOException {
        requireNonNull(classpath, "classpath not initialized");
        requireNonNull(target, "target not initialized");

        Classpath myClasspath = new Classpath();
        for (File file : classpath)
            myClasspath.addRoot(file.toPath());

        ApinaProcessor processor = new ApinaProcessor(myClasspath);
        String output = processor.process();

        writeFile(output, target, "UTF-8");
    }

    @InputFiles
    public FileCollection getClasspath() {
        return classpath;
    }

    public void setClasspath(FileCollection classpath) {
        this.classpath = classpath;
    }

    @OutputFile
    public File getTarget() {
        return target;
    }

    public void setTarget(File target) {
        this.target = target;
    }
}

@@ -194,24 +194,59 @@
 Collection;%0A
+import org.gradle.api.tasks.Input;%0A
 import org.g
@@ -368,52 +368,42 @@
 org.
-slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
+intellij.lang.annotations.Language
 ;%0A%0Ai
@@ -449,16 +449,67 @@
 ception;
+%0Aimport java.util.ArrayList;%0Aimport java.util.List;
 %0A%0Aimport
@@ -730,73 +730,55 @@
 ate 
-static final Logger log = LoggerFactory.getLogger(ApinaTask.class
+List%3CString%3E blackBoxClasses = new ArrayList%3C%3E(
 );%0A%0A
@@ -1249,16 +1249,153 @@
 spath);%0A
+%0A        for (@Language(%22RegExp%22) String pattern : blackBoxClasses)%0A            processor.settings.blackBoxClasses.addPattern(pattern);%0A%0A
         
@@ -1827,11 +1827,240 @@
 t;%0A    %7D
+%0A%0A    @Input%0A    public List%3CString%3E getBlackBoxClasses() %7B%0A        return blackBoxClasses;%0A    %7D%0A%0A    public void setBlackBoxClasses(List%3CString%3E blackBoxTypePatterns) %7B%0A        this.blackBoxClasses = blackBoxTypePatterns;%0A    %7D
 %0A%7D%0A

Support specifying black box classes to ApinaTask