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

com.likethesalad.stem.locator.entrypoints.common.utils.TemplatesProviderJarsFinder.kt Maven / Gradle / Ivy

Go to download

This is a Gradle plugin for Android applications which resolves XML string references in other XML strings.

There is a newer version: 2.12.0
Show newest version
package com.likethesalad.stem.locator.entrypoints.common.utils

import com.likethesalad.android.templates.common.utils.CommonConstants.PROVIDER_PACKAGE_NAME
import com.likethesalad.android.templates.provider.api.TemplatesProvider
import io.github.classgraph.ClassGraph
import io.github.classgraph.ScanResult
import org.gradle.api.file.FileCollection
import java.io.File

class TemplatesProviderJarsFinder(val allJarFiles: FileCollection) {

    val templateProviderJars: List by lazy {
        findTemplateProviderJars(allJarFiles.files)
    }

    private fun findTemplateProviderJars(allJars: Set): List {
        val scanResult = scanJars(allJars) ?: return emptyList()

        return scanResult.use {
            scanResult.getClassesImplementing(TemplatesProvider::class.java.name).map { info ->
                info.classpathElementFile
            }
        }
    }

    private fun scanJars(jarFiles: Set): ScanResult? {
        if (jarFiles.isEmpty()) {
            return null
        }
        return ClassGraph()
            .acceptPackages(PROVIDER_PACKAGE_NAME)
            .overrideClasspath(jarFiles)
            .scan()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy