Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option for user provided path to sbt binary for bleep import command. #382

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bleep-cli/src/scala/bleep/commands/Import.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ case class Import(
override def run(): Either[BleepException, Unit] = {
if (!options.skipSbt) {
val resolvedJvm = fetchJvm(model.Jvm.system)
sbtimport.runSbt(logger, sbtBuildDir, destinationPaths, resolvedJvm)
sbtimport.runSbt(logger, sbtBuildDir, destinationPaths, resolvedJvm, options.sbtPath)
}

val inputData = sbtimport.ImportInputData.collectFromFileSystem(destinationPaths, logger)
Expand Down
15 changes: 13 additions & 2 deletions bleep-cli/src/scala/bleep/sbtimport/ImportOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import cats.data.{Validated, ValidatedNel}
import cats.syntax.apply.*
import com.monovore.decline.{Argument, Opts}

case class ImportOptions(ignoreWhenInferringTemplates: Set[model.ProjectName], skipSbt: Boolean, skipGeneratedResourcesScript: Boolean, jvm: model.Jvm)
case class ImportOptions(
ignoreWhenInferringTemplates: Set[model.ProjectName],
skipSbt: Boolean,
skipGeneratedResourcesScript: Boolean,
jvm: model.Jvm,
sbtPath: Option[String]
)

object ImportOptions {
val ignoreWhenInferringTemplates: Opts[Set[model.ProjectName]] = Opts
Expand Down Expand Up @@ -36,6 +42,11 @@ object ImportOptions {
.withDefault(Some(model.Jvm.system))
.map(_.get)

val sbtPath: Opts[Option[String]] =
Opts
.option[String]("sbt-path", "optional path to sbt executable if sbt provided by coursier can not be used.")
.orNone

val opts: Opts[ImportOptions] =
(ignoreWhenInferringTemplates, skipSbt, skipGeneratedResourcesScript, jvm).mapN(ImportOptions.apply)
(ignoreWhenInferringTemplates, skipSbt, skipGeneratedResourcesScript, jvm, sbtPath).mapN(ImportOptions.apply)
}
8 changes: 5 additions & 3 deletions bleep-cli/src/scala/bleep/sbtimport/runSbt.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ object runSbt {
*
* I'm sure it's possible to do the same thing from within sbt and only launch it first, but you know. it's not at all easy.
*/
def apply(logger: Logger, sbtBuildDir: Path, destinationPaths: BuildPaths, jvm: ResolvedJvm): Unit = {
val fetchSbt = new FetchSbt(new BleepCacheLogger(logger), ExecutionContext.global)
def apply(logger: Logger, sbtBuildDir: Path, destinationPaths: BuildPaths, jvm: ResolvedJvm, providedSbtPath: Option[String]): Unit = {
val version = readSbtVersionFromFile(sbtBuildDir).getOrElse("1.8.0")
val sbtPath = fetchSbt(version)
val sbtPath = providedSbtPath.getOrElse {
val fetchSbt = new FetchSbt(new BleepCacheLogger(logger), ExecutionContext.global)
fetchSbt(version)
}
def sbtCommands(cmds: Iterable[String]) =
cli.In.Provided(cmds.mkString("", "\n", "\nexit\n").getBytes)

Expand Down
5 changes: 3 additions & 2 deletions bleep-tests/src/scala/bleep/IntegrationSnapshotTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class IntegrationSnapshotTests extends SnapshotTest {
val cacheLogger = new BleepCacheLogger(logger)
val fetchJvm = new FetchJvm(Some(userPaths.resolveJvmCacheDir), cacheLogger, ExecutionContext.global)
val fetchedJvm = fetchJvm(jvm)
sbtimport.runSbt(logger, sbtBuildDir, sbtDestinationPaths, fetchedJvm)
sbtimport.runSbt(logger, sbtBuildDir, sbtDestinationPaths, fetchedJvm, None)

val inputData = sbtimport.ImportInputData.collectFromFileSystem(sbtDestinationPaths, logger)
FileUtils.writeGzippedBytes(
Expand All @@ -97,7 +97,8 @@ class IntegrationSnapshotTests extends SnapshotTest {

val importedBuildLoader = BuildLoader.inDirectory(importedPath)
val importedDestinationPaths = BuildPaths(cwd = FileUtils.TempDir, importedBuildLoader, model.BuildVariant.Normal)
val importerOptions = sbtimport.ImportOptions(ignoreWhenInferringTemplates = Set.empty, skipSbt = false, skipGeneratedResourcesScript = false, jvm = jvm)
val importerOptions =
sbtimport.ImportOptions(ignoreWhenInferringTemplates = Set.empty, skipSbt = false, skipGeneratedResourcesScript = false, jvm = jvm, sbtPath = None)

// generate a build file and store it
val buildFiles: Map[Path, String] =
Expand Down
Loading