package ru.yandex.qatools.allure.data;

import org.apache.commons.io.FileUtils;
import ru.yandex.qatools.allure.data.providers.*;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static ru.yandex.qatools.allure.config.AllureNamingUtils.listAttachmentFiles;


/**
 * @author Dmitry Baev charlie@yandex-team.ru
 *         Date: 31.10.13
 */
public class AllureReportGenerator {

    private List<DataProvider> dataProviders = new ArrayList<>();

    protected File[] inputDirectories;

    public AllureReportGenerator(File... inputDirectories) {
        this.inputDirectories = inputDirectories;
        registerDataProviders(defaultProviders());
    }

    public void generate(File outputDirectory) {
        copyAttachments(inputDirectories, outputDirectory);

        String testRun = new TestSuiteFiles(inputDirectories).generateTestRun();

        for (DataProvider provider : dataProviders) {
            provider.provide(testRun, outputDirectory);
        }

    }

    public void registerDataProviders(DataProvider... ts) {
        Collections.addAll(dataProviders, ts);
    }

    public static DataProvider[] defaultProviders() {
        return new DataProvider[]{
                new XUnitDataProvider(),
                new GraphDataProvider(),
                new TestCasesDataProvider(),
                new BehaviorDataProvider()
        };
    }

    public static void copyAttachments(File[] dirs, File outputDirectory) {
        for (File attach : listAttachmentFiles(dirs)) {
            try {
                copyAttachment(attach, new File(outputDirectory, attach.getName()));
            } catch (IOException e) {
                throw new ReportGenerationException(e);
            }
        }
    }

    public static void copyAttachment(File srcFile, File destFile) throws IOException {
        if (!srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
            FileUtils.copyFile(srcFile, destFile);
        }
    }
}

@@ -168,44 +168,11 @@
 rray
-List;%0Aimport java.util.Collection
 s;%0A
+
 impo
@@ -446,25 +446,41 @@
 rs =
- new
  Array
-List%3C%3E(
+s.asList(defaultProviders()
 );%0A%0A
@@ -634,59 +634,8 @@
 es;%0A
-        registerDataProviders(defaultProviders());%0A
     
@@ -961,122 +961,8 @@
  %7D%0A%0A
-    public void registerDataProviders(DataProvider... ts) %7B%0A        Collections.addAll(dataProviders, ts);%0A    %7D%0A%0A
     

remove overrided method from constructor