package ru.yandex.qatools.allure.data.io;

import ru.yandex.qatools.allure.data.AllureReportInfo;
import ru.yandex.qatools.allure.data.AllureTestCase;
import ru.yandex.qatools.allure.data.plugins.PluginData;

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

import static ru.yandex.qatools.allure.data.utils.AllureReportUtils.serialize;

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

    private File outputDirectory;

    private long start;

    private long size = 0;

    public ReportWriter(File outputDirectory) {
        this.outputDirectory = outputDirectory;
        this.start = System.currentTimeMillis();
    }

    public void write(AllureTestCase testCase) {
        size += serialize(outputDirectory, testCase.getUid() + "-testcase.json", testCase);
    }

    public void write(List<PluginData> pluginData) {
        if (pluginData == null) {
            return;
        }
        for (PluginData data : pluginData) {
            write(data);
        }
    }

    public void write(PluginData pluginData) {
        if (pluginData == null) {
            return;
        }
        size += serialize(outputDirectory, pluginData.getName(), pluginData.getData());
    }

    public void write(Object object) {
        //        do nothing
    }

    public void close() {
        long stop = System.currentTimeMillis();
        AllureReportInfo info = new AllureReportInfo();
        info.setTime(stop - start);
        info.setSize(size);
        serialize(outputDirectory, "report.json", info);
    }
}

@@ -36,16 +36,113 @@
 ta.io;%0A%0A
+import org.apache.commons.io.FileUtils;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import r
@@ -241,16 +241,69 @@
 stCase;%0A
+import ru.yandex.qatools.allure.data.AttachmentInfo;%0A
 import r
@@ -373,16 +373,44 @@
 o.File;%0A
+import java.io.IOException;%0A
 import j
@@ -614,16 +614,103 @@
 iter %7B%0A%0A
+    private static final Logger LOGGER = LoggerFactory.getLogger(ReportWriter.class);%0A%0A
     priv
@@ -1491,32 +1491,684 @@
 Data());%0A    %7D%0A%0A
+    public void write(AttachmentInfo attachmentInfo) %7B%0A        if (attachmentInfo == null) %7B%0A            return;%0A        %7D%0A        File from = new File(attachmentInfo.getPath());%0A        File to = new File(outputDirectory, attachmentInfo.getName());%0A        try %7B%0A            if (!from.getCanonicalPath().equals(to.getCanonicalPath())) %7B%0A                FileUtils.copyFile(from, to);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            LOGGER.error(String.format(%22Can't copy attachment %25s from %25s%22,%0A                    attachmentInfo.getName(), attachmentInfo.getPath()));%0A            LOGGER.trace(%22Can't copy attachment%22, e);%0A        %7D%0A    %7D%0A%0A
     public void 

add writer for attachments