From b438156d0a560868a348b9be206ba53852e19939 Mon Sep 17 00:00:00 2001 From: Robinson Date: Wed, 14 Apr 2021 11:39:25 +0200 Subject: [PATCH] Changed from coroutine to futures (so we don't require coroutines as part of the build script) --- LICENSE | 6 --- build.gradle.kts | 2 - src/dorkbox/gradle/GetVersionInfoTask.kt | 53 ++++++++++++------------ 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/LICENSE b/LICENSE index a639a5b..1e23897 100644 --- a/LICENSE +++ b/LICENSE @@ -13,12 +13,6 @@ 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 - - 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. [The JSON License] https://github.com/stleary/JSON-java diff --git a/build.gradle.kts b/build.gradle.kts index ab8d9ee..cebefaa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -83,8 +83,6 @@ repositories { 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 compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin") diff --git a/src/dorkbox/gradle/GetVersionInfoTask.kt b/src/dorkbox/gradle/GetVersionInfoTask.kt index 0f219b9..38fa126 100644 --- a/src/dorkbox/gradle/GetVersionInfoTask.kt +++ b/src/dorkbox/gradle/GetVersionInfoTask.kt @@ -16,7 +16,6 @@ package dorkbox.gradle import com.dorkbox.version.Version -import kotlinx.coroutines.* import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.tasks.TaskAction @@ -24,6 +23,7 @@ import java.io.InputStreamReader import java.net.URL import java.util.* import java.util.concurrent.Executors +import java.util.concurrent.Future import java.util.concurrent.locks.ReentrantReadWriteLock import kotlin.concurrent.write @@ -49,7 +49,7 @@ GetVersionInfoTask : DefaultTask() { private val releaseMatcher = """^.*()(.*)(<\/release>)""".toRegex() private val versionMatcher = """^.*()(.*)(<\/version>)""".toRegex() - private val httpDispatcher = Executors.newFixedThreadPool(8).asCoroutineDispatcher() + private val httpDispatcher = Executors.newFixedThreadPool(8) private fun getLatestVersionInfo( repositories: List, @@ -58,7 +58,7 @@ GetVersionInfoTask : DefaultTask() { // first get all version information across ALL projects. // do this in parallel with coroutines! - val jobs = mutableListOf() + val futures = mutableListOf>() val mergedVersionInfo = mutableMapOf() val downloadLock = ReentrantReadWriteLock() @@ -73,42 +73,41 @@ GetVersionInfoTask : DefaultTask() { } } - val job = GlobalScope.launch { - withContext(httpDispatcher) { - repositories.forEach { repoUrl -> - try { - val url = URL(repoUrl + metadataUrl) - // println("Trying: $url") - with(url.openConnection() as java.net.HttpURLConnection) { - InputStreamReader(inputStream).readLines().forEach { line -> - var matchResult = releaseMatcher.find(line) - if (matchResult != null) { - val (_, ver, _) = matchResult.destructured - downloadLock.write { - depVersionInfo.updateReleaseVersion(ver) - } + val future = httpDispatcher.submit { + repositories.forEach { repoUrl -> + try { + val url = URL(repoUrl + metadataUrl) + // println("Trying: $url") + with(url.openConnection() as java.net.HttpURLConnection) { + InputStreamReader(inputStream).readLines().forEach { line -> + var matchResult = releaseMatcher.find(line) + if (matchResult != null) { + val (_, ver, _) = matchResult.destructured + downloadLock.write { + depVersionInfo.updateReleaseVersion(ver) } + } - matchResult = versionMatcher.find(line) - if (matchResult != null) { - val (_, ver, _) = matchResult.destructured - downloadLock.write { - depVersionInfo.addVersion(ver) - } + matchResult = versionMatcher.find(line) + if (matchResult != null) { + val (_, ver, _) = matchResult.destructured + downloadLock.write { + depVersionInfo.addVersion(ver) } } } - } catch (e: Exception) { } + } catch (e: Exception) { } } } - jobs.add(job) + + futures.add(future) } println("\tGetting version data for ${mergedDeps.size} dependencies...") - runBlocking { - jobs.forEach { it.join() } + futures.forEach { + it.get() } downloadLock.write {