Skip to content

Commit 56ba667

Browse files
authored
Merge pull request #34 from codacy/scala-2.12
Use Scala 2.12
2 parents 97b5b65 + a37451a commit 56ba667

28 files changed

+776
-224
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ dist
1818
*.iml
1919
codacy.pylint.conf
2020
npm-debug.log
21-
config
21+
config
22+
.ensime

build.sbt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@ name := """bitbucket-scala-client"""
77

88
version := "1.9.0-SNAPSHOT"
99

10-
scalaVersion := "2.10.5"
10+
scalaVersion := "2.12.6"
1111

12-
crossScalaVersions := Seq("2.10.5", "2.11.7")
12+
crossScalaVersions := Seq("2.11.12", "2.12.6")
13+
14+
unmanagedSourceDirectories in Compile += {
15+
(scalaVersion.value, (sourceDirectory in Compile).value) match {
16+
case (v, dir) if v startsWith "2.11" => dir / "scala-2.11"
17+
case (v, dir) if v startsWith "2.12" => dir / "scala-2.12"
18+
}
19+
}
1320

1421
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Ywarn-adapted-args", "-Xlint")
1522

1623
resolvers += "Typesafe maven repository" at "http://repo.typesafe.com/typesafe/maven-releases/"
1724

1825
libraryDependencies ++= Seq(
19-
jodaTime,
20-
playWS,
21-
scalaTest
26+
Dependencies.playWS,
27+
Dependencies.playJson(scalaVersion.value),
28+
Dependencies.scalaTest
2229
)
2330

2431
mimaPreviousArtifacts := {

circle.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
machine:
2+
pre:
3+
- mkdir -p $HOME/.sbt/.lib/1.1.6 && wget http://central.maven.org/maven2/org/scala-sbt/sbt-launch/1.1.6/sbt-launch-1.1.6.jar -O $HOME/.sbt/.lib/1.1.6/sbt-launch.jar
24
java:
35
version: oraclejdk8
46

57
test:
6-
pre:
7-
- sbt mimaReportBinaryIssues
8+
override:
9+
- sbt +test

project/Dependencies.scala

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@ import sbt._
22

33
object Dependencies {
44

5-
// Generic
6-
lazy val jodaTime = "joda-time" % "joda-time" % "2.7"
5+
val playWsStandaloneVersion = "1.1.9"
6+
val playWS = "com.typesafe.play" %% "play-ahc-ws-standalone" % playWsStandaloneVersion
7+
val playWSjson = "com.typesafe.play" %% "play-ws-standalone-json" % playWsStandaloneVersion
8+
val playJson_211 = "com.typesafe.play" %% "play-json" % "2.4.3"
79

8-
// Play framework
9-
lazy val playWS = "com.typesafe.play" %% "play-ws" % "2.4.3"
10+
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" % "test"
11+
12+
def playJson(scalaVersion: String): ModuleID = withScalaVersion(scalaVersion)(
13+
playWSjson,
14+
playJson_211
15+
)
16+
17+
private def withScalaVersion(scalaVersion: String)(
18+
scala212: ModuleID,
19+
scalaFallback: ModuleID): ModuleID = {
20+
if (scalaVersion.startsWith("2.12")) scala212 else scalaFallback
21+
}
1022

11-
lazy val scalaTest = "org.scalatest" %% "scalatest" % "2.2.6" % "test"
1223
}

project/build.properties

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#Activator-generated Properties
2-
#Sat Jul 12 15:51:18 WEST 2014
3-
template.uuid=a855816c-0367-44ba-9adb-6a903f6ad599
4-
sbt.version=0.13.8
1+
sbt.version=1.1.6

project/plugins.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ resolvers ++= Seq(
99
Classpaths.sbtPluginReleases
1010
)
1111

12-
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.5.0")
12+
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
1313

14-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
14+
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
1515

1616
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package play.api.libs
2+
3+
import java.time.{Instant, LocalDateTime, ZoneOffset}
4+
5+
import play.api.data.validation.ValidationError
6+
7+
package object json {
8+
val JsonValidationError: ValidationError.type = play.api.data.validation.ValidationError
9+
val __ : JsPath.type = play.api.libs.json.JsPath
10+
11+
implicit class ReadsMethods(json: Reads.type) {
12+
def localDateTimeReads[T](parsing: T, corrector: String => String = identity)
13+
(implicit p: T => TemporalParser[LocalDateTime]): Reads[LocalDateTime] =
14+
new TemporalReads[T, LocalDateTime](parsing, corrector, p, { millis: Long =>
15+
LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC)
16+
})
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package play.api.libs.json
2+
3+
import java.time.temporal.Temporal
4+
5+
import play.api.data.validation.ValidationError
6+
7+
import scala.language.implicitConversions
8+
9+
trait TemporalParser[T <: Temporal] {
10+
def parse(input: String): Option[T]
11+
}
12+
13+
private[json] final class TemporalReads[A, B <: Temporal](
14+
parsing: A,
15+
corrector: String => String,
16+
p: A => TemporalParser[B],
17+
epoch: Long => B
18+
) extends Reads[B] {
19+
def reads(json: JsValue): JsResult[B] = json match {
20+
case JsNumber(d) => JsSuccess(epoch(d.toLong))
21+
case JsString(s) => p(parsing).parse(corrector(s)) match {
22+
case Some(d) => JsSuccess(d)
23+
case None => JsError(Seq(JsPath ->
24+
Seq(ValidationError("error.expected.date.isoformat", parsing))))
25+
}
26+
case _ => JsError(Seq(JsPath ->
27+
Seq(ValidationError("error.expected.date"))))
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package play.api.libs.ws
2+
3+
/**
4+
* Provides implicit for converting a response to JsValue.
5+
*
6+
* See https://github.com/playframework/play-json for details of Play-JSON.
7+
*/
8+
trait JsonBodyReadables {
9+
10+
import play.api.libs.json._
11+
12+
/**
13+
* Converts a response body into Play JSON format:
14+
*
15+
* {{{
16+
* val json = response.body[play.api.libs.json.JsValue]
17+
* }}}
18+
*/
19+
implicit val readableAsJson: BodyReadable[JsValue] = BodyReadable { response =>
20+
Json.parse(response.bodyAsBytes.toArray)
21+
}
22+
}
23+
24+
object JsonBodyReadables extends JsonBodyReadables
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package play.api.libs.ws
2+
3+
import akka.util.ByteString
4+
import com.fasterxml.jackson.databind.{ JsonNode, ObjectMapper }
5+
import play.api.libs.json.{ JsValue, Json }
6+
7+
trait JsonBodyWritables {
8+
9+
/**
10+
* Creates an InMemoryBody with "application/json" content type, using the static ObjectMapper.
11+
*/
12+
implicit val writeableOf_JsValue: BodyWritable[JsValue] = {
13+
BodyWritable(a => InMemoryBody(ByteString.fromString(Json.stringify(a))), "application/json")
14+
}
15+
16+
def body(objectMapper: ObjectMapper): BodyWritable[JsonNode] = BodyWritable(json =>
17+
InMemoryBody(ByteString.fromArrayUnsafe(objectMapper.writeValueAsBytes(json))), "application/json")
18+
}
19+
20+
object JsonBodyWritables extends JsonBodyWritables

0 commit comments

Comments
 (0)