$VNUM_REGEX(\\+\\-$OPT_REGEX)?)"
@@ -104,7 +103,7 @@ object VersionParser {
if (version != null) {
return version
}
- } catch (e: Exception) {
+ } catch (_: Exception) {
}
throw FailedToParse("Failed to parse $publishName")
}
@@ -126,7 +125,7 @@ object VersionParser {
if (!sanityCheck || sanityCheck(parsed)) {
return parsed
}
- } catch (e: Exception) {
+ } catch (_: Exception) {
}
return null
}
@@ -185,7 +184,7 @@ object VersionParser {
private fun sanityCheck(parsed: VersionData): Boolean {
- if (!(parsed.major in 101 downTo 7)) {
+ if (parsed.major !in 101 downTo 7) {
// Sanity check as javas parser can match a single number
// sane range is 8 to 100
// TODO update me before 2062 and java 100 is released
diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/parser/maven/SemverParser.kt b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/parser/maven/SemverParser.kt
index 3aadc2618..69722c602 100644
--- a/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/parser/maven/SemverParser.kt
+++ b/adoptium-models-parent/adoptium-api-v3-models/src/main/kotlin/net/adoptium/api/v3/parser/maven/SemverParser.kt
@@ -1,14 +1,14 @@
-package net.adoptium.api.v3.parser.maven;
+package net.adoptium.api.v3.parser.maven
import net.adoptium.api.v3.models.VersionData
import net.adoptium.api.v3.parser.FailedToParse
import java.util.regex.Pattern
object SemverParser {
- val PRE = """(\-(?[\.A-Za-z0-9]+))?"""
- val BUILD = """(\+(?[\.A-Za-z0-9]+))?"""
- val VERSION_CORE = """(?[0-9]+)\.(?[0-9]+)\.(?[0-9]+)$PRE$BUILD"""
- val MATCHER = Pattern.compile("^$VERSION_CORE$")
+ private const val PRE = """(\-(?[\.A-Za-z0-9]+))?"""
+ private const val BUILD = """(\+(?[\.A-Za-z0-9]+))?"""
+ private const val VERSION_CORE = """(?[0-9]+)\.(?[0-9]+)\.(?[0-9]+)$PRE$BUILD"""
+ private val MATCHER = Pattern.compile("^$VERSION_CORE$")
fun parseAdoptSemverNonNull(version: String): VersionData {
return parseAdoptSemver(version) ?: throw FailedToParse("Failed to parse $version")
@@ -49,7 +49,7 @@ object SemverParser {
optional = if (parts.size > 2) parts[2] else null
adoptBuildNum = if (parts.size > 1) parts[1].toInt() else null
- build = if (parts.size > 0) parts[0].toInt() else null
+ build = if (parts.isNotEmpty()) parts[0].toInt() else null
if (build != null) {
patch = build / 100
diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/SemverParserTest.kt b/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/SemverParserTest.kt
similarity index 99%
rename from adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/SemverParserTest.kt
rename to adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/SemverParserTest.kt
index 5bb85b1ff..df1b28c60 100644
--- a/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/SemverParserTest.kt
+++ b/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/SemverParserTest.kt
@@ -1,4 +1,4 @@
-package api;
+package net.adoptium.api
import net.adoptium.api.v3.models.VersionData
import net.adoptium.api.v3.parser.VersionParser
diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/VersionParserTest.kt b/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/VersionParserTest.kt
similarity index 100%
rename from adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/VersionParserTest.kt
rename to adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/VersionParserTest.kt
diff --git a/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/VersionRangeTest.kt b/adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/VersionRangeTest.kt
similarity index 100%
rename from adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/api/VersionRangeTest.kt
rename to adoptium-models-parent/adoptium-api-v3-models/src/test/kotlin/net/adoptium/api/VersionRangeTest.kt
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/pom.xml b/adoptium-updater-parent/adoptium-api-v3-updater/pom.xml
index b4fbf4f96..5a2291db6 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/pom.xml
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/pom.xml
@@ -21,7 +21,11 @@
io.quarkus
- quarkus-resteasy-reactive
+ quarkus-rest
+
+
+ io.quarkus
+ quarkus-smallrye-metrics
jakarta.enterprise
@@ -74,17 +78,6 @@
weld-junit5
test
-
- org.litote.kmongo
- kmongo-flapdoodle
- test
-
-
- org.slf4j
- slf4j-simple
-
-
-
io.mockk
mockk-jvm
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptReposBuilder.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptReposBuilder.kt
index 2b1040e93..6a6a1bf4b 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptReposBuilder.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptReposBuilder.kt
@@ -1,6 +1,8 @@
package net.adoptium.api.v3
import jakarta.enterprise.context.ApplicationScoped
+import jakarta.inject.Inject
+import net.adoptium.api.v3.dataSources.VersionSupplier
import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHReleaseSummary
import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHRepositorySummary
import net.adoptium.api.v3.dataSources.models.AdoptRepos
@@ -12,11 +14,13 @@ import net.adoptium.api.v3.models.GHReleaseMetadata
import net.adoptium.api.v3.models.Release
import org.slf4j.LoggerFactory
import java.time.temporal.ChronoUnit
-import jakarta.inject.Inject
import kotlin.math.absoluteValue
@ApplicationScoped
-class AdoptReposBuilder @Inject constructor(private var adoptRepository: AdoptRepository) {
+class AdoptReposBuilder @Inject constructor(
+ private var adoptRepository: AdoptRepository,
+ private var versionSupplier: VersionSupplier
+ ) {
companion object {
@JvmStatic
@@ -156,13 +160,14 @@ class AdoptReposBuilder @Inject constructor(private var adoptRepository: AdoptRe
}
}
- suspend fun build(versions: Array): AdoptRepos {
+ suspend fun build(filter: ReleaseIncludeFilter): AdoptRepos {
excluded.clear()
// Fetch repos in parallel
- val reposMap = versions
+ val reposMap = versionSupplier
+ .getAllVersions()
.reversed()
.mapNotNull { version ->
- adoptRepository.getRelease(version)
+ adoptRepository.getRelease(version, filter)
}
.associateBy { it.featureVersion }
LOGGER.info("DONE")
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptRepository.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptRepository.kt
index 2618b0e0d..91e39fa09 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptRepository.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/AdoptRepository.kt
@@ -1,10 +1,10 @@
package net.adoptium.api.v3
import jakarta.enterprise.context.ApplicationScoped
+import jakarta.inject.Inject
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
-import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.dataSources.github.GitHubApi
import net.adoptium.api.v3.dataSources.github.graphql.models.GHAsset
import net.adoptium.api.v3.dataSources.github.graphql.models.PageInfo
@@ -20,17 +20,13 @@ import net.adoptium.api.v3.models.Release
import net.adoptium.api.v3.models.ReleaseType
import net.adoptium.api.v3.models.Vendor
import org.slf4j.LoggerFactory
-import jakarta.inject.Inject
interface AdoptRepository {
- suspend fun getRelease(version: Int): FeatureRelease?
+ suspend fun getRelease(version: Int, filter: ReleaseIncludeFilter): FeatureRelease?
suspend fun getSummary(version: Int): GHRepositorySummary
suspend fun getReleaseById(gitHubId: GitHubId): ReleaseResult?
suspend fun getReleaseFilesForId(gitHubId: GitHubId): List?
- companion object {
- val VENDORS_EXCLUDED_FROM_FULL_UPDATE = setOf(Vendor.adoptopenjdk)
- }
}
@ApplicationScoped
@@ -79,7 +75,7 @@ open class AdoptRepositoryImpl @Inject constructor(
override suspend fun getReleaseById(gitHubId: GitHubId): ReleaseResult? {
val release = client.getReleaseById(gitHubId)
- if (release == null) return null;
+ if (release == null) return null
return getMapperForRepo(release.url)
.toAdoptRelease(release)
@@ -92,31 +88,25 @@ open class AdoptRepositoryImpl @Inject constructor(
?.assets
}
- override suspend fun getRelease(version: Int): FeatureRelease {
+ override suspend fun getRelease(version: Int, filter: ReleaseIncludeFilter): FeatureRelease {
+
val repo = getDataForEachRepo(
version,
- ::getRepository,
- getFullUpdateFilter()
+ filter,
+ getRepository(filter)
)
.await()
.filterNotNull()
.map { AdoptRepo(it) }
- return FeatureRelease(version, repo)
- }
- // If not explicitly updating AdoptOpenJDK exclude them
- private fun getFullUpdateFilter(): (Vendor) -> Boolean = if (APIConfig.UPDATE_ADOPTOPENJDK) {
- { true } // include all vendors
- } else {
- { vendor -> !AdoptRepository.VENDORS_EXCLUDED_FROM_FULL_UPDATE.contains(vendor) } // exclude AdoptOpenjdk
+ return FeatureRelease(version, repo)
}
override suspend fun getSummary(version: Int): GHRepositorySummary {
val releaseSummaries = getDataForEachRepo(
version,
- { owner: String, repoName: String -> client.getRepositorySummary(owner, repoName) },
- { true } // include all vendors in summary update
- )
+ ReleaseIncludeFilter.INCLUDE_ALL
+ ) { _: Vendor, owner: String, repoName: String -> client.getRepositorySummary(owner, repoName) }
.await()
.filterNotNull()
.flatMap { it.releases.releases }
@@ -124,9 +114,13 @@ open class AdoptRepositoryImpl @Inject constructor(
return GHRepositorySummary(GHReleasesSummary(releaseSummaries, PageInfo(false, "")))
}
- private suspend fun getRepository(owner: String, repoName: String): List {
+ private fun getRepository(filter: ReleaseIncludeFilter): suspend (Vendor, String, String) -> List {
+ return { vendor: Vendor, owner: String, repoName: String -> getRepository(filter, vendor, owner, repoName) }
+ }
+
+ private suspend fun getRepository(filter: ReleaseIncludeFilter, vendor: Vendor, owner: String, repoName: String): List {
return client
- .getRepository(owner, repoName)
+ .getRepository(owner, repoName) { updatedAt, isPrerelease -> filter.filter(vendor, updatedAt, isPrerelease) }
.getReleases()
.flatMap {
try {
@@ -152,10 +146,10 @@ open class AdoptRepositoryImpl @Inject constructor(
}
}
- private suspend fun getDataForEachRepo(
+ private fun getDataForEachRepo(
version: Int,
- getFun: suspend (String, String) -> E,
- filter: (Vendor) -> Boolean
+ filter: ReleaseIncludeFilter,
+ getFun: suspend (Vendor, String, String) -> E
): Deferred> {
LOGGER.info("getting $version")
return GlobalScope.async {
@@ -182,15 +176,15 @@ open class AdoptRepositoryImpl @Inject constructor(
owner: String,
vendor: Vendor,
repoName: String,
- getFun: suspend (String, String) -> E,
- filter: (Vendor) -> Boolean
+ getFun: suspend (Vendor, String, String) -> E,
+ filter: ReleaseIncludeFilter
): Deferred {
return GlobalScope.async {
- if (!Vendor.validVendor(vendor) || !filter.invoke(vendor)) {
+ if (!Vendor.validVendor(vendor) || !filter.filterVendor(vendor)) {
return@async null
}
LOGGER.info("getting $owner $repoName")
- val releases = getFun(owner, repoName)
+ val releases = getFun(vendor, owner, repoName)
LOGGER.info("Done getting $owner $repoName")
return@async releases
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt
index 0c08e89ad..e3e917337 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/Main.kt
@@ -1,5 +1,7 @@
package net.adoptium.api.v3
+import net.adoptium.api.v3.config.APIConfig
+import net.adoptium.api.v3.config.DeploymentType
import org.jboss.weld.environment.se.Weld
class Main {
@@ -8,6 +10,7 @@ class Main {
fun main(args: Array) {
// Force eager App insights loading
// AppInsightsTelemetry.enabled
+ APIConfig.DEPLOYMENT_TYPE = DeploymentType.UPDATER
val container = Weld().containerId("STATIC_INSTANCE").initialize()
val v3Updater = container.select(V3Updater::class.java).get()
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/ReleaseIncludeFilter.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/ReleaseIncludeFilter.kt
new file mode 100644
index 000000000..949040caa
--- /dev/null
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/ReleaseIncludeFilter.kt
@@ -0,0 +1,60 @@
+package net.adoptium.api.v3
+
+import net.adoptium.api.v3.config.APIConfig
+import net.adoptium.api.v3.mapping.ReleaseMapper
+import net.adoptium.api.v3.models.Vendor
+import java.time.Duration
+import java.time.ZonedDateTime
+
+enum class ReleaseFilterType {
+ RELEASES_ONLY,
+ SNAPSHOTS_ONLY,
+ ALL
+}
+
+class ReleaseIncludeFilter(
+ private val now: ZonedDateTime,
+ private val filterType: ReleaseFilterType,
+ private val includeAll: Boolean = false,
+ private val excludedVendors: Set = VENDORS_EXCLUDED_FROM_FULL_UPDATE
+) {
+ companion object {
+ val VENDORS_EXCLUDED_FROM_FULL_UPDATE = setOf(Vendor.adoptopenjdk)
+
+ val INCLUDE_ALL = ReleaseIncludeFilter(TimeSource.now(), ReleaseFilterType.ALL, true)
+ }
+
+ fun filterVendor(vendor: Vendor): Boolean {
+ return if (includeAll || APIConfig.UPDATE_ADOPTOPENJDK) {
+ true // include all vendors
+ } else {
+ !excludedVendors.contains(vendor)
+ }
+ }
+
+ fun filter(vendor: Vendor, startTime: String, isPrerelease: Boolean): Boolean {
+ return filter(vendor, ReleaseMapper.parseDate(startTime), isPrerelease)
+ }
+
+ fun filter(vendor: Vendor, startTime: ZonedDateTime, isPrerelease: Boolean): Boolean {
+ if (includeAll || APIConfig.UPDATE_ADOPTOPENJDK) {
+ return true // include all vendors
+ } else {
+ if (excludedVendors.contains(vendor)) {
+ return false
+ }
+
+ var include = true
+
+ if (filterType == ReleaseFilterType.RELEASES_ONLY) {
+ return !isPrerelease
+ } else if (filterType == ReleaseFilterType.SNAPSHOTS_ONLY) {
+ include = isPrerelease
+ }
+
+ return include && Duration.between(startTime, now).toDays() < APIConfig.UPDATE_DAY_CUTOFF
+ // exclude AdoptOpenjdk
+ // Don't Update releases more than a year old
+ }
+ }
+}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/V3Updater.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/V3Updater.kt
index 98984eb56..1764c6ed8 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/V3Updater.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/V3Updater.kt
@@ -13,10 +13,11 @@ import net.adoptium.api.v3.config.APIConfig
import net.adoptium.api.v3.dataSources.APIDataStore
import net.adoptium.api.v3.dataSources.ReleaseVersionResolver
import net.adoptium.api.v3.dataSources.UpdaterJsonMapper
+import net.adoptium.api.v3.dataSources.UpdatableVersionSupplier
import net.adoptium.api.v3.dataSources.models.AdoptRepos
import net.adoptium.api.v3.dataSources.persitence.ApiPersistence
import net.adoptium.api.v3.models.Release
-import net.adoptium.api.v3.models.Versions
+import net.adoptium.api.v3.models.ReleaseType
import net.adoptium.api.v3.releaseNotes.AdoptReleaseNotes
import net.adoptium.api.v3.stats.StatsInterface
import org.slf4j.LoggerFactory
@@ -26,6 +27,7 @@ import java.util.*
import java.util.concurrent.ConcurrentSkipListSet
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
+import java.util.concurrent.atomic.AtomicBoolean
import kotlin.concurrent.timerTask
@UnlessBuildProfile("test")
@@ -41,7 +43,8 @@ class V3Updater @Inject constructor(
private val database: ApiPersistence,
private val statsInterface: StatsInterface,
private val releaseVersionResolver: ReleaseVersionResolver,
- private val adoptReleaseNotes: AdoptReleaseNotes
+ private val adoptReleaseNotes: AdoptReleaseNotes,
+ private val updatableVersionSupplier: UpdatableVersionSupplier
) : Updater {
private val mutex = Mutex()
@@ -63,18 +66,14 @@ class V3Updater @Inject constructor(
return String(Base64.getEncoder().encode(md.digest()))
}
- fun copyOldReleasesIntoNewRepo(currentRepo: AdoptRepos, newRepoData: AdoptRepos) = newRepoData
+ fun copyOldReleasesIntoNewRepo(currentRepo: AdoptRepos, newRepoData: AdoptRepos, filter: ReleaseIncludeFilter) = newRepoData
.addAll(currentRepo
.allReleases
.getReleases()
- .filter { AdoptRepository.VENDORS_EXCLUDED_FROM_FULL_UPDATE.contains(it.vendor) }
+ .filter { !filter.filter(it.vendor, it.updated_at.dateTime, it.release_type == ReleaseType.ea) }
.toList())
}
- init {
- //AppInsightsTelemetry.start()
- }
-
override fun addToUpdate(toUpdate: String): List {
val repo = apiDataStore.loadDataFromDb(true)
val toUpdateList = repo
@@ -140,10 +139,10 @@ class V3Updater @Inject constructor(
.forEach { releaseA ->
val releaseB = repoB.allReleases.getReleaseById(releaseA.id)
if (releaseB == null) {
- LOGGER.debug("Release disapeared ${releaseA.id} ${releaseA.version_data.semver}")
+ LOGGER.debug("Release disappeared ${releaseA.id} ${releaseA.version_data.semver}")
} else if (releaseA != releaseB) {
- LOGGER.debug("Release changedA $releaseA")
- LOGGER.debug("Release changedB $releaseB")
+ LOGGER.debug("Release changedA {}", releaseA)
+ LOGGER.debug("Release changedB {}", releaseB)
releaseA
.binaries
.forEach { binaryA ->
@@ -208,6 +207,7 @@ class V3Updater @Inject constructor(
fun run(instantFullUpdate: Boolean) {
val executor = Executors.newScheduledThreadPool(2)
+
val delay = if (instantFullUpdate) 0L else 1L
var repo: AdoptRepos = try {
@@ -217,30 +217,44 @@ class V3Updater @Inject constructor(
AdoptRepos(emptyList())
}
- executor.scheduleWithFixedDelay(
- timerTask {
- repo = fullUpdate(repo) ?: repo
- },
- delay, 1, TimeUnit.DAYS
- )
+ val incrementalUpdateScheduled = AtomicBoolean(false)
executor.scheduleWithFixedDelay(
timerTask {
- repo = incrementalUpdate(repo) ?: repo
+ repo = fullUpdate(repo, true) ?: repo
+ if (!incrementalUpdateScheduled.getAndSet(true)) {
+ executor.scheduleWithFixedDelay(
+ timerTask {
+ repo = incrementalUpdate(repo) ?: repo
+ },
+ 1, 6, TimeUnit.MINUTES
+ )
+ }
+ repo = fullUpdate(repo, false) ?: repo
},
- 1, 6, TimeUnit.MINUTES
+ delay, 1, TimeUnit.DAYS
)
}
- fun fullUpdate(currentRepo: AdoptRepos): AdoptRepos? {
+ private fun fullUpdate(currentRepo: AdoptRepos, releasesOnly: Boolean): AdoptRepos? {
// Must catch errors or may kill the scheduler
try {
return runBlocking {
- LOGGER.info("Starting Full update")
+ LOGGER.info("Starting Full update {}", releasesOnly)
+
+ updatableVersionSupplier.updateVersions()
+
+ val filterType: ReleaseFilterType = if (releasesOnly) {
+ ReleaseFilterType.RELEASES_ONLY
+ } else {
+ ReleaseFilterType.ALL
+ }
- val newRepoData = adoptReposBuilder.build(Versions.versions)
+ val filter = ReleaseIncludeFilter(TimeSource.now(), filterType)
- val repo = carryOverExcludedReleases(currentRepo, newRepoData)
+ val newRepoData = adoptReposBuilder.build(filter)
+
+ val repo = copyOldReleasesIntoNewRepo(currentRepo, newRepoData, filter)
val checksum = calculateChecksum(repo)
@@ -268,13 +282,4 @@ class V3Updater @Inject constructor(
return null
}
- // Releases that were excluded from the update due to being archived, copy them over from existing data
- private fun carryOverExcludedReleases(currentRepo: AdoptRepos, newRepoData: AdoptRepos) = if (!APIConfig.UPDATE_ADOPTOPENJDK) {
- // AdoptOpenJdk were excluded from full update so copy them from previous
- copyOldReleasesIntoNewRepo(currentRepo, newRepoData)
- } else {
- newRepoData
- }
-
-
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/ReleaseVersionResolver.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/ReleaseVersionResolver.kt
index e849aee71..913c8dba3 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/ReleaseVersionResolver.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/ReleaseVersionResolver.kt
@@ -1,31 +1,17 @@
package net.adoptium.api.v3.dataSources
import jakarta.enterprise.context.ApplicationScoped
+import jakarta.inject.Inject
import net.adoptium.api.v3.dataSources.models.AdoptRepos
import net.adoptium.api.v3.models.ReleaseInfo
import net.adoptium.api.v3.models.ReleaseType
-import net.adoptium.api.v3.models.Versions
-import jakarta.inject.Inject
@ApplicationScoped
class ReleaseVersionResolver @Inject constructor(
- private val updaterHtmlClient: UpdaterHtmlClient
+ private val versionSupplier: VersionSupplier
) {
- private val VERSION_FILE_URL = "https://raw.githubusercontent.com/openjdk/jdk/master/make/conf/version-numbers.conf"
-
- private suspend fun getTipVersion(): Int? {
- val versionFile = updaterHtmlClient.get(VERSION_FILE_URL)
-
- return if (versionFile != null) {
- Regex(""".*DEFAULT_VERSION_FEATURE=(?\d+).*""", setOf(RegexOption.MULTILINE, RegexOption.DOT_MATCHES_ALL))
- .matchEntire(versionFile)?.groups?.get("num")?.value?.toInt()
- } else {
- null
- }
- }
-
- suspend fun formReleaseInfo(repo: AdoptRepos): ReleaseInfo {
+ fun formReleaseInfo(repo: AdoptRepos): ReleaseInfo {
val gaReleases = repo
.allReleases
.getReleases()
@@ -40,9 +26,11 @@ class ReleaseVersionResolver @Inject constructor(
.toTypedArray()
val mostRecentFeatureRelease: Int = availableReleases.lastOrNull() ?: 0
+ val ltsVersions = versionSupplier.getLtsVersions()
+
val availableLtsReleases: Array = gaReleases
.asSequence()
- .filter { Versions.ltsVersions.contains(it.version_data.major) }
+ .filter { ltsVersions.contains(it.version_data.major) }
.map { it.version_data.major }
.distinct()
.sorted()
@@ -58,7 +46,7 @@ class ReleaseVersionResolver @Inject constructor(
.sorted()
.lastOrNull() ?: 0
- val tip = getTipVersion() ?: mostRecentFeatureVersion
+ val tip = versionSupplier.getTipVersion() ?: mostRecentFeatureVersion
return ReleaseInfo(
availableReleases,
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplier.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplier.kt
new file mode 100644
index 000000000..0f01490ac
--- /dev/null
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplier.kt
@@ -0,0 +1,5 @@
+package net.adoptium.api.v3.dataSources
+
+interface UpdatableVersionSupplier : VersionSupplier {
+ suspend fun updateVersions()
+}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplierImpl.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplierImpl.kt
new file mode 100644
index 000000000..6d51b22f9
--- /dev/null
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdatableVersionSupplierImpl.kt
@@ -0,0 +1,66 @@
+package net.adoptium.api.v3.dataSources
+
+import jakarta.enterprise.context.ApplicationScoped
+import jakarta.inject.Inject
+import kotlinx.coroutines.runBlocking
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
+
+@ApplicationScoped
+class UpdatableVersionSupplierImpl @Inject constructor(val updaterHtmlClient: UpdaterHtmlClient) : VersionSupplier, UpdatableVersionSupplier {
+ companion object {
+ private val LOGGER: Logger = LoggerFactory.getLogger(UpdatableVersionSupplierImpl::class.java)
+ }
+
+ private val DEFAULT_LATEST_JAVA_VERSION = 24
+ private val LATEST_JAVA_VERSION_PROPERTY = "LATEST_JAVA_VERSION"
+
+ private val VERSION_FILE_URL = "https://raw.githubusercontent.com/openjdk/jdk/master/make/conf/version-numbers.conf"
+
+ private var tipVersion: Int? = null
+ private var latestJavaVersion: Int
+ private var versions: Array
+ private var ltsVersions: Array = arrayOf(8, 11, 17, 21)
+
+ init {
+ latestJavaVersion = Integer.parseInt(System.getProperty(LATEST_JAVA_VERSION_PROPERTY, DEFAULT_LATEST_JAVA_VERSION.toString()))
+ versions = (8..latestJavaVersion).toList().toTypedArray()
+ runBlocking {
+ updateVersions()
+ }
+ }
+
+ override suspend fun updateVersions() {
+ try {
+ val versionFile = updaterHtmlClient.get(VERSION_FILE_URL)
+
+ if (versionFile != null) {
+ tipVersion = Regex(""".*DEFAULT_VERSION_FEATURE=(?\d+).*""", setOf(RegexOption.MULTILINE, RegexOption.DOT_MATCHES_ALL))
+ .matchEntire(versionFile)?.groups?.get("num")?.value?.toInt()
+ } else {
+ LOGGER.warn("Failed to get tip version")
+ }
+
+
+ if (tipVersion != null && tipVersion!! > latestJavaVersion) {
+ latestJavaVersion = tipVersion as Int
+ versions = (8..latestJavaVersion).toList().toTypedArray()
+ }
+
+ } catch (e: Exception) {
+ LOGGER.warn("Failed to get tip version", e)
+ }
+ }
+
+ override fun getTipVersion(): Int? {
+ return this.tipVersion
+ }
+
+ override fun getLtsVersions(): Array {
+ return ltsVersions
+ }
+
+ override fun getAllVersions(): Array {
+ return versions
+ }
+}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/stats/GitHubDownloadStatsCalculator.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/stats/GitHubDownloadStatsCalculator.kt
index f56aa7eb6..552f1b1a7 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/stats/GitHubDownloadStatsCalculator.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/main/kotlin/net/adoptium/api/v3/stats/GitHubDownloadStatsCalculator.kt
@@ -1,6 +1,7 @@
package net.adoptium.api.v3.stats
import jakarta.enterprise.context.ApplicationScoped
+import jakarta.inject.Inject
import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.dataSources.models.AdoptRepos
import net.adoptium.api.v3.dataSources.persitence.ApiPersistence
@@ -9,7 +10,6 @@ import net.adoptium.api.v3.models.JvmImpl
import net.adoptium.api.v3.models.Vendor
import org.slf4j.LoggerFactory
import java.time.ZonedDateTime
-import jakarta.inject.Inject
@ApplicationScoped
open class GitHubDownloadStatsCalculator @Inject constructor(private val database: ApiPersistence) {
@@ -32,7 +32,7 @@ open class GitHubDownloadStatsCalculator @Inject constructor(private val databas
val stats = repos
.repos
.values
- .map { featureRelease ->
+ .sumOf { featureRelease ->
val total = featureRelease
.releases
.getReleases()
@@ -48,7 +48,6 @@ open class GitHubDownloadStatsCalculator @Inject constructor(private val databas
LOGGER.info("Stats ${featureRelease.featureVersion} $total")
total
}
- .sum()
LOGGER.info("Stats total $stats")
}
@@ -67,21 +66,21 @@ open class GitHubDownloadStatsCalculator @Inject constructor(private val databas
}
// Tally up jvmImpl download stats
- val jvmImplMap: Map = JvmImpl.values().map { jvmImpl ->
- jvmImpl to
- featureRelease
- .releases
- .getReleases()
- .filter { it.vendor == Vendor.getDefault() }
- .sumOf {
- it.binaries
- .filter { binary -> binary.jvm_impl == jvmImpl }
- .sumOf { binary ->
- binary.download_count.toInt()
- }
- }
+ val jvmImplMap: Map = JvmImpl.entries
+ .associateWith { jvmImpl ->
+ featureRelease
+ .releases
+ .getReleases()
+ .filter { it.vendor == Vendor.getDefault() }
+ .sumOf {
+ it.binaries
+ .filter { binary -> binary.jvm_impl == jvmImpl }
+ .sumOf { binary ->
+ binary.download_count.toInt()
+ }
+ }
.toLong()
- }.toMap()
+ }
GitHubDownloadStatsDbEntry(
date,
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/APIDataStoreTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/APIDataStoreTest.kt
index 86b6ac46a..32859f170 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/APIDataStoreTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/APIDataStoreTest.kt
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import org.skyscreamer.jsonassert.JSONAssert
import org.slf4j.LoggerFactory
+import java.util.*
class APIDataStoreTest : MongoTest() {
@@ -27,7 +28,7 @@ class APIDataStoreTest : MongoTest() {
fun reposHasElements() {
runBlocking {
val repo = BaseTest.adoptRepos
- assert(repo.getFeatureRelease(8)!!.releases.getReleases().toList().size > 0)
+ assert(repo.getFeatureRelease(8)!!.releases.getReleases().toList().isNotEmpty())
}
}
@@ -63,20 +64,20 @@ class APIDataStoreTest : MongoTest() {
@Test
fun `updated at is set`(apiPersistence: ApiPersistence) {
runBlocking {
- apiPersistence.updateAllRepos(BaseTest.adoptRepos, "")
+ apiPersistence.updateAllRepos(BaseTest.adoptRepos, Base64.getEncoder().encodeToString("1234".toByteArray()))
val time = TimeSource.now()
delay(1000)
- apiPersistence.updateAllRepos(BaseTest.adoptRepos, "a-checksum")
+ apiPersistence.updateAllRepos(BaseTest.adoptRepos, Base64.getEncoder().encodeToString("a-checksum".toByteArray()))
val updatedTime = apiPersistence.getUpdatedAt()
assertTrue(updatedTime.time.isAfter(time))
- assertEquals("a-checksum", updatedTime.checksum)
+ assertEquals(Base64.getEncoder().encodeToString("a-checksum".toByteArray()), updatedTime.checksum)
}
}
@Test
fun `update is not scheduled by default`(apiDataStore: APIDataStoreImpl) {
- assertNull(apiDataStore.schedule)
+ assertNull(apiDataStore.getSchedule())
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptMetadataVersionParsingTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptMetadataVersionParsingTest.kt
index d225eee13..b890a3c2a 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptMetadataVersionParsingTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptMetadataVersionParsingTest.kt
@@ -23,7 +23,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
class AdoptMetadataVersionParsingTest : BaseTest() {
val client: UpdaterHtmlClient = object : UpdaterHtmlClient {
- override suspend fun get(url: String): String? {
+ override suspend fun get(url: String): String {
return """
{
"WARNING": "THIS METADATA FILE IS STILL IN ALPHA DO NOT USE ME",
@@ -49,10 +49,10 @@ class AdoptMetadataVersionParsingTest : BaseTest() {
""".trimIndent()
}
- override suspend fun getFullResponse(request: UrlRequest): HttpResponse? {
+ override suspend fun getFullResponse(request: UrlRequest): HttpResponse {
val metadataResponse = mockk()
val entity = mockk()
- every { entity.content } returns get(request.url)?.byteInputStream()
+ every { entity.content } returns get(request.url).byteInputStream()
every { metadataResponse.statusLine } returns BasicStatusLine(ProtocolVersion("", 1, 1), 200, "")
every { metadataResponse.entity } returns entity
every { metadataResponse.getFirstHeader("Last-Modified") } returns BasicHeader("Last-Modified", "Thu, 01 Jan 1970 00:00:00 GMT")
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseMapperTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseMapperTest.kt
index 79e579bfd..1b88224ef 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseMapperTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseMapperTest.kt
@@ -197,11 +197,11 @@ class AdoptReleaseMapperTest : BaseTest() {
private fun buildGhAssets(assetNames: List>) =
GHAssets(assetNames
- .map { it ->
+ .map {
GHAsset(
it.first,
1L,
- "${it.second}",
+ it.second,
1L,
"2013-02-27T19:35:32Z"
)
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseNotesTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseNotesTest.kt
index 24f25e449..8699ad6ca 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseNotesTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReleaseNotesTest.kt
@@ -1,5 +1,6 @@
package net.adoptium.api
+import net.adoptium.api.v3.ReleaseIncludeFilter
import kotlinx.coroutines.runBlocking
import net.adoptium.api.testDoubles.InMemoryApiPersistence
import net.adoptium.api.v3.AdoptRepository
@@ -56,15 +57,15 @@ class AdoptReleaseNotesTest : BaseTest() {
]
""".trimIndent()
} else {
- return null;
+ return null
}
}
}
private fun addReleaseNotesFiles(adoptRepository: AdoptRepository) = object : AdoptRepository {
- override suspend fun getRelease(version: Int): FeatureRelease? {
- return adoptRepository.getRelease(version)
+ override suspend fun getRelease(version: Int, filter: ReleaseIncludeFilter): FeatureRelease? {
+ return adoptRepository.getRelease(version, filter)
}
override suspend fun getSummary(version: Int): GHRepositorySummary {
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposBuilderTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposBuilderTest.kt
index 52048444c..8e69ef132 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposBuilderTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposBuilderTest.kt
@@ -5,15 +5,16 @@ import io.mockk.coVerify
import io.mockk.spyk
import kotlinx.coroutines.runBlocking
import net.adoptium.api.testDoubles.AdoptRepositoryStub
+import net.adoptium.api.testDoubles.UpdatableVersionSupplierStub
import net.adoptium.api.v3.AdoptReposBuilder
import net.adoptium.api.v3.AdoptRepository
import net.adoptium.api.v3.ReleaseResult
+import net.adoptium.api.v3.dataSources.VersionSupplier
import net.adoptium.api.v3.dataSources.models.AdoptRepos
import net.adoptium.api.v3.dataSources.models.GitHubId
import net.adoptium.api.v3.models.GHReleaseMetadata
import org.jboss.weld.junit5.auto.EnableAutoWeld
import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
@EnableAutoWeld
@@ -21,7 +22,7 @@ class AdoptReposBuilderTest : BaseTest() {
companion object {
private val stub = AdoptRepositoryStub()
- private val adoptReposBuilder: AdoptReposBuilder = AdoptReposBuilder(stub)
+ private val adoptReposBuilder: AdoptReposBuilder = AdoptReposBuilder(stub, UpdatableVersionSupplierStub())
private var before: AdoptRepos = stub.repo
private var updated: AdoptRepos = runBlocking {
adoptReposBuilder.incrementalUpdate(emptySet(), before) { null }
@@ -29,11 +30,11 @@ class AdoptReposBuilderTest : BaseTest() {
}
@Test
- @Disabled("FIX ME, pending spyk fix from mockk")
- fun addReleaseIsUpdatedExplicitly(adoptRepository: AdoptRepository) {
+ fun addReleaseIsUpdatedExplicitly() {
runBlocking {
+ val adoptRepository = AdoptRepositoryStub()
val adoptRepo = spyk(adoptRepository)
- val adoptReposBuilder = AdoptReposBuilder(adoptRepo)
+ val adoptReposBuilder = AdoptReposBuilder(adoptRepo, UpdatableVersionSupplierStub())
adoptReposBuilder.incrementalUpdate(setOf(before.repos[8]?.releases?.nodeList?.first()?.release_name!!), before) { null }
@@ -83,12 +84,9 @@ class AdoptReposBuilderTest : BaseTest() {
fun updatedReleaseIsNotUpdatedWhenThingsDontChange() {
runBlocking {
- val updated2 = runBlocking {
- adoptReposBuilder.incrementalUpdate(emptySet(), before) { null }
- }
- val updated3 = runBlocking {
- adoptReposBuilder.incrementalUpdate(emptySet(), before) { null }
- }
+ val updated2 = adoptReposBuilder.incrementalUpdate(emptySet(), before) { null }
+
+ val updated3 = adoptReposBuilder.incrementalUpdate(emptySet(), before) { null }
assertTrue { updated == updated2 }
assertTrue { updated2 == updated3 }
@@ -96,11 +94,12 @@ class AdoptReposBuilderTest : BaseTest() {
}
@Test
- @Disabled("FIX ME, pending spyk fix from mockk")
- fun `young releases continue to be pulled`(repo: AdoptRepos, adoptRepository: AdoptRepository) {
+ fun `young releases continue to be pulled`() {
runBlocking {
+ val repo = stub.repo
+ val adoptRepository = AdoptRepositoryStub()
val adoptRepo = spyk(adoptRepository)
- val adoptReposBuilder = AdoptReposBuilder(adoptRepo)
+ val adoptReposBuilder = AdoptReposBuilder(adoptRepo, UpdatableVersionSupplierStub())
coEvery { adoptRepo.getReleaseById(GitHubId(AdoptRepositoryStub.toAddSemiYoungRelease.id)) } returns ReleaseResult(listOf(AdoptRepositoryStub.toAddSemiYoungRelease))
@@ -112,11 +111,11 @@ class AdoptReposBuilderTest : BaseTest() {
}
@Test
- @Disabled("FIX ME, pending spyk fix from mockk")
- fun `release is updated when binary count changes`(adoptRepository: AdoptRepository) {
+ fun `release is updated when binary count changes`() {
runBlocking {
+ val adoptRepository = AdoptRepositoryStub()
val adoptRepo = spyk(adoptRepository)
- val adoptReposBuilder = AdoptReposBuilder(adoptRepo)
+ val adoptReposBuilder = AdoptReposBuilder(adoptRepo, UpdatableVersionSupplierStub())
adoptReposBuilder.incrementalUpdate(emptySet(), before) {
if (before.repos[11]?.releases?.nodeList?.first()?.id == it.id) {
@@ -137,10 +136,10 @@ class AdoptReposBuilderTest : BaseTest() {
}
@Test
- fun `release is not updated when binary count does not change`(adoptRepository: AdoptRepository) {
+ fun `release is not updated when binary count does not change`(adoptRepository: AdoptRepository, versionSupplier: VersionSupplier) {
runBlocking {
val adoptRepo = spyk(adoptRepository)
- val adoptReposBuilder = AdoptReposBuilder(adoptRepo)
+ val adoptReposBuilder = AdoptReposBuilder(adoptRepo, versionSupplier)
adoptReposBuilder.incrementalUpdate(emptySet(), before) {
GHReleaseMetadata(
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposTestDataGenerator.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposTestDataGenerator.kt
index 2144e8b24..831553cfc 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposTestDataGenerator.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/AdoptReposTestDataGenerator.kt
@@ -28,7 +28,7 @@ object AdoptReposTestDataGenerator {
private val TEST_VERSIONS = listOf(8, 10, 11, 12)
private val TEST_RESOURCES = listOf(
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.adoptopenjdk),
listOf(Project.jdk),
listOf(JvmImpl.hotspot),
@@ -38,17 +38,17 @@ object AdoptReposTestDataGenerator {
listOf(HeapSize.normal),
),
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.adoptopenjdk),
listOf(Project.jdk),
listOf(JvmImpl.openj9),
listOf(ImageType.jre, ImageType.jdk),
listOf(Architecture.x64, Architecture.x32, Architecture.arm),
listOf(OperatingSystem.linux, OperatingSystem.mac, OperatingSystem.windows),
- HeapSize.values().asList()
+ HeapSize.entries
),
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.openjdk),
listOf(Project.jdk),
listOf(JvmImpl.hotspot),
@@ -59,7 +59,7 @@ object AdoptReposTestDataGenerator {
listOf(8, 11)
),
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.alibaba),
listOf(Project.jdk),
listOf(JvmImpl.dragonwell),
@@ -70,7 +70,7 @@ object AdoptReposTestDataGenerator {
listOf(8, 11)
),
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.eclipse),
listOf(Project.jdk),
listOf(JvmImpl.hotspot),
@@ -81,7 +81,7 @@ object AdoptReposTestDataGenerator {
listOf(8, 11, 12)
),
PermittedValues(
- ReleaseType.values().asList(),
+ ReleaseType.entries,
listOf(Vendor.eclipse),
listOf(Project.jdk),
listOf(JvmImpl.hotspot),
@@ -232,7 +232,7 @@ object AdoptReposTestDataGenerator {
}
private fun exhaustiveBinaryList(): List {
- return HeapSize.values()
+ return HeapSize.entries
.map {
Binary(
createPackage(),
@@ -250,7 +250,7 @@ object AdoptReposTestDataGenerator {
)
}
.union(
- OperatingSystem.values()
+ OperatingSystem.entries
.map {
Binary(
createPackage(),
@@ -269,7 +269,7 @@ object AdoptReposTestDataGenerator {
}
)
.union(
- Architecture.values()
+ Architecture.entries
.map {
Binary(
createPackage(),
@@ -288,7 +288,7 @@ object AdoptReposTestDataGenerator {
}
)
.union(
- ImageType.values()
+ ImageType.entries
.map {
Binary(
createPackage(),
@@ -307,7 +307,7 @@ object AdoptReposTestDataGenerator {
}
)
.union(
- JvmImpl.values()
+ JvmImpl.entries
.map {
Binary(
createPackage(),
@@ -326,7 +326,7 @@ object AdoptReposTestDataGenerator {
}
)
.union(
- Project.values()
+ Project.entries
.map {
Binary(
createPackage(),
@@ -383,6 +383,7 @@ object AdoptReposTestDataGenerator {
return emptyList()
}
return releaseType
+ .asSequence()
.map { releaseBuilder()(it) }
.flatMap { builder -> vendor.map { builder(it) } }
.flatMap { builder -> getVersions(majorVersion).map { builder(it) } }
@@ -390,6 +391,7 @@ object AdoptReposTestDataGenerator {
.filter {
Vendor.validVendor(it.vendor)
}
+ .toList()
}
private fun getBinaries(): Array {
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/BaseTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/BaseTest.kt
index 76572aa1f..d9a556d96 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/BaseTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/BaseTest.kt
@@ -5,6 +5,7 @@ import io.mockk.junit5.MockKExtension
import io.mockk.mockk
import net.adoptium.api.testDoubles.InMemoryApiPersistence
import net.adoptium.api.testDoubles.InMemoryInternalDbStore
+import net.adoptium.api.testDoubles.UpdatableVersionSupplierStub
import net.adoptium.api.v3.dataSources.APIDataStoreImpl
import net.adoptium.api.v3.dataSources.UpdaterHtmlClient
import net.adoptium.api.v3.dataSources.UrlRequest
@@ -26,7 +27,7 @@ import org.junit.jupiter.api.extension.ExtendWith
@EnableAutoWeld
@ExtendWith(MockKExtension::class)
-@AddPackages(value = [InMemoryApiPersistence::class, InMemoryInternalDbStore::class, APIDataStoreImpl::class])
+@AddPackages(value = [InMemoryApiPersistence::class, InMemoryInternalDbStore::class, APIDataStoreImpl::class, UpdatableVersionSupplierStub::class])
@EnableAlternatives
abstract class BaseTest {
@@ -51,7 +52,7 @@ abstract class BaseTest {
return null
}
- override suspend fun getFullResponse(request: UrlRequest): HttpResponse? {
+ override suspend fun getFullResponse(request: UrlRequest): HttpResponse {
val metadataResponse = mockk()
val entity = mockk()
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/CachedGitHubHtmlClientTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/CachedGitHubHtmlClientTest.kt
index 23cda7411..c8718de7c 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/CachedGitHubHtmlClientTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/CachedGitHubHtmlClientTest.kt
@@ -1,6 +1,5 @@
package net.adoptium.api
-import io.mockk.Called
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.confirmVerified
@@ -15,14 +14,14 @@ import net.adoptium.api.v3.dataSources.UpdaterHtmlClient
import net.adoptium.api.v3.dataSources.UrlRequest
import net.adoptium.api.v3.dataSources.github.CachedGitHubHtmlClient
import net.adoptium.api.v3.dataSources.mongo.CacheDbEntry
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestFactory
import org.junit.jupiter.api.extension.ExtendWith
import java.time.ZonedDateTime
import java.util.stream.Stream
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertNull
@ExtendWith(MockKExtension::class)
class CachedGitHubHtmlClientTest {
@@ -115,9 +114,11 @@ class CachedGitHubHtmlClientTest {
while (client.getQueueLength() > 0) {
delay(1000)
}
- coVerify(timeout = 3000) {
- updaterHtmlClient.getFullResponse(request)?.wasNot(Called)
+
+ coVerify(timeout = 3000, exactly = 0) {
+ updaterHtmlClient.getFullResponse(request)
}
+
confirmVerified(updaterHtmlClient)
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DateTimeMigrationTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DateTimeMigrationTest.kt
index 8064d0178..567d0598f 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DateTimeMigrationTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DateTimeMigrationTest.kt
@@ -1,23 +1,29 @@
package net.adoptium.api
+import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.runBlocking
import net.adoptium.api.v3.JsonMapper
import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.dataSources.persitence.mongo.MongoClient
import net.adoptium.api.v3.models.DateTime
+import net.adoptium.api.v3.models.GitHubDownloadStatsDbEntry
+import org.bson.Document
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
-import java.util.UUID
+import java.util.*
import java.util.concurrent.TimeUnit
-class DateTimeMigrationTest : MongoTest() {
+data class HasZonedDateTime(
+ val zdt: ZonedDateTime)
+
+data class HasDateTime(
+ val zdt: DateTime)
- class HasZonedDateTime(val zdt: ZonedDateTime)
+class DateTimeMigrationTest : MongoTest() {
- class HasDateTime(val zdt: DateTime)
@Test
fun `can serialize as zdt and deserialize as DateTime`() {
@@ -39,19 +45,41 @@ class DateTimeMigrationTest : MongoTest() {
.minus(1, TimeUnit.MILLISECONDS.toChronoUnit())
val hzdt = HasZonedDateTime(date)
- val client1 = mongoClient.database.getCollection(collectionName)
+ val client1 = mongoClient.getDatabase().getCollection(collectionName)
client1.insertOne(hzdt)
- val hzdt2 = client1.findOne()
+ val hzdt2 = client1.find().firstOrNull()
assertEquals(hzdt.zdt, hzdt2?.zdt)
- val client2 = mongoClient.database.getCollection(collectionName)
- val fromDb = client2.findOne("{}")
- assertEquals(hzdt.zdt, fromDb?.zdt?.dateTime)
+ val client2 = mongoClient.getDatabase().getCollection(collectionName)
+ val fromDb = client2.find().firstOrNull()
+ assertEquals(hzdt.zdt, fromDb?.zdt)
} finally {
- mongoClient.database.dropCollection(collectionName)
+ mongoClient.getDatabase().getCollection(collectionName).drop()
+ }
+ }
+ }
+
+ @Test
+ fun `github stats`(mongoClient: MongoClient) {
+ runBlocking {
+ val collectionName = UUID.randomUUID().toString()
+ val client1 = mongoClient.getDatabase().getCollection(collectionName)
+
+ client1.insertOne(
+ GitHubDownloadStatsDbEntry(
+ TimeSource.now(),
+ 1,
+ mapOf(),
+ 1
+ )
+ )
+
+ client1.find().firstOrNull()?.let {
+ assertEquals(1, it.downloads)
}
}
+
}
@Test
@@ -67,22 +95,22 @@ class DateTimeMigrationTest : MongoTest() {
runBlocking {
try {
val hzdt = HasZonedDateTime(TimeSource.now())
- val client1 = mongoClient.database.getCollection(collectionName)
+ val client1 = mongoClient.getDatabase().getCollection(collectionName)
client1.insertOne(hzdt)
- val hzdt2 = client1.findOne()
+ val hzdt2 = client1.find().firstOrNull()
assertEquals(hzdt.zdt, hzdt2?.zdt)
- val client2 = mongoClient.database.getCollection(collectionName)
- val fromDb = client2.findOne("{}")
- assertEquals(hzdt.zdt, fromDb?.zdt?.dateTime)
+ val client2 = mongoClient.getDatabase().getCollection(collectionName)
+ val fromDb = client2.find(Document.parse("{}")).firstOrNull()
+ assertEquals(hzdt.zdt, fromDb?.zdt)
- client2.deleteMany()
+ client2.deleteMany(Document.parse("{}"))
client2.insertOne(fromDb!!)
- val fromDb2 = client2.findOne("{}")
- assertEquals(fromDb.zdt.dateTime, fromDb2?.zdt?.dateTime)
+ val fromDb2 = client2.find(Document.parse("{}")).firstOrNull()
+ assertEquals(fromDb.zdt, fromDb2?.zdt)
} finally {
- mongoClient.database.dropCollection(collectionName)
+ mongoClient.getDatabase().getCollection(collectionName).drop()
}
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DockerStatsInterfaceTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DockerStatsInterfaceTest.kt
index 077f921ed..04cd682e7 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DockerStatsInterfaceTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/DockerStatsInterfaceTest.kt
@@ -4,6 +4,7 @@ import io.mockk.coEvery
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import net.adoptium.api.testDoubles.InMemoryApiPersistence
+import net.adoptium.api.testDoubles.UpdatableVersionSupplierStub
import net.adoptium.api.v3.DownloadStatsInterface
import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.dataSources.DefaultUpdaterHtmlClient
@@ -33,7 +34,7 @@ class DockerStatsInterfaceTest : BaseTest() {
dockerStatsInterface.updateDb()
val stats = apiPersistence.getLatestAllDockerStats()
- Assertions.assertTrue(stats.size > 0)
+ Assertions.assertTrue(stats.isNotEmpty())
}
}
@@ -61,7 +62,7 @@ class DockerStatsInterfaceTest : BaseTest() {
DockerDownloadStatsDbEntry(baseTime, 100, "a-stats-repo", 8, JvmImpl.hotspot)
)
- val downloadStatsInterface = DownloadStatsInterface(apiPersistanceMock)
+ val downloadStatsInterface = DownloadStatsInterface(apiPersistanceMock, UpdatableVersionSupplierStub())
var stats = downloadStatsInterface.getTrackingStats(10, source = StatsSource.github, featureVersion = 8)
assertEquals(70, stats[0].total)
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/GraphQLGitHubReleaseClientTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/GraphQLGitHubReleaseClientTest.kt
index 40627f4e6..59ff296bb 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/GraphQLGitHubReleaseClientTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/GraphQLGitHubReleaseClientTest.kt
@@ -1,15 +1,24 @@
package net.adoptium.api
+import net.adoptium.api.v3.ReleaseFilterType
+import net.adoptium.api.v3.ReleaseIncludeFilter
import com.expediagroup.graphql.client.types.GraphQLClientRequest
import com.expediagroup.graphql.client.types.GraphQLClientResponse
+import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import net.adoptium.api.v3.AdoptRepositoryImpl
+import net.adoptium.api.v3.ReleaseResult
+import net.adoptium.api.v3.TimeSource
+import net.adoptium.api.v3.config.Ecosystem
+import net.adoptium.api.v3.dataSources.github.GitHubHtmlClient
+import net.adoptium.api.v3.dataSources.github.graphql.GraphQLGitHubClient
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubInterface
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubReleaseClient
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubReleaseRequest
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubRepositoryClient
+import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubRepositoryClient.GetQueryData
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLGitHubSummaryClient
import net.adoptium.api.v3.dataSources.github.graphql.clients.GraphQLRequest
import net.adoptium.api.v3.dataSources.github.graphql.models.GHAsset
@@ -27,8 +36,20 @@ import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHReleaseSu
import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHReleasesSummary
import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHRepositorySummary
import net.adoptium.api.v3.dataSources.models.GitHubId
+import net.adoptium.api.v3.mapping.ReleaseMapper
+import net.adoptium.api.v3.mapping.ReleaseMapper.Companion.parseDate
+import net.adoptium.api.v3.mapping.adopt.AdoptReleaseMapperFactory
+import net.adoptium.api.v3.models.DateTime
+import net.adoptium.api.v3.models.Release
+import net.adoptium.api.v3.models.ReleaseType
+import net.adoptium.api.v3.models.Vendor
+import net.adoptium.api.v3.models.VersionData
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.DynamicTest
import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.TestFactory
+import java.time.ZonedDateTime
+import java.util.stream.Stream
class GraphQLGitHubReleaseClientTest : BaseTest() {
companion object {
@@ -103,14 +124,14 @@ class GraphQLGitHubReleaseClientTest : BaseTest() {
every { builder.errors } returns null
return builder
}
- };
+ }
val graphQLGitHubInterface = GraphQLGitHubInterface(graphQLRequest, mockkHttpClient())
val graphQLGitHubReleaseRequest = GraphQLGitHubReleaseRequest(graphQLGitHubInterface)
val client = GraphQLGitHubRepositoryClient(graphQLGitHubInterface, graphQLGitHubReleaseRequest)
- val repo = client.getRepository(AdoptRepositoryImpl.ADOPT_ORG, "a-repo-name")
+ val repo = client.getRepository(AdoptRepositoryImpl.ADOPT_ORG, "a-repo-name") { _, _ -> true }
assertEquals(Companion.repo, repo)
}
@@ -182,15 +203,147 @@ class GraphQLGitHubReleaseClientTest : BaseTest() {
}
}
-
val graphQLGitHubInterface = GraphQLGitHubInterface(graphQLRequest, mockkHttpClient())
val graphQLGitHubReleaseRequest = GraphQLGitHubReleaseRequest(graphQLGitHubInterface)
val client = GraphQLGitHubRepositoryClient(graphQLGitHubInterface, graphQLGitHubReleaseRequest)
- val repo = client.getRepository(AdoptRepositoryImpl.ADOPT_ORG, "a-repo-name")
+ val repo = client.getRepository(AdoptRepositoryImpl.ADOPT_ORG, "a-repo-name") { _, _ -> true }
assertEquals(2, repo.releases.releases.size)
}
}
+
+ @TestFactory
+ fun filtersReleases(): Stream {
+ val releaseDate = parseDate("2013-02-27T19:35:32Z")
+ return listOf(
+ Triple(
+ "prereleases more than 90 days old are ignored",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(91),
+ ReleaseFilterType.ALL,
+ excludedVendors = setOf()
+ ),
+ 0
+ ),
+ Triple(
+ "prereleases less than 90 days old are not ignored",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(89),
+ ReleaseFilterType.ALL,
+ excludedVendors = setOf()
+ ),
+ 1
+ ),
+ Triple(
+ "release type filter is applied",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(89),
+ ReleaseFilterType.RELEASES_ONLY,
+ excludedVendors = setOf()
+ ),
+ 0
+ ),
+ Triple(
+ "date filter is applied to non-excluded vendor",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(91),
+ ReleaseFilterType.RELEASES_ONLY,
+ excludedVendors = setOf()
+ ),
+ 0
+ ),
+ Triple(
+ "Excluded vendor more than 90 days is ignored",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(91),
+ ReleaseFilterType.ALL,
+ excludedVendors = setOf(Vendor.getDefault())
+ ),
+ 0
+ ),
+ Triple(
+ "Excluded vendor less than 90 days is ignored",
+ ReleaseIncludeFilter(
+ releaseDate.plusDays(89),
+ ReleaseFilterType.ALL,
+ excludedVendors = setOf(Vendor.getDefault())
+ ),
+ 0
+ ),
+ )
+ .map {
+ return@map DynamicTest.dynamicTest(it.first) {
+ runBlocking {
+ val repository = setupFilterTest()
+ val repo = repository.getRelease(8, it.second)
+ assertEquals(it.third, repo.releases.getReleases().count())
+ }
+ }
+ }
+ .stream()
+ }
+
+ private fun setupFilterTest(): AdoptRepositoryImpl {
+ val graphQLRequest = object : GraphQLRequest {
+ override suspend fun request(query: GraphQLClientRequest): GraphQLClientResponse {
+ val builder = mockk>()
+
+ val match = if (Ecosystem.CURRENT == Ecosystem.adoptopenjdk) {
+ (query as GetQueryData).owner.lowercase() == "adoptopenjdk" &&
+ (query as GetQueryData).repoName == "openjdk8-binaries"
+ } else {
+ (query as GetQueryData).owner.lowercase() == "adoptium" &&
+ (query as GetQueryData).repoName == "temurin8-binaries"
+ }
+
+ if (match) {
+ every { builder.data } returns QueryData(repo, RateLimit(0, 5000)) as F
+ } else {
+ every { builder.data } returns QueryData(GHRepository(GHReleases(listOf(), PageInfo(false, null))), RateLimit(0, 5000)) as F
+ }
+
+ every { builder.errors } returns null
+ return builder
+ }
+ }
+
+ val graphQLGitHubInterface = GraphQLGitHubInterface(graphQLRequest, mockkHttpClient())
+ val graphQLGitHubReleaseRequest = GraphQLGitHubReleaseRequest(graphQLGitHubInterface)
+
+ val client = GraphQLGitHubRepositoryClient(graphQLGitHubInterface, graphQLGitHubReleaseRequest)
+
+
+ val htmlClient = mockk()
+ coEvery { htmlClient.getUrl(any()) }.returns(null)
+
+ val adoptReleaseMapperFactory = mockk()
+ every { adoptReleaseMapperFactory.get(any()) }.returns(
+ object : ReleaseMapper() {
+ override suspend fun toAdoptRelease(ghRelease: GHRelease): ReleaseResult {
+ return ReleaseResult(
+ listOf(
+ Release(
+ "foo", ReleaseType.ga, "a", "foo",
+ DateTime(ZonedDateTime.of(2010, 1, 1, 1, 1, 0, 0, TimeSource.ZONE)),
+ DateTime(ZonedDateTime.of(2010, 1, 1, 1, 1, 0, 0, TimeSource.ZONE)),
+ arrayOf(), 2, Vendor.getDefault(),
+ VersionData(8, 0, 242, "b", null, 4, "b", "")
+ ),
+ )
+ )
+ }
+ })
+
+ val repository = AdoptRepositoryImpl(
+ GraphQLGitHubClient(
+ mockk(),
+ mockk(),
+ client
+ ),
+ adoptReleaseMapperFactory
+ )
+ return repository
+ }
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/InternalDbStoreTests.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/InternalDbStoreTests.kt
index a51196edc..639431528 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/InternalDbStoreTests.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/InternalDbStoreTests.kt
@@ -5,16 +5,15 @@ import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.dataSources.mongo.CacheDbEntry
import net.adoptium.api.v3.dataSources.mongo.InternalDbStoreImpl
import net.adoptium.api.v3.dataSources.persitence.mongo.MongoClient
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
class InternalDbStoreTests : MongoTest() {
@Test
- fun `checked time is set`(mongoClient: MongoClient) {
+ fun `checked time is set`() {
runBlocking {
- val internalDbStore = InternalDbStoreImpl(mongoClient)
+ val internalDbStore = InternalDbStoreImpl(MongoClient())
val now = TimeSource.now()
val data = CacheDbEntry("foo", "bar", now, "some data")
@@ -30,7 +29,7 @@ class InternalDbStoreTests : MongoTest() {
internalDbStore.updateCheckedTime("foo", newTime)
val updated = internalDbStore.getCachedWebpage("foo")
- Assertions.assertEquals(CacheDbEntry(data.url, data.lastModified, newTime, data.data), updated)
+ assertEquals(CacheDbEntry(data.url, data.lastModified, newTime, data.data), updated)
}
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MetadataSerializationTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MetadataSerializationTest.kt
index d7e5aa52b..f56b4f692 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MetadataSerializationTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MetadataSerializationTest.kt
@@ -55,7 +55,7 @@ class MetadataSerializationTest {
val metadata = generateMetadata()
val serialized = UpdaterJsonMapper.mapper.writeValueAsString(metadata)
- var json = UpdaterJsonMapper.mapper.readValue(serialized, ObjectNode::class.java)
+ val json = UpdaterJsonMapper.mapper.readValue(serialized, ObjectNode::class.java)
json.remove("WARNING")
val noWarning = GHMetaData(null, metadata.os, metadata.arch, metadata.variant, metadata.version, metadata.scmRef, metadata.version_data, metadata.binary_type, metadata.sha256)
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoAPIPersistenceTests.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoAPIPersistenceTests.kt
index 3cd0ee542..fc8082866 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoAPIPersistenceTests.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoAPIPersistenceTests.kt
@@ -4,16 +4,15 @@ import kotlinx.coroutines.runBlocking
import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.dataSources.models.GitHubId
import net.adoptium.api.v3.dataSources.persitence.mongo.MongoApiPersistence
+import net.adoptium.api.v3.dataSources.persitence.mongo.MongoClient
import net.adoptium.api.v3.models.GHReleaseMetadata
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
class MongoAPIPersistenceTests : MongoTest() {
@Test
- fun `update time is set`(apiPersistence: MongoApiPersistence) {
+ fun `update time is set`(api: MongoApiPersistence) {
runBlocking {
- val api = apiPersistence
api.updateUpdatedTime(TimeSource.now(), "", 0)
api.updateUpdatedTime(TimeSource.now(), "", 0)
api.updateUpdatedTime(TimeSource.now(), "", 0)
@@ -22,19 +21,21 @@ class MongoAPIPersistenceTests : MongoTest() {
val stored = api.getUpdatedAt()
- Assertions.assertEquals(time, stored.time)
+ assertEquals(time, stored.time)
}
}
@Test
- fun `metadata is persisted`(apiPersistence: MongoApiPersistence) {
+ fun `metadata is persisted`() {
runBlocking {
+ val apiPersistence = MongoApiPersistence(MongoClient())
val metadata = GHReleaseMetadata(10, GitHubId("foo"))
apiPersistence.setGhReleaseMetadata(metadata)
val saved = apiPersistence.getGhReleaseMetadata(GitHubId("foo"))
+
assertEquals(metadata, saved)
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoTest.kt
index 6c1f57900..794c536b8 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/MongoTest.kt
@@ -1,11 +1,12 @@
package net.adoptium.api
+import de.flapdoodle.embed.mongo.config.ImmutableNet
import de.flapdoodle.embed.mongo.config.Net
import de.flapdoodle.embed.mongo.distribution.Version
import de.flapdoodle.embed.mongo.transitions.Mongod
import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess
-import de.flapdoodle.embed.process.runtime.Network
import de.flapdoodle.reverse.transitions.Start
+import net.adoptium.api.testDoubles.UpdatableVersionSupplierStub
import net.adoptium.api.v3.dataSources.APIDataStoreImpl
import org.jboss.weld.junit5.auto.AddPackages
import org.jboss.weld.junit5.auto.EnableAutoWeld
@@ -14,7 +15,7 @@ import org.junit.jupiter.api.BeforeAll
import org.slf4j.LoggerFactory
@EnableAutoWeld
-@AddPackages(value = [APIDataStoreImpl::class])
+@AddPackages(value = [APIDataStoreImpl::class, UpdatableVersionSupplierStub::class])
abstract class MongoTest {
companion object {
@@ -33,12 +34,13 @@ abstract class MongoTest {
@JvmStatic
fun startFongo() {
val bindIp = "localhost"
- val net = Net.of("localhost",
- Network.freeServerPort(Network.getLocalHost()),
- Network.localhostIsIPv6()
- )
- val mongodbTestConnectionString = "mongodb://$bindIp:${net.port}"
+ val net = ImmutableNet.defaults()
+
+ val port = net.port
+
+ val mongodbTestConnectionString = "mongodb://$bindIp:$port"
+
LOGGER.info("Mongo test connection string - $mongodbTestConnectionString")
System.setProperty("MONGODB_TEST_CONNECTION_STRING", mongodbTestConnectionString)
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/ReleaseVersionResolverTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/ReleaseVersionResolverTest.kt
index b7f62f1f2..ba9ddf803 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/ReleaseVersionResolverTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/ReleaseVersionResolverTest.kt
@@ -1,37 +1,16 @@
package net.adoptium.api
import kotlinx.coroutines.runBlocking
+import net.adoptium.api.testDoubles.UpdatableVersionSupplierStub
import net.adoptium.api.v3.dataSources.ReleaseVersionResolver
-import net.adoptium.api.v3.dataSources.UpdaterHtmlClient
-import net.adoptium.api.v3.dataSources.UrlRequest
import net.adoptium.api.v3.models.ReleaseInfo
-import org.apache.http.HttpResponse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
class ReleaseVersionResolverTest : BaseTest() {
private fun getReleaseVersionResolver(): ReleaseVersionResolver {
- return ReleaseVersionResolver(
-
- object : UpdaterHtmlClient {
- override suspend fun get(url: String): String? {
- return getTipMetadata()
- }
-
- fun getTipMetadata(): String {
- return """
- DEFAULT_VERSION_FEATURE=15
- DEFAULT_VERSION_INTERIM=0
- """.trimIndent()
- }
-
- override suspend fun getFullResponse(request: UrlRequest): HttpResponse? {
- return null
- }
- }
-
- )
+ return ReleaseVersionResolver(UpdatableVersionSupplierStub())
}
@Test
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/UpdateRunner.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/UpdateRunner.kt
index d75cb90b6..7f5c56121 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/UpdateRunner.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/UpdateRunner.kt
@@ -3,6 +3,7 @@ package net.adoptium.api
import kotlinx.coroutines.runBlocking
import net.adoptium.api.testDoubles.InMemoryInternalDbStore
import net.adoptium.api.v3.AdoptRepositoryImpl
+import net.adoptium.api.v3.ReleaseIncludeFilter
import net.adoptium.api.v3.V3Updater
import net.adoptium.api.v3.dataSources.DefaultUpdaterHtmlClient
import net.adoptium.api.v3.dataSources.HttpClientFactory
@@ -35,7 +36,7 @@ class UpdateRunner {
fun run(updater: V3Updater) {
System.clearProperty("GITHUB_TOKEN")
updater.run(false)
- Awaitility.await().atMost(Long.MAX_VALUE, TimeUnit.NANOSECONDS).until({ 4 == 5 })
+ Awaitility.await().atMost(Long.MAX_VALUE, TimeUnit.NANOSECONDS).until { 4 == 5 }
}
@Test
@@ -76,7 +77,7 @@ class UpdateRunner {
)
val repo = AdoptRepositoryImpl(client, AdoptReleaseMapperFactory(AdoptBinaryMapper(gitHubHtmlClient), gitHubHtmlClient))
- repo.getRelease(8)
+ repo.getRelease(8, ReleaseIncludeFilter.INCLUDE_ALL)
}
}
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/V3UpdaterTest.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/V3UpdaterTest.kt
index b4e0a8035..75997d588 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/V3UpdaterTest.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/V3UpdaterTest.kt
@@ -1,8 +1,12 @@
package net.adoptium.api
+import net.adoptium.api.v3.ReleaseIncludeFilter
import kotlinx.coroutines.runBlocking
+import net.adoptium.api.v3.ReleaseFilterType
+import net.adoptium.api.v3.TimeSource
import net.adoptium.api.v3.V3Updater
import net.adoptium.api.v3.dataSources.models.AdoptRepos
+import net.adoptium.api.v3.models.ReleaseType
import net.adoptium.api.v3.models.Vendor
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertTrue
@@ -30,23 +34,30 @@ class V3UpdaterTest {
fun `adoptOpenJdk releases are copied over`() {
runBlocking {
- val repo = AdoptReposTestDataGenerator.generate();
+ val repo = AdoptReposTestDataGenerator.generate()
+
+ val filter = ReleaseIncludeFilter(
+ TimeSource.now(),
+ ReleaseFilterType.ALL,
+ false,
+ setOf(Vendor.adoptopenjdk)
+ )
val adoptopenjdk = AdoptRepos(emptyList()).addAll(repo
.allReleases
.getReleases()
- .filter { it.vendor == Vendor.adoptopenjdk }
+ .filter { filter.filter(it.vendor, it.updated_at.dateTime, it.release_type == ReleaseType.ea) }
.toList()
)
val notAdoptopenjdk = AdoptRepos(emptyList()).addAll(repo
.allReleases
.getReleases()
- .filter { it.vendor != Vendor.adoptopenjdk }
+ .filter { !filter.filter(it.vendor, it.updated_at.dateTime, it.release_type == ReleaseType.ea) }
.toList()
)
- val concated = V3Updater.copyOldReleasesIntoNewRepo(adoptopenjdk, notAdoptopenjdk)
+ val concated = V3Updater.copyOldReleasesIntoNewRepo(adoptopenjdk, notAdoptopenjdk, filter)
Assertions.assertEquals(repo, concated)
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/AdoptRepositoryStub.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/AdoptRepositoryStub.kt
index 0b942761e..b08bd2477 100644
--- a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/AdoptRepositoryStub.kt
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/AdoptRepositoryStub.kt
@@ -1,5 +1,6 @@
package net.adoptium.api.testDoubles
+import net.adoptium.api.v3.ReleaseIncludeFilter
import jakarta.annotation.Priority
import jakarta.enterprise.context.ApplicationScoped
import jakarta.enterprise.inject.Alternative
@@ -48,7 +49,7 @@ open class AdoptRepositoryStub : AdoptRepository {
.addRelease(8, toAddSemiYoungRelease)
companion object {
- val unchangedIndex = 3
+ const val unchangedIndex = 3
val toAdd = Release(
"foo", ReleaseType.ga, "openjdk-8u", "jdk8u-2018-09-27-08-50",
@@ -74,7 +75,7 @@ open class AdoptRepositoryStub : AdoptRepository {
)
}
- override suspend fun getRelease(version: Int): FeatureRelease? {
+ override suspend fun getRelease(version: Int, filter: ReleaseIncludeFilter): FeatureRelease? {
return updated.getFeatureRelease(version)
}
diff --git a/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/UpdatableVersionSupplierStub.kt b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/UpdatableVersionSupplierStub.kt
new file mode 100644
index 000000000..5e5db25c3
--- /dev/null
+++ b/adoptium-updater-parent/adoptium-api-v3-updater/src/test/kotlin/net/adoptium/api/testDoubles/UpdatableVersionSupplierStub.kt
@@ -0,0 +1,27 @@
+package net.adoptium.api.testDoubles
+
+import jakarta.annotation.Priority
+import jakarta.enterprise.context.ApplicationScoped
+import jakarta.enterprise.inject.Alternative
+import net.adoptium.api.v3.dataSources.UpdatableVersionSupplier
+
+@Priority(1)
+@Alternative
+@ApplicationScoped
+class UpdatableVersionSupplierStub : UpdatableVersionSupplier {
+ override suspend fun updateVersions() {
+ // NOP
+ }
+
+ override fun getTipVersion(): Int {
+ return 15
+ }
+
+ override fun getLtsVersions(): Array {
+ return arrayOf(8, 11)
+ }
+
+ override fun getAllVersions(): Array {
+ return listOf(8, 10, 11, 12, 18).toList().toTypedArray()
+ }
+}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/pom.xml b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/pom.xml
index 4fe3a3957..7d32ca974 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/pom.xml
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/pom.xml
@@ -19,18 +19,18 @@
io.jsonwebtoken
jjwt-api
- 0.12.5
+ 0.12.6
io.jsonwebtoken
jjwt-impl
- 0.12.5
+ 0.12.6
runtime
io.jsonwebtoken
jjwt-jackson
- 0.12.5
+ 0.12.6
runtime
@@ -50,12 +50,27 @@
org.kohsuke
github-api
- 1.321
+ 1.326
net.adoptium.api
adoptium-api-v3-persistence
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
+ jakarta.ws.rs
+ jakarta.ws.rs-api
+
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdaterJsonMapper.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdaterJsonMapper.kt
index 1a6bbaa20..27afdb0da 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdaterJsonMapper.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/UpdaterJsonMapper.kt
@@ -5,11 +5,21 @@ import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsonp.JSONPModule
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
+import jakarta.ws.rs.Produces
+import jakarta.ws.rs.ext.Provider
-object UpdaterJsonMapper {
- val mapper: ObjectMapper = ObjectMapper()
- .setSerializationInclusion(JsonInclude.Include.NON_NULL)
- .registerModule(KotlinModule.Builder().build())
- .registerModule(JavaTimeModule())
- .registerModule(JSONPModule())
+@Provider
+class UpdaterJsonMapper {
+ companion object {
+ val mapper: ObjectMapper = ObjectMapper()
+ .setSerializationInclusion(JsonInclude.Include.NON_NULL)
+ .registerModule(KotlinModule.Builder().build())
+ .registerModule(JavaTimeModule())
+ .registerModule(JSONPModule())
+ }
+
+ @Produces
+ fun getObjectMapper(): ObjectMapper {
+ return mapper
+ }
}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubApi.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubApi.kt
index 5144c9bd5..f27d1f49f 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubApi.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubApi.kt
@@ -6,7 +6,7 @@ import net.adoptium.api.v3.dataSources.github.graphql.models.summary.GHRepositor
import net.adoptium.api.v3.dataSources.models.GitHubId
interface GitHubApi {
- suspend fun getRepository(owner: String, repoName: String): GHRepository
+ suspend fun getRepository(owner: String, repoName: String, filter: (updatedAt: String, isPrerelease: Boolean) -> Boolean): GHRepository
suspend fun getRepositorySummary(owner: String, repoName: String): GHRepositorySummary
suspend fun getReleaseById(id: GitHubId): GHRelease?
}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubAuth.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubAuth.kt
index 354b9187b..c4b129b08 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubAuth.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/GitHubAuth.kt
@@ -75,7 +75,7 @@ class GitHubAuth {
return token
}
- private suspend fun authenticateAsGitHubApp(appId: String, privateKey: String, installationId: String): GHAppInstallationToken {
+ private fun authenticateAsGitHubApp(appId: String, privateKey: String, installationId: String): GHAppInstallationToken {
try {
// Remove the first and last lines
val sanitizedKey = privateKey
@@ -101,7 +101,7 @@ class GitHubAuth {
.compact()
val gitHubApp: GitHub = GitHubBuilder().withJwtToken(jwtToken).build()
- val appInstallation: GHAppInstallation = gitHubApp.getApp().getInstallationById(installationId.toLong())
+ val appInstallation: GHAppInstallation = gitHubApp.app.getInstallationById(installationId.toLong())
return appInstallation.createToken().create()
} catch (e: Exception) {
LOGGER.error("Error authenticating as GitHub App", e)
@@ -110,5 +110,5 @@ class GitHubAuth {
}
}
- class FailedToAuthenticateException : Exception("Failed to authenticate to GitHub") {}
+ class FailedToAuthenticateException : Exception("Failed to authenticate to GitHub")
}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/GraphQLGitHubClient.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/GraphQLGitHubClient.kt
index ae9772c88..15166684c 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/GraphQLGitHubClient.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/GraphQLGitHubClient.kt
@@ -26,7 +26,7 @@ open class GraphQLGitHubClient @Inject constructor(
return releaseClient.getReleaseById(id)
}
- override suspend fun getRepository(owner: String, repoName: String): GHRepository {
- return repositoryClientClient.getRepository(owner, repoName)
+ override suspend fun getRepository(owner: String, repoName: String, filter: (updatedAt: String, isPrerelease: Boolean) -> Boolean): GHRepository {
+ return repositoryClientClient.getRepository(owner, repoName, filter)
}
}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubInterface.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubInterface.kt
index 11ada77b3..d17f0b0e1 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubInterface.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubInterface.kt
@@ -188,7 +188,7 @@ open class GraphQLGitHubInterface @Inject constructor(
}
} catch (e: MismatchedInputException) {
- return null;
+ return null
} catch (e: Exception) {
LOGGER.error("Query failed", e)
throw e
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubReleaseRequest.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubReleaseRequest.kt
index eff1d4cc1..05678ccad 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubReleaseRequest.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubReleaseRequest.kt
@@ -3,7 +3,6 @@ package net.adoptium.api.v3.dataSources.github.graphql.clients
import com.expediagroup.graphql.client.types.GraphQLClientRequest
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
-import net.adoptium.api.v3.dataSources.UpdaterHtmlClient
import net.adoptium.api.v3.dataSources.github.graphql.models.GHAssets
import net.adoptium.api.v3.dataSources.github.graphql.models.GHRelease
import net.adoptium.api.v3.dataSources.github.graphql.models.PageInfo
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubRepositoryClient.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubRepositoryClient.kt
index c011b6414..f110a88f0 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubRepositoryClient.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLGitHubRepositoryClient.kt
@@ -23,14 +23,17 @@ open class GraphQLGitHubRepositoryClient @Inject constructor(
private val LOGGER = LoggerFactory.getLogger(this::class.java)
}
- open suspend fun getRepository(owner: String, repoName: String): GHRepository {
+ open suspend fun getRepository(
+ owner: String,
+ repoName: String,
+ filter: (updateTime: String, isPrerelease: Boolean) -> Boolean): GHRepository {
val query = GetQueryData(owner, repoName)
LOGGER.info("Getting repo $repoName")
val releases = graphQLGitHubInterface.getAll(
query::withCursor,
- { request -> getAllAssets(request) },
+ { request -> getAllAssets(request, filter) },
{ it.repository!!.releases.pageInfo.hasNextPage },
{ it.repository!!.releases.pageInfo.endCursor }
)
@@ -40,11 +43,18 @@ open class GraphQLGitHubRepositoryClient @Inject constructor(
return GHRepository(GHReleases(releases, PageInfo(false, null)))
}
- private suspend fun getAllAssets(request: QueryData): List {
+ private suspend fun getAllAssets(request: QueryData, filter: (updateTime: String, isPrerelease: Boolean) -> Boolean): List {
if (request.repository == null) return listOf()
// nested releases based on how we deserialise githubs data
return request.repository.releases.releases
+ .filter {
+ val include = filter(it.updatedAt, it.isPrerelease)
+ if (!include) {
+ LOGGER.debug("Excluding " + it.url)
+ }
+ return@filter include
+ }
.map { release ->
if (release.releaseAssets.pageInfo.hasNextPage) {
graphQLGitHubReleaseRequest.getAllReleaseAssets(release)
@@ -54,7 +64,7 @@ open class GraphQLGitHubRepositoryClient @Inject constructor(
}
}
- private class GetQueryData(private val owner: String, private val repoName: String, override val variables: Any = mapOf()) :
+ class GetQueryData(val owner: String, val repoName: String, override val variables: Any = mapOf()) :
GraphQLClientRequest {
fun withCursor(cursor: String?): GetQueryData {
@@ -75,7 +85,7 @@ open class GraphQLGitHubRepositoryClient @Inject constructor(
updatedAt,
isPrerelease,
resourcePath,
- releaseAssets(first:50) {
+ releaseAssets(first:1) {
totalCount,
nodes {
downloadCount,
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLRequestImpl.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLRequestImpl.kt
index ac2ea79f3..f044e55b6 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLRequestImpl.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/github/graphql/clients/GraphQLRequestImpl.kt
@@ -15,11 +15,10 @@ import java.net.URL
open class GraphQLRequestImpl : GraphQLRequest {
private val client: GraphQLKtorClient
- private val httpClient: HttpClient
+ private val httpClient: HttpClient = HttpClient()
val BASE_URL = "https://api.github.com/graphql"
init {
- httpClient = HttpClient()
client = GraphQLKtorClient(
url = URL(BASE_URL),
httpClient = httpClient,
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/mongo/InternalDbStore.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/mongo/InternalDbStore.kt
index dc9779039..13f3f1f48 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/mongo/InternalDbStore.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-github-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/mongo/InternalDbStore.kt
@@ -1,11 +1,13 @@
package net.adoptium.api.v3.dataSources.mongo
import com.mongodb.client.model.IndexOptions
-import com.mongodb.client.model.UpdateOptions
+import com.mongodb.client.model.ReplaceOptions
+import com.mongodb.kotlin.client.coroutine.MongoCollection
import jakarta.enterprise.context.ApplicationScoped
import jakarta.inject.Inject
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
+import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import net.adoptium.api.v3.dataSources.persitence.mongo.MongoClient
@@ -13,7 +15,6 @@ import net.adoptium.api.v3.dataSources.persitence.mongo.MongoInterface
import org.bson.BsonDateTime
import org.bson.BsonDocument
import org.bson.Document
-import org.litote.kmongo.coroutine.CoroutineCollection
import java.time.ZonedDateTime
interface InternalDbStore {
@@ -24,27 +25,26 @@ interface InternalDbStore {
@ApplicationScoped
open class InternalDbStoreImpl @Inject constructor(mongoClient: MongoClient) : MongoInterface(), InternalDbStore {
- private val webCache: CoroutineCollection = createCollection(mongoClient.database, "web-cache")
+ private val webCache: MongoCollection = createCollection(mongoClient.getDatabase(), "web-cache")
init {
runBlocking {
- webCache.createIndex("""{"url":1}""", IndexOptions().background(true))
+ webCache.createIndex(Document.parse("""{"url":1}"""), IndexOptions().background(true))
}
}
override fun putCachedWebpage(url: String, lastModified: String?, date: ZonedDateTime, data: String?): Job {
return GlobalScope.launch {
- webCache.updateOne(
+ webCache.replaceOne(
Document("url", url),
CacheDbEntry(url, lastModified, date, data),
- UpdateOptions().upsert(true),
- false
+ ReplaceOptions().upsert(true)
)
}
}
override suspend fun getCachedWebpage(url: String): CacheDbEntry? {
- return webCache.findOne(Document("url", url))
+ return webCache.find(Document("url", url)).firstOrNull()
}
override suspend fun updateCheckedTime(url: String, dateTime: ZonedDateTime) {
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/pom.xml b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/pom.xml
index bce43c779..813146b4f 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/pom.xml
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/pom.xml
@@ -51,24 +51,35 @@
io.jsonwebtoken
jjwt-api
- 0.12.5
+ 0.12.6
io.jsonwebtoken
jjwt-impl
- 0.12.5
+ 0.12.6
runtime
io.jsonwebtoken
jjwt-jackson
- 0.12.5
+ 0.12.6
runtime
org.kohsuke
github-api
- 1.321
+ 1.326
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/DefaultUpdaterHtmlClient.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/DefaultUpdaterHtmlClient.kt
index 07e75b73e..9ca335361 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/DefaultUpdaterHtmlClient.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/DefaultUpdaterHtmlClient.kt
@@ -141,7 +141,7 @@ open class DefaultUpdaterHtmlClient @Inject constructor(
try {
LOGGER.debug("Getting ${request.url} ${request.lastModified}")
val response: HttpResponse = withTimeout(REQUEST_TIMEOUT) {
- suspendCoroutine { continuation ->
+ suspendCoroutine { continuation ->
getData(request, continuation, authInfo?.token)
}
}
diff --git a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/GitHubAuth.kt b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/GitHubAuth.kt
index c2cc24a74..0f5532943 100644
--- a/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/GitHubAuth.kt
+++ b/adoptium-updater-parent/adoptium-datasources-parent/adoptium-http-client-datasource/src/main/kotlin/net/adoptium/api/v3/dataSources/GitHubAuth.kt
@@ -73,7 +73,7 @@ class GitHubAuth {
return token
}
- private suspend fun authenticateAsGitHubApp(appId: String, privateKey: String, installationId: String): GHAppInstallationToken {
+ private fun authenticateAsGitHubApp(appId: String, privateKey: String, installationId: String): GHAppInstallationToken {
try {
// Remove the first and last lines
val sanitizedKey = privateKey
@@ -99,7 +99,7 @@ class GitHubAuth {
.compact()
val gitHubApp: GitHub = GitHubBuilder().withJwtToken(jwtToken).build()
- val appInstallation: GHAppInstallation = gitHubApp.getApp().getInstallationById(installationId.toLong())
+ val appInstallation: GHAppInstallation = gitHubApp.app.getInstallationById(installationId.toLong())
return appInstallation.createToken().create()
} catch (e: Exception) {
LOGGER.error("Error authenticating as GitHub App", e)
@@ -108,5 +108,5 @@ class GitHubAuth {
}
}
- class FailedToAuthenticateException : Exception("Failed to authenticate as GitHub App") {}
+ class FailedToAuthenticateException : Exception("Failed to authenticate as GitHub App")
}
diff --git a/adoptium-updater-parent/adoptium-mappers-parent/adopt-mappers/pom.xml b/adoptium-updater-parent/adoptium-mappers-parent/adopt-mappers/pom.xml
index 0cf0cc5c1..2e63a2388 100644
--- a/adoptium-updater-parent/adoptium-mappers-parent/adopt-mappers/pom.xml
+++ b/adoptium-updater-parent/adoptium-mappers-parent/adopt-mappers/pom.xml
@@ -22,11 +22,21 @@
adoptium-github-datasource
${project.version}