Skip to content

Commit 1641080

Browse files
committed
refactor(EvaluatorCommand): Avoid storing URLs in sets
`URL`'s `equals()` and `hashCode()` methods can perform a DNS lookup to resolve the host name, which may cause significant delays. So avoid using `URL` instances in sets by using `URI` instances instead. Also see 17e7327. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 758b439 commit 1641080

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

plugins/commands/evaluator/src/main/kotlin/EvaluatorCommand.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import com.github.ajalt.clikt.parameters.types.enum
3232
import com.github.ajalt.clikt.parameters.types.file
3333

3434
import java.io.File
35-
import java.net.URL
35+
import java.net.URI
3636
import java.time.Duration
3737

3838
import kotlin.time.toKotlinDuration
@@ -198,13 +198,13 @@ class EvaluatorCommand : OrtCommand(
198198
).flag()
199199

200200
override fun run() {
201-
val scriptUrls = mutableSetOf<URL>()
201+
val scriptUrls = mutableSetOf<URI>()
202202

203-
rulesFile.mapTo(scriptUrls) { it.toURI().toURL() }
204-
rulesResource.mapTo(scriptUrls) { javaClass.getResource(it) }
203+
rulesFile.mapTo(scriptUrls) { it.toURI() }
204+
rulesResource.mapTo(scriptUrls) { javaClass.getResource(it).toURI() }
205205

206206
if (scriptUrls.isEmpty()) {
207-
scriptUrls += ortConfigDirectory.resolve(ORT_EVALUATOR_RULES_FILENAME).toURI().toURL()
207+
scriptUrls += ortConfigDirectory.resolve(ORT_EVALUATOR_RULES_FILENAME).toURI()
208208
}
209209

210210
val configurationFiles = listOfNotNull(
@@ -238,7 +238,7 @@ class EvaluatorCommand : OrtCommand(
238238
var allChecksSucceeded = true
239239

240240
scriptUrls.forEach {
241-
if (evaluator.checkSyntax(it.readText())) {
241+
if (evaluator.checkSyntax(it.toURL().readText())) {
242242
println("Syntax check for $it succeeded.")
243243
} else {
244244
println("Syntax check for $it failed.")
@@ -312,7 +312,7 @@ class EvaluatorCommand : OrtCommand(
312312
licenseClassificationsFile.takeIf { it.isFile }?.readValue<LicenseClassifications>().orEmpty()
313313
val evaluator = Evaluator(ortResultInput, licenseInfoResolver, resolutionProvider, licenseClassifications)
314314

315-
val scripts = scriptUrls.map { it.readText() }
315+
val scripts = scriptUrls.map { it.toURL().readText() }
316316
val evaluatorRun = evaluator.run(*scripts.toTypedArray())
317317

318318
val duration = with(evaluatorRun) { Duration.between(startTime, endTime).toKotlinDuration() }

0 commit comments

Comments
 (0)