|
| 1 | +package org.ossreviewtoolkit.tools.curations |
| 2 | + |
| 3 | +import org.gradle.api.tasks.TaskAction |
| 4 | +import org.ossreviewtoolkit.model.Identifier |
| 5 | + |
| 6 | +open class GenerateAwsSdkForNetCurationsTask : BaseGenerateCurationsTask() { |
| 7 | + private val fourDigitVersionRegex = Regex("""\d+\.\d+\.\d+\.\d+""") |
| 8 | + |
| 9 | + @TaskAction |
| 10 | + fun generate() { |
| 11 | + val data = mutableSetOf<PathCurationData>() |
| 12 | + val targetFrameworkRegex = Regex("""\.Net.+$""") |
| 13 | + |
| 14 | + getTagsFromRepository(owner = "aws", repository = "aws-sdk-net") |
| 15 | + .filter { it.isFourDigitVersion() } |
| 16 | + .forEach { tag -> |
| 17 | + logger.quiet("Processing tag $tag.") |
| 18 | + |
| 19 | + getFilesFromRepository(owner = "aws", repository = "aws-sdk-net", ref = tag) |
| 20 | + .filter { it.startsWith("sdk/src/Services/") && it.endsWith(".csproj") } |
| 21 | + .forEach { |
| 22 | + val project = it.substringAfterLast("/") |
| 23 | + .removeSuffix(".csproj") |
| 24 | + .replace(targetFrameworkRegex, "") |
| 25 | + val path = it.substringBeforeLast("/") |
| 26 | + val id = Identifier("NuGet::$project") |
| 27 | + |
| 28 | + // The AWS SDK for .NET uses a four-part version number for all packages. However, Semver4j |
| 29 | + // does not support four-part version numbers. Therefore, remove the fourth digit. |
| 30 | + val threeDigitVersionTag = |
| 31 | + if (tag.count { c -> c == '.' } == 3) tag.substringBeforeLast(".") else tag |
| 32 | + |
| 33 | + if ("AWSSDK." in project) { |
| 34 | + data += PathCurationData(id, path, threeDigitVersionTag) |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + data.groupBy { it.id }.forEach { (_, curationData) -> |
| 40 | + curationData.toPathCurations().forEach { saveCuration(it) } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private fun String.isFourDigitVersion() = fourDigitVersionRegex.matches(this) |
| 45 | +} |
0 commit comments