Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross build for SBT 1.0.0-RC3 #57

Merged
merged 9 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ developers := List(

sbtPlugin := true

crossSbtVersions := Vector("0.13.15", "1.0.0-M6")

scalacOptions ++= List(
"-unchecked",
"-deprecation",
"-Xlint",
"-language:_",
"-target:jvm-1.6",
"-encoding", "UTF-8"
)
) ++ (if (scalaVersion.value startsWith "2.10.") List("-target:jvm-1.6") else List.empty)

resolvers ++= Seq(sonatypeSnapshots, sonatypeReleases)

libraryDependencies += "org.scalariform" %% "scalariform" % "0.1.8"
libraryDependencies += {
if (scalaVersion.value startsWith "2.10.")
"org.scalariform" %% "scalariform" % "0.1.8"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, the reason for mentioning cross publishing is that library dependencies can now simply be:

libraryDependencies += "org.scalariform" %% "scalariform" % "0.2.0"

Copy link
Contributor Author

@liff liff Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems I failed to properly parse your last comment, sorry. Update on its way.

I was trying to look for 0.2.0 for 2.10 on Maven Central but I suppose its indexing hasn't caught up yet or something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, it's not yet up on maven central, but the dependency resolves (0.2.0 was published an hour or so ago)

else
"org.scalariform" %% "scalariform" % "0.2.0"
}

com.typesafe.sbt.SbtScalariform.ScalariformKeys.preferences := {
import scalariform.formatter.preferences._
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.13
sbt.version=0.13.16-M1
17 changes: 17 additions & 0 deletions src/main/scala-sbt-0.13/com/typesafe/sbt/SbtCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.typesafe.sbt

import java.io.File
import sbt.{ Changed, FilesInfo }
import sbinary.Format

object SbtCompat {
val Analysis = sbt.inc.Analysis
type UpdateFunction = sbt.FileFunction.UpdateFunction

object FileFunction {
def cached(cacheBaseDirectory: File)(inStyle: FilesInfo.Style, outStyle: FilesInfo.Style)(action: UpdateFunction): Set[File] => Set[File] =
sbt.FileFunction.cached(cacheBaseDirectory)(inStyle, outStyle)(action)
}

def changed[O: Equiv: Format](cacheFile: File): Changed[O] = new Changed[O](cacheFile)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.typesafe.sbt

import java.io.{ StringReader, StringWriter }
import java.util.Properties
import scalariform.formatter.preferences.{ PreferencesImporterExporter, IFormattingPreferences }
import sjsonnew.{ Builder, JsonFormat, Unbuilder }

object PreferencesProtocol {

implicit object PrefFormat extends JsonFormat[IFormattingPreferences] {
override def write[J](value: IFormattingPreferences, builder: Builder[J]): Unit = {
val outStream = new StringWriter()
PreferencesImporterExporter.asProperties(value).store(outStream, null)
builder.writeString(outStream.toString)
}

override def read[J](jsOpt: Option[J], unbuilder: Unbuilder[J]): IFormattingPreferences = {
val properties = new Properties
jsOpt match {
case Some(js) =>
val str = unbuilder.readString(js)
properties.load(new StringReader(str))
case None =>
}
PreferencesImporterExporter.getPreferences(properties)
}
}
}
18 changes: 18 additions & 0 deletions src/main/scala-sbt-1.0.0-M6/com/typesafe/sbt/SbtCompat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.typesafe.sbt

import java.io.File
import sbt.{ Changed, FileInfo }
import sbt.util.{ CacheStore, CacheStoreFactory }
import sjsonnew.JsonFormat

object SbtCompat {
val Analysis = sbt.internal.inc.Analysis
type UpdateFunction = sbt.FileFunction.UpdateFunction

object FileFunction {
def cached(cacheBaseDirectory: File)(inStyle: FileInfo.Style, outStyle: FileInfo.Style)(action: UpdateFunction): Set[File] => Set[File] =
sbt.FileFunction.cached(CacheStoreFactory(cacheBaseDirectory), inStyle, outStyle)(action)
}

def changed[O: Equiv: JsonFormat](store: File): Changed[O] = new Changed[O](CacheStore(store))
}
10 changes: 5 additions & 5 deletions src/main/scala/com/typesafe/sbt/Scalariform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package com.typesafe.sbt

import sbt._
import sbt.Keys._
import sbt.{ File, FileFilter, _ }
import sbt.{ File, FileFilter, FileFunction => _, _ }
import scala.collection.immutable.Seq
import scalariform.formatter.ScalaFormatter
import scalariform.formatter.preferences.{ IFormattingPreferences, PreferencesImporterExporter }
import scalariform.parser.ScalaParserException
import SbtCompat._

private object Scalariform {
object Scalariform {

def apply(
preferences: IFormattingPreferences,
Expand Down Expand Up @@ -75,7 +75,7 @@ private object Scalariform {

def handleUpdate(in: ChangeReport[File], out: ChangeReport[File]) = {
val files = in.modified -- in.removed
inc.Analysis.counted("Scala source", "", "s", files.size) foreach logFun
Analysis.counted("Scala source", "", "s", files.size) foreach logFun
updateFun(files)
files
}
Expand All @@ -88,7 +88,7 @@ private object Scalariform {

protected def preferencesChanged(cacheDir: File): IFormattingPreferences => Boolean = {
import com.typesafe.sbt.PreferencesProtocol._
val prefChanged = new Changed[IFormattingPreferences](cacheDir)
val prefChanged = changed[IFormattingPreferences](cacheDir)
prefChanged({ _ => true }, { _ => false })
}

Expand Down