Skip to content

Commit

Permalink
Merge pull request #34 from codacy/scala-2.12
Browse files Browse the repository at this point in the history
Use Scala 2.12
  • Loading branch information
rtfpessoa authored Jul 29, 2018
2 parents 97b5b65 + a37451a commit 56ba667
Show file tree
Hide file tree
Showing 28 changed files with 776 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ dist
*.iml
codacy.pylint.conf
npm-debug.log
config
config
.ensime
17 changes: 12 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ name := """bitbucket-scala-client"""

version := "1.9.0-SNAPSHOT"

scalaVersion := "2.10.5"
scalaVersion := "2.12.6"

crossScalaVersions := Seq("2.10.5", "2.11.7")
crossScalaVersions := Seq("2.11.12", "2.12.6")

unmanagedSourceDirectories in Compile += {
(scalaVersion.value, (sourceDirectory in Compile).value) match {
case (v, dir) if v startsWith "2.11" => dir / "scala-2.11"
case (v, dir) if v startsWith "2.12" => dir / "scala-2.12"
}
}

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

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

libraryDependencies ++= Seq(
jodaTime,
playWS,
scalaTest
Dependencies.playWS,
Dependencies.playJson(scalaVersion.value),
Dependencies.scalaTest
)

mimaPreviousArtifacts := {
Expand Down
6 changes: 4 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
machine:
pre:
- 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
java:
version: oraclejdk8

test:
pre:
- sbt mimaReportBinaryIssues
override:
- sbt +test
21 changes: 16 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ import sbt._

object Dependencies {

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

// Play framework
lazy val playWS = "com.typesafe.play" %% "play-ws" % "2.4.3"
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5" % "test"

def playJson(scalaVersion: String): ModuleID = withScalaVersion(scalaVersion)(
playWSjson,
playJson_211
)

private def withScalaVersion(scalaVersion: String)(
scala212: ModuleID,
scalaFallback: ModuleID): ModuleID = {
if (scalaVersion.startsWith("2.12")) scala212 else scalaFallback
}

lazy val scalaTest = "org.scalatest" %% "scalatest" % "2.2.6" % "test"
}
5 changes: 1 addition & 4 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#Activator-generated Properties
#Sat Jul 12 15:51:18 WEST 2014
template.uuid=a855816c-0367-44ba-9adb-6a903f6ad599
sbt.version=0.13.8
sbt.version=1.1.6
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ resolvers ++= Seq(
Classpaths.sbtPluginReleases
)

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

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

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.2.0")
18 changes: 18 additions & 0 deletions src/main/scala-2.11/play/api/libs/json.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package play.api.libs

import java.time.{Instant, LocalDateTime, ZoneOffset}

import play.api.data.validation.ValidationError

package object json {
val JsonValidationError: ValidationError.type = play.api.data.validation.ValidationError
val __ : JsPath.type = play.api.libs.json.JsPath

implicit class ReadsMethods(json: Reads.type) {
def localDateTimeReads[T](parsing: T, corrector: String => String = identity)
(implicit p: T => TemporalParser[LocalDateTime]): Reads[LocalDateTime] =
new TemporalReads[T, LocalDateTime](parsing, corrector, p, { millis: Long =>
LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneOffset.UTC)
})
}
}
29 changes: 29 additions & 0 deletions src/main/scala-2.11/play/api/libs/json/TemporalParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package play.api.libs.json

import java.time.temporal.Temporal

import play.api.data.validation.ValidationError

import scala.language.implicitConversions

trait TemporalParser[T <: Temporal] {
def parse(input: String): Option[T]
}

private[json] final class TemporalReads[A, B <: Temporal](
parsing: A,
corrector: String => String,
p: A => TemporalParser[B],
epoch: Long => B
) extends Reads[B] {
def reads(json: JsValue): JsResult[B] = json match {
case JsNumber(d) => JsSuccess(epoch(d.toLong))
case JsString(s) => p(parsing).parse(corrector(s)) match {
case Some(d) => JsSuccess(d)
case None => JsError(Seq(JsPath ->
Seq(ValidationError("error.expected.date.isoformat", parsing))))
}
case _ => JsError(Seq(JsPath ->
Seq(ValidationError("error.expected.date"))))
}
}
24 changes: 24 additions & 0 deletions src/main/scala-2.11/play/api/libs/ws/JsonBodyReadables.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package play.api.libs.ws

/**
* Provides implicit for converting a response to JsValue.
*
* See https://github.com/playframework/play-json for details of Play-JSON.
*/
trait JsonBodyReadables {

import play.api.libs.json._

/**
* Converts a response body into Play JSON format:
*
* {{{
* val json = response.body[play.api.libs.json.JsValue]
* }}}
*/
implicit val readableAsJson: BodyReadable[JsValue] = BodyReadable { response =>
Json.parse(response.bodyAsBytes.toArray)
}
}

object JsonBodyReadables extends JsonBodyReadables
20 changes: 20 additions & 0 deletions src/main/scala-2.11/play/api/libs/ws/JsonBodyWritables.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package play.api.libs.ws

import akka.util.ByteString
import com.fasterxml.jackson.databind.{ JsonNode, ObjectMapper }
import play.api.libs.json.{ JsValue, Json }

trait JsonBodyWritables {

/**
* Creates an InMemoryBody with "application/json" content type, using the static ObjectMapper.
*/
implicit val writeableOf_JsValue: BodyWritable[JsValue] = {
BodyWritable(a => InMemoryBody(ByteString.fromString(Json.stringify(a))), "application/json")
}

def body(objectMapper: ObjectMapper): BodyWritable[JsonNode] = BodyWritable(json =>
InMemoryBody(ByteString.fromArrayUnsafe(objectMapper.writeValueAsBytes(json))), "application/json")
}

object JsonBodyWritables extends JsonBodyWritables
13 changes: 7 additions & 6 deletions src/main/scala/com/codacy/client/bitbucket/Commit.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class Commit(hash: String, authorName: String, parents: Option[Seq[String]], date: DateTime, message: String)
case class Commit(hash: String, authorName: String, parents: Option[Seq[String]], date: LocalDateTime, message: String)

object Commit {
val dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZ"
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
val dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXX"
implicit val dateTimeReads: Reads[LocalDateTime] = Reads.localDateTimeReads(dateFormat)

implicit def optionSeqStringReader: Reads[Option[Seq[String]]] = Reads { (json: JsValue) =>
json match {
Expand All @@ -21,7 +22,7 @@ object Commit {
(__ \ "hash").read[String] and
(__ \ "author" \ "user" \ "username").read[String] and
(__ \ "parents" \\ "hash").read[Option[Seq[String]]] and
(__ \ "date").read[DateTime] and
(__ \ "date").read[LocalDateTime] and
(__ \ "message").read[String]
)(Commit.apply _)
}
}
13 changes: 7 additions & 6 deletions src/main/scala/com/codacy/client/bitbucket/CommitComment.scala
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class CommitComment(id: Long, username: String, commit: String, display_name: String, content: String, created_on: DateTime)
case class CommitComment(id: Long, username: String, commit: String, display_name: String, content: String, created_on: LocalDateTime)

object CommitComment {
val dateFormat = "yyyy-MM-dd HH:mm:ssZZ"
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
val dateFormat = "yyyy-MM-dd HH:mm:ssXXX"
implicit val dateTimeReads: Reads[LocalDateTime] = Reads.localDateTimeReads(dateFormat)

implicit val reader: Reads[CommitComment] = (
(__ \ "comment_id").read[Long] and
(__ \ "username").read[String] and
(__ \ "node").read[String] and
(__ \ "display_name").read[String] and
(__ \ "content").read[String] and
(__ \ "utc_created_on").read[DateTime]
(__ \ "utc_created_on").read[LocalDateTime]
)(CommitComment.apply _)
}
}
11 changes: 6 additions & 5 deletions src/main/scala/com/codacy/client/bitbucket/Issue.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class Issue(id: Long, status: String, priority: String, title: String, content: String, owner: String,
created_on: DateTime, kind: String)
created_on: LocalDateTime, kind: String)

object Issue {
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
implicit val dateTimeReads: Reads[LocalDateTime] = Reads.localDateTimeReads(dateFormat)

implicit val reader: Reads[Issue] = (
(__ \ "local_id").read[Long] and
Expand All @@ -18,7 +19,7 @@ object Issue {
(__ \ "title").read[String] and
(__ \ "content").read[String] and
(__ \ "reported_by" \ "username").read[String] and
(__ \ "created_on").read[DateTime] and
(__ \ "created_on").read[LocalDateTime] and
(__ \ "metadata" \ "kind").read[String]
)(Issue.apply _)
}
}
14 changes: 8 additions & 6 deletions src/main/scala/com/codacy/client/bitbucket/PullRequest.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class PullRequest(id: Long, title: String, description: String,
authorUsername: Option[String], authorAvatar: Option[String], state: String, created_on: DateTime, updated_on: DateTime,
authorUsername: Option[String], authorAvatar: Option[String],
state: String, created_on: LocalDateTime, updated_on: LocalDateTime,
sourceRepository: String, sourceBranch: String, sourceCommit: String,
destRepository: String, destBranch: String, destCommit: Option[String],
apiUrls: Seq[ApiUrl], authorUUID: Option[String] = None) {
Expand All @@ -32,8 +34,8 @@ object ApiUrlType extends Enumeration {
case class ApiUrl(urlType: ApiUrlType.Value, link: String)

object PullRequest {
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"
implicit val dateTimeReads: Reads[LocalDateTime] = Reads.localDateTimeReads(dateFormat)

implicit def optionStringReader: Reads[Option[String]] = Reads { (json: JsValue) =>
json match {
Expand All @@ -49,8 +51,8 @@ object PullRequest {
(__ \ "author" \ "username").readNullable[String] and
(__ \ "author" \ "links" \ "avatar" \ "href").readNullable[String].orElse((__ \ "author" \ "links").readNullable[String]) and
(__ \ "state").read[String] and
(__ \ "created_on").read[DateTime] and
(__ \ "updated_on").read[DateTime] and
(__ \ "created_on").read[LocalDateTime] and
(__ \ "updated_on").read[LocalDateTime] and
(__ \ "source" \ "repository" \ "full_name").read[String] and
(__ \ "source" \ "branch" \ "name").read[String] and
(__ \ "source" \ "commit" \ "hash").read[String] and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class PullRequestComment(id: Long, username: String, display_name: String, content: String, created_on: DateTime)
case class PullRequestComment(id: Long, username: String, display_name: String, content: String, created_on: LocalDateTime)

object PullRequestComment {
val dateFormat = "yyyy-MM-dd HH:mm:ssZZ"
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
val dateFormat = "yyyy-MM-dd HH:mm:ssXXX"
implicit val dateTimeReads: Reads[LocalDateTime] = Reads.localDateTimeReads(dateFormat)

implicit val reader: Reads[PullRequestComment] = (
(__ \ "comment_id").read[Long] and
(__ \ "username").read[String] and
(__ \ "display_name").read[String] and
(__ \ "content").read[String] and
(__ \ "utc_created_on").read[DateTime]
(__ \ "utc_created_on").read[LocalDateTime]
)(PullRequestComment.apply _)
}
}
20 changes: 11 additions & 9 deletions src/main/scala/com/codacy/client/bitbucket/Repository.scala
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
package com.codacy.client.bitbucket

import org.joda.time.DateTime
import java.time.LocalDateTime

import play.api.libs.functional.syntax._
import play.api.libs.json._

case class Repository(name: String, full_name: String, description: String, scm: String,
created_on: DateTime, updated_on: DateTime, owner: String, size: Long,
created_on: LocalDateTime, updated_on: LocalDateTime, owner: String, size: Long,
has_issues: Boolean, is_private: Boolean, language: String,
url: Seq[RepositoryUrl])

object Repository {
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
val dateFormatWithoutMillis = "yyyy-MM-dd'T'HH:mm:ssZZ"
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSXXX"
val dateFormatWithoutMillis = "yyyy-MM-dd'T'HH:mm:ssXXX"

implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
.orElse(Reads.jodaDateReads(dateFormatWithoutMillis))
implicit val dateTimeReads: Reads[LocalDateTime] =
Reads.localDateTimeReads(dateFormat)
.orElse(Reads.localDateTimeReads(dateFormatWithoutMillis))

implicit val reader: Reads[Repository] = {
((__ \ "name").read[String] and
(__ \ "full_name").read[String] and
(__ \ "description").read[String] and
(__ \ "scm").read[String] and
(__ \ "created_on").read[DateTime] and
(__ \ "updated_on").read[DateTime] and
(__ \ "created_on").read[LocalDateTime] and
(__ \ "updated_on").read[LocalDateTime] and
(__ \ "owner" \ "username").read[String] and
(__ \ "size").read[Long] and
(__ \ "has_issues").read[Boolean] and
(__ \ "is_private").read[Boolean] and
(__ \ "language").read[String] and
(__ \ "links").read[Map[String, JsValue]].map(parseLinks)
)(Repository.apply _)
) (Repository.apply _)
}

private def parseLinks(links: Map[String, JsValue]): Seq[RepositoryUrl] = {
Expand Down
Loading

0 comments on commit 56ba667

Please sign in to comment.