Skip to content

Commit

Permalink
Merge pull request #7706 from guardian/scala-2-11
Browse files Browse the repository at this point in the history
Scala 2.11.4
  • Loading branch information
Richard Nguyen committed Jan 9, 2015
2 parents a195285 + 6297025 commit 7609091
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 107 deletions.
2 changes: 1 addition & 1 deletion admin/app/commercial/TravelOffersCacheJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object TravelOffersCacheJob extends ExecutionContexts with Dates with Logging {


def run() {
future {
Future {
url map {u =>
val start = System.currentTimeMillis

Expand Down
5 changes: 3 additions & 2 deletions admin/app/dfp/DataAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package dfp
import common.{AkkaAgent, ExecutionContexts, Logging}
import conf.Switches._

import org.apache.commons.lang.exception.ExceptionUtils
import scala.concurrent.Future
import scala.util.{Failure, Success, Try}

trait DataAgent[K, V] extends ExecutionContexts with Logging {
trait DataAgent[K, V] extends ExecutionContexts with Logging with implicits.Strings {

private val initialCache: DataCache[K, V] = DataCache(Map.empty[K, V])
private lazy val cache = AkkaAgent(initialCache)
Expand All @@ -29,7 +30,7 @@ trait DataAgent[K, V] extends ExecutionContexts with Logging {
oldCache
}
case Failure(e) =>
log.error(e.getStackTraceString)
log.error(ExceptionUtils.getStackTrace(e))
oldCache
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions admin/app/dfp/DfpDataCacheJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import org.joda.time.DateTime
import play.api.libs.json.Json.{toJson, _}
import tools.Store

import scala.concurrent.{Future, future}
import scala.concurrent.Future

object DfpDataCacheJob extends ExecutionContexts with Logging {

def run(): Future[Unit] = future {
def run(): Future[Unit] = Future {
if (DfpCachingSwitch.isSwitchedOn) {
log.info("Refreshing data cache")
val start = System.currentTimeMillis
Expand Down
3 changes: 2 additions & 1 deletion admin/app/dfp/DfpDataHydrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.api.ads.dfp.axis.v201411._
import common.Logging
import conf.Configuration.commercial.guMerchandisingAdvertiserId
import dfp.DfpApiWrapper.DfpSessionException
import org.apache.commons.lang.exception.ExceptionUtils
import org.joda.time.{DateTimeZone, DateTime => JodaDateTime}

import scala.util.{Failure, Try}
Expand Down Expand Up @@ -108,7 +109,7 @@ class DfpDataHydrator extends Logging {

} catch {
case e: Exception =>
log.error(e.getStackTraceString)
log.error(ExceptionUtils.getStackTrace(e))
Nil
}
}
Expand Down
16 changes: 8 additions & 8 deletions admin/app/jobs/OmnitureReportJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.joda.time.{DateTimeZone, DateTime}
import services.Omniture._
import OmnitureMethods._
import scala.concurrent.duration._
import scala.concurrent.future
import scala.concurrent.Future

object OmnitureVariables {
// Metrics
Expand Down Expand Up @@ -50,7 +50,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
val dateFrom = dateTo.minusWeeks(2)

// Stagger each report request, otherwise omniture request nonce values will be identical.
akka.pattern.after(1.seconds, actorSystem.scheduler) (future {
akka.pattern.after(1.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -60,7 +60,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, galleryPageViews)
})

akka.pattern.after(5.seconds, actorSystem.scheduler) (future {
akka.pattern.after(5.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -70,7 +70,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, galleryVisits)
})

akka.pattern.after(10.seconds, actorSystem.scheduler) (future {
akka.pattern.after(10.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -80,7 +80,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, galleryLightBox)
})

akka.pattern.after(15.seconds, actorSystem.scheduler) ( future {
akka.pattern.after(15.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -90,7 +90,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, gallerySocialShare)
})

akka.pattern.after(20.seconds, actorSystem.scheduler) ( future {
akka.pattern.after(20.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -101,7 +101,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, googleReferrerVisits)
})

akka.pattern.after(25.seconds, actorSystem.scheduler) ( future {
akka.pattern.after(25.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand All @@ -111,7 +111,7 @@ object OmnitureReportJob extends ExecutionContexts with Logging {
), QUEUE_OVERTIME, networkTotalVisits)
})

akka.pattern.after(30.seconds, actorSystem.scheduler) ( future {
akka.pattern.after(30.seconds, actorSystem.scheduler) (Future {
generateReport(OmnitureReportDescription(
dateGranularity = Some("day"),
dateTo = dateTo.toString("yyyy-MM-dd"),
Expand Down
4 changes: 1 addition & 3 deletions common/app/common/JsonComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import play.api.http.ContentTypes._

object JsonComponent extends Results with implicits.Requests {

type ListOfString = List[String]

private val ValidCallback = """([a-zA-Z0-9_]+)""".r

def apply(html: Html)(implicit request: RequestHeader): Result = {
Expand Down Expand Up @@ -54,7 +52,7 @@ object JsonComponent extends Results with implicits.Requests {
case (name, value: Int) => name -> toJson(value)
case (name, value: Double) => name -> toJson(value)
case (name, value: Float) => name -> toJson(value)
case (name, value: ListOfString) => name -> toJson(value)
case (name, value: List[_]) if value.forall(_.isInstanceOf[String]) => name -> toJson(value.asInstanceOf[List[String]])
case (name, value: JsValue) => name -> value
}
))
Expand Down
12 changes: 12 additions & 0 deletions common/app/implicits/Collections.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ trait Collections {
builder.result
}
}

// A non-inlined implementation of drop while. This is needed because scala 2.11
// currently throws warnings (fatal warnings are on) when using standard drop while.
// https://issues.scala-lang.org/browse/SI-7529
implicit class List2DropWhile[A](list: List[A]) {
def safeDropWhile(p: A => Boolean): List[A] = {
def loop(xs: List[A]): List[A] =
if (xs.isEmpty || !p(xs.head)) xs
else loop(xs.tail)
loop(list)
}
}
}
2 changes: 1 addition & 1 deletion common/app/performance/MemcachedAction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private[performance] trait MemcachedSupport extends ExecutionContexts with impli

lazy val isConfigured = Configuration.memcached.host.isDefined
lazy val host = Configuration.memcached.host.head
lazy val memcached = Memcached(MemcachedConf(host), actorSystem.scheduler, memcachedExecutionContext)
lazy val memcached = Memcached(MemcachedConf(host), memcachedExecutionContext)

implicit object ResultCodec extends Codec[CachedResponse] {

Expand Down
2 changes: 1 addition & 1 deletion common/app/performance/MemcachedFallback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object MemcacheTypeclass {
object MemcachedFallback extends ExecutionContexts with Dates with Logging {
private def connectToMemcached(host: String) = {
val tryConnect = Try {
Memcached(MemcachedConf(host), actorSystem.scheduler, memcachedExecutionContext)
Memcached(MemcachedConf(host), memcachedExecutionContext)
}

tryConnect.failed foreach { error =>
Expand Down
25 changes: 10 additions & 15 deletions common/app/services/S3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,20 @@ trait S3 extends Logging {
}
}

def get(key: String)(implicit codec: Codec): Option[String] = try {
withS3Result(key) {
result => Source.fromInputStream(result.getObjectContent).mkString
}
def get(key: String)(implicit codec: Codec): Option[String] = withS3Result(key) {
result => Source.fromInputStream(result.getObjectContent).mkString
}

def getWithLastModified(key: String): Option[(String, DateTime)] = try {
withS3Result(key) {
result =>
val content = Source.fromInputStream(result.getObjectContent).mkString
val lastModified = new DateTime(result.getObjectMetadata.getLastModified)
(content, lastModified)
}

def getWithLastModified(key: String): Option[(String, DateTime)] = withS3Result(key) {
result =>
val content = Source.fromInputStream(result.getObjectContent).mkString
val lastModified = new DateTime(result.getObjectMetadata.getLastModified)
(content, lastModified)
}

def getLastModified(key: String): Option[DateTime] = try {
withS3Result(key) {
result => new DateTime(result.getObjectMetadata.getLastModified)
}
def getLastModified(key: String): Option[DateTime] = withS3Result(key) {
result => new DateTime(result.getObjectMetadata.getLastModified)
}

def putPublic(key: String, value: String, contentType: String) {
Expand Down
8 changes: 0 additions & 8 deletions common/app/views/support/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import common._
import model._

import org.apache.commons.lang.StringEscapeUtils
import org.jboss.dna.common.text.Inflector
import org.joda.time.{LocalDate, DateTime}
import org.joda.time.format.DateTimeFormat
import org.jsoup.Jsoup
Expand Down Expand Up @@ -82,8 +81,6 @@ object ContributorLinks {

object `package` extends Formats {

private object inflector extends Inflector

def withJsoup(html: Html)(cleaners: HtmlCleaner*): Html = withJsoup(html.body) { cleaners: _* }

def withJsoup(html: String)(cleaners: HtmlCleaner*): Html = {
Expand All @@ -105,11 +102,6 @@ object `package` extends Formats {
def typeOrTone: Option[Tag] = t.types.find(_.id != "type/article").orElse(t.tones.headOption)
}

implicit class Tags2inflector(t: Tag) {
lazy val singularName: String = inflector.singularize(t.name)
lazy val pluralName: String = inflector.pluralize(t.name)
}

implicit class Seq2zipWithRowInfo[A](seq: Seq[A]) {
def zipWithRowInfo = seq.zipWithIndex.map {
case (item, index) => (item, RowInfo(index + 1, seq.length == index + 1))
Expand Down
2 changes: 1 addition & 1 deletion common/test/common/ExternalLinksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ExternalLinksTest extends FlatSpec with Matchers with Inspectors {
it should "be false for malformed URLs" in {
forAll(Seq(
"htt://",
"\0"
"\u0000"
)) { id =>
external(id) should be(false)
}
Expand Down
2 changes: 1 addition & 1 deletion common/test/common/TrailsToRss.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TrailsToRssTest extends FlatSpec with Matchers {

it should "strip invalid Unicode characters from XML" in {
isWellFormedXML(TrailsToRss(Option("foo"), Seq(
TestTrail("h", customTitle = Some("\0LOL"))
TestTrail("h", customTitle = Some("\u0000LOL"))
))(request)) shouldBe true
}

Expand Down
9 changes: 0 additions & 9 deletions common/test/views/support/TemplatesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ class TemplatesTest extends FlatSpec with Matchers {
tags.typeOrTone.get.id should be("tone/foo")
}

"Inflector" should "singularize tag name" in {
Tag(tag("Minute by minutes")).singularName should be("Minute by minute")
Tag(tag("News")).singularName should be("News")
}

it should "pluralize tag name" in {
Tag(tag("Article")).pluralName should be("Articles")
}

"PictureCleaner" should "correctly format inline pictures" in {

val body = XML.loadString(withJsoup(bodyTextWithInlineElements)(PictureCleaner(testContent)).body.trim)
Expand Down
4 changes: 2 additions & 2 deletions discussion/test/discussion/DiscussionApiTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.language.postfixOps
val discussionApi = new DiscussionApi {
override protected def GET(url: String, headers: (String, String)*): Future[WSResponse] = {
assert(expectedUrl === url)
future {null} // Don't care what is returned for this test
Future {null} // Don't care what is returned for this test
}
protected val clientHeaderValue: String = ""
protected val apiRoot: String = ""
Expand All @@ -39,7 +39,7 @@ import scala.language.postfixOps
val discussionApi = new DiscussionApi {
override protected def GET(url: String, headers: (String, String)*): Future[WSResponse] = {
assert(expectedUrl === url)
future {null}
Future {null}
}
protected val clientHeaderValue: String = ""
protected val apiRoot: String = ""
Expand Down
2 changes: 1 addition & 1 deletion identity/app/client/parser/JsonBodyParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait JsonBodyParser extends Logging {
case HttpResponse(body, status, message) if status > 299 =>
Left(extractErrorFromResponse(parse(body), httpResponse.statusCode))
case HttpResponse(body, status, message) if successType == manifest[Unit] =>
Right().asInstanceOf[Right[List[client.Error], T]]
Right(()).asInstanceOf[Right[List[client.Error], T]]
case HttpResponse(body, status, message) =>
Right(extractJsonObj(parse(body)).extract[T])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EmailVerificationControllerTest extends path.FreeSpec with ShouldMatchers
val token = "myToken"

"when the api call succeeds" - {
when(api.validateEmail(token, trackingData)).thenReturn(Future.successful(Right()))
when(api.validateEmail(token, trackingData)).thenReturn(Future.successful(Right(())))
val result = controller.verify(token)(testRequest)

"should display the validation completed page" in {
Expand Down
4 changes: 2 additions & 2 deletions identity/test/controllers/ResetPasswordControllerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ResetPasswordControllerTest extends path.FreeSpec with ShouldMatchers with
val fakeRequest = FakeRequest(POST, "/reset").withFormUrlEncodedBody("email-address" -> emailAddress)

"with an api response validating the user" - {
when(api.sendPasswordResetEmail(any[String], any[TrackingData])).thenReturn(Future.successful(Right()))
when(api.sendPasswordResetEmail(any[String], any[TrackingData])).thenReturn(Future.successful(Right(())))

"should ask the api to send a reset email to the the the specified user" in Fake {
resetPasswordController.processPasswordResetRequestForm(fakeRequest)
Expand Down Expand Up @@ -107,7 +107,7 @@ class ResetPasswordControllerTest extends path.FreeSpec with ShouldMatchers with

val fakeRequest = FakeRequest(POST, "/reset_password" ).withFormUrlEncodedBody("password" -> "newpassword", "password-confirm" -> "newpassword", "email-address" -> "test@somewhere.com")
"when the token provided is valid" - {
when(api.resetPassword(Matchers.any[String], Matchers.any[String])).thenReturn(Future.successful(Right()))
when(api.resetPassword(Matchers.any[String], Matchers.any[String])).thenReturn(Future.successful(Right(())))
"should call the api the password with the provided new password and token" in Fake {
resetPasswordController.resetPassword("1234")(fakeRequest)
verify(api).resetPassword(Matchers.eq("1234"), Matchers.eq("newpassword"))
Expand Down
2 changes: 1 addition & 1 deletion png-resizer/app/controllers/Resizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object Resizer extends Controller with Logging with implicits.Requests {
log.info(s"won't resize image to be bigger - $originalWidth to $width - redirecting to original")
-\/(Cached(1.day)(Found(fallbackUri)))
} else {
\/-()
\/-(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion png-resizer/app/load/LoadLimit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object LoadLimit extends ExecutionContexts with Logging {
limit
}

def tryOperation[T](operation: => Future[T])(outOfCapacity: => Future[T]): Future[T] = try {
def tryOperation[T](operation: => Future[T])(outOfCapacity: => Future[T]): Future[T] = {
val concurrentRequests = currentNumberOfRequests.incrementAndGet
if (concurrentRequests <= requestLimit) try {
log.info(s"Resize $concurrentRequests/$requestLimit")
Expand Down
Loading

0 comments on commit 7609091

Please sign in to comment.