Bring EvaluateConfigurations and DslEntry to internal

This commit is contained in:
Eugene Yokota 2016-05-06 17:32:26 -04:00
parent 6304b24916
commit ce3926fbed
24 changed files with 125 additions and 127 deletions

View File

@ -72,7 +72,7 @@ object BuildUtil {
} }
} }
def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, dsl._, syntax._" :: Nil def baseImports: Seq[String] = "import scala.xml.{TopScope=>$scope}" :: "import sbt._, Keys._, syntax._" :: Nil
def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports ++ unit.definitions.dslDefinitions.imports def getImports(unit: BuildUnit): Seq[String] = unit.plugins.detected.imports ++ unit.definitions.dslDefinitions.imports

View File

@ -3,7 +3,7 @@
*/ */
package sbt package sbt
import sbt.internal.Load import sbt.internal.{ Load, EvaluateConfigurations }
import sbt.internal.util.{ AttributeKey, AttributeMap, complete, ConsoleOut, GlobalLogging, LineRange, MainLogging, SimpleReader, Types } import sbt.internal.util.{ AttributeKey, AttributeMap, complete, ConsoleOut, GlobalLogging, LineRange, MainLogging, SimpleReader, Types }
import sbt.util.{ Level, Logger } import sbt.util.{ Level, Logger }

View File

@ -3,7 +3,7 @@
*/ */
package sbt package sbt
import sbt.internal.Load import sbt.internal.{ Load, EvaluateConfigurations }
import sbt.librarymanagement.Configurations import sbt.librarymanagement.Configurations
import sbt.util.Level import sbt.util.Level

View File

@ -12,7 +12,7 @@ import Types.Endo
import compiler.Eval import compiler.Eval
import SessionSettings._ import SessionSettings._
import sbt.internals.parser.SbtRefactorings import sbt.internal.parser.SbtRefactorings
import sbt.io.IO import sbt.io.IO

View File

@ -1,17 +0,0 @@
package sbt
import sbt.librarymanagement.Configuration
import internals.{
DslEntry,
DslConfigs,
DslEnablePlugins,
DslDisablePlugins
}
package object dsl {
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslDisablePlugins(ps)
def configs(cs: Configuration*): DslEntry = DslConfigs(cs)
}

View File

@ -0,0 +1,65 @@
package sbt
package internal
import sbt.internal.util.RangePosition
import sbt.librarymanagement.Configuration
import Def._
/** This reprsents a `Setting` expression configured by the sbt DSL. */
sealed trait DslEntry {
/** Called by the parser. Sets the position where this entry was defined in the build.sbt file. */
def withPos(pos: RangePosition): DslEntry
}
object DslEntry {
implicit def fromSettingsDef(inc: SettingsDefinition): DslEntry =
DslSetting(inc)
implicit def fromSettingsDef(inc: Seq[Setting[_]]): DslEntry =
DslSetting(inc)
/** Represents a DSL entry which adds settings to the current project. */
sealed trait ProjectSettings extends DslEntry {
def toSettings: Seq[Setting[_]]
}
object ProjectSettings {
def unapply(e: DslEntry): Option[Seq[Setting[_]]] =
e match {
case e: ProjectSettings => Some(e.toSettings)
case _ => None
}
}
/** Represents a DSL entry which manipulates the current project. */
sealed trait ProjectManipulation extends DslEntry {
def toFunction: Project => Project
// TODO - Should we store this?
final def withPos(pos: RangePosition): DslEntry = this
}
object ProjectManipulation {
def unapply(e: DslEntry): Option[Project => Project] =
e match {
case e: ProjectManipulation => Some(e.toFunction)
case _ => None
}
}
/** this represents an actually Setting[_] or Seq[Setting[_]] configured by the sbt DSL. */
case class DslSetting(settings: SettingsDefinition) extends ProjectSettings {
def toSettings = settings.settings
final def withPos(pos: RangePosition): DslEntry = DslSetting(settings.settings.map(_.withPos(pos)))
}
/** this represents an `enablePlugins()` in the sbt DSL */
case class DslEnablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.enablePlugins(plugins: _*)
}
/** this represents an `disablePlugins()` in the sbt DSL */
case class DslDisablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.disablePlugins(plugins: _*)
}
/** Represents registering a set of configurations with the current project. */
case class DslConfigs(cs: Seq[Configuration]) extends ProjectManipulation {
override val toFunction: Project => Project = _.configs(cs: _*)
}
}

View File

@ -2,6 +2,7 @@
* Copyright 2011 Mark Harrah * Copyright 2011 Mark Harrah
*/ */
package sbt package sbt
package internal
import sbt.internal.util.{ complete, AttributeEntry, AttributeKey, LineRange, MessageOnlyException, RangePosition, Settings } import sbt.internal.util.{ complete, AttributeEntry, AttributeKey, LineRange, MessageOnlyException, RangePosition, Settings }
@ -10,7 +11,7 @@ import compiler.{ Eval, EvalImports }
import complete.DefaultParsers.validID import complete.DefaultParsers.validID
import Def.{ ScopedKey, Setting } import Def.{ ScopedKey, Setting }
import Scope.GlobalScope import Scope.GlobalScope
import sbt.internals.parser.SbtParser import sbt.internal.parser.SbtParser
import scala.annotation.tailrec import scala.annotation.tailrec
@ -27,7 +28,7 @@ import sbt.io.IO
* *
* *
*/ */
object EvaluateConfigurations { private[sbt] object EvaluateConfigurations {
type LazyClassLoaded[T] = ClassLoader => T type LazyClassLoaded[T] = ClassLoader => T
@ -130,15 +131,15 @@ object EvaluateConfigurations {
} }
val (settingsRaw, manipulationsRaw) = val (settingsRaw, manipulationsRaw) =
dslEntries map (_.result apply loader) partition { dslEntries map (_.result apply loader) partition {
case internals.ProjectSettings(_) => true case DslEntry.ProjectSettings(_) => true
case _ => false case _ => false
} }
val settings = settingsRaw flatMap { val settings = settingsRaw flatMap {
case internals.ProjectSettings(settings) => settings case DslEntry.ProjectSettings(settings) => settings
case _ => Nil case _ => Nil
} }
val manipulations = manipulationsRaw map { val manipulations = manipulationsRaw map {
case internals.ProjectManipulation(f) => f case DslEntry.ProjectManipulation(f) => f
} }
// TODO -get project manipulations. // TODO -get project manipulations.
new LoadedSbtFile(settings, projects, importDefs, manipulations, definitions, allGeneratedFiles) new LoadedSbtFile(settings, projects, importDefs, manipulations, definitions, allGeneratedFiles)
@ -158,8 +159,8 @@ object EvaluateConfigurations {
* The name of the class we cast DSL "setting" (vs. definition) lines to. * The name of the class we cast DSL "setting" (vs. definition) lines to.
*/ */
val SettingsDefinitionName = { val SettingsDefinitionName = {
val _ = classOf[sbt.internals.DslEntry] // this line exists to try to provide a compile-time error when the following line needs to be changed val _ = classOf[DslEntry] // this line exists to try to provide a compile-time error when the following line needs to be changed
"sbt.internals.DslEntry" "sbt.internal.DslEntry"
} }
/** /**
@ -171,10 +172,10 @@ object EvaluateConfigurations {
* @param expression The scala expression we're compiling * @param expression The scala expression we're compiling
* @param range The original position in source of the expression, for error messages. * @param range The original position in source of the expression, for error messages.
* *
* @return A method that given an sbt classloader, can return the actual [[internals.DslEntry]] defined by * @return A method that given an sbt classloader, can return the actual [[sbt.internal.DslEntry]] defined by
* the expression, and the sequence of .class files generated. * the expression, and the sequence of .class files generated.
*/ */
private[sbt] def evaluateDslEntry(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): TrackedEvalResult[internals.DslEntry] = { private[sbt] def evaluateDslEntry(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): TrackedEvalResult[DslEntry] = {
// TODO - Should we try to namespace these between.sbt files? IF they hash to the same value, they may actually be // TODO - Should we try to namespace these between.sbt files? IF they hash to the same value, they may actually be
// exactly the same setting, so perhaps we don't care? // exactly the same setting, so perhaps we don't care?
val result = try { val result = try {
@ -186,7 +187,7 @@ object EvaluateConfigurations {
TrackedEvalResult(result.generated, TrackedEvalResult(result.generated,
loader => { loader => {
val pos = RangePosition(name, range shift 1) val pos = RangePosition(name, range shift 1)
result.getValue(loader).asInstanceOf[internals.DslEntry].withPos(pos) result.getValue(loader).asInstanceOf[DslEntry].withPos(pos)
}) })
} }
@ -207,8 +208,8 @@ object EvaluateConfigurations {
def evaluateSetting(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): LazyClassLoaded[Seq[Setting[_]]] = def evaluateSetting(eval: Eval, name: String, imports: Seq[(String, Int)], expression: String, range: LineRange): LazyClassLoaded[Seq[Setting[_]]] =
{ {
evaluateDslEntry(eval, name, imports, expression, range).result andThen { evaluateDslEntry(eval, name, imports, expression, range).result andThen {
case internals.ProjectSettings(values) => values case DslEntry.ProjectSettings(values) => values
case _ => Nil case _ => Nil
} }
} }
private[this] def isSpace = (c: Char) => Character isWhitespace c private[this] def isSpace = (c: Char) => Character isWhitespace c

View File

@ -1,12 +1,12 @@
package sbt package sbt
package internals package internal
package parser package parser
import sbt.internal.util.{ LineRange, MessageOnlyException } import sbt.internal.util.{ LineRange, MessageOnlyException }
import java.io.File import java.io.File
import sbt.internals.parser.SbtParser._ import sbt.internal.parser.SbtParser._
import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._
@ -60,7 +60,7 @@ private[sbt] case class SbtParser(file: File, lines: Seq[String]) extends Parsed
val (imports, settings, settingsTrees) = splitExpressions(file, lines) val (imports, settings, settingsTrees) = splitExpressions(file, lines)
private def splitExpressions(file: File, lines: Seq[String]): (Seq[(String, Int)], Seq[(String, LineRange)], Seq[(String, Tree)]) = { private def splitExpressions(file: File, lines: Seq[String]): (Seq[(String, Int)], Seq[(String, LineRange)], Seq[(String, Tree)]) = {
import sbt.internals.parser.MissingBracketHandler._ import sbt.internal.parser.MissingBracketHandler._
import scala.compat.Platform.EOL import scala.compat.Platform.EOL
import scala.reflect.runtime._ import scala.reflect.runtime._

View File

@ -1,12 +1,12 @@
package sbt package sbt
package internals package internal
package parser package parser
import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._
private[sbt] object SbtRefactorings { private[sbt] object SbtRefactorings {
import sbt.internals.parser.SbtParser.{ END_OF_LINE, FAKE_FILE } import sbt.internal.parser.SbtParser.{ END_OF_LINE, FAKE_FILE }
import sbt.SessionSettings.{ SessionSetting, SbtConfigFile } import sbt.SessionSettings.{ SessionSetting, SbtConfigFile }
val EMPTY_STRING = "" val EMPTY_STRING = ""

View File

@ -1,65 +0,0 @@
package sbt
package internals
import sbt.internal.util.RangePosition
import sbt.librarymanagement.Configuration
import Def._
/** This reprsents a `Setting` expression configured by the sbt DSL. */
sealed trait DslEntry {
/** Called by the parser. Sets the position where this entry was defined in the build.sbt file. */
def withPos(pos: RangePosition): DslEntry
}
object DslEntry {
implicit def fromSettingsDef(inc: SettingsDefinition): DslEntry =
DslSetting(inc)
implicit def fromSettingsDef(inc: Seq[Setting[_]]): DslEntry =
DslSetting(inc)
}
/** Represents a DSL entry which adds settings to the current project. */
sealed trait ProjectSettings extends DslEntry {
def toSettings: Seq[Setting[_]]
}
object ProjectSettings {
def unapply(e: DslEntry): Option[Seq[Setting[_]]] =
e match {
case e: ProjectSettings => Some(e.toSettings)
case _ => None
}
}
/** Represents a DSL entry which manipulates the current project. */
sealed trait ProjectManipulation extends DslEntry {
def toFunction: Project => Project
// TODO - Should we store this?
final def withPos(pos: RangePosition): DslEntry = this
}
object ProjectManipulation {
def unapply(e: DslEntry): Option[Project => Project] =
e match {
case e: ProjectManipulation => Some(e.toFunction)
case _ => None
}
}
/** this represents an actually Setting[_] or Seq[Setting[_]] configured by the sbt DSL. */
case class DslSetting(settings: SettingsDefinition) extends ProjectSettings {
def toSettings = settings.settings
final def withPos(pos: RangePosition): DslEntry = DslSetting(settings.settings.map(_.withPos(pos)))
}
/** this represents an `enablePlugins()` in the sbt DSL */
case class DslEnablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.enablePlugins(plugins: _*)
}
/** this represents an `disablePlugins()` in the sbt DSL */
case class DslDisablePlugins(plugins: Seq[AutoPlugin]) extends ProjectManipulation {
override val toFunction: Project => Project = _.disablePlugins(plugins: _*)
}
/** Represents registering a set of configurations with the current project. */
case class DslConfigs(cs: Seq[Configuration]) extends ProjectManipulation {
override val toFunction: Project => Project = _.configs(cs: _*)
}

View File

@ -0,0 +1,5 @@
package sbt.internal.parser
import org.specs2.mutable._
trait AbstractSpec extends Specification with SplitExpression

View File

@ -1,6 +1,6 @@
package sbt.internals.parser package sbt
package internal
import sbt.EvaluateConfigurations package parser
abstract class CheckIfParsedSpec(implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions) extends AbstractSpec { abstract class CheckIfParsedSpec(implicit val splitter: SplitExpressions.SplitExpression = EvaluateConfigurations.splitExpressions) extends AbstractSpec {

View File

@ -1,4 +1,4 @@
package sbt.internals.parser package sbt.internal.parser
class CommentedXmlSpec extends CheckIfParsedSpec { class CommentedXmlSpec extends CheckIfParsedSpec {

View File

@ -1,4 +1,4 @@
package sbt.internals.parser package sbt.internal.parser
import sbt.internal.util.MessageOnlyException import sbt.internal.util.MessageOnlyException

View File

@ -1,9 +1,10 @@
package sbt.internals.parser package sbt
package internal
package parser
import java.io.File import java.io.File
import org.specs2.ScalaCheck import org.specs2.ScalaCheck
import sbt.EvaluateConfigurations
import sbt.internal.util.MessageOnlyException import sbt.internal.util.MessageOnlyException
import scala.io.Source import scala.io.Source

View File

@ -1,8 +1,9 @@
package sbt.internals.parser package sbt
package internal
package parser
import java.io.File import java.io.File
import sbt.EvaluateConfigurations
import sbt.internal.util.LineRange import sbt.internal.util.LineRange
import scala.annotation.tailrec import scala.annotation.tailrec

View File

@ -1,10 +1,11 @@
package sbt.internals.parser package sbt
package internal
package parser
import java.io.File import java.io.File
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner import org.specs2.runner.JUnitRunner
import sbt.EvaluateConfigurations
import scala.io.Source import scala.io.Source

View File

@ -1,5 +1,5 @@
package sbt package sbt
package internals package internal
package parser package parser
import java.io.{ File, FilenameFilter } import java.io.{ File, FilenameFilter }

View File

@ -1,4 +1,6 @@
package sbt.internals.parser package sbt
package internal
package parser
import java.io.File import java.io.File

View File

@ -1,4 +1,6 @@
package sbt.internals.parser package sbt
package internal
package parser
import java.io.File import java.io.File

View File

@ -1,5 +1,5 @@
package sbt package sbt
package internals package internal
package parser package parser
import java.io.File import java.io.File

View File

@ -1,7 +1,8 @@
package sbt.internals.parser package sbt
package internal
package parser
import org.specs2.mutable.Specification import org.specs2.mutable.Specification
import sbt.EvaluateConfigurations
class SplitExpressionsTest extends Specification with SplitExpressionsBehavior { class SplitExpressionsTest extends Specification with SplitExpressionsBehavior {

View File

@ -1,5 +0,0 @@
package sbt.internals.parser
import org.specs2.mutable._
trait AbstractSpec extends Specification with SplitExpression

View File

@ -1,5 +1,7 @@
package sbt package sbt
import sbt.internal.DslEntry
object syntax extends syntax object syntax extends syntax
abstract class syntax extends IOSyntax0 with sbt.std.TaskExtra with sbt.internal.util.Types with sbt.ProcessExtra abstract class syntax extends IOSyntax0 with sbt.std.TaskExtra with sbt.internal.util.Types with sbt.ProcessExtra
@ -45,6 +47,10 @@ abstract class syntax extends IOSyntax0 with sbt.std.TaskExtra with sbt.internal
def settingKey[T](description: String): SettingKey[T] = macro std.KeyMacro.settingKeyImpl[T] def settingKey[T](description: String): SettingKey[T] = macro std.KeyMacro.settingKeyImpl[T]
def taskKey[T](description: String): TaskKey[T] = macro std.KeyMacro.taskKeyImpl[T] def taskKey[T](description: String): TaskKey[T] = macro std.KeyMacro.taskKeyImpl[T]
def inputKey[T](description: String): InputKey[T] = macro std.KeyMacro.inputKeyImpl[T] def inputKey[T](description: String): InputKey[T] = macro std.KeyMacro.inputKeyImpl[T]
def enablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslEnablePlugins(ps)
def disablePlugins(ps: AutoPlugin*): DslEntry = DslEntry.DslDisablePlugins(ps)
def configs(cs: Configuration*): DslEntry = DslEntry.DslConfigs(cs)
} }
// Todo share this this io.syntax // Todo share this this io.syntax