Skip to content

Commit

Permalink
Merge pull request #34 from rockjam/master
Browse files Browse the repository at this point in the history
Add sbt 1.0.0-RC2 support
  • Loading branch information
joeycozza authored Jul 27, 2017
2 parents 895361b + 64c19ea commit 0bccd58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
An sbt plugin for [Scalafmt](http://scalameta.org/scalafmt/) that

* formats .sbt and .scala files
* supports sbt 0.13 and 1.0.0-M6
* supports sbt 0.13 and 1.0.0-RC2
* supports Scalafmt 0.6 and 1.0
* runs in-process
* uses sbt's ivy2 for dependency resolution
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ lazy val `sbt-scalafmt_0.13` = `sbt-scalafmt`("0.13.15")
},
scriptedLaunchOpts += s"-Dplugin.version=${version.value}"
)
lazy val `sbt-scalafmt_1.0.0-M6` = `sbt-scalafmt`("1.0.0-M6")
lazy val `sbt-scalafmt_1.0.0-RC2` = `sbt-scalafmt`("1.0.0-RC2")

lazy val `sbt-scalafmt-coursier` = project.cross(sbtVersionAxis).dependsOn(`sbt-scalafmt`)
lazy val `sbt-scalafmt-coursier_0.13` = `sbt-scalafmt-coursier`("0.13.15")
lazy val `sbt-scalafmt-coursier_1.0.0-M6` = `sbt-scalafmt-coursier`("1.0.0-M6")
lazy val `sbt-scalafmt-coursier_1.0.0-RC2` = `sbt-scalafmt-coursier`("1.0.0-RC2")
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lucidchart.sbt.scalafmt

import sbinary.DefaultProtocol._
import sbt.Keys._
import sbt._
import sbt.FileInfo.full.{format => hashModifiedFormat}
import sbt.inc.Analysis
Expand All @@ -25,5 +26,13 @@ object CommandPlatform {
}

object LibraryPlatform {
def withOverrideScalaVersion(ivyScala: IvyScala, value: Boolean) = ivyScala.copy(overrideScalaVersion = value)
def moduleInfo(useIvy: SettingKey[Boolean]) =
ivyScala := {
if (useIvy.value) {
// otherwise scala-library conflicts
ivyScala.value.map(_.copy(overrideScalaVersion = false))
} else {
ivyScala.value
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.lucidchart.sbt.scalafmt

import sbt.Keys._
import sbt._
import sbt.internal.inc.Analysis
import sbt.librarymanagement.IvyScala
import sbt.util.CacheImplicits._
import sbt.util.CacheStore
import scala.reflect.runtime.universe
Expand Down Expand Up @@ -35,5 +35,13 @@ object CommandPlatform {
}

object LibraryPlatform {
def withOverrideScalaVersion(ivyScala: IvyScala, value: Boolean) = ivyScala.withOverrideScalaVersion(value)
def moduleInfo(useIvy: SettingKey[Boolean]) =
scalaModuleInfo := {
if (useIvy.value) {
// otherwise scala-library conflicts
scalaModuleInfo.value.map(_.withOverrideScalaVersion(false))
} else {
scalaModuleInfo.value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ object ScalafmtCorePlugin extends AutoPlugin {
override val projectSettings = Seq(
externalDependencyClasspath in Scalafmt := Classpaths.managedJars(Scalafmt, classpathTypes.value, update.value),
ivyConfigurations ++= (if (scalafmtUseIvy.value) Seq(Scalafmt) else Seq.empty),
ivyScala := {
if (scalafmtUseIvy.value) {
// otherwise scala-library conflicts
ivyScala.value.map(LibraryPlatform.withOverrideScalaVersion(_, false))
} else {
ivyScala.value
}
},
libraryDependencies ++=
(if (scalafmtUseIvy.value) (libraryDependencies in Scalafmt).value.map(_ % Scalafmt) else Seq.empty),
libraryDependencies in Scalafmt := {
Expand All @@ -258,7 +250,7 @@ object ScalafmtCorePlugin extends AutoPlugin {
)
},
scalafmtUseIvy := true
)
) :+ LibraryPlatform.moduleInfo(scalafmtUseIvy)

override val requires = IvyPlugin && JvmPlugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ object ScalafmtPlugin extends AutoPlugin {
if (!sourcesInBase.value) {
Def.task(Seq.empty[File])
} else if (includeFilter.value == UseScalafmtConfigFilter) {
(baseDirectory, scalafmtter)
.map((base, scalafmtter) => (base * (new ScalafmtFileFilter(scalafmtter) && "*.scala")).get)
Def.task((baseDirectory.value * (new ScalafmtFileFilter(scalafmtter.value) && "*.scala")).get)
} else {
(baseDirectory, includeFilter, excludeFilter).map(
(base, include, exclude) => (base * include --- base * exclude).get
)
Def.task((baseDirectory.value * includeFilter.value --- baseDirectory.value * excludeFilter.value).get)
}
}
.value
Expand Down

0 comments on commit 0bccd58

Please sign in to comment.