com.likethesalad.tools.resource.collector.ResourceCollector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resource-collector Show documentation
Show all versions of resource-collector Show documentation
Plugin that gathers resources from Android projects for compilation purposes.
package com.likethesalad.tools.resource.collector
import com.likethesalad.tools.resource.api.collection.ResourceCollection
import com.likethesalad.tools.resource.collector.extractor.ResourceExtractor
import com.likethesalad.tools.resource.collector.extractor.ResourceExtractorProvider
import com.likethesalad.tools.resource.collector.merger.ResourceMerger
import com.likethesalad.tools.resource.collector.source.ResourceSource
import com.likethesalad.tools.resource.collector.source.ResourceSourceProvider
abstract class ResourceCollector {
fun collect(): ResourceCollection {
val collections = mutableListOf()
val sources = getSourceProvider().getSources()
val extractors = getExtractorProvider().getExtractors()
for (source in sources) {
collections.addAll(getCollectionsFromSource(extractors, source))
}
return getMerger().merge(collections)
}
private fun getCollectionsFromSource(
extractors: List>,
source: ResourceSource,
): List {
val collections = mutableListOf()
for (extractor in extractors) {
extractor.extract(source)?.let { collection ->
if (!collection.isEmpty()) {
collections.add(collection)
}
}
}
return collections
}
abstract fun getSourceProvider(): ResourceSourceProvider
abstract fun getExtractorProvider(): ResourceExtractorProvider
abstract fun getMerger(): ResourceMerger
}