All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.yandex.qatools.allure.data.index.DefaultAttachmentsIndex.groovy Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package ru.yandex.qatools.allure.data.index

import com.google.inject.Inject
import com.google.inject.Singleton
import groovy.transform.CompileStatic
import ru.yandex.qatools.allure.data.AttachmentInfo
import ru.yandex.qatools.allure.data.io.ResultDirectories
import ru.yandex.qatools.allure.data.plugins.AttachmentsIndex

import static java.util.Collections.unmodifiableList
import static ru.yandex.qatools.allure.commons.AllureFileUtils.listAttachmentFiles
import static ru.yandex.qatools.allure.data.utils.TextUtils.generateUid

/**
 * The default implementation of {@link AttachmentsIndex}.
 * There is two different indexes: by id and by source.
 *
 * @author Dmitry Baev [email protected]
 *         Date: 10.07.15
 */
@Singleton
@CompileStatic
class DefaultAttachmentsIndex implements AttachmentsIndex {

    Map byUid = new HashMap<>()

    Map bySource = new HashMap<>()

    /**
     * Creates an instance of index.
     * @param directories the directories to find attachments.
     * Should not be empty.
     */
    @Inject
    public DefaultAttachmentsIndex(@ResultDirectories File... directories) {
        for (def file : listAttachmentFiles(directories)) {
            def uid = generateUid()
            def source = file.name
            def attachment = new AttachmentInfo(
                    uid: uid,
                    source: source,
                    size: file.length(),
                    path: file.absolutePath
            )
            byUid[uid] = attachment
            bySource[source] = attachment
        }
    }

    /**
     * @inheritDoc
     */
    @Override
    AttachmentInfo find(String uid) {
        byUid[uid]
    }

    /**
     * @inheritDoc
     */
    @Override
    AttachmentInfo findBySource(String source) {
        bySource[source]
    }

    /**
     * @inheritDoc
     */
    @Override
    List findAll() {
        unmodifiableList(byUid.values() as List)
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy