Skip to content

Commit

Permalink
Use build-info for friendlier intellij setup
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Dec 13, 2016
1 parent a5b666a commit ab34355
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 53 deletions.
69 changes: 43 additions & 26 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sbt.ScriptedPlugin
import sbt.ScriptedPlugin._
import sbtbuildinfo.BuildInfoKey.Entry
organization in ThisBuild := "ch.epfl.scala"
version in ThisBuild := scalafix.Versions.nightly
version in ThisBuild := "0.2.0-SNAPSHOT"

lazy val crossVersions = Seq("2.11.8", "2.12.1")

lazy val buildSettings = Seq(
assemblyJarName in assembly := "scalafix.jar",
// See core/src/main/scala/ch/epfl/scala/Versions.scala
scalaVersion := scalafix.Versions.scala,
scalaVersion := "2.11.8",
updateOptions := updateOptions.value.withCachedResolution(true)
)

Expand Down Expand Up @@ -72,14 +72,28 @@ lazy val noPublish = Seq(
publishLocal := {}
)

lazy val allSettings = commonSettings ++ buildSettings ++ publishSettings
lazy val buildInfoSettings: Seq[Def.Setting[_]] = Seq(
buildInfoKeys := Seq[BuildInfoKey](
name,
version,
scalaVersion,
sbtVersion
),
buildInfoPackage := "scalafix",
buildInfoObject := "Versions"
)

lazy val root = project
lazy val allSettings =
commonSettings ++
buildSettings ++
publishSettings

lazy val `scalafix-root` = project
.in(file("."))
.settings(moduleName := "scalafix")
.settings(allSettings)
.settings(noPublish)
.settings(
moduleName := "scalafix",
allSettings,
noPublish,
initialCommands in console :=
"""
|import scala.meta._
Expand All @@ -99,6 +113,7 @@ lazy val root = project
lazy val core = project
.settings(
allSettings,
buildInfoSettings,
crossScalaVersions := crossVersions,
moduleName := "scalafix-core",
addCompilerPlugin(
Expand All @@ -113,6 +128,7 @@ lazy val core = project
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % "test"
)
)
.enablePlugins(BuildInfoPlugin)

lazy val `scalafix-nsc` = project
.settings(
Expand Down Expand Up @@ -181,24 +197,25 @@ lazy val publishedArtifacts = Seq(
publishLocal in core
)

lazy val `scalafix-sbt` = project.settings(
allSettings,
ScriptedPlugin.scriptedSettings,
sbtPlugin := true,
scripted := scripted.dependsOn(publishedArtifacts: _*).evaluated,
scalaVersion := "2.10.5",
moduleName := "sbt-scalafix",
sources in Compile +=
baseDirectory.value / "../core/src/main/scala/scalafix/Versions.scala",
scriptedLaunchOpts ++= Seq(
"-Dplugin.version=" + version.value,
// .jvmopts is ignored, simulate here
"-XX:MaxPermSize=256m",
"-Xmx2g",
"-Xss2m"
),
scriptedBufferLog := false
)
lazy val `scalafix-sbt` = project
.settings(
allSettings,
buildInfoSettings,
ScriptedPlugin.scriptedSettings,
sbtPlugin := true,
scripted := scripted.dependsOn(publishedArtifacts: _*).evaluated,
scalaVersion := "2.10.5",
moduleName := "sbt-scalafix",
scriptedLaunchOpts ++= Seq(
"-Dplugin.version=" + version.value,
// .jvmopts is ignored, simulate here
"-XX:MaxPermSize=256m",
"-Xmx2g",
"-Xss2m"
),
scriptedBufferLog := false
)
.enablePlugins(BuildInfoPlugin)

lazy val `scalafix-tests` = project
.settings(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/scala/scalafix/cli/Cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ case class CommonOptions(
)

@AppName("scalafix")
@AppVersion(scalafix.Versions.nightly)
@AppVersion(scalafix.Versions.version)
@ProgName("scalafix")
case class ScalafixOptions(
@HelpMessage(
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/scala/scalafix/Versions.scala

This file was deleted.

3 changes: 0 additions & 3 deletions project/build.sbt

This file was deleted.

1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.3")
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.5")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M15")
Expand Down
4 changes: 2 additions & 2 deletions readme/Installation.scalatex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

@sect{sbt}
@hl.scala
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "@scalafix.Versions.stable")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "@scalafix.Versions.version")

@ul
@li
Expand All @@ -66,7 +66,7 @@
Scalafix can be used directly as a compiler plugin:
@hl.scala
// download
"ch.epfl.scala" %% "scalafix-nsc" % "@scalafix.Versions.stable"
"ch.epfl.scala" %% "scalafix-nsc" % "@scalafix.Versions.version"
// compile
scalac -Xplugin:/path/to/scalafix-nsc.jar mycode.scala

Expand Down
2 changes: 1 addition & 1 deletion readme/Readme.scalatex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@import Main._
@import scalafix.Readme._

@sect("scalafix - a Scala rewrite tool", scalafix.Versions.stable)
@sect("scalafix - a Scala rewrite tool", scalafix.Versions.version)
@scalatex.Intro()
@scalatex.Installation()
@scalatex.Configuration()
Expand Down
32 changes: 19 additions & 13 deletions scalafix-sbt/src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,28 @@ object rewrite {
object ScalafixPlugin extends AutoPlugin with ScalafixKeys {
object autoImport extends ScalafixKeys
private val Version = "2\\.(\\d\\d)\\..*".r
private val nightlyVersion = _root_.scalafix.Versions.nightly
private val scalafixVersion = _root_.scalafix.Versions.version
private val disabled = sys.props.contains("scalafix.disable")
private def jar(report: UpdateReport): Option[File] =
report.allFiles.find(
_.getAbsolutePath.matches(s".*scalafix-nsc_2.[12].jar$$"))
private def stub(version: String) =
Project(id = "scalafix-stub", base = file("project/scalafix")).settings(
description :=
"""Serves as a caching layer for extracting the jar location of the
|scalafix-nsc compiler plugin. If the dependecy was added to all
|projects, the (slow) update task will be re-run for every project.""".stripMargin,
scalaVersion := version,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "scalafix-nsc" % nightlyVersion
report.allFiles.find { x =>
println("X: " + x)
x.getAbsolutePath.matches(s".*scalafix-nsc_2.1[12].jar$$")
}

private def stub(version: String) = {
val Version(id) = version
Project(id = s"scalafix-$id", base = file(s"project/scalafix/$id"))
.settings(
description :=
"""Serves as a caching layer for extracting the jar location of the
|scalafix-nsc compiler plugin. If the dependecy was added to all
|projects, the (slow) update task will be re-run for every project.""".stripMargin,
scalaVersion := version,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "scalafix-nsc" % scalafixVersion
)
)
)
}
private val scalafix211 = stub("2.11.8")
private val scalafix212 = stub("2.12.1")

Expand Down

0 comments on commit ab34355

Please sign in to comment.