Skip to content

Commit bb640ee

Browse files
committed
Depend on play-json 2.4 for 2.11 and 2.6 for 2.12
1 parent 8518334 commit bb640ee

15 files changed

+136
-15
lines changed

.gitignore

+2-1
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ version := "1.9.0-SNAPSHOT"
44

55
scalaVersion := "2.11.12"
66

7-
crossScalaVersions := Seq("2.11.12", "2.12.5")
7+
crossScalaVersions := Seq("2.11.12", "2.12.6")
8+
9+
unmanagedSourceDirectories in Compile += {
10+
(scalaVersion.value, (sourceDirectory in Compile).value) match {
11+
case (v, dir) if v startsWith "2.11" => dir / "scala-2.11"
12+
case (v, dir) if v startsWith "2.12" => dir / "scala-2.12"
13+
}
14+
}
15+
16+
ensimeScalaVersion in ThisBuild := "2.11.12"
817

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

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

1322
libraryDependencies ++= Seq(
1423
Dependencies.playWS,
15-
Dependencies.playWSjson,
24+
Dependencies.playJson(scalaVersion.value),
1625
Dependencies.scalaTest
1726
)
1827

circle.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
machine:
22
pre:
3-
- mkdir -p $HOME/.sbt/.lib/0.13.17 && wget https://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.17/sbt-launch.jar -O $HOME/.sbt/.lib/0.13.17/sbt-launch.jar
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
44
java:
55
version: oraclejdk8
6+
7+
test:
8+
override:
9+
- sbt +test

project/Dependencies.scala

+12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ object Dependencies {
55
val playWsStandaloneVersion = "2.0.0-M1"
66
val playWS = "com.typesafe.play" %% "play-ahc-ws-standalone" % playWsStandaloneVersion
77
val playWSjson = "com.typesafe.play" %% "play-ws-standalone-json" % playWsStandaloneVersion
8+
val playJson_211 = "com.typesafe.play" %% "play-json" % "2.4.3"
89

910
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" % "test"
1011

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+
}
22+
1123
}

project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.17
1+
sbt.version=1.1.6

project/plugins.sbt

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ 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

16-
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8")
16+
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
17+
18+
addSbtPlugin("org.ensime" % "sbt-ensime" % "2.5.1")
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+
}
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+
}
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
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

src/main/scala/com/codacy/client/bitbucket/PullRequest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import play.api.libs.json._
77

88
case class PullRequest(id: Long, title: String, description: String,
99
authorUsername: Option[String], authorAvatar: Option[String],
10-
state: String, created_on: DateTime, updated_on: DateTime,
10+
state: String, created_on: LocalDateTime, updated_on: LocalDateTime,
1111
sourceRepository: String, sourceBranch: String, sourceCommit: String,
1212
destRepository: String, destBranch: String, destCommit: Option[String],
1313
apiUrls: Seq[ApiUrl], authorUUID: Option[String] = None) {

src/main/scala/com/codacy/client/bitbucket/Repository.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.codacy.client.bitbucket
22

3-
import java.time.{LocalDateTime, LocalTime}
3+
import java.time.LocalDateTime
44

55
import play.api.libs.functional.syntax._
66
import play.api.libs.json._
@@ -14,9 +14,9 @@ object Repository {
1414
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"
1515
val dateFormatWithoutMillis = "yyyy-MM-dd'T'HH:mm:ssXXX"
1616

17-
implicit val dateTimeReads: Reads[LocalTime] =
18-
Reads.localTimeReads(dateFormat)
19-
.orElse(Reads.localTimeReads(dateFormatWithoutMillis))
17+
implicit val dateTimeReads: Reads[LocalDateTime] =
18+
Reads.localDateTimeReads(dateFormat)
19+
.orElse(Reads.localDateTimeReads(dateFormatWithoutMillis))
2020

2121
implicit val reader: Reads[Repository] = {
2222
((__ \ "name").read[String] and

src/main/scala/com/codacy/client/bitbucket/client/Authentication.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object Authentication {
4747
}
4848

4949
class OAuth2Authenticator(credentials: OAuth2Credentials) extends Authenticator {
50-
override def authenticate(req: WSRequest): WSRequest = req.withQueryString("access_token" -> credentials.accessToken)
50+
override def authenticate(req: WSRequest): WSRequest = req.withQueryStringParameters("access_token" -> credentials.accessToken)
5151
}
5252

5353
class BasicAuthAuthenticator(credentials: BasicAuthCredentials) extends Authenticator {

src/main/scala/com/codacy/client/bitbucket/client/BitbucketClient.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import play.api.libs.ws.JsonBodyWritables._
1313
import play.api.libs.ws.ahc.StandaloneAhcWSClient
1414
import play.shaded.ahc.org.asynchttpclient.DefaultAsyncHttpClient
1515

16+
import scala.compat.Platform.EOL
1617
import scala.concurrent.Await
1718
import scala.concurrent.duration.{Duration, SECONDS}
1819
import scala.util.{Failure, Properties, Success, Try}
@@ -208,7 +209,7 @@ class BitbucketClient(credentials: Credentials)(implicit materializer: Materiali
208209

209210
private def getFullStackTrace(throwableOpt: Throwable, accumulator: String = ""): String = {
210211
Option(throwableOpt).map { throwable =>
211-
val newAccumulator = s"$accumulator${Properties.lineSeparator}${throwable.getStackTraceString}"
212+
val newAccumulator = s"$accumulator${Properties.lineSeparator}${throwable.getStackTrace.mkString("", EOL, EOL)}"
212213
getFullStackTrace(throwable.getCause, newAccumulator)
213214
}.getOrElse(accumulator)
214215
}

src/main/scala/com/codacy/client/bitbucket/util/Implicits.scala

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.codacy.client.bitbucket.util
22

33
import java.net.URI
44

5+
import play.api.libs.json._
56
import play.api.libs.json.{Json, JsonValidationError, Reads, Writes}
67

78
import scala.language.implicitConversions

0 commit comments

Comments
 (0)