From 5f595b23a4d7e6f9dd8cc5e0af61926021141c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Thu, 25 Jun 2020 23:17:47 +0200 Subject: [PATCH] Reuse thread pool from `FileCache` --- .../lmcoursier/internal/ArtifactsRun.scala | 90 +++++++++---------- .../lmcoursier/internal/ResolutionRun.scala | 85 +++++++++--------- 2 files changed, 83 insertions(+), 92 deletions(-) diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ArtifactsRun.scala b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ArtifactsRun.scala index f208fd2ec..356aaf447 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ArtifactsRun.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ArtifactsRun.scala @@ -2,7 +2,6 @@ package lmcoursier.internal import java.io.File -import coursier.cache.internal.ThreadUtil import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay, RefreshLogger} import coursier.core.Type import coursier.util.Artifact @@ -38,53 +37,50 @@ object ArtifactsRun { else "" - ThreadUtil.withFixedThreadPool(params.parallel) { pool => - - coursier.Artifacts() - .withResolutions(params.resolutions) - .withArtifactTypes(Set(Type.all)) - .withClassifiers(params.classifiers.getOrElse(Nil).toSet) - .withClasspathOrder(params.classpathOrder) - .addExtraArtifacts { l => - if (params.includeSignatures) - l.flatMap(_._3.extra.get("sig").toSeq) - else - Nil - } - .addTransformArtifacts { artifacts => - if (params.missingOk) - artifacts.map { - case (dependency, publication, artifact) => - (dependency, publication, artifact.withOptional(true)) + coursier.Artifacts() + .withResolutions(params.resolutions) + .withArtifactTypes(Set(Type.all)) + .withClassifiers(params.classifiers.getOrElse(Nil).toSet) + .withClasspathOrder(params.classpathOrder) + .addExtraArtifacts { l => + if (params.includeSignatures) + l.flatMap(_._3.extra.get("sig").toSeq) + else + Nil + } + .addTransformArtifacts { artifacts => + if (params.missingOk) + artifacts.map { + case (dependency, publication, artifact) => + (dependency, publication, artifact.withOptional(true)) + } + else + artifacts + } + .withCache( + params + .cache + .withLogger( + params.loggerOpt.getOrElse { + RefreshLogger.create( + if (RefreshLogger.defaultFallbackMode) + new FallbackRefreshDisplay() + else + ProgressBarRefreshDisplay.create( + if (printOptionalMessage) log.info(artifactInitialMessage), + if (printOptionalMessage || verbosityLevel >= 2) + log.info( + s"Fetched artifacts of ${params.projectName}" + + (if (params.sbtClassifiers) " (sbt classifiers)" else "") + ) + ) + ) } - else - artifacts - } - .withCache( - params - .cache - .withPool(pool) - .withLogger( - params.loggerOpt.getOrElse { - RefreshLogger.create( - if (RefreshLogger.defaultFallbackMode) - new FallbackRefreshDisplay() - else - ProgressBarRefreshDisplay.create( - if (printOptionalMessage) log.info(artifactInitialMessage), - if (printOptionalMessage || verbosityLevel >= 2) - log.info( - s"Fetched artifacts of ${params.projectName}" + - (if (params.sbtClassifiers) " (sbt classifiers)" else "") - ) - ) - ) - } - ) - ) - .eitherResult() - .map(_.fullDetailedArtifacts) // FIXME Misses extraArtifacts, that we don't use for now though - } + ) + ) + .eitherResult() + .map(_.fullDetailedArtifacts) // FIXME Misses extraArtifacts, that we don't use for now though + } } diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionRun.scala b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionRun.scala index 3a976d71d..0f9c6d8ea 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionRun.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionRun.scala @@ -1,6 +1,5 @@ package lmcoursier.internal -import coursier.cache.internal.ThreadUtil import coursier.{Resolution, Resolve} import coursier.cache.loggers.{FallbackRefreshDisplay, ProgressBarRefreshDisplay, RefreshLogger} import coursier.core._ @@ -80,51 +79,47 @@ object ResolutionRun { if (verbosityLevel >= 2) log.info(initialMessage) - ThreadUtil.withFixedThreadPool(params.parallel) { pool => - - Resolve() - // re-using various caches from a resolution of a configuration we extend - .withInitialResolution(startingResolutionOpt) - .withDependencies( - params.dependencies.collect { - case (config, dep) if configs(config) => - dep - } - ) - .withRepositories(repositories) - .withResolutionParams( - params - .params - .addForceVersion((if (isSandboxConfig) Nil else params.interProjectDependencies.map(_.moduleVersion)): _*) - .withForceScalaVersion(params.autoScalaLibOpt.nonEmpty) - .withScalaVersionOpt(params.autoScalaLibOpt.map(_._2)) - .withTypelevel(params.params.typelevel) - .withRules(rules) - ) - .withCache( - params - .cache - .withPool(pool) - .withLogger( - params.loggerOpt.getOrElse { - RefreshLogger.create( - if (RefreshLogger.defaultFallbackMode) - new FallbackRefreshDisplay() - else - ProgressBarRefreshDisplay.create( - if (printOptionalMessage) log.info(initialMessage), - if (printOptionalMessage || verbosityLevel >= 2) - log.info(s"Resolved ${params.projectName} dependencies") - ) - ) - } - ) - ) - .either() match { - case Left(err) if params.missingOk => Right(err.resolution) - case others => others + Resolve() + // re-using various caches from a resolution of a configuration we extend + .withInitialResolution(startingResolutionOpt) + .withDependencies( + params.dependencies.collect { + case (config, dep) if configs(config) => + dep } - } + ) + .withRepositories(repositories) + .withResolutionParams( + params + .params + .addForceVersion((if (isSandboxConfig) Nil else params.interProjectDependencies.map(_.moduleVersion)): _*) + .withForceScalaVersion(params.autoScalaLibOpt.nonEmpty) + .withScalaVersionOpt(params.autoScalaLibOpt.map(_._2)) + .withTypelevel(params.params.typelevel) + .withRules(rules) + ) + .withCache( + params + .cache + .withLogger( + params.loggerOpt.getOrElse { + RefreshLogger.create( + if (RefreshLogger.defaultFallbackMode) + new FallbackRefreshDisplay() + else + ProgressBarRefreshDisplay.create( + if (printOptionalMessage) log.info(initialMessage), + if (printOptionalMessage || verbosityLevel >= 2) + log.info(s"Resolved ${params.projectName} dependencies") + ) + ) + } + ) + ) + .either() match { + case Left(err) if params.missingOk => Right(err.resolution) + case others => others + } } def resolutions(