Skip to content

Commit

Permalink
Moving applySettings method to SbtStateOps trait #SCL-22163
Browse files Browse the repository at this point in the history
  • Loading branch information
Sa1to committed Apr 15, 2024
1 parent 360dc09 commit 0f3055c
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 26 deletions.
Binary file removed .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package sbt.jetbrains

import sbt._
import org.jetbrains.sbt.{CreateTasks, SbtStateOps}
import org.jetbrains.sbt.SbtStateOps

object LogDownloadArtifacts extends (State => State) with SbtStateOps {

def apply(state: State): State =
CreateTasks.applySettings(state, Seq[Setting[_]](), Seq[Setting[_]]())
applySettings(state, Seq[Setting[_]](), Seq[Setting[_]]())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.jetbrains

import sbt.{Def, File, Task, Setting, TaskKey}
import sbt.{Def, File, Task, Setting}

object keysAdapterEx {
val myScalaCompilerBridgeBinaryJar: Def.Initialize[Task[Option[File]]] = Def.taskDyn {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package sbt.jetbrains

import sbt._
import org.jetbrains.sbt.{CreateTasks, SbtStateOps}
import org.jetbrains.sbt.SbtStateOps

object LogDownloadArtifacts extends (State => State) with SbtStateOps {

def apply(state: State): State =
CreateTasks.applySettings(state, Seq[Setting[_]](), Seq[Setting[_]]())
applySettings(state, Seq[Setting[_]](), Seq[Setting[_]]())
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.jetbrains

import sbt.{Def, File, Task, Setting, TaskKey}
import sbt.{Def, File, Task, Setting}

object keysAdapterEx {
val myScalaCompilerBridgeBinaryJar: Def.Initialize[Task[Option[File]]] = Def.taskDyn {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sbt.jetbrains

import org.jetbrains.sbt.{CreateTasks, SbtStateOps}
import org.jetbrains.sbt.SbtStateOps
import sbt.Keys.csrLogger
import sbt._

Expand All @@ -11,5 +11,5 @@ object LogDownloadArtifacts extends (State => State) with SbtStateOps {
)

def apply(state: State): State =
CreateTasks.applySettings(state, globalSettings, Seq[Setting[_]]())
applySettings(state, globalSettings, Seq[Setting[_]]())
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sbt.jetbrains

import lmcoursier.definitions.CacheLogger
import sbt.Keys.useSuperShell
import sbt.{Def, File, Keys, Logger, Setting, Task, TaskKey, ThisBuild}
import sbt.{Def, File, Keys, Logger, Setting, Task, ThisBuild}

object keysAdapterEx {
//NOTE: sbt.Keys.scalaCompilerBridgeBinaryJar exists since SBT 1.2.3, so we detect it only since 1.3.0
Expand Down
17 changes: 0 additions & 17 deletions extractor/src/main/scala/org/jetbrains/sbt/CreateTasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,4 @@ object CreateTasks extends (State => State) with SbtStateOps {
def apply(state: State): State =
applySettings(state, globalSettings, projectSettings)

def applySettings(state: State, globalSettings: Seq[Setting[_]], projectSettings: Seq[Setting[_]]): State = {
val extracted = Project.extract(state)
import extracted.{structure => extractedStructure, _}
val transformedGlobalSettings = Project.transform(_ => GlobalScope, globalSettings)
val transformedProjectSettings = extractedStructure.allProjectRefs.flatMap { projectRef =>
transformSettings(projectScope(projectRef), projectRef.build, rootProject, projectSettings)
}
reapply(extracted.session.appendRaw(transformedGlobalSettings ++ transformedProjectSettings), state)
}

// copied from sbt.internal.Load
private def transformSettings(thisScope: Scope, uri: URI, rootProject: URI => String, settings: Seq[Setting[_]]): Seq[Setting[_]] =
Project.transform(Scope.resolveScope(thisScope, uri, rootProject), settings)

// copied from sbt.internal.SessionSettings
private def reapply(session: SessionSettings, s: State): State =
BuiltinCommands.reapply(session, Project.structure(s), s)
}
19 changes: 19 additions & 0 deletions extractor/src/main/scala/org/jetbrains/sbt/operations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ import sbt.jetbrains.apiAdapter._
* @since 4/10/15.
*/
trait SbtStateOps {

def applySettings(state: State, globalSettings: Seq[Setting[_]], projectSettings: Seq[Setting[_]]): State = {
val extracted = Project.extract(state)
import extracted.{structure => extractedStructure, _}
val transformedGlobalSettings = Project.transform(_ => GlobalScope, globalSettings)
val transformedProjectSettings = extractedStructure.allProjectRefs.flatMap { projectRef =>
transformSettings(projectScope(projectRef), projectRef.build, rootProject, projectSettings)
}
reapply(extracted.session.appendRaw(transformedGlobalSettings ++ transformedProjectSettings), state)
}

// copied from sbt.internal.Load
private def transformSettings(thisScope: Scope, uri: URI, rootProject: URI => String, settings: Seq[Setting[_]]): Seq[Setting[_]] =
Project.transform(Scope.resolveScope(thisScope, uri, rootProject), settings)

// copied from sbt.internal.SessionSettings
private def reapply(session: SessionSettings, s: State): State =
BuiltinCommands.reapply(session, Project.structure(s), s)

def structure(state: State): BuildStructure =
sbt.Project.structure(state)

Expand Down

0 comments on commit 0f3055c

Please sign in to comment.