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

com.github.squirrelgrip.plugin.resolver.ArtifactDetailsFactory.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.github.squirrelgrip.plugin.resolver

import com.github.squirrelgrip.plugin.model.ArtifactDetails
import com.github.squirrelgrip.plugin.model.MavenMetaData
import com.github.squirrelgrip.plugin.model.Version

interface ArtifactDetailsFactory {

    fun create(groupId: String, artifactId: String, version: String): ArtifactDetails =
        ArtifactDetails(groupId, artifactId, Version(version))

    fun ArtifactDetails.getMavenMetaDataFile(id: String = ""): String =
        if (id.isNotBlank()) {
            "${this.getDirectory()}/maven-metadata-$id.xml"
        } else {
            "${this.getDirectory()}/maven-metadata.xml"
        }

    fun List.toVersions(): List =
        this
            .flatMap { metaData ->
                val ignoredVersions = getIgnoredVersions(metaData.groupId, metaData.artifactId)
                val versions = metaData.versioning.versions
                if (ignoredVersions.isNotEmpty()) {
                    versions.filter {  version ->
                        !ignoredVersions.any {
                            it.toRegex().matches(version)
                        }
                    }
                } else {
                    versions
                }
            }
            .distinct()
            .map {
                Version(it)
            }

    fun ArtifactDetails.getDirectory(): String =
        "${groupId.replace(".", "/")}/$artifactId"

    fun getAvailableVersions(artifact: ArtifactDetails): List
    fun hasMetaData(artifact: ArtifactDetails): Boolean
    fun metaDataUp2Date(artifact: ArtifactDetails): Boolean
    fun getIgnoredVersions(groupId: String, artifactId: String): Collection
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy