in intellij-plugin-verifier/verifier-repository/src/main/java/com/jetbrains/pluginverifier/ide/IntelliJRepositoryIndexParser.kt [21:66]
fun parseArtifacts(artifacts: List<ArtifactJson>, channel: IntelliJIdeRepository.Channel): List<AvailableIde> {
val allAvailableIdes = arrayListOf<AvailableIde>()
/**
* (group-id, version) is a unique key for grouping artifacts.
*/
val groupedArtifacts = artifacts.groupBy { it.groupId to it.version }
for ((groupAndVersion, artifactsOfVersion) in groupedArtifacts) {
val (groupId, version) = groupAndVersion
/**
* Build number of this IDE is written in "BUILD".content artifact's key.
*/
val buildNumber = artifactsOfVersion.find { it.artifactId == "BUILD" }?.content ?: continue
val ideArtifacts = artifactsOfVersion.filter {
it.packaging == "zip" && IntelliJIdeRepository.getProductCodeByArtifactId(it.artifactId) != null
}
for (artifactInfo in ideArtifacts) {
val productCode = IntelliJIdeRepository.getProductCodeByArtifactId(artifactInfo.artifactId) ?: continue
val ideVersion = IdeVersion.createIdeVersionIfValid(buildNumber)
?.setProductCodeIfAbsent(productCode)
?: continue
val product = IntelliJPlatformProduct.fromIdeVersion(ideVersion) ?: continue
val downloadUrl = buildDownloadUrl(artifactInfo, channel, groupId, version)
val isRelease = channel == IntelliJIdeRepository.Channel.RELEASE && isReleaseLikeVersion(artifactInfo.version)
val releasedVersion = version.takeIf { isRelease }
val uploadDate = Instant.ofEpochMilli(artifactInfo.lastModifiedUnixTimeMs).atZone(ZoneOffset.UTC).toLocalDate()
val availableIde = AvailableIde(ideVersion, releasedVersion, downloadUrl, uploadDate, product)
allAvailableIdes.add(availableIde)
}
}
/**
* Remove duplicated IDEs.
*/
return allAvailableIdes
.groupBy { it.version }
.mapValues { getUniqueIde(it.value) }
.values.toList()
}