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

com.avito.impact.util.AndroidProject.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

The newest version!
package com.avito.impact.util

import com.avito.android.isAndroid
import org.gradle.api.Project
import java.io.File

/**
 * Simplified android project model
 */
internal class AndroidProject(project: Project) : Project by project {

    init {
        require(project.isAndroid()) { "Trying to create AndroidProject from non-android ${project.path}" }
    }

    val manifest = AndroidManifest.from(project)

    override fun toString(): String {
        return "AndroidProject(name=$displayName, pkg=${manifest.getPackage()})"
    }
}

internal class AndroidManifest(
    private val projectDir: File,
    private val sourceSet: String = "main"
) {

    private val packageParser = AndroidManifestPackageParser

    fun getPackage(): String {
        val manifest = File("$projectDir/src/$sourceSet/AndroidManifest.xml")

        return packageParser.parse(manifest)
            ?: error("Project $projectDir doesn't have AndroidManifest or package in it")
    }

    companion object {
        fun from(project: Project): AndroidManifest = AndroidManifest(project.projectDir)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy