Skip to content

Commit

Permalink
Misc build stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed May 7, 2012
1 parent 4cb9d3c commit 8615089
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 37 deletions.
34 changes: 22 additions & 12 deletions project/Build.scala
Expand Up @@ -10,45 +10,44 @@ import scalariform.formatter.preferences._

object ScalariformBuild extends Build {

lazy val buildSettings = Defaults.defaultSettings ++ ScalariformPlugin.defaultScalariformSettings ++ Seq(
lazy val commonSettings = Defaults.defaultSettings ++ ScalariformPlugin.defaultScalariformSettings ++ Seq(
organization := "scalariform",
version := "0.1.2-SNAPSHOT",
scalaVersion := "2.9.2",
crossScalaVersions := Seq("2.8.0", "2.8.1", "2.8.2", "2.9.0", "2.9.0-1", "2.9.1", "2.9.2", "2.10.0-SNAPSHOT"),
crossScalaVersions := Seq("2.8.0", "2.8.1", "2.8.2", "2.9.0", "2.9.1", "2.9.2"),
resolvers += ScalaToolsSnapshots,
retrieveManaged := true,
scalacOptions += "-deprecation",
pomExtra := pomExtraXml,
parallelExecution in Test := false,
publishMavenStyle := true,
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials"),
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
EclipseKeys.withSource := true,
EclipseKeys.eclipseOutput := Some("bin"))

lazy val subprojectSettings = buildSettings ++ Seq(
lazy val subprojectSettings = commonSettings ++ Seq(
ScalariformKeys.preferences <<= baseDirectory.apply(dir PreferencesImporterExporter.loadPreferences((dir / ".." / "formatterPreferences.properties").getPath)))

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

lazy val scalariform: Project = Project("scalariform", file("scalariform"), settings = subprojectSettings ++
Seq(
libraryDependencies <<= (scalaVersion, libraryDependencies) { (sv, deps)
val scalatestVersion = sv match {
case "2.8.0" "org.scalatest" %% "scalatest" % "1.3.1.RC2" % "test"

// case "2.8.1" => "org.scalatest" %% "scalatest" % "1.5.1" % "test"
// case "2.8.2" => "org.scalatest" %% "scalatest" % "1.5.1" % "test"
case "2.10.0-SNAPSHOT" "org.scalatest" % "scalatest_2.10.0-M2" % "1.8-SNAPSHOT" % "test"
case "2.10.0-M3" "org.scalatest" % "scalatest_2.10.0-M3" % "1.8-SNAPSHOT" % "test"
case _ "org.scalatest" %% "scalatest" % "1.7.2" % "test"
}
deps :+ scalatestVersion
},
exportJars := true, // Needed for cli oneJar
publishTo <<= version { (v: String)
if (v endsWith "-SNAPSHOT")
Some(ScalaToolsSnapshots)
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some(ScalaToolsReleases)
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}))

lazy val cli = Project("cli", file("cli"), settings = subprojectSettings ++ SbtOneJar.oneJarSettings ++
Expand All @@ -73,5 +72,16 @@ object ScalariformBuild extends Build {
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>git@github.com:mdr/scalariform.git</url>
<connection>scm:git:git@github.com:mdr/scalariform</connection>
</scm>
<developers>
<developer>
<id>mdr</id>
<name>Matt Russell</name>
<url>https://github.com/mdr/</url>
</developer>
</developers>

}
4 changes: 4 additions & 0 deletions project/plugins.sbt
Expand Up @@ -12,3 +12,7 @@ resolvers += Classpaths.typesafeSnapshots
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0-SNAPSHOT")

addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.0")

resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)

addSbtPlugin("com.jsuereth" % "xsbt-gpg-plugin" % "0.6")
Expand Up @@ -183,7 +183,7 @@ class AstSelector(source: String, scalaVersion: String = ScalaVersions.DEFAULT_V
nodeStack match {
case List(_: BlockExpr, _: MatchExpr, _*) false
case List(_: BlockExpr, _: ProcFunBody, _*) false
case List(node, _*) !(nonSelectableAstNodes contains node.getClass)
case List(node, _*) !(nonSelectableAstNodes contains node.getClass.asInstanceOf[Class[_ <: AstNode]])
case Nil false
}

Expand Down
Expand Up @@ -6,7 +6,7 @@ import scalariform.utils.TextEdit
import scalariform.utils.TextEditProcessor
import scalariform.ScalaVersions

object RedundantSemicolonDetector extends App {
object RedundantSemicolonDetector {

/**
* @return all semicolons in the source that could safely be removed without changing the meaning
Expand All @@ -33,21 +33,4 @@ object RedundantSemicolonDetector extends App {
def getEditsToRemoveRedundantSemis(s: String): List[TextEdit] =
findRedundantSemis(s).map(_.range).map(TextEdit.delete)

}

object Demo extends App {

val source = """
class A {
def foo = 42;
def bar = 123; def baz = 1234
};"""
val redundantSemis = RedundantSemicolonDetector.findRedundantSemis(source)
val annotated = redundantSemis.reverse.foldLeft(source) { (s, semi) replaceRange(s, semi.range, "<;>") }
val purged = RedundantSemicolonDetector.removeRedundantSemis(source)
println(source)
println("-------------------------------------------------")
println(annotated)
println("-------------------------------------------------")
println(purged)
}
Expand Up @@ -11,20 +11,20 @@ import scalariform.utils.Utils._
class RedundantSemicolonDetectorTest extends FlatSpec with ShouldMatchers {

implicit def stringToCheckable(s: String)(implicit scalaVersion: String = ScalaVersions.DEFAULT_VERSION) =
new { def check = checkSemis(s, scalaVersion) } // Expected redundant semicolons are indicated with <;>
new { def check() = checkSemis(s, scalaVersion) }; // Expected redundant semicolons are indicated with <;>

"""
class A {
def foo = 42<;>
def bar = 123; def baz = 1234
}<;>
""".check
""".check();

"""
{
println("Foo")<;>
}
""".check
""".check();

"""
class A {
Expand All @@ -33,17 +33,17 @@ class RedundantSemicolonDetectorTest extends FlatSpec with ShouldMatchers {
y <- 1 to 10
) yield x + y<;>
}
""".check
""".check()

{
implicit val scalaVersion = "2.10.0"
implicit val scalaVersion = "2.10.0";
"""
s"my name is ${person.name<;>}"
""".check
}

private def checkSemis(encodedSource: String, scalaVersion: String) {
val ordinarySource = encodedSource.replaceAllLiterally("<;>", ";")
val ordinarySource = encodedSource.replace("<;>", ";")
val semis = RedundantSemicolonDetector.findRedundantSemis(ordinarySource, scalaVersion)
val encodedSourceAgain = semis.reverse.foldLeft(ordinarySource) { (s, semi) replaceRange(s, semi.range, "<;>") }
encodedSourceAgain should equal(encodedSource)
Expand Down

0 comments on commit 8615089

Please sign in to comment.