-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make plugin a State => State too (#2)
To load it via the apply command of sbt, like sbt-structure does.
- Loading branch information
1 parent
dd728e8
commit b96ee21
Showing
2 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
sbt-cs-publish/src/main/scala/sbtcspublish/ApplyState.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sbtcspublish | ||
|
||
import java.net.URI | ||
|
||
import sbt.internal.SessionSettings | ||
import sbt.{BuiltinCommands, GlobalScope, Project, Reference, Scope, Select, Setting, State, Zero} | ||
|
||
trait ApplyState extends (State => State) { | ||
|
||
def projectSettings: Seq[Setting[_]] | ||
def globalSettings: Seq[Setting[_]] | ||
|
||
|
||
// from https://github.com/JetBrains/sbt-structure/blob/16574c8d17afcc99de9aa6d73ac0e5349c9a32a4/extractor/src/main/scala-sbt-0.13-1.0/org/jetbrains/sbt/CreateTasks.scala | ||
|
||
def apply(state: State): State = | ||
applySettings(state, globalSettings, projectSettings) | ||
|
||
private 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) | ||
} | ||
|
||
private def transformSettings(thisScope: Scope, uri: URI, rootProject: URI => String, settings: Seq[Setting[_]]): Seq[Setting[_]] = | ||
Project.transform(Scope.resolveScope(thisScope, uri, rootProject), settings) | ||
|
||
private def reapply(session: SessionSettings, s: State): State = | ||
BuiltinCommands.reapply(session, Project.structure(s), s) | ||
|
||
private def projectScope(project: Reference): Scope = Scope(Select(project), Zero, Zero, Zero) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters