Skip to content

Commit

Permalink
Refactored Build.scala
Browse files Browse the repository at this point in the history
Bumped SBT, Scala versions
Bumped plugins & library dependencies
GitHub is https by default
Removed legacy Eclipse project settings
  • Loading branch information
melezov committed Mar 30, 2016
1 parent 144faa1 commit 5c09f1e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scalariform.commandline
import java.io.File
import java.util.{ ArrayList, Collection }
import scala.collection.JavaConversions._
import scala.collection.mutable.Buffer

import org.apache.commons.io._
import org.apache.commons.io.filefilter._
Expand Down
27 changes: 0 additions & 27 deletions project/.classpath

This file was deleted.

12 changes: 0 additions & 12 deletions project/.project

This file was deleted.

117 changes: 55 additions & 62 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,59 @@ import scalariform.formatter.preferences._
import xerial.sbt.Sonatype._
import xerial.sbt.Sonatype.SonatypeKeys._
import sbtassembly.AssemblyPlugin.autoImport._
import sbtbuildinfo.BuildInfoPlugin.autoImport._

object ScalariformBuild extends Build {

lazy val commonSettings = inConfig(Test)(Defaults.testSettings) ++ SbtScalariform.defaultScalariformSettings ++ sonatypeSettings ++ Seq(
organization := "org.scalariform",
profileName := "org.scalariform",
sonatypeProfileName := organization.value,
version := "0.2.0-SNAPSHOT",
scalaVersion := "2.11.7",
scalaVersion := crossScalaVersions.value.head,
crossScalaVersions := Seq(
"2.11.7",
"2.11.8",
"2.10.6"
),
exportJars := true, // Needed for cli oneJar
scalacOptions ++= (scalaBinaryVersion.value match {
case "2.11" => Seq(
"-deprecation:false",
"-encoding", "UTF-8",
"-feature",
"-language:_",
"-unchecked",
"-Xlint",
"-Xfuture",
"-Xfatal-warnings",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-unused-import",
"-Ywarn-unused"
)
case _ => Seq()
}),
credentials += Credentials(Path.userHome / ".m2" / "credentials")
scalacOptions ++= Seq(
"-deprecation:false",
"-encoding", "UTF-8",
"-feature",
"-language:_",
"-unchecked",
"-Xlint",
"-Xfuture",
"-Xfatal-warnings",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-unused-import",
"-Ywarn-unused"
),
credentials ++= {
val creds = Path.userHome / ".m2" / "credentials"
if (creds.exists) Seq(Credentials(creds)) else Nil
}
)

lazy val subprojectSettings = commonSettings ++ Seq(
ScalariformKeys.preferences <<= baseDirectory.apply(getScalariformPreferences))

def getScalariformPreferences(dir: File) =
PreferencesImporterExporter.loadPreferences((dir / ".." / "formatterPreferences.properties").getPath)
lazy val subprojectSettings = commonSettings :+ (
ScalariformKeys.preferences := scalariformPreferences.value)

lazy val root: Project = Project("root", file("."), settings = commonSettings) aggregate (scalariform, cli)

implicit class Regex(sc: StringContext) {
def r = new util.matching.Regex(sc.parts.mkString, sc.parts.tail.map(_ => "x"): _*)
def scalariformPreferences = Def.setting {
PreferencesImporterExporter.loadPreferences((baseDirectory.value / ".." / "formatterPreferences.properties").getPath)
}

def getScalaTestDependency(scalaVersion: String) = scalaVersion match {
case r"2.11.\d+[-\w]*" | r"2.10.\d+[-\w]*" => "org.scalatest" %% "scalatest" % "2.2.4" % "test"
case "2.9.3" => "org.scalatest" %% "scalatest" % "1.9.1" % "test"
case _ => "org.scalatest" %% "scalatest" % "1.7.2" % "test"
}
lazy val root = project in file(".") settings(commonSettings) aggregate(scalariform, cli)

def get2_11Dependencies(scalaVersion: String): List[ModuleID] = scalaVersion match {
case r"2.11.\d+[-\w]*" => List(
"org.scala-lang.modules" %% "scala-xml" % "1.0.1",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.1"
)
case _ => Nil
def getScalaTestDependency = "org.scalatest" %% "scalatest" % "2.2.6" % "test"

def get2_11Dependencies = Def.setting {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq(
"org.scala-lang.modules" %% "scala-xml" % "1.0.5",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.0.4"
)
case _ => Nil
}
}

def publishSettings(projectName: String) = Seq(
Expand All @@ -72,48 +68,45 @@ object ScalariformBuild extends Build {
publishArtifact in (Compile, packageDoc) := true,
publishArtifact in (Compile, packageSrc) := true,
pomIncludeRepository := { _ false },
sbtbuildinfo.Plugin.buildInfoKeys := Seq[sbtbuildinfo.Plugin.BuildInfoKey](version),
sourceGenerators in Compile <+= sbtbuildinfo.Plugin.buildInfo,
sbtbuildinfo.Plugin.buildInfoPackage := projectName
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := projectName,
publishTo := getPublishToRepo.value
)

lazy val scalariform: Project = Project("scalariform", file("scalariform"), settings =
subprojectSettings ++ sbtbuildinfo.Plugin.buildInfoSettings ++ publishSettings("scalariform") ++
lazy val scalariform = project enablePlugins(sbtbuildinfo.BuildInfoPlugin) settings(
subprojectSettings ++ publishSettings("scalariform") ++
Seq(
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps)
deps ++ get2_11Dependencies(sv) :+ getScalaTestDependency(sv)
},
// sbt doesn't automatically load the content of the MANIFST.MF file, therefore we have to do it here by ourselves
libraryDependencies ++= get2_11Dependencies.value :+ getScalaTestDependency,
// sbt doesn't automatically load the content of the MANIFEST.MF file, therefore we have to do it here by ourselves
packageOptions in Compile in packageBin += {
val m = Using.fileInputStream(new java.io.File("scalariform/META-INF/MANIFEST.MF"))(in => new java.util.jar.Manifest(in))
val m = Using.fileInputStream(file("scalariform/META-INF/MANIFEST.MF"))(in => new java.util.jar.Manifest(in))
Package.JarManifest(m)
},
testOptions in Test += Tests.Argument("-oI"),
publishTo <<= isSnapshot(getPublishToRepo)))
testOptions in Test += Tests.Argument("-oI")))

def getPublishToRepo(isSnapshot: Boolean) =
if (isSnapshot)
Some("snapshots" at "https://oss.sonatype.org/content/repositories/snapshots")
def getPublishToRepo = Def.setting {
if (isSnapshot.value)
Some(Opts.resolver.sonatypeSnapshots)
else
Some("releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
Some(Opts.resolver.sonatypeStaging)
}

lazy val cli = Project("cli", file("cli"), settings = subprojectSettings ++ publishSettings("cli") ++
sbtbuildinfo.Plugin.buildInfoSettings ++
lazy val cli = project enablePlugins(sbtbuildinfo.BuildInfoPlugin) settings(
subprojectSettings ++ publishSettings("cli") ++
Seq(
libraryDependencies += "commons-io" % "commons-io" % "1.4",
mainClass in (Compile, packageBin) := Some("scalariform.commandline.Main"),
mainClass in assembly := Some("scalariform.commandline.Main"),
publishTo <<= isSnapshot(getPublishToRepo),
artifact in (Compile, assembly) := {
val art = (artifact in (Compile, assembly)).value
art.copy(`classifier` = Some("assembly"))
}
) ++ addArtifact(artifact in (Compile, assembly), assembly)
) dependsOn (scalariform)
) dependsOn(scalariform)

def pomExtraXml =
<inceptionYear>2010</inceptionYear>
<url>http://github.com/scala-ide/scalariform</url>
<url>https://github.com/scala-ide/scalariform</url>
<licenses>
<license>
<name>MIT License</name>
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.9
sbt.version=0.13.11
12 changes: 4 additions & 8 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.5.1")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.6.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.3.0")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.1")

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.2")

0 comments on commit 5c09f1e

Please sign in to comment.