Changed from coroutine to futures (so we don't require coroutines as part of the build script)

This commit is contained in:
Robinson 2021-04-14 11:39:25 +02:00
parent 8a74fe2ff9
commit b438156d0a
3 changed files with 26 additions and 35 deletions

View File

@ -13,12 +13,6 @@
Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply Kotlin Compiler, Test Data+Libraries, and Tools repository contain third-party code, to which different licenses may apply
See: https://github.com/JetBrains/kotlin/blob/master/license/README.md See: https://github.com/JetBrains/kotlin/blob/master/license/README.md
- kotlinx.coroutines - Library support for Kotlin coroutines with multiplatform support
[The Apache Software License, Version 2.0]
https://github.com/Kotlin/kotlinx.coroutines
Copyright 2021
JetBrains s.r.o.
- JSON in Java - A light-weight language independent data interchange format. - JSON in Java - A light-weight language independent data interchange format.
[The JSON License] [The JSON License]
https://github.com/stleary/JSON-java https://github.com/stleary/JSON-java

View File

@ -83,8 +83,6 @@ repositories {
dependencies { dependencies {
// compile only, so we dont force kotlin/dsl version info into dependencies // compile only, so we dont force kotlin/dsl version info into dependencies
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9")
// the kotlin version is taken from the plugin, so it is not necessary to set it here // the kotlin version is taken from the plugin, so it is not necessary to set it here
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin") compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin")

View File

@ -16,7 +16,6 @@
package dorkbox.gradle package dorkbox.gradle
import com.dorkbox.version.Version import com.dorkbox.version.Version
import kotlinx.coroutines.*
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskAction
@ -24,6 +23,7 @@ import java.io.InputStreamReader
import java.net.URL import java.net.URL
import java.util.* import java.util.*
import java.util.concurrent.Executors import java.util.concurrent.Executors
import java.util.concurrent.Future
import java.util.concurrent.locks.ReentrantReadWriteLock import java.util.concurrent.locks.ReentrantReadWriteLock
import kotlin.concurrent.write import kotlin.concurrent.write
@ -49,7 +49,7 @@ GetVersionInfoTask : DefaultTask() {
private val releaseMatcher = """^.*(<release>)(.*)(<\/release>)""".toRegex() private val releaseMatcher = """^.*(<release>)(.*)(<\/release>)""".toRegex()
private val versionMatcher = """^.*(<version>)(.*)(<\/version>)""".toRegex() private val versionMatcher = """^.*(<version>)(.*)(<\/version>)""".toRegex()
private val httpDispatcher = Executors.newFixedThreadPool(8).asCoroutineDispatcher() private val httpDispatcher = Executors.newFixedThreadPool(8)
private fun getLatestVersionInfo( private fun getLatestVersionInfo(
repositories: List<String>, repositories: List<String>,
@ -58,7 +58,7 @@ GetVersionInfoTask : DefaultTask() {
// first get all version information across ALL projects. // first get all version information across ALL projects.
// do this in parallel with coroutines! // do this in parallel with coroutines!
val jobs = mutableListOf<Job>() val futures = mutableListOf<Future<*>>()
val mergedVersionInfo = mutableMapOf<DependencyScanner.Maven, VersionHolder>() val mergedVersionInfo = mutableMapOf<DependencyScanner.Maven, VersionHolder>()
val downloadLock = ReentrantReadWriteLock() val downloadLock = ReentrantReadWriteLock()
@ -73,42 +73,41 @@ GetVersionInfoTask : DefaultTask() {
} }
} }
val job = GlobalScope.launch { val future = httpDispatcher.submit {
withContext(httpDispatcher) { repositories.forEach { repoUrl ->
repositories.forEach { repoUrl -> try {
try { val url = URL(repoUrl + metadataUrl)
val url = URL(repoUrl + metadataUrl) // println("Trying: $url")
// println("Trying: $url") with(url.openConnection() as java.net.HttpURLConnection) {
with(url.openConnection() as java.net.HttpURLConnection) { InputStreamReader(inputStream).readLines().forEach { line ->
InputStreamReader(inputStream).readLines().forEach { line -> var matchResult = releaseMatcher.find(line)
var matchResult = releaseMatcher.find(line) if (matchResult != null) {
if (matchResult != null) { val (_, ver, _) = matchResult.destructured
val (_, ver, _) = matchResult.destructured downloadLock.write {
downloadLock.write { depVersionInfo.updateReleaseVersion(ver)
depVersionInfo.updateReleaseVersion(ver)
}
} }
}
matchResult = versionMatcher.find(line) matchResult = versionMatcher.find(line)
if (matchResult != null) { if (matchResult != null) {
val (_, ver, _) = matchResult.destructured val (_, ver, _) = matchResult.destructured
downloadLock.write { downloadLock.write {
depVersionInfo.addVersion(ver) depVersionInfo.addVersion(ver)
}
} }
} }
} }
} catch (e: Exception) {
} }
} catch (e: Exception) {
} }
} }
} }
jobs.add(job)
futures.add(future)
} }
println("\tGetting version data for ${mergedDeps.size} dependencies...") println("\tGetting version data for ${mergedDeps.size} dependencies...")
runBlocking { futures.forEach {
jobs.forEach { it.join() } it.get()
} }
downloadLock.write { downloadLock.write {