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

com.avito.test.gradle.dependencies.GradleDependency.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2024.32
Show newest version
package com.avito.test.gradle.dependencies

import com.avito.test.gradle.dependencies.GradleDependency.Safe.Coordinate.External
import com.avito.test.gradle.dependencies.GradleDependency.Safe.Coordinate.Platform
import com.avito.test.gradle.dependencies.GradleDependency.Safe.Coordinate.Project
import org.gradle.util.Path

public sealed class GradleDependency : GradleScriptCompatible {

    public data class Raw(val rawDependency: String) : GradleDependency() {
        override fun getScriptRepresentation(): String = rawDependency
    }

    public data class Safe(
        private val configuration: CONFIGURATION,
        private val dep: Coordinate
    ) : GradleDependency() {

        public enum class CONFIGURATION(private val representation: String) : GradleScriptCompatible {
            IMPLEMENTATION("implementation"),
            TEST_IMPLEMENTATION("testImplementation"),
            ANDROID_TEST_IMPLEMENTATION("androidTestImplementation"),
            API("api");

            override fun getScriptRepresentation(): String = representation
        }

        public sealed class Coordinate : GradleScriptCompatible {

            public data class External(val coordinates: String) : Coordinate() {
                override fun getScriptRepresentation(): String = "\"$coordinates\""
            }

            public data class Project(val path: Path) : Coordinate() {
                override fun getScriptRepresentation(): String = "project(\"${path.path}\")"
            }

            public data class Platform(val coordinate: Coordinate) : Coordinate() {
                override fun getScriptRepresentation(): String {
                    return "platform(${
                        when (coordinate) {
                            is External -> coordinate.getScriptRepresentation()
                            is Project -> coordinate.getScriptRepresentation()
                            else -> throw IllegalArgumentException(
                                "Platform coordinate could be either External or Project"
                            )
                        }
                    })"
                }
            }
        }

        override fun getScriptRepresentation(): String {
            return "${configuration.getScriptRepresentation()}(${dep.getScriptRepresentation()})"
        }

        public companion object {

            public fun external(
                coordinate: String,
                configuration: CONFIGURATION = CONFIGURATION.IMPLEMENTATION
            ): Safe = Safe(configuration, External(coordinate))

            public fun project(
                path: String,
                configuration: CONFIGURATION = CONFIGURATION.IMPLEMENTATION
            ): Safe = Safe(configuration, Project(Path.path(path)))

            public fun platformProject(
                path: String,
                configuration: CONFIGURATION = CONFIGURATION.IMPLEMENTATION
            ): Safe = Safe(
                configuration,
                Platform(Project(Path.path(path)))
            )

            public fun platformExternal(
                coordinate: String,
                configuration: CONFIGURATION = CONFIGURATION.IMPLEMENTATION
            ): Safe = Safe(configuration, External(coordinate))
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy